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 it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your 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 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * @file transport/plugin_transport_udp.h
21 * @brief Implementation of the UDP transport protocol
22 * @author Christian Grothoff
23 * @author Nathan Evans
24 * @author Matthias Wachs
26 #ifndef PLUGIN_TRANSPORT_UDP_H
27 #define PLUGIN_TRANSPORT_UDP_H
30 #include "gnunet_hello_lib.h"
31 #include "gnunet_util_lib.h"
32 #include "gnunet_fragmentation_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"
42 #define LOG(kind,...) GNUNET_log_from (kind, "transport-udp", __VA_ARGS__)
44 #define PLUGIN_NAME "udp"
46 #define DEBUG_UDP GNUNET_NO
48 #define DEBUG_UDP_BROADCASTING GNUNET_NO
51 * MTU for fragmentation subsystem. Should be conservative since
52 * all communicating peers MUST work with this MTU.
57 GNUNET_NETWORK_STRUCT_BEGIN
59 * Network format for IPv4 addresses.
64 * Optional options and flags for this address
66 uint32_t options GNUNET_PACKED;
69 * IPv4 address, in network byte order.
71 uint32_t ipv4_addr GNUNET_PACKED;
74 * Port number, in network byte order.
76 uint16_t u4_port GNUNET_PACKED;
81 * Network format for IPv6 addresses.
86 * Optional options and flags for this address
88 uint32_t options GNUNET_PACKED;
93 struct in6_addr ipv6_addr GNUNET_PACKED;
96 * Port number, in network byte order.
98 uint16_t u6_port GNUNET_PACKED;
100 GNUNET_NETWORK_STRUCT_END
103 * Either an IPv4 or IPv6 UDP address. Note that without a "length",
104 * one cannot tell which one of the two types this address represents.
111 struct IPv4UdpAddress v4;
116 struct IPv6UdpAddress v6;
121 * Information we track for each message in the queue.
123 struct UDP_MessageWrapper;
127 * Closure for #append_port().
129 struct PrettyPrinterContext;
133 * Encapsulation of all of the state of the plugin.
141 struct GNUNET_TRANSPORT_PluginEnvironment *env;
144 * Session of peers with whom we are currently connected,
145 * map of peer identity to `struct GNUNET_ATS_Session *`.
147 struct GNUNET_CONTAINER_MultiPeerMap *sessions;
150 * Heap with all of our defragmentation activities.
152 struct GNUNET_CONTAINER_Heap *defrag_ctxs;
155 * ID of select task for IPv4
157 struct GNUNET_SCHEDULER_Task *select_task_v4;
160 * ID of select task for IPv6
162 struct GNUNET_SCHEDULER_Task *select_task_v6;
165 * Bandwidth tracker to limit global UDP traffic.
167 struct GNUNET_BANDWIDTH_Tracker tracker;
170 * Address we were told to bind to exclusively (IPv4).
175 * Address we were told to bind to exclusively (IPv6).
180 * Handle to NAT traversal support.
182 struct GNUNET_NAT_Handle *nat;
185 * Handle to NAT traversal support.
187 struct GNUNET_NAT_STUN_Handle *stun;
190 * The read socket for IPv4
192 struct GNUNET_NETWORK_Handle *sockv4;
195 * The read socket for IPv6
197 struct GNUNET_NETWORK_Handle *sockv6;
200 * Head of DLL of broadcast addresses
202 struct BroadcastAddress *broadcast_tail;
205 * Tail of DLL of broadcast addresses
207 struct BroadcastAddress *broadcast_head;
210 * Head of messages in IPv4 queue.
212 struct UDP_MessageWrapper *ipv4_queue_head;
215 * Tail of messages in IPv4 queue.
217 struct UDP_MessageWrapper *ipv4_queue_tail;
220 * Head of messages in IPv6 queue.
222 struct UDP_MessageWrapper *ipv6_queue_head;
225 * Tail of messages in IPv6 queue.
227 struct UDP_MessageWrapper *ipv6_queue_tail;
230 * Running pretty printers: head
232 struct PrettyPrinterContext *ppc_dll_head;
235 * Running pretty printers: tail
237 struct PrettyPrinterContext *ppc_dll_tail;
240 * Function to call about session status changes.
242 GNUNET_TRANSPORT_SessionInfoCallback sic;
245 * Closure for @e sic.
250 * IPv6 multicast address
252 struct sockaddr_in6 ipv6_multicast_address;
257 struct GNUNET_TIME_Relative broadcast_interval;
260 * Bytes currently in buffer
262 int64_t bytes_in_buffer;
270 * Is IPv6 enabled: #GNUNET_YES or #GNUNET_NO
275 * Is IPv4 enabled: #GNUNET_YES or #GNUNET_NO
280 * Is broadcasting enabled: #GNUNET_YES or #GNUNET_NO
282 int enable_broadcasting;
285 * Is receiving broadcasts enabled: #GNUNET_YES or #GNUNET_NO
287 int enable_broadcasting_receiving;
290 * Port we broadcasting on.
292 uint16_t broadcast_port;
300 * Port we advertise on.
308 * Function called for a quick conversion of the binary address to
309 * a numeric address. Note that the caller must not free the
310 * address and that the next call to this function is allowed
311 * to override the address again.
314 * @param addr binary address (a `union UdpAddress`)
315 * @param addrlen length of the @a addr
316 * @return string representing the same address
319 udp_address_to_string (void *cls,
325 * We received a broadcast message. Process it and all subsequent
326 * messages in the same packet.
328 * @param plugin the UDP plugin
329 * @param buf the buffer with the message(s)
330 * @param size number of bytes in @a buf
331 * @param udp_addr address of the sender
332 * @param udp_addr_len number of bytes in @a udp_addr
333 * @param network_type network type of the sender's address
336 udp_broadcast_receive (struct Plugin *plugin,
339 const union UdpAddress *udp_addr,
341 enum GNUNET_ATS_Network_Type network_type);
345 setup_broadcast (struct Plugin *plugin,
346 struct sockaddr_in6 *server_addrv6,
347 struct sockaddr_in *server_addrv4);
351 stop_broadcast (struct Plugin *plugin);
353 /*#ifndef PLUGIN_TRANSPORT_UDP_H*/
355 /* end of plugin_transport_udp.h */