working distance vector transport plugin implementation. after spending days on...
[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_NO
33 #define DEBUG_DV_GOSSIP_RECEIPT GNUNET_NO
34 #define DEBUG_DV_MESSAGES GNUNET_NO
35 #define DEBUG_DV GNUNET_NO
36 #define DEBUG_DV_PEER_NUMBERS GNUNET_NO
37 #define DEBUG_MESSAGE_DROP GNUNET_YES
38
39 typedef void (*GNUNET_DV_MessageReceivedHandler) (void *cls,
40                                                   struct GNUNET_PeerIdentity *sender,
41                                                   char *msg,
42                                                   size_t msg_len,
43                                                   uint32_t distance,
44                                                   char *sender_address,
45                                                   size_t sender_address_len);
46
47 /**
48  * DV Message, contains a message that was received
49  * via DV for this peer!
50  *
51  * Sender address is copied to the end of this struct,
52  * followed by the actual message received.
53  */
54 struct GNUNET_DV_MessageReceived
55 {
56   /**
57    * Type:  GNUNET_MESSAGE_TYPE_TRANSPORT_DV_MESSAGE
58    */
59   struct GNUNET_MessageHeader header;
60
61   /**
62    * The sender of the message
63    */
64   struct GNUNET_PeerIdentity sender;
65
66   /**
67    * The message that was sent
68    */
69   uint32_t msg_len;
70
71   /**
72    * The distance to the peer that we received the message from
73    */
74   uint32_t distance;
75
76   /**
77    * Length of the sender address, appended to end of this message
78    */
79   uint32_t sender_address_len;
80
81 };
82
83
84 /**
85  * DV Message, indicates that we have learned of a new DV level peer.
86  *
87  * Sender address is copied to the end of this struct.
88  */
89 struct GNUNET_DV_ConnectMessage
90 {
91   /**
92    * Type:  GNUNET_MESSAGE_TYPE_TRANSPORT_DV_MESSAGE
93    */
94   struct GNUNET_MessageHeader header;
95
96   /**
97    * The sender of the message
98    */
99   struct GNUNET_PeerIdentity *sender;
100
101   /**
102    * The message that was sent
103    */
104   struct GNUNET_MessageHeader *msg;
105
106   /**
107    * The distance to the peer that we received the message from
108    */
109   uint32_t distance;
110
111   /**
112    * Length of the sender address, appended to end of this message
113    */
114   uint32_t sender_address_len;
115
116 };
117
118 /**
119  * Message to return result from a send attempt
120  */
121 struct GNUNET_DV_SendResultMessage
122 {
123   /**
124    * Type: GNUNET_MESSAGE_TYPE_DV_SEND_RESULT
125    */
126   struct GNUNET_MessageHeader header;
127
128   /**
129    * Unique ID for attempted sent message.
130    */
131   uint32_t uid;
132
133   /**
134    * Result of attempted send, 0 for send okay,
135    * 1 for failure of any reason.
136    */
137   uint32_t result;
138 };
139
140 /**
141  * Message to send a message over DV via a specific peer
142  */
143 struct GNUNET_DV_SendMessage
144 {
145   /**
146    * Type: GNUNET_MESSAGE_TYPE_DV_SEND
147    */
148   struct GNUNET_MessageHeader header;
149
150   /**
151    * Intended final recipient of this message
152    */
153   struct GNUNET_PeerIdentity target;
154
155   /**
156    * The size of the msgbuf
157    */
158   uint32_t msgbuf_size;
159
160   /**
161    * Message priority
162    */
163   uint32_t priority;
164
165   /**
166    * Unique ID for this message, for confirm callback.
167    */
168   uint32_t uid;
169
170   /**
171    * How long can we delay sending?
172    */
173   struct GNUNET_TIME_Relative timeout;
174
175   /**
176    * Size of the address (appended to end of struct)
177    */
178   uint32_t addrlen;
179
180   /**
181    * The message(s) to be sent.
182    */
183   char *msgbuf;
184
185   /*
186    * Sender, appended to end of struct tells via whom
187    * to send this message.
188    */
189
190 };
191
192 /**
193  * Message that gets sent between nodes updating dv infos
194  */
195 typedef struct
196 {
197   /* Message Header */
198   struct GNUNET_MessageHeader header;
199
200   /**
201    * Cost from received from node to neighbor node, takes distance into account
202    */
203   unsigned int cost GNUNET_PACKED;
204
205   /**
206    * Identity of neighbor we learned information about
207    */
208   struct GNUNET_PeerIdentity neighbor;
209
210   /**
211    * PublicKey of neighbor.
212    */
213   struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pkey;
214
215   /**
216    * Neighbor ID to use when sending to this peer
217    */
218   uint32_t neighbor_id GNUNET_PACKED;
219
220 } p2p_dv_MESSAGE_NeighborInfo;
221
222 /**
223  * Message that gets sent between nodes carrying information
224  */
225 typedef struct
226 {
227   struct GNUNET_MessageHeader header;
228
229   /**
230    * Identity of peer that ultimately sent the message.
231    * Should be looked up in the set of 'neighbor_id's of
232    * the referring peer.
233    */
234   unsigned int sender GNUNET_PACKED;
235
236   /**
237    * Identity of neighbor this message is going to.  Should
238    * be looked up in the set of our own identifiers for
239    * neighbors!
240    */
241   unsigned int recipient GNUNET_PACKED;
242
243 #if TRACK_MESSAGES
244   /**
245    * Unique ID for this message.
246    */
247   unsigned int uid GNUNET_PACKED;
248 #endif
249
250 } p2p_dv_MESSAGE_Data;
251
252 /**
253  * Message that gets sent between nodes indicating a peer
254  * was disconnected.
255  */
256 typedef struct
257 {
258   struct GNUNET_MessageHeader header;
259
260   /**
261    * Identity of neighbor that was disconnected.
262    */
263   uint32_t peer_id GNUNET_PACKED;
264
265 } p2p_dv_MESSAGE_Disconnect;
266
267
268 struct GNUNET_DV_Handle *
269 GNUNET_DV_connect (struct GNUNET_SCHEDULER_Handle *sched,
270                   const struct GNUNET_CONFIGURATION_Handle *cfg,
271                   GNUNET_DV_MessageReceivedHandler receive_handler,
272                   void *receive_handler_cls);
273
274 #endif