fixing mess with search update serialization and parenting
[oweals/gnunet.git] / src / dv / dv.h
1 /*
2      This file is part of GNUnet.
3      (C) 2001, 2002, 2003, 2004, 2009 Christian Grothoff (and other contributing authors)
4
5      GNUnet is free software; you can redistribute it and/or modify
6      it under the terms of the GNU General Public License as published
7      by the Free Software Foundation; either version 2, or (at your
8      option) any later version.
9
10      GNUnet is distributed in the hope that it will be useful, but
11      WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13      General Public License for more details.
14
15      You should have received a copy of the GNU General Public License
16      along with GNUnet; see the file COPYING.  If not, write to the
17      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18      Boston, MA 02111-1307, USA.
19 */
20
21 /**
22  * @author Christian Grothoff
23  * @author NOT Nathan Evans
24  * @file dv/dv.h
25  */
26 #ifndef DV_H
27 #define DV_H
28
29 #include "gnunet_common.h"
30
31 #define DEBUG_DV_GOSSIP GNUNET_NO
32 #define DEBUG_DV_GOSSIP_SEND GNUNET_YES
33 #define DEBUG_DV_GOSSIP_RECEIPT GNUNET_YES
34 #define DEBUG_DV GNUNET_YES
35 #define DEBUG_DV_API GNUNET_YES
36
37 typedef void (*GNUNET_DV_MessageReceivedHandler) (void *cls,
38                                                   struct GNUNET_PeerIdentity *sender,
39                                                   char *msg,
40                                                   size_t msg_len,
41                                                   uint32_t distance,
42                                                   char *sender_address,
43                                                   size_t sender_address_len);
44
45 /**
46  * DV Message, contains a message that was received
47  * via DV for this peer!
48  *
49  * Sender address is copied to the end of this struct,
50  * followed by the actual message received.
51  */
52 struct GNUNET_DV_MessageReceived
53 {
54   /**
55    * Type:  GNUNET_MESSAGE_TYPE_TRANSPORT_DV_MESSAGE
56    */
57   struct GNUNET_MessageHeader header;
58
59   /**
60    * The sender of the message
61    */
62   struct GNUNET_PeerIdentity sender;
63
64   /**
65    * The message that was sent
66    */
67   uint32_t msg_len;
68
69   /**
70    * The distance to the peer that we received the message from
71    */
72   uint32_t distance;
73
74   /**
75    * Length of the sender address, appended to end of this message
76    */
77   uint32_t sender_address_len;
78
79 };
80
81
82 /**
83  * DV Message, indicates that we have learned of a new DV level peer.
84  *
85  * Sender address is copied to the end of this struct.
86  */
87 struct GNUNET_DV_ConnectMessage
88 {
89   /**
90    * Type:  GNUNET_MESSAGE_TYPE_TRANSPORT_DV_MESSAGE
91    */
92   struct GNUNET_MessageHeader header;
93
94   /**
95    * The sender of the message
96    */
97   struct GNUNET_PeerIdentity *sender;
98
99   /**
100    * The message that was sent
101    */
102   struct GNUNET_MessageHeader *msg;
103
104   /**
105    * The distance to the peer that we received the message from
106    */
107   uint32_t distance;
108
109   /**
110    * Length of the sender address, appended to end of this message
111    */
112   uint32_t sender_address_len;
113
114 };
115
116 /**
117  * Message to return result from a send attempt
118  */
119 struct GNUNET_DV_SendResultMessage
120 {
121   /**
122    * Type: GNUNET_MESSAGE_TYPE_DV_SEND_RESULT
123    */
124   struct GNUNET_MessageHeader header;
125
126   /**
127    * Unique ID for attempted sent message.
128    */
129   uint32_t uid;
130
131   /**
132    * Result of attempted send, 0 for send okay,
133    * 1 for failure of any reason.
134    */
135   uint32_t result;
136 };
137
138 /**
139  * Message to send a message over DV via a specific peer
140  */
141 struct GNUNET_DV_SendMessage
142 {
143   /**
144    * Type: GNUNET_MESSAGE_TYPE_DV_SEND
145    */
146   struct GNUNET_MessageHeader header;
147
148   /**
149    * Intended final recipient of this message
150    */
151   struct GNUNET_PeerIdentity target;
152
153   /**
154    * The size of the msgbuf
155    */
156   uint32_t msgbuf_size;
157
158   /**
159    * Message priority
160    */
161   uint32_t priority;
162
163   /**
164    * Unique ID for this message, for confirm callback.
165    */
166   uint32_t uid;
167
168   /**
169    * How long can we delay sending?
170    */
171   struct GNUNET_TIME_Relative timeout;
172
173   /**
174    * Size of the address (appended to end of struct)
175    */
176   uint32_t addrlen;
177
178   /**
179    * The message(s) to be sent.
180    */
181   char *msgbuf;
182
183   /*
184    * Sender, appended to end of struct tells via whom
185    * to send this message.
186    */
187
188 };
189
190 /**
191  * Message that gets sent between nodes updating dv infos
192  */
193 typedef struct
194 {
195   /* Message Header */
196   struct GNUNET_MessageHeader header;
197
198   /**
199    * Cost from received from node to neighbor node, takes distance into account
200    */
201   unsigned int cost GNUNET_PACKED;
202
203   /**
204    * Identity of neighbor we learned information about
205    */
206   struct GNUNET_PeerIdentity neighbor;
207
208   /**
209    * PublicKey of neighbor.
210    */
211   struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pkey;
212
213   /**
214    * Neighbor ID to use when sending to this peer
215    */
216   uint32_t neighbor_id GNUNET_PACKED;
217
218 } p2p_dv_MESSAGE_NeighborInfo;
219
220 /**
221  * Message that gets sent between nodes carrying information
222  */
223 typedef struct
224 {
225   struct GNUNET_MessageHeader header;
226
227   /**
228    * Identity of peer that ultimately sent the message.
229    * Should be looked up in the set of 'neighbor_id's of
230    * the referring peer.
231    */
232   unsigned int sender GNUNET_PACKED;
233
234   /**
235    * Identity of neighbor this message is going to.  Should
236    * be looked up in the set of our own identifiers for
237    * neighbors!
238    */
239   unsigned int recipient GNUNET_PACKED;
240
241 } p2p_dv_MESSAGE_Data;
242
243 /**
244  * Message that gets sent between nodes indicating a peer
245  * was disconnected.
246  */
247 typedef struct
248 {
249   struct GNUNET_MessageHeader header;
250
251   /**
252    * Identity of neighbor that was disconnected.
253    */
254   uint32_t peer_id GNUNET_PACKED;
255
256 } p2p_dv_MESSAGE_Disconnect;
257
258
259 struct GNUNET_DV_Handle *
260 GNUNET_DV_connect (struct GNUNET_SCHEDULER_Handle *sched,
261                   const struct GNUNET_CONFIGURATION_Handle *cfg,
262                   GNUNET_DV_MessageReceivedHandler receive_handler,
263                   void *receive_handler_cls);
264
265 #endif