- changes
[oweals/gnunet.git] / src / transport / plugin_transport_udp_new.h
1 /*
2      This file is part of GNUnet
3      (C) 2010, 2011 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  * @file transport/plugin_transport_udp.h
23  * @brief Implementation of the UDP transport protocol
24  * @author Christian Grothoff
25  * @author Nathan Evans
26  * @author Matthias Wachs
27  */
28 #include "platform.h"
29 #include "gnunet_hello_lib.h"
30 #include "gnunet_util_lib.h"
31 #include "gnunet_fragmentation_lib.h"
32 #include "gnunet_nat_lib.h"
33 #include "gnunet_protocols.h"
34 #include "gnunet_resolver_service.h"
35 #include "gnunet_signatures.h"
36 #include "gnunet_constants.h"
37 #include "gnunet_statistics_service.h"
38 #include "gnunet_transport_service.h"
39 #include "gnunet_transport_plugin.h"
40 #include "transport.h"
41
42 #define LOG(kind,...) GNUNET_log_from (kind, "transport-udp", __VA_ARGS__)
43
44 #define DEBUG_UDP GNUNET_YES
45
46 /**
47  * MTU for fragmentation subsystem.  Should be conservative since
48  * all communicating peers MUST work with this MTU.
49  */
50 #define UDP_MTU 1400
51
52
53 GNUNET_NETWORK_STRUCT_BEGIN
54 /**
55  * Network format for IPv4 addresses.
56  */
57 struct IPv4UdpAddress
58 {
59   /**
60    * IPv4 address, in network byte order.
61    */
62   uint32_t ipv4_addr GNUNET_PACKED;
63
64   /**
65    * Port number, in network byte order.
66    */
67   uint16_t u4_port GNUNET_PACKED;
68 };
69
70
71 /**
72  * Network format for IPv6 addresses.
73  */
74 struct IPv6UdpAddress
75 {
76
77   /**
78    * IPv6 address.
79    */
80   struct in6_addr ipv6_addr GNUNET_PACKED;
81
82   /**
83    * Port number, in network byte order.
84    */
85   uint16_t u6_port GNUNET_PACKED;
86 };
87 GNUNET_NETWORK_STRUCT_END
88
89
90 /**
91  * UDP Message-Packet header (after defragmentation).
92  */
93 struct UDPMessage
94 {
95   /**
96    * Message header.
97    */
98   struct GNUNET_MessageHeader header;
99
100   /**
101    * Always zero for now.
102    */
103   uint32_t reserved;
104
105   /**
106    * What is the identity of the sender
107    */
108   struct GNUNET_PeerIdentity sender;
109
110 };
111
112
113 /**
114  * Encapsulation of all of the state of the plugin.
115  */
116 struct Plugin
117 {
118
119   /**
120    * Our environment.
121    */
122   struct GNUNET_TRANSPORT_PluginEnvironment *env;
123
124   /**
125    * Session of peers with whom we are currently connected,
126    * map of peer identity to 'struct PeerSession'.
127    */
128   struct GNUNET_CONTAINER_MultiHashMap *sessions;
129
130   /**
131    * Session of peers with whom we are currently connected,
132    * map of peer identity to 'struct PeerSession'.
133    */
134   struct GNUNET_CONTAINER_MultiHashMap *inbound_sessions;
135
136   /**
137    * Heap with all of our defragmentation activities.
138    */
139   struct GNUNET_CONTAINER_Heap *defrags;
140
141   /**
142    * ID of select task
143    */
144   GNUNET_SCHEDULER_TaskIdentifier select_task;
145
146   /**
147    * Tokenizer for inbound messages.
148    */
149   struct GNUNET_SERVER_MessageStreamTokenizer *mst;
150
151   /**
152    * Bandwidth tracker to limit global UDP traffic.
153    */
154   struct GNUNET_BANDWIDTH_Tracker tracker;
155
156   /**
157    * Address we were told to bind to exclusively (IPv4).
158    */
159   char *bind4_address;
160
161   /**
162    * Address we were told to bind to exclusively (IPv6).
163    */
164   char *bind6_address;
165
166   /**
167    * Handle to NAT traversal support.
168    */
169   struct GNUNET_NAT_Handle *nat;
170
171   /**
172    * FD Read set
173    */
174   struct GNUNET_NETWORK_FDSet *rs;
175
176   /**
177    * FD Write set
178    */
179   struct GNUNET_NETWORK_FDSet *ws;
180
181   /**
182    * The read socket for IPv4
183    */
184   struct GNUNET_NETWORK_Handle *sockv4;
185
186   /**
187    * The read socket for IPv6
188    */
189   struct GNUNET_NETWORK_Handle *sockv6;
190
191   /**
192    * Beacon broadcasting
193    * -------------------
194    */
195
196   /**
197    * Broadcast interval
198    */
199   struct GNUNET_TIME_Relative broadcast_interval;
200
201   /**
202    * Broadcast with IPv4
203    */
204   int broadcast_ipv4;
205
206   /**
207    * Broadcast with IPv6
208    */
209   int broadcast_ipv6;
210
211
212   /**
213    * Tokenizer for inbound messages.
214    */
215   struct GNUNET_SERVER_MessageStreamTokenizer *broadcast_ipv6_mst;
216   struct GNUNET_SERVER_MessageStreamTokenizer *broadcast_ipv4_mst;
217
218   /**
219    * ID of select broadcast task
220    */
221   GNUNET_SCHEDULER_TaskIdentifier send_ipv4_broadcast_task;
222
223   /**
224    * ID of select broadcast task
225    */
226   GNUNET_SCHEDULER_TaskIdentifier send_ipv6_broadcast_task;
227
228   /**
229    * IPv6 multicast address
230    */
231   struct sockaddr_in6 ipv6_multicast_address;
232
233   /**
234    * DLL of IPv4 broadcast addresses
235    */
236   struct BroadcastAddress *ipv4_broadcast_tail;
237   struct BroadcastAddress *ipv4_broadcast_head;
238
239
240   /**
241    * expected delay for ACKs
242    */
243   struct GNUNET_TIME_Relative last_expected_delay;
244
245   /**
246    * Enable IPv6
247    */
248   int enable_ipv6;
249
250   /**
251    * Port we broadcasting on.
252    */
253   uint16_t broadcast_port;
254
255   /**
256    * Port we listen on.
257    */
258   uint16_t port;
259
260   /**
261    * Port we advertise on.
262    */
263   uint16_t aport;
264
265 };
266
267
268 const char *
269 udp_address_to_string (void *cls, const void *addr, size_t addrlen);
270
271 void
272 udp_broadcast_receive ();
273
274 void
275 setup_broadcast (struct Plugin *plugin, struct sockaddr_in6 *serverAddrv6, struct sockaddr_in *serverAddrv4);
276
277 void
278 stop_broadcast (struct Plugin *plugin);
279
280 /* end of plugin_transport_udp.h */