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#include "hmac.hh"
16#include "string_queue.hh"
17
18typedef enum
19 {
20 source_role = 1,
21 sink_role = 2,
22 source_and_sink_role = 3
23 }
24protocol_role;
25
26typedef enum
27 {
28 // general commands
29 error_cmd = 0,
30 bye_cmd = 1,
31
32 // authentication commands
33 hello_cmd = 2,
34 anonymous_cmd = 3,
35 auth_cmd = 4,
36 confirm_cmd = 5,
37
38 // refinement commands
39 refine_cmd = 6,
40 done_cmd = 7,
41
42 // transmission commands
43 send_data_cmd = 8,
44 send_delta_cmd = 9,
45 data_cmd = 10,
46 delta_cmd = 11,
47 nonexistant_cmd = 12,
48
49 // usher commands
50 // usher_cmd is sent by a server farm (or anyone else who wants to serve
51 // from multiple databases over the same port), and the reply (containing
52 // the client's include pattern) is used to choose a server to forward the
53 // connection to.
54 // usher_cmd is never sent by the monotone server itself.
55 usher_cmd = 100,
56 usher_reply_cmd = 101
57 }
58netcmd_code;
59
60class netcmd
61{
62private:
63 u8 version;
64 netcmd_code cmd_code;
65 std::string payload;
66public:
67 netcmd();
68 netcmd(u8 _version);
69 netcmd_code get_cmd_code() const {return cmd_code;}
70 u8 get_version() const {return version;}
71 size_t encoded_size();
72 bool operator==(netcmd const & other) const;
73
74
75 // basic cmd i/o (including checksums)
76 void write(std::string & out,
77 chained_hmac & hmac) const;
78 bool read(string_queue & inbuf,
79 chained_hmac & hmac);
80 bool read_string(std::string & inbuf,
81 chained_hmac & hmac) {
82 // this is here only for the regression tests because they want to
83 // read and write to the same type, but we want to have reads from
84 // a string queue so that when data is read in from the network it
85 // can be processed efficiently
86 string_queue tmp(inbuf.size());
87 tmp.append(inbuf);
88 bool ret = read(tmp, hmac);
89 inbuf = tmp.substr(0,tmp.size());
90 return ret;
91 }
92 // i/o functions for each type of command payload
93 void read_error_cmd(std::string & errmsg) const;
94 void write_error_cmd(std::string const & errmsg);
95
96//void read_bye_cmd() {}
97 void write_bye_cmd() {cmd_code = bye_cmd;}
98
99 void read_hello_cmd(rsa_keypair_id & server_keyname,
100 rsa_pub_key & server_key,
101 id & nonce) const;
102 void write_hello_cmd(rsa_keypair_id const & server_keyname,
103 rsa_pub_key const & server_key,
104 id const & nonce);
105
106 void read_anonymous_cmd(protocol_role & role,
107 utf8 & include_pattern,
108 utf8 & exclude_pattern,
109 rsa_oaep_sha_data & hmac_key_encrypted) const;
110 void write_anonymous_cmd(protocol_role role,
111 utf8 const & include_pattern,
112 utf8 const & exclude_pattern,
113 rsa_oaep_sha_data const & hmac_key_encrypted);
114
115 void read_auth_cmd(protocol_role & role,
116 utf8 & include_pattern,
117 utf8 & exclude_pattern,
118 id & client,
119 id & nonce1,
120 rsa_oaep_sha_data & hmac_key_encrypted,
121 std::string & signature) const;
122 void write_auth_cmd(protocol_role role,
123 utf8 const & include_pattern,
124 utf8 const & exclude_pattern,
125 id const & client,
126 id const & nonce1,
127 rsa_oaep_sha_data const & hmac_key_encrypted,
128 std::string const & signature);
129
130 void read_confirm_cmd() const;
131 void write_confirm_cmd();
132
133 void read_refine_cmd(merkle_node & node) const;
134 void write_refine_cmd(merkle_node const & node);
135
136 void read_done_cmd(size_t & level, netcmd_item_type & type) const;
137 void write_done_cmd(size_t level, netcmd_item_type type);
138
139 void read_send_data_cmd(netcmd_item_type & type,
140 id & item) const;
141 void write_send_data_cmd(netcmd_item_type type,
142 id const & item);
143
144 void read_send_delta_cmd(netcmd_item_type & type,
145 id & base,
146 id & ident) const;
147 void write_send_delta_cmd(netcmd_item_type type,
148 id const & base,
149 id const & ident);
150
151 void read_data_cmd(netcmd_item_type & type,
152 id & item,
153 std::string & dat) const;
154 void write_data_cmd(netcmd_item_type type,
155 id const & item,
156 std::string const & dat);
157
158 void read_delta_cmd(netcmd_item_type & type,
159 id & base, id & ident,
160 delta & del) const;
161 void write_delta_cmd(netcmd_item_type & type,
162 id const & base, id const & ident,
163 delta const & del);
164
165 void read_nonexistant_cmd(netcmd_item_type & type,
166 id & item) const;
167 void write_nonexistant_cmd(netcmd_item_type type,
168 id const & item);
169
170 void read_usher_cmd(utf8 & greeting) const;
171 void write_usher_reply_cmd(utf8 const & pattern);
172
173};
174
175#endif // __NETCMD_HH__

Archive Download this file

Branches

Tags

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