adding GNUNET_CRYPTO_setup_hostkey to setup a hostkey ahead of time, using this funct...
[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_EXTRA_LOGGING
32 #define DEBUG_DV_GOSSIP_SEND GNUNET_EXTRA_LOGGING
33 #define DEBUG_DV_GOSSIP_RECEIPT GNUNET_EXTRA_LOGGING
34 #define DEBUG_DV_MESSAGES GNUNET_EXTRA_LOGGING
35 #define DEBUG_DV GNUNET_EXTRA_LOGGING
36 #define DEBUG_DV_PEER_NUMBERS GNUNET_EXTRA_LOGGING
37 #define DEBUG_MESSAGE_DROP GNUNET_EXTRA_LOGGING
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 GNUNET_NETWORK_STRUCT_BEGIN
48
49 /**
50  * DV Message, contains a message that was received
51  * via DV for this peer! Internal.
52  *
53  * Sender address is copied to the end of this struct,
54  * followed by the actual message received.
55  */
56 struct GNUNET_DV_MessageReceived
57 {
58   /**
59    * Type:  GNUNET_MESSAGE_TYPE_TRANSPORT_DV_MESSAGE
60    */
61   struct GNUNET_MessageHeader header;
62
63   /**
64    * The sender of the message
65    */
66   struct GNUNET_PeerIdentity sender;
67
68   /**
69    * The length of the message that was sent (appended to this end of struct)
70    */
71   uint32_t msg_len;
72
73   /**
74    * The distance to the peer that we received the message from
75    */
76   uint32_t distance;
77
78 };
79
80
81 /**
82  * DV Message, indicates that we have learned of a new DV level peer.
83  * Internal.
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  * Internal.
119  */
120 struct GNUNET_DV_SendResultMessage
121 {
122   /**
123    * Type: GNUNET_MESSAGE_TYPE_DV_SEND_RESULT
124    */
125   struct GNUNET_MessageHeader header;
126
127   /**
128    * Unique ID for attempted sent message.
129    */
130   uint32_t uid;
131
132   /**
133    * Result of attempted send, 0 for send okay,
134    * 1 for failure of any reason.
135    */
136   uint32_t result;
137 };
138
139 /**
140  * Message to send a message over DV via a specific peer.
141  * Internal.
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    * Message priority
157    */
158   uint32_t priority;
159
160   /**
161    * Unique ID for this message, for confirm callback.
162    */
163   uint32_t uid;
164
165   /**
166    * How long can we delay sending?
167    */
168   struct GNUNET_TIME_Relative timeout;
169
170   /**
171    * Size of the address (appended to end of struct)
172    */
173   uint32_t addrlen;
174
175   /**
176    * The message(s) to be sent.
177    */
178   char *msgbuf;
179
180   /*
181    * Sender, appended to end of struct tells via whom
182    * to send this message.
183    */
184
185 };
186
187 /**
188  * Message that gets sent between nodes updating dv infos
189  */
190 typedef struct
191 {
192   /* Message Header */
193   struct GNUNET_MessageHeader header;
194
195   /**
196    * Cost from received from node to neighbor node, takes distance into account
197    */
198   uint32_t cost GNUNET_PACKED;
199
200   /**
201    * Identity of neighbor we learned information about
202    */
203   struct GNUNET_PeerIdentity neighbor;
204
205   /**
206    * PublicKey of neighbor.
207    */
208   struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pkey;
209
210   /**
211    * Neighbor ID to use when sending to this peer
212    */
213   uint32_t neighbor_id GNUNET_PACKED;
214
215 } p2p_dv_MESSAGE_NeighborInfo;
216
217 /**
218  * Message that gets sent between nodes carrying information
219  */
220 typedef struct
221 {
222   struct GNUNET_MessageHeader header;
223
224   /**
225    * Unique ID for this message.  Will be zero unless
226    * message tracking is desired.
227    */
228   uint32_t uid GNUNET_PACKED;
229
230   /**
231    * Identity of peer that ultimately sent the message.
232    * Should be looked up in the set of 'neighbor_id's of
233    * the referring peer.
234    */
235   uint32_t sender GNUNET_PACKED;
236
237   /**
238    * Identity of neighbor this message is going to.  Should
239    * be looked up in the set of our own identifiers for
240    * neighbors!
241    */
242   uint32_t recipient GNUNET_PACKED;
243
244 } p2p_dv_MESSAGE_Data;
245
246 /**
247  * Message that gets sent between nodes indicating a peer
248  * was disconnected.
249  */
250 typedef struct
251 {
252   struct GNUNET_MessageHeader header;
253
254   /**
255    * Identity of neighbor that was disconnected.
256    */
257   uint32_t peer_id GNUNET_PACKED;
258
259 } p2p_dv_MESSAGE_Disconnect;
260 GNUNET_NETWORK_STRUCT_END
261
262 struct GNUNET_DV_Handle *
263 GNUNET_DV_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
264                    GNUNET_DV_MessageReceivedHandler receive_handler,
265                    void *receive_handler_cls);
266
267 /**
268  * Disconnect from the DV service
269  *
270  * @param handle the current handle to the service to disconnect
271  */
272 void
273 GNUNET_DV_disconnect (struct GNUNET_DV_Handle *handle);
274
275 #endif