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 id & server,
71 id & nonce);
72void write_hello_cmd_payload(id const & server,
73 id const & nonce,
74 std::string & out);
75
76void read_anonymous_cmd_payload(std::string const & in,
77protocol_role & role,
78std::string & collection,
79id & nonce2);
80void write_anonymous_cmd_payload(protocol_role role,
81 std::string const & collection,
82 id const & nonce2,
83 std::string & out);
84
85void read_auth_cmd_payload(std::string const & in,
86 protocol_role & role,
87 std::string & collection,
88 id & client,
89 id & nonce1,
90 id & nonce2,
91 std::string & signature);
92void write_auth_cmd_payload(protocol_role role,
93 std::string const & collection,
94 id const & client,
95 id const & nonce1,
96 id const & nonce2,
97 std::string const & signature,
98 std::string & out);
99
100void read_confirm_cmd_payload(std::string const & in, std::string & signature);
101void write_confirm_cmd_payload(std::string const & signature, std::string & out);
102
103void read_refine_cmd_payload(std::string const & in, merkle_node & node);
104void write_refine_cmd_payload(merkle_node const & node, std::string & out);
105
106void read_done_cmd_payload(std::string const & in, size_t & level, netcmd_item_type & type);
107void write_done_cmd_payload(size_t level, netcmd_item_type type, std::string & out);
108
109void read_send_data_cmd_payload(std::string const & in,
110netcmd_item_type & type,
111id & item);
112void write_send_data_cmd_payload(netcmd_item_type type,
113 id const & item,
114 std::string & out);
115
116void read_send_delta_cmd_payload(std::string const & in,
117 netcmd_item_type & type,
118 id & base,
119 id & ident);
120void write_send_delta_cmd_payload(netcmd_item_type type,
121 id const & base,
122 id const & ident,
123 std::string & out);
124
125void read_data_cmd_payload(std::string const & in,
126 netcmd_item_type & type,
127 id & item,
128 std::string & dat);
129void write_data_cmd_payload(netcmd_item_type type,
130 id const & item,
131 std::string const & dat,
132 std::string & out);
133
134void read_delta_cmd_payload(std::string const & in,
135 netcmd_item_type & type,
136 id & base, id & ident,
137 delta & del);
138void write_delta_cmd_payload(netcmd_item_type & type,
139 id const & base, id const & ident,
140 delta const & del,
141 std::string & out);
142
143void read_nonexistant_cmd_payload(std::string const & in,
144 netcmd_item_type & type,
145 id & item);
146void write_nonexistant_cmd_payload(netcmd_item_type type,
147 id const & item,
148 std::string & out);
149
150
151#endif // __NETCMD_HH__

Archive Download this file

Branches

Tags

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