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

Archive Download this file

Branches

Tags

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