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_nat_lib.h"
36 #include "gnunet_protocols.h"
37 #include "gnunet_resolver_service.h"
38 #include "gnunet_signatures.h"
39 #include "gnunet_constants.h"
40 #include "gnunet_statistics_service.h"
41 #include "gnunet_transport_service.h"
42 #include "gnunet_transport_plugin.h"
43 #include "transport.h"
45 #define LOG(kind,...) GNUNET_log_from (kind, "transport-udp", __VA_ARGS__)
47 #define PLUGIN_NAME "udp"
49 #define DEBUG_UDP GNUNET_NO
51 #define DEBUG_UDP_BROADCASTING GNUNET_NO
54 * MTU for fragmentation subsystem. Should be conservative since
55 * all communicating peers MUST work with this MTU.
60 GNUNET_NETWORK_STRUCT_BEGIN
62 * Network format for IPv4 addresses.
67 * Optional options and flags for this address
69 uint32_t options GNUNET_PACKED;
72 * IPv4 address, in network byte order.
74 uint32_t ipv4_addr GNUNET_PACKED;
77 * Port number, in network byte order.
79 uint16_t u4_port GNUNET_PACKED;
84 * Network format for IPv6 addresses.
89 * Optional options and flags for this address
91 uint32_t options GNUNET_PACKED;
96 struct in6_addr ipv6_addr GNUNET_PACKED;
99 * Port number, in network byte order.
101 uint16_t u6_port GNUNET_PACKED;
103 GNUNET_NETWORK_STRUCT_END
106 * Either an IPv4 or IPv6 UDP address. Note that without a "length",
107 * one cannot tell which one of the two types this address represents.
114 struct IPv4UdpAddress v4;
119 struct IPv6UdpAddress v6;
124 * Information we track for each message in the queue.
126 struct UDP_MessageWrapper;
130 * Closure for #append_port().
132 struct PrettyPrinterContext;
136 * Encapsulation of all of the state of the plugin.
144 struct GNUNET_TRANSPORT_PluginEnvironment *env;
147 * Session of peers with whom we are currently connected,
148 * map of peer identity to `struct GNUNET_ATS_Session *`.
150 struct GNUNET_CONTAINER_MultiPeerMap *sessions;
153 * Heap with all of our defragmentation activities.
155 struct GNUNET_CONTAINER_Heap *defrag_ctxs;
158 * ID of select task for IPv4
160 struct GNUNET_SCHEDULER_Task *select_task_v4;
163 * ID of select task for IPv6
165 struct GNUNET_SCHEDULER_Task *select_task_v6;
168 * Tokenizer for inbound messages.
170 struct GNUNET_SERVER_MessageStreamTokenizer *mst;
173 * Bandwidth tracker to limit global UDP traffic.
175 struct GNUNET_BANDWIDTH_Tracker tracker;
178 * Address we were told to bind to exclusively (IPv4).
183 * Address we were told to bind to exclusively (IPv6).
188 * Handle to NAT traversal support.
190 struct GNUNET_NAT_Handle *nat;
193 * Handle to NAT traversal support.
195 struct GNUNET_NAT_STUN_Handle *stun;
198 * The read socket for IPv4
200 struct GNUNET_NETWORK_Handle *sockv4;
203 * The read socket for IPv6
205 struct GNUNET_NETWORK_Handle *sockv6;
208 * Tokenizer for inbound messages.
210 struct GNUNET_SERVER_MessageStreamTokenizer *broadcast_mst;
213 * Head of DLL of broadcast addresses
215 struct BroadcastAddress *broadcast_tail;
218 * Tail of DLL of broadcast addresses
220 struct BroadcastAddress *broadcast_head;
223 * Head of messages in IPv4 queue.
225 struct UDP_MessageWrapper *ipv4_queue_head;
228 * Tail of messages in IPv4 queue.
230 struct UDP_MessageWrapper *ipv4_queue_tail;
233 * Head of messages in IPv6 queue.
235 struct UDP_MessageWrapper *ipv6_queue_head;
238 * Tail of messages in IPv6 queue.
240 struct UDP_MessageWrapper *ipv6_queue_tail;
243 * Running pretty printers: head
245 struct PrettyPrinterContext *ppc_dll_head;
248 * Running pretty printers: tail
250 struct PrettyPrinterContext *ppc_dll_tail;
253 * Function to call about session status changes.
255 GNUNET_TRANSPORT_SessionInfoCallback sic;
258 * Closure for @e sic.
263 * IPv6 multicast address
265 struct sockaddr_in6 ipv6_multicast_address;
270 struct GNUNET_TIME_Relative broadcast_interval;
273 * Bytes currently in buffer
275 int64_t bytes_in_buffer;
283 * Is IPv6 enabled: #GNUNET_YES or #GNUNET_NO
288 * Is IPv4 enabled: #GNUNET_YES or #GNUNET_NO
293 * Is broadcasting enabled: #GNUNET_YES or #GNUNET_NO
295 int enable_broadcasting;
298 * Is receiving broadcasts enabled: #GNUNET_YES or #GNUNET_NO
300 int enable_broadcasting_receiving;
303 * Port we broadcasting on.
305 uint16_t broadcast_port;
313 * Port we advertise on.
321 * Function called for a quick conversion of the binary address to
322 * a numeric address. Note that the caller must not free the
323 * address and that the next call to this function is allowed
324 * to override the address again.
327 * @param addr binary address (a `union UdpAddress`)
328 * @param addrlen length of the @a addr
329 * @return string representing the same address
332 udp_address_to_string (void *cls,
338 * We received a broadcast message. Process it and all subsequent
339 * messages in the same packet.
341 * @param plugin the UDP plugin
342 * @param buf the buffer with the message(s)
343 * @param size number of bytes in @a buf
344 * @param udp_addr address of the sender
345 * @param udp_addr_len number of bytes in @a udp_addr
346 * @param network_type network type of the sender's address
349 udp_broadcast_receive (struct Plugin *plugin,
352 const union UdpAddress *udp_addr,
354 enum GNUNET_ATS_Network_Type network_type);
358 setup_broadcast (struct Plugin *plugin,
359 struct sockaddr_in6 *server_addrv6,
360 struct sockaddr_in *server_addrv4);
364 stop_broadcast (struct Plugin *plugin);
366 /*#ifndef PLUGIN_TRANSPORT_UDP_H*/
368 /* end of plugin_transport_udp.h */