monotone

monotone Mtn Source Tree

Root/netcmd.hh

1#ifndef __NETCMD_HH__
2#define __NETCMD_HH__
3
4// Copyright (C) 2004 Graydon Hoare <graydon@pobox.com>
5//
6// This program is made available under the GNU GPL version 2.0 or
7// greater. See the accompanying file COPYING for details.
8//
9// This program is distributed WITHOUT ANY WARRANTY; without even the
10// implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11// PURPOSE.
12
13#include "vector.hh"
14#include <list>
15#include <utility>
16
17#include "merkle_tree.hh"
18#include "numeric_vocab.hh"
19#include "vocab.hh"
20#include "hmac.hh"
21#include "string_queue.hh"
22
23struct globish;
24
25typedef enum
26 {
27 server_voice,
28 client_voice
29 }
30protocol_voice;
31
32typedef enum
33 {
34 source_role = 1,
35 sink_role = 2,
36 source_and_sink_role = 3
37 }
38protocol_role;
39
40typedef enum
41 {
42 refinement_query = 0,
43 refinement_response = 1
44 }
45refinement_type;
46
47typedef enum
48 {
49 // general commands
50 error_cmd = 0,
51 bye_cmd = 1,
52
53 // authentication commands
54 hello_cmd = 2,
55 anonymous_cmd = 3,
56 auth_cmd = 4,
57 confirm_cmd = 5,
58
59 // refinement commands
60 refine_cmd = 6,
61 done_cmd = 7,
62
63 // transmission commands
64 data_cmd = 8,
65 delta_cmd = 9,
66
67 // usher commands
68 // usher_cmd is sent by a server farm (or anyone else who wants to serve
69 // from multiple databases over the same port), and the reply (containing
70 // the client's include pattern) is used to choose a server to forward the
71 // connection to.
72 // usher_cmd is never sent by the monotone server itself.
73 usher_cmd = 100,
74 usher_reply_cmd = 101
75 }
76netcmd_code;
77
78class netcmd
79{
80private:
81 u8 version;
82 netcmd_code cmd_code;
83 std::string payload;
84public:
85 netcmd();
86 netcmd_code get_cmd_code() const {return cmd_code;}
87 size_t encoded_size();
88 bool operator==(netcmd const & other) const;
89
90
91 // basic cmd i/o (including checksums)
92 void write(std::string & out,
93 chained_hmac & hmac) const;
94 bool read(string_queue & inbuf,
95 chained_hmac & hmac);
96 bool read_string(std::string & inbuf,
97 chained_hmac & hmac) {
98 // this is here only for the regression tests because they want to
99 // read and write to the same type, but we want to have reads from
100 // a string queue so that when data is read in from the network it
101 // can be processed efficiently
102 string_queue tmp(inbuf.size());
103 tmp.append(inbuf);
104 bool ret = read(tmp, hmac);
105 inbuf = tmp.substr(0,tmp.size());
106 return ret;
107 }
108 // i/o functions for each type of command payload
109 void read_error_cmd(std::string & errmsg) const;
110 void write_error_cmd(std::string const & errmsg);
111
112 void read_hello_cmd(rsa_keypair_id & server_keyname,
113 rsa_pub_key & server_key,
114 id & nonce) const;
115 void write_hello_cmd(rsa_keypair_id const & server_keyname,
116 rsa_pub_key const & server_key,
117 id const & nonce);
118
119 void read_bye_cmd(u8 & phase) const;
120 void write_bye_cmd(u8 phase);
121
122 void read_anonymous_cmd(protocol_role & role,
123 globish & include_pattern,
124 globish & exclude_pattern,
125 rsa_oaep_sha_data & hmac_key_encrypted) const;
126 void write_anonymous_cmd(protocol_role role,
127 globish const & include_pattern,
128 globish const & exclude_pattern,
129 rsa_oaep_sha_data const & hmac_key_encrypted);
130
131 void read_auth_cmd(protocol_role & role,
132 globish & include_pattern,
133 globish & exclude_pattern,
134 id & client,
135 id & nonce1,
136 rsa_oaep_sha_data & hmac_key_encrypted,
137 std::string & signature) const;
138 void write_auth_cmd(protocol_role role,
139 globish const & include_pattern,
140 globish const & exclude_pattern,
141 id const & client,
142 id const & nonce1,
143 rsa_oaep_sha_data const & hmac_key_encrypted,
144 std::string const & signature);
145
146 void read_confirm_cmd() const;
147 void write_confirm_cmd();
148
149 void read_refine_cmd(refinement_type & ty, merkle_node & node) const;
150 void write_refine_cmd(refinement_type ty, merkle_node const & node);
151
152 void read_done_cmd(netcmd_item_type & type, size_t & n_items) const;
153 void write_done_cmd(netcmd_item_type type, size_t n_items);
154
155 void read_data_cmd(netcmd_item_type & type,
156 id & item,
157 std::string & dat) const;
158 void write_data_cmd(netcmd_item_type type,
159 id const & item,
160 std::string const & dat);
161
162 void read_delta_cmd(netcmd_item_type & type,
163 id & base, id & ident,
164 delta & del) const;
165 void write_delta_cmd(netcmd_item_type & type,
166 id const & base, id const & ident,
167 delta const & del);
168
169 void read_usher_cmd(utf8 & greeting) const;
170 void write_usher_reply_cmd(utf8 const & server, globish const & pattern);
171
172};
173
174class app_state;
175void run_netsync_protocol(protocol_voice voice,
176 protocol_role role,
177 std::list<utf8> const & addrs,
178 globish const & include_pattern,
179 globish const & exclude_pattern,
180 app_state & app);
181
182// Local Variables:
183// mode: C++
184// fill-column: 76
185// c-file-style: "gnu"
186// indent-tabs-mode: nil
187// End:
188// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s:
189
190#endif // __NETCMD_HH__

Archive Download this file

Branches

Tags

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