monotone

monotone Mtn Source Tree

Root/packet.hh

1#ifndef __PACKET_HH__
2#define __PACKET_HH__
3
4// copyright (C) 2002, 2003 graydon hoare <graydon@pobox.com>
5// all rights reserved.
6// licensed to the public under the terms of the GNU GPL (>= 2)
7// see the file COPYING for details
8
9#include <iosfwd>
10#include <memory>
11
12#include <boost/function.hpp>
13
14#include "app_state.hh"
15#include "ui.hh"
16#include "vocab.hh"
17
18// the idea here is that monotone can produce and consume "packet streams",
19// where each packet is *informative* rather than transactional. that is to
20// say, they contain no information which needs to be replied to or processed
21// in any particular manner during some communication session.
22//
23// unlike nearly every other part of this program, the packet stream
24// interface is really *stream* oriented. the idea being that, while you
25// might be able to keep any one delta or file in memory at once, asking
26// you to keep *all* the deltas or files associated with a large chunk of
27// work, in memory, is a bit much.
28//
29// packet streams are ascii text, formatted for comfortable viewing on a
30// terminal or inclusion in an email / netnews post. they can be edited with
31// vi, filtered with grep, and concatenated with cat.
32//
33// there are currently 8 types of packets, though this can grow without hurting
34// anyone's feelings. if there's a backwards compatibility problem, just introduce
35// a new packet type.
36
37struct packet_consumer
38{
39protected:
40 boost::function1<void, revision_id> on_revision_written;
41 boost::function1<void, cert const &> on_cert_written;
42 boost::function1<void, rsa_keypair_id> on_pubkey_written;
43 boost::function1<void, rsa_keypair_id> on_privkey_written;
44public:
45
46 virtual void set_on_revision_written(boost::function1<void, revision_id>
47 const & x);
48 virtual void set_on_cert_written(boost::function1<void, cert const &>
49 const & x);
50 virtual void set_on_pubkey_written(boost::function1<void, rsa_keypair_id>
51 const & x);
52 virtual void set_on_privkey_written(boost::function1<void, rsa_keypair_id>
53 const & x);
54
55 virtual ~packet_consumer() {}
56 virtual void consume_file_data(file_id const & ident,
57 file_data const & dat) = 0;
58 virtual void consume_file_delta(file_id const & id_old,
59 file_id const & id_new,
60 file_delta const & del) = 0;
61 virtual void consume_file_reverse_delta(file_id const & id_new,
62 file_id const & id_old,
63 file_delta const & del) = 0;
64
65
66 virtual void consume_manifest_data(manifest_id const & ident,
67 manifest_data const & dat) = 0;
68 virtual void consume_manifest_delta(manifest_id const & id_old,
69 manifest_id const & id_new,
70 manifest_delta const & del) = 0;
71 virtual void consume_manifest_reverse_delta(manifest_id const & id_new,
72 manifest_id const & id_old,
73 manifest_delta const & del) = 0;
74
75
76 virtual void consume_revision_data(revision_id const & ident,
77 revision_data const & dat) = 0;
78 virtual void consume_revision_cert(revision<cert> const & t) = 0;
79
80
81 virtual void consume_public_key(rsa_keypair_id const & ident,
82 base64< rsa_pub_key > const & k) = 0;
83 virtual void consume_private_key(rsa_keypair_id const & ident,
84 base64< arc4<rsa_priv_key> > const & k) = 0;
85};
86
87// this writer writes packets into a stream
88
89struct packet_writer : public packet_consumer
90{
91 std::ostream & ost;
92 explicit packet_writer(std::ostream & o);
93 virtual ~packet_writer() {}
94 virtual void consume_file_data(file_id const & ident,
95 file_data const & dat);
96 virtual void consume_file_delta(file_id const & id_old,
97 file_id const & id_new,
98 file_delta const & del);
99 virtual void consume_file_reverse_delta(file_id const & id_new,
100 file_id const & id_old,
101 file_delta const & del);
102
103 virtual void consume_manifest_data(manifest_id const & ident,
104 manifest_data const & dat);
105 virtual void consume_manifest_delta(manifest_id const & id_old,
106 manifest_id const & id_new,
107 manifest_delta const & del);
108 virtual void consume_manifest_reverse_delta(manifest_id const & id_new,
109 manifest_id const & id_old,
110 manifest_delta const & del);
111
112 virtual void consume_revision_data(revision_id const & ident,
113 revision_data const & dat);
114 virtual void consume_revision_cert(revision<cert> const & t);
115
116 virtual void consume_public_key(rsa_keypair_id const & ident,
117 base64< rsa_pub_key > const & k);
118 virtual void consume_private_key(rsa_keypair_id const & ident,
119 base64< arc4<rsa_priv_key> > const & k);
120};
121
122// this writer injects packets it receives to the database.
123
124struct packet_db_writer : public packet_consumer
125{
126private:
127 struct impl;
128 std::auto_ptr<impl> pimpl;
129
130public:
131 packet_db_writer(app_state & app,
132 bool take_keys = false);
133 virtual ~packet_db_writer();
134 virtual void consume_file_data(file_id const & ident,
135 file_data const & dat);
136 virtual void consume_file_delta(file_id const & id_old,
137 file_id const & id_new,
138 file_delta const & del);
139 virtual void consume_file_reverse_delta(file_id const & id_new,
140 file_id const & id_old,
141 file_delta const & del);
142
143 virtual void consume_manifest_data(manifest_id const & ident,
144 manifest_data const & dat);
145 virtual void consume_manifest_delta(manifest_id const & id_old,
146 manifest_id const & id_new,
147 manifest_delta const & del);
148 virtual void consume_manifest_reverse_delta(manifest_id const & id_new,
149 manifest_id const & id_old,
150 manifest_delta const & del);
151
152 virtual void consume_revision_data(revision_id const & ident,
153 revision_data const & dat);
154 virtual void consume_revision_cert(revision<cert> const & t);
155
156 virtual void consume_public_key(rsa_keypair_id const & ident,
157 base64< rsa_pub_key > const & k);
158 virtual void consume_private_key(rsa_keypair_id const & ident,
159 base64< arc4<rsa_priv_key> > const & k);
160};
161
162// this writer is just like packet_db_writer, except that none of your calls
163// have any effect until after calling open_valve; at that point, all previous
164// consume_* calls will suddenly take effect.
165
166struct packet_db_valve : public packet_consumer
167{
168private:
169 struct impl;
170 std::auto_ptr<impl> pimpl;
171public:
172 packet_db_valve(app_state & app,
173 bool take_keys = false);
174 virtual ~packet_db_valve();
175 virtual void set_on_revision_written(boost::function1<void, revision_id>
176 const & x);
177 virtual void set_on_cert_written(boost::function1<void, cert const &>
178 const & x);
179 virtual void set_on_pubkey_written(boost::function1<void, rsa_keypair_id>
180 const & x);
181 virtual void set_on_privkey_written(boost::function1<void, rsa_keypair_id>
182 const & x);
183 virtual void consume_file_data(file_id const & ident,
184 file_data const & dat);
185 virtual void consume_file_delta(file_id const & id_old,
186 file_id const & id_new,
187 file_delta const & del);
188 virtual void consume_file_reverse_delta(file_id const & id_new,
189 file_id const & id_old,
190 file_delta const & del);
191
192 virtual void consume_manifest_data(manifest_id const & ident,
193 manifest_data const & dat);
194 virtual void consume_manifest_delta(manifest_id const & id_old,
195 manifest_id const & id_new,
196 manifest_delta const & del);
197 virtual void consume_manifest_reverse_delta(manifest_id const & id_new,
198 manifest_id const & id_old,
199 manifest_delta const & del);
200
201 virtual void consume_revision_data(revision_id const & ident,
202 revision_data const & dat);
203 virtual void consume_revision_cert(revision<cert> const & t);
204
205 virtual void consume_public_key(rsa_keypair_id const & ident,
206 base64< rsa_pub_key > const & k);
207 virtual void consume_private_key(rsa_keypair_id const & ident,
208 base64< arc4<rsa_priv_key> > const & k);
209
210 virtual void open_valve();
211};
212
213size_t read_packets(std::istream & in, packet_consumer & cons);
214
215#endif

Archive Download this file

Branches

Tags

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