remove ugly ifdef for message tracking
[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_YES
35 #define DEBUG_DV GNUNET_NO
36 #define DEBUG_DV_PEER_NUMBERS GNUNET_NO
37 #define DEBUG_MESSAGE_DROP GNUNET_NO
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! Internal.
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  * Internal.
87  *
88  * Sender address is copied to the end of this struct.
89  */
90 struct GNUNET_DV_ConnectMessage
91 {
92   /**
93    * Type:  GNUNET_MESSAGE_TYPE_TRANSPORT_DV_MESSAGE
94    */
95   struct GNUNET_MessageHeader header;
96
97   /**
98    * The sender of the message
99    */
100   struct GNUNET_PeerIdentity *sender;
101
102   /**
103    * The message that was sent
104    */
105   struct GNUNET_MessageHeader *msg;
106
107   /**
108    * The distance to the peer that we received the message from
109    */
110   uint32_t distance;
111
112   /**
113    * Length of the sender address, appended to end of this message
114    */
115   uint32_t sender_address_len;
116
117 };
118
119 /**
120  * Message to return result from a send attempt.
121  * Internal.
122  */
123 struct GNUNET_DV_SendResultMessage
124 {
125   /**
126    * Type: GNUNET_MESSAGE_TYPE_DV_SEND_RESULT
127    */
128   struct GNUNET_MessageHeader header;
129
130   /**
131    * Unique ID for attempted sent message.
132    */
133   uint32_t uid;
134
135   /**
136    * Result of attempted send, 0 for send okay,
137    * 1 for failure of any reason.
138    */
139   uint32_t result;
140 };
141
142 /**
143  * Message to send a message over DV via a specific peer.
144  * Internal.
145  */
146 struct GNUNET_DV_SendMessage
147 {
148   /**
149    * Type: GNUNET_MESSAGE_TYPE_DV_SEND
150    */
151   struct GNUNET_MessageHeader header;
152
153   /**
154    * Intended final recipient of this message
155    */
156   struct GNUNET_PeerIdentity target;
157
158   /**
159    * The size of the msgbuf
160    */
161   uint32_t msgbuf_size;
162
163   /**
164    * Message priority
165    */
166   uint32_t priority;
167
168   /**
169    * Unique ID for this message, for confirm callback.
170    */
171   uint32_t uid;
172
173   /**
174    * How long can we delay sending?
175    */
176   struct GNUNET_TIME_Relative timeout;
177
178   /**
179    * Size of the address (appended to end of struct)
180    */
181   uint32_t addrlen;
182
183   /**
184    * The message(s) to be sent.
185    */
186   char *msgbuf;
187
188   /*
189    * Sender, appended to end of struct tells via whom
190    * to send this message.
191    */
192
193 };
194
195 /**
196  * Message that gets sent between nodes updating dv infos
197  */
198 typedef struct
199 {
200   /* Message Header */
201   struct GNUNET_MessageHeader header;
202
203   /**
204    * Cost from received from node to neighbor node, takes distance into account
205    */
206   uint32_t cost GNUNET_PACKED;
207
208   /**
209    * Identity of neighbor we learned information about
210    */
211   struct GNUNET_PeerIdentity neighbor;
212
213   /**
214    * PublicKey of neighbor.
215    */
216   struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pkey;
217
218   /**
219    * Neighbor ID to use when sending to this peer
220    */
221   uint32_t neighbor_id GNUNET_PACKED;
222
223 } p2p_dv_MESSAGE_NeighborInfo;
224
225 /**
226  * Message that gets sent between nodes carrying information
227  */
228 typedef struct
229 {
230   struct GNUNET_MessageHeader header;
231
232   /**
233    * Unique ID for this message.  Will be zero unless
234    * message tracking is desired.
235    */
236   uint32_t uid GNUNET_PACKED;
237
238   /**
239    * Identity of peer that ultimately sent the message.
240    * Should be looked up in the set of 'neighbor_id's of
241    * the referring peer.
242    */
243   uint32_t sender GNUNET_PACKED;
244
245   /**
246    * Identity of neighbor this message is going to.  Should
247    * be looked up in the set of our own identifiers for
248    * neighbors!
249    */
250   uint32_t recipient GNUNET_PACKED;
251
252 } p2p_dv_MESSAGE_Data;
253
254 /**
255  * Message that gets sent between nodes indicating a peer
256  * was disconnected.
257  */
258 typedef struct
259 {
260   struct GNUNET_MessageHeader header;
261
262   /**
263    * Identity of neighbor that was disconnected.
264    */
265   uint32_t peer_id GNUNET_PACKED;
266
267 } p2p_dv_MESSAGE_Disconnect;
268
269
270 struct GNUNET_DV_Handle *
271 GNUNET_DV_connect (struct GNUNET_SCHEDULER_Handle *sched,
272                   const struct GNUNET_CONFIGURATION_Handle *cfg,
273                   GNUNET_DV_MessageReceivedHandler receive_handler,
274                   void *receive_handler_cls);
275
276 #endif