2 This file is part of GNUnet
3 Copyright (C) 2010-2014 GNUnet e.V.
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.
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.
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., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
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
28 #ifndef PLUGIN_TRANSPORT_UDP_H
29 #define PLUGIN_TRANSPORT_UDP_H
32 #include "gnunet_hello_lib.h"
33 #include "gnunet_util_lib.h"
34 #include "gnunet_fragmentation_lib.h"
35 #include "gnunet_protocols.h"
36 #include "gnunet_resolver_service.h"
37 #include "gnunet_signatures.h"
38 #include "gnunet_constants.h"
39 #include "gnunet_statistics_service.h"
40 #include "gnunet_transport_service.h"
41 #include "gnunet_transport_plugin.h"
42 #include "transport.h"
44 #define LOG(kind,...) GNUNET_log_from (kind, "transport-udp", __VA_ARGS__)
46 #define PLUGIN_NAME "udp"
48 #define DEBUG_UDP GNUNET_NO
50 #define DEBUG_UDP_BROADCASTING GNUNET_NO
53 * MTU for fragmentation subsystem. Should be conservative since
54 * all communicating peers MUST work with this MTU.
59 GNUNET_NETWORK_STRUCT_BEGIN
61 * Network format for IPv4 addresses.
66 * Optional options and flags for this address
68 uint32_t options GNUNET_PACKED;
71 * IPv4 address, in network byte order.
73 uint32_t ipv4_addr GNUNET_PACKED;
76 * Port number, in network byte order.
78 uint16_t u4_port GNUNET_PACKED;
83 * Network format for IPv6 addresses.
88 * Optional options and flags for this address
90 uint32_t options GNUNET_PACKED;
95 struct in6_addr ipv6_addr GNUNET_PACKED;
98 * Port number, in network byte order.
100 uint16_t u6_port GNUNET_PACKED;
102 GNUNET_NETWORK_STRUCT_END
105 * Either an IPv4 or IPv6 UDP address. Note that without a "length",
106 * one cannot tell which one of the two types this address represents.
113 struct IPv4UdpAddress v4;
118 struct IPv6UdpAddress v6;
123 * Information we track for each message in the queue.
125 struct UDP_MessageWrapper;
129 * Closure for #append_port().
131 struct PrettyPrinterContext;
135 * Encapsulation of all of the state of the plugin.
143 struct GNUNET_TRANSPORT_PluginEnvironment *env;
146 * Session of peers with whom we are currently connected,
147 * map of peer identity to `struct GNUNET_ATS_Session *`.
149 struct GNUNET_CONTAINER_MultiPeerMap *sessions;
152 * Heap with all of our defragmentation activities.
154 struct GNUNET_CONTAINER_Heap *defrag_ctxs;
157 * ID of select task for IPv4
159 struct GNUNET_SCHEDULER_Task *select_task_v4;
162 * ID of select task for IPv6
164 struct GNUNET_SCHEDULER_Task *select_task_v6;
167 * Tokenizer for inbound messages.
169 struct GNUNET_SERVER_MessageStreamTokenizer *mst;
172 * Bandwidth tracker to limit global UDP traffic.
174 struct GNUNET_BANDWIDTH_Tracker tracker;
177 * Address we were told to bind to exclusively (IPv4).
182 * Address we were told to bind to exclusively (IPv6).
187 * Handle to NAT traversal support.
189 struct GNUNET_NAT_Handle *nat;
192 * Handle to NAT traversal support.
194 struct GNUNET_NAT_STUN_Handle *stun;
197 * The read socket for IPv4
199 struct GNUNET_NETWORK_Handle *sockv4;
202 * The read socket for IPv6
204 struct GNUNET_NETWORK_Handle *sockv6;
207 * Tokenizer for inbound messages.
209 struct GNUNET_SERVER_MessageStreamTokenizer *broadcast_mst;
212 * Head of DLL of broadcast addresses
214 struct BroadcastAddress *broadcast_tail;
217 * Tail of DLL of broadcast addresses
219 struct BroadcastAddress *broadcast_head;
222 * Head of messages in IPv4 queue.
224 struct UDP_MessageWrapper *ipv4_queue_head;
227 * Tail of messages in IPv4 queue.
229 struct UDP_MessageWrapper *ipv4_queue_tail;
232 * Head of messages in IPv6 queue.
234 struct UDP_MessageWrapper *ipv6_queue_head;
237 * Tail of messages in IPv6 queue.
239 struct UDP_MessageWrapper *ipv6_queue_tail;
242 * Running pretty printers: head
244 struct PrettyPrinterContext *ppc_dll_head;
247 * Running pretty printers: tail
249 struct PrettyPrinterContext *ppc_dll_tail;
252 * Function to call about session status changes.
254 GNUNET_TRANSPORT_SessionInfoCallback sic;
257 * Closure for @e sic.
262 * IPv6 multicast address
264 struct sockaddr_in6 ipv6_multicast_address;
269 struct GNUNET_TIME_Relative broadcast_interval;
272 * Bytes currently in buffer
274 int64_t bytes_in_buffer;
282 * Is IPv6 enabled: #GNUNET_YES or #GNUNET_NO
287 * Is IPv4 enabled: #GNUNET_YES or #GNUNET_NO
292 * Is broadcasting enabled: #GNUNET_YES or #GNUNET_NO
294 int enable_broadcasting;
297 * Is receiving broadcasts enabled: #GNUNET_YES or #GNUNET_NO
299 int enable_broadcasting_receiving;
302 * Port we broadcasting on.
304 uint16_t broadcast_port;
312 * Port we advertise on.
320 * Function called for a quick conversion of the binary address to
321 * a numeric address. Note that the caller must not free the
322 * address and that the next call to this function is allowed
323 * to override the address again.
326 * @param addr binary address (a `union UdpAddress`)
327 * @param addrlen length of the @a addr
328 * @return string representing the same address
331 udp_address_to_string (void *cls,
337 * We received a broadcast message. Process it and all subsequent
338 * messages in the same packet.
340 * @param plugin the UDP plugin
341 * @param buf the buffer with the message(s)
342 * @param size number of bytes in @a buf
343 * @param udp_addr address of the sender
344 * @param udp_addr_len number of bytes in @a udp_addr
345 * @param network_type network type of the sender's address
348 udp_broadcast_receive (struct Plugin *plugin,
351 const union UdpAddress *udp_addr,
353 enum GNUNET_ATS_Network_Type network_type);
357 setup_broadcast (struct Plugin *plugin,
358 struct sockaddr_in6 *server_addrv6,
359 struct sockaddr_in *server_addrv4);
363 stop_broadcast (struct Plugin *plugin);
365 /*#ifndef PLUGIN_TRANSPORT_UDP_H*/
367 /* end of plugin_transport_udp.h */