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