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