f18819a3ae6697db9d17aaff5f03ad64336e4e34
[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_RECEIPT GNUNET_YES
33 #define DEBUG_DV GNUNET_NO
34 #define DEBUG_DV_API GNUNET_YES
35
36 typedef void (*GNUNET_DV_MessageReceivedHandler) (void *cls,
37                                                   struct GNUNET_PeerIdentity *sender,
38                                                   char *msg,
39                                                   size_t msg_len,
40                                                   uint32_t distance,
41                                                   char *sender_address,
42                                                   size_t sender_address_len);
43
44 /**
45  * DV Message, contains a message that was received
46  * via DV for this peer!
47  *
48  * Sender address is copied to the end of this struct,
49  * followed by the actual message received.
50  */
51 struct GNUNET_DV_MessageReceived
52 {
53   /**
54    * Type:  GNUNET_MESSAGE_TYPE_TRANSPORT_DV_MESSAGE
55    */
56   struct GNUNET_MessageHeader header;
57
58   /**
59    * The sender of the message
60    */
61   struct GNUNET_PeerIdentity sender;
62
63   /**
64    * The message that was sent
65    */
66   uint32_t msg_len;
67
68   /**
69    * The distance to the peer that we received the message from
70    */
71   uint32_t distance;
72
73   /**
74    * Length of the sender address, appended to end of this message
75    */
76   uint32_t sender_address_len;
77
78 };
79
80
81 /**
82  * DV Message, indicates that we have learned of a new DV level peer.
83  *
84  * Sender address is copied to the end of this struct.
85  */
86 struct GNUNET_DV_ConnectMessage
87 {
88   /**
89    * Type:  GNUNET_MESSAGE_TYPE_TRANSPORT_DV_MESSAGE
90    */
91   struct GNUNET_MessageHeader header;
92
93   /**
94    * The sender of the message
95    */
96   struct GNUNET_PeerIdentity *sender;
97
98   /**
99    * The message that was sent
100    */
101   struct GNUNET_MessageHeader *msg;
102
103   /**
104    * The distance to the peer that we received the message from
105    */
106   uint32_t distance;
107
108   /**
109    * Length of the sender address, appended to end of this message
110    */
111   uint32_t sender_address_len;
112
113 };
114
115
116 /**
117  * Message to send a message over DV via a specific peer
118  */
119 struct GNUNET_DV_SendMessage
120 {
121   /**
122    * Type: GNUNET_MESSAGE_TYPE_DV_SEND
123    */
124   struct GNUNET_MessageHeader header;
125
126   /**
127    * Intended final recipient of this message
128    */
129   struct GNUNET_PeerIdentity target;
130
131   /**
132    * The size of the msgbuf
133    */
134   uint32_t msgbuf_size;
135
136   /**
137    * Message priority
138    */
139   uint32_t priority;
140
141   /**
142    * How long can we delay sending?
143    */
144   struct GNUNET_TIME_Relative timeout;
145
146   /**
147    * Size of the address (appended to end of struct)
148    */
149   uint32_t addrlen;
150
151   /**
152    * The message(s) to be sent.
153    */
154   char *msgbuf;
155
156   /*
157    * Sender, appended to end of struct tells via whom
158    * to send this message.
159    */
160
161 };
162
163 /**
164  * Message that gets sent between nodes updating dv infos
165  */
166 typedef struct
167 {
168   /* Message Header */
169   struct GNUNET_MessageHeader header;
170
171   /**
172    * Cost from received from node to neighbor node, takes distance into account
173    */
174   unsigned int cost GNUNET_PACKED;
175
176   /**
177    * Identity of neighbor we learned information about
178    */
179   struct GNUNET_PeerIdentity neighbor;
180
181   /**
182    * PublicKey of neighbor.
183    */
184   struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pkey;
185
186   /**
187    * Neighbor ID to use when sending to this peer
188    */
189   uint32_t neighbor_id GNUNET_PACKED;
190
191 } p2p_dv_MESSAGE_NeighborInfo;
192
193 /**
194  * Message that gets sent between nodes carrying information
195  */
196 typedef struct
197 {
198   struct GNUNET_MessageHeader header;
199
200   /**
201    * Identity of peer that ultimately sent the message.
202    * Should be looked up in the set of 'neighbor_id's of
203    * the referring peer.
204    */
205   unsigned int sender GNUNET_PACKED;
206
207   /**
208    * Identity of neighbor this message is going to.  Should
209    * be looked up in the set of our own identifiers for
210    * neighbors!
211    */
212   unsigned int recipient GNUNET_PACKED;
213
214 } p2p_dv_MESSAGE_Data;
215
216
217 struct GNUNET_DV_Handle *
218 GNUNET_DV_connect (struct GNUNET_SCHEDULER_Handle *sched,
219                   const struct GNUNET_CONFIGURATION_Handle *cfg,
220                   GNUNET_DV_MessageReceivedHandler receive_handler,
221                   void *receive_handler_cls);
222
223 #endif