monotone

monotone Mtn Source Tree

Root/netcmd.hh

1#ifndef __NETCMD_HH__
2#define __NETCMD_HH__
3// copyright (C) 2004 graydon hoare <graydon@pobox.com>
4// all rights reserved.
5// licensed to the public under the terms of the GNU GPL (>= 2)
6// see the file COPYING for details
7
8#include <string>
9#include <vector>
10#include <utility>
11
12#include "merkle_tree.hh"
13#include "numeric_vocab.hh"
14#include "vocab.hh"
15
16typedef enum
17 {
18 source_role = 1,
19 sink_role = 2,
20 source_and_sink_role = 3
21 }
22protocol_role;
23
24typedef enum
25 {
26 // general commands
27 error_cmd = 0,
28 bye_cmd = 1,
29
30 // authentication commands
31 hello_cmd = 2,
32 anonymous_cmd = 3,
33 auth_cmd = 4,
34 confirm_cmd = 5,
35
36 // refinement commands
37 refine_cmd = 6,
38 done_cmd = 7,
39
40 // transmission commands
41 send_data_cmd = 8,
42 send_delta_cmd = 9,
43 data_cmd = 10,
44 delta_cmd = 11,
45 nonexistant_cmd = 12
46 }
47netcmd_code;
48
49struct netcmd
50{
51 u8 version;
52 netcmd_code cmd_code;
53 std::string payload;
54 netcmd();
55 size_t encoded_size();
56 bool operator==(netcmd const & other) const;
57};
58
59// basic cmd i/o (including checksums)
60void write_netcmd(netcmd const & in, std::string & out);
61bool read_netcmd(std::string & inbuf, netcmd & out);
62
63// i/o functions for each type of command payload
64void read_error_cmd_payload(std::string const & in,
65 std::string & errmsg);
66void write_error_cmd_payload(std::string const & errmsg,
67 std::string & out);
68
69void read_hello_cmd_payload(std::string const & in,
70 rsa_keypair_id & server_keyname,
71 rsa_pub_key & server_key,
72 id & nonce);
73void write_hello_cmd_payload(rsa_keypair_id const & server_keyname,
74 rsa_pub_key const & server_key,
75 id const & nonce,
76 std::string & out);
77
78void read_anonymous_cmd_payload(std::string const & in,
79 protocol_role & role,
80 std::string & collection,
81 id & nonce2);
82void write_anonymous_cmd_payload(protocol_role role,
83 std::string const & collection,
84 id const & nonce2,
85 std::string & out);
86
87void read_auth_cmd_payload(std::string const & in,
88 protocol_role & role,
89 std::string & collection,
90 id & client,
91 id & nonce1,
92 id & nonce2,
93 std::string & signature);
94void write_auth_cmd_payload(protocol_role role,
95 std::string const & collection,
96 id const & client,
97 id const & nonce1,
98 id const & nonce2,
99 std::string const & signature,
100 std::string & out);
101
102void read_confirm_cmd_payload(std::string const & in,
103 std::string & signature);
104void write_confirm_cmd_payload(std::string const & signature,
105 std::string & out);
106
107void read_refine_cmd_payload(std::string const & in, merkle_node & node);
108void write_refine_cmd_payload(merkle_node const & node, std::string & out);
109
110void read_done_cmd_payload(std::string const & in, size_t & level, netcmd_item_type & type);
111void write_done_cmd_payload(size_t level, netcmd_item_type type, std::string & out);
112
113void read_send_data_cmd_payload(std::string const & in,
114 netcmd_item_type & type,
115 id & item);
116void write_send_data_cmd_payload(netcmd_item_type type,
117 id const & item,
118 std::string & out);
119
120void read_send_delta_cmd_payload(std::string const & in,
121 netcmd_item_type & type,
122 id & base,
123 id & ident);
124void write_send_delta_cmd_payload(netcmd_item_type type,
125 id const & base,
126 id const & ident,
127 std::string & out);
128
129void read_data_cmd_payload(std::string const & in,
130 netcmd_item_type & type,
131 id & item,
132 std::string & dat);
133void write_data_cmd_payload(netcmd_item_type type,
134 id const & item,
135 std::string const & dat,
136 std::string & out);
137
138void read_delta_cmd_payload(std::string const & in,
139 netcmd_item_type & type,
140 id & base, id & ident,
141 delta & del);
142void write_delta_cmd_payload(netcmd_item_type & type,
143 id const & base, id const & ident,
144 delta const & del,
145 std::string & out);
146
147void read_nonexistant_cmd_payload(std::string const & in,
148 netcmd_item_type & type,
149 id & item);
150void write_nonexistant_cmd_payload(netcmd_item_type type,
151 id const & item,
152 std::string & out);
153
154
155#endif // __NETCMD_HH__

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status