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 <iostream>
10#include <set>
11#include <map>
12
13#include <boost/optional.hpp>
14
15#include "app_state.hh"
16#include "ui.hh"
17#include "vocab.hh"
18
19// the idea here is that monotone can produce and consume "packet streams",
20// where each packet is *informative* rather than transactional. that is to
21// say, they contain no information which needs to be replied to or processed
22// in any particular manner during some communication session.
23//
24// unlike nearly every other part of this program, the packet stream
25// interface is really *stream* oriented. the idea being that, while you
26// might be able to keep any one delta or file in memory at once, asking
27// you to keep *all* the deltas or files associated with a large chunk of
28// work, in memory, is a bit much.
29//
30// packet streams are ascii text, formatted for comfortable viewing on a
31// terminal or inclusion in an email / netnews post. they can be edited with
32// vi, filtered with grep, and concatenated with cat.
33//
34// there are currently 8 types of packets, though this can grow without hurting
35// anyone's feelings. if there's a backwards compatibility problem, just introduce
36// a new packet type.
37
38struct packet_consumer
39{
40 virtual ~packet_consumer() {}
41 virtual void consume_file_data(file_id const & ident,
42 file_data const & dat) = 0;
43 virtual void consume_file_delta(file_id const & id_old,
44 file_id const & id_new,
45 file_delta const & del) = 0;
46 virtual void consume_file_cert(file<cert> const & t) = 0;
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_cert(manifest<cert> const & t) = 0;
54
55 virtual void consume_public_key(rsa_keypair_id const & ident,
56 base64< rsa_pub_key > const & k) = 0;
57 virtual void consume_private_key(rsa_keypair_id const & ident,
58 base64< arc4<rsa_priv_key> > const & k) = 0;
59};
60
61// this writer queues packets to be sent to the network
62
63struct queueing_packet_writer : public packet_consumer
64{
65 app_state & app;
66 std::set<url> targets;
67 boost::optional<reverse_queue> rev;
68
69 ticker n_bytes;
70 ticker n_packets;
71
72 queueing_packet_writer(app_state & a, std::set<url> const & t);
73 virtual ~queueing_packet_writer() {}
74
75 void queue_blob_for_network(std::string const & str);
76
77 virtual void consume_file_data(file_id const & ident,
78 file_data const & dat);
79 virtual void consume_file_delta(file_id const & id_old,
80 file_id const & id_new,
81 file_delta const & del);
82 virtual void consume_file_cert(file<cert> const & t);
83
84 virtual void consume_manifest_data(manifest_id const & ident,
85 manifest_data const & dat);
86 virtual void consume_manifest_delta(manifest_id const & id_old,
87 manifest_id const & id_new,
88 manifest_delta const & del);
89 virtual void consume_manifest_cert(manifest<cert> const & t);
90
91 virtual void consume_public_key(rsa_keypair_id const & ident,
92 base64< rsa_pub_key > const & k);
93 virtual void consume_private_key(rsa_keypair_id const & ident,
94 base64< arc4<rsa_priv_key> > const & k);
95};
96
97// this writer writes packets into a stream
98
99struct packet_writer : public packet_consumer
100{
101 std::ostream & ost;
102 explicit packet_writer(std::ostream & o);
103 virtual ~packet_writer() {}
104 virtual void consume_file_data(file_id const & ident,
105 file_data const & dat);
106 virtual void consume_file_delta(file_id const & id_old,
107 file_id const & id_new,
108 file_delta const & del);
109 virtual void consume_file_cert(file<cert> const & t);
110
111 virtual void consume_manifest_data(manifest_id const & ident,
112 manifest_data const & dat);
113 virtual void consume_manifest_delta(manifest_id const & id_old,
114 manifest_id const & id_new,
115 manifest_delta const & del);
116 virtual void consume_manifest_cert(manifest<cert> const & t);
117
118 virtual void consume_public_key(rsa_keypair_id const & ident,
119 base64< rsa_pub_key > const & k);
120 virtual void consume_private_key(rsa_keypair_id const & ident,
121 base64< arc4<rsa_priv_key> > const & k);
122};
123
124// this writer injects packets it receives to the database.
125
126struct packet_db_writer : public packet_consumer
127{
128 app_state & app;
129 bool take_keys;
130 size_t count;
131
132 boost::optional<url> server;
133
134 packet_db_writer(app_state & app, bool take_keys = false);
135 virtual ~packet_db_writer() {}
136 virtual void consume_file_data(file_id const & ident,
137 file_data const & dat);
138 virtual void consume_file_delta(file_id const & id_old,
139 file_id const & id_new,
140 file_delta const & del);
141 virtual void consume_file_cert(file<cert> const & t);
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_cert(manifest<cert> const & t);
149
150 virtual void consume_public_key(rsa_keypair_id const & ident,
151 base64< rsa_pub_key > const & k);
152 virtual void consume_private_key(rsa_keypair_id const & ident,
153 base64< arc4<rsa_priv_key> > const & k);
154};
155
156size_t read_packets(std::istream & in, packet_consumer & cons);
157
158#endif

Archive Download this file

Branches

Tags

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