File: netcmd.hh

package info (click to toggle)
monotone 0.18-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 16,440 kB
  • ctags: 13,394
  • sloc: sh: 130,618; ansic: 70,657; cpp: 51,980; perl: 421; makefile: 359; python: 184; lisp: 132; sql: 83
file content (155 lines) | stat: -rw-r--r-- 5,494 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#ifndef __NETCMD_HH__
#define __NETCMD_HH__
// copyright (C) 2004 graydon hoare <graydon@pobox.com>
// all rights reserved.
// licensed to the public under the terms of the GNU GPL (>= 2)
// see the file COPYING for details

#include <string>
#include <vector>
#include <utility>

#include "merkle_tree.hh"
#include "numeric_vocab.hh"
#include "vocab.hh"

typedef enum 
  { 
    source_role = 1, 
    sink_role = 2, 
    source_and_sink_role = 3
  }
protocol_role;

typedef enum 
  { 
    // general commands
    error_cmd = 0,
    bye_cmd = 1,

    // authentication commands
    hello_cmd = 2,
    anonymous_cmd = 3,
    auth_cmd = 4,
    confirm_cmd = 5,
      
    // refinement commands
    refine_cmd = 6,
    done_cmd = 7,
      
    // transmission commands
    send_data_cmd = 8,
    send_delta_cmd = 9,
    data_cmd = 10,
    delta_cmd = 11,
    nonexistant_cmd = 12
  }
netcmd_code;

struct netcmd
{
  u8 version;
  netcmd_code cmd_code;
  std::string payload;
  netcmd();
  size_t encoded_size();
  bool operator==(netcmd const & other) const;
};

// basic cmd i/o (including checksums)
void write_netcmd(netcmd const & in, std::string & out);
bool read_netcmd(std::string & inbuf, netcmd & out);

// i/o functions for each type of command payload
void read_error_cmd_payload(std::string const & in, 
                            std::string & errmsg);
void write_error_cmd_payload(std::string const & errmsg, 
                             std::string & out);

void read_hello_cmd_payload(std::string const & in, 
                            rsa_keypair_id & server_keyname,
                            rsa_pub_key & server_key,
                            id & nonce);
void write_hello_cmd_payload(rsa_keypair_id const & server_keyname,
                             rsa_pub_key const & server_key,
                             id const & nonce, 
                             std::string & out);

void read_anonymous_cmd_payload(std::string const & in, 
                                protocol_role & role, 
                                std::string & collection,
                                id & nonce2);
void write_anonymous_cmd_payload(protocol_role role, 
                                 std::string const & collection,
                                 id const & nonce2,
                                 std::string & out);

void read_auth_cmd_payload(std::string const & in, 
                           protocol_role & role, 
                           std::string & collection,
                           id & client, 
                           id & nonce1, 
                           id & nonce2,
                           std::string & signature);
void write_auth_cmd_payload(protocol_role role, 
                            std::string const & collection, 
                            id const & client,
                            id const & nonce1, 
                            id const & nonce2, 
                            std::string const & signature, 
                            std::string & out);

void read_confirm_cmd_payload(std::string const & in, 
                              std::string & signature);
void write_confirm_cmd_payload(std::string const & signature, 
                               std::string & out);

void read_refine_cmd_payload(std::string const & in, merkle_node & node);
void write_refine_cmd_payload(merkle_node const & node, std::string & out);

void read_done_cmd_payload(std::string const & in, size_t & level, netcmd_item_type & type);
void write_done_cmd_payload(size_t level, netcmd_item_type type, std::string & out);

void read_send_data_cmd_payload(std::string const & in, 
                                netcmd_item_type & type,
                                id & item);
void write_send_data_cmd_payload(netcmd_item_type type,
                                 id const & item,
                                 std::string & out);

void read_send_delta_cmd_payload(std::string const & in, 
                                 netcmd_item_type & type,
                                 id & base,
                                 id & ident);
void write_send_delta_cmd_payload(netcmd_item_type type,
                                  id const & base,
                                  id const & ident,
                                  std::string & out);

void read_data_cmd_payload(std::string const & in,
                           netcmd_item_type & type,
                           id & item,
                           std::string & dat);
void write_data_cmd_payload(netcmd_item_type type,
                            id const & item,
                            std::string const & dat,
                            std::string & out);

void read_delta_cmd_payload(std::string const & in, 
                            netcmd_item_type & type,
                            id & base, id & ident, 
                            delta & del);
void write_delta_cmd_payload(netcmd_item_type & type,
                             id const & base, id const & ident, 
                             delta const & del,
                             std::string & out);

void read_nonexistant_cmd_payload(std::string const & in, 
                                  netcmd_item_type & type,
                                  id & item);
void write_nonexistant_cmd_payload(netcmd_item_type type,
                                   id const & item,
                                   std::string & out);


#endif // __NETCMD_HH__