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