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