plugin not receiving messages
[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_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    * 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   uint32_t 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    * Unique ID for this message.  Will be zero unless
229    * message tracking is desired.
230    */
231   uint32_t uid GNUNET_PACKED;
232
233   /**
234    * Identity of peer that ultimately sent the message.
235    * Should be looked up in the set of 'neighbor_id's of
236    * the referring peer.
237    */
238   uint32_t sender GNUNET_PACKED;
239
240   /**
241    * Identity of neighbor this message is going to.  Should
242    * be looked up in the set of our own identifiers for
243    * neighbors!
244    */
245   uint32_t recipient GNUNET_PACKED;
246
247 } p2p_dv_MESSAGE_Data;
248
249 /**
250  * Message that gets sent between nodes indicating a peer
251  * was disconnected.
252  */
253 typedef struct
254 {
255   struct GNUNET_MessageHeader header;
256
257   /**
258    * Identity of neighbor that was disconnected.
259    */
260   uint32_t peer_id GNUNET_PACKED;
261
262 } p2p_dv_MESSAGE_Disconnect;
263
264
265 struct GNUNET_DV_Handle *
266 GNUNET_DV_connect (struct GNUNET_SCHEDULER_Handle *sched,
267                   const struct GNUNET_CONFIGURATION_Handle *cfg,
268                   GNUNET_DV_MessageReceivedHandler receive_handler,
269                   void *receive_handler_cls);
270
271 /**
272  * Disconnect from the DV service
273  *
274  * @param handle the current handle to the service to disconnect
275  */
276 void GNUNET_DV_disconnect(struct GNUNET_DV_Handle *handle);
277
278 #endif