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/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
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.
63 struct IPv4UdpAddress {
65 * Optional options and flags for this address
67 uint32_t options GNUNET_PACKED;
70 * IPv4 address, in network byte order.
72 uint32_t ipv4_addr GNUNET_PACKED;
75 * Port number, in network byte order.
77 uint16_t u4_port GNUNET_PACKED;
82 * Network format for IPv6 addresses.
84 struct IPv6UdpAddress {
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.
110 struct IPv4UdpAddress v4;
115 struct IPv6UdpAddress v6;
120 * Information we track for each message in the queue.
122 struct UDP_MessageWrapper;
126 * Closure for #append_port().
128 struct PrettyPrinterContext;
132 * Encapsulation of all of the state of the plugin.
138 struct GNUNET_TRANSPORT_PluginEnvironment *env;
141 * Session of peers with whom we are currently connected,
142 * map of peer identity to `struct GNUNET_ATS_Session *`.
144 struct GNUNET_CONTAINER_MultiPeerMap *sessions;
147 * Heap with all of our defragmentation activities.
149 struct GNUNET_CONTAINER_Heap *defrag_ctxs;
152 * ID of select task for IPv4
154 struct GNUNET_SCHEDULER_Task *select_task_v4;
157 * ID of select task for IPv6
159 struct GNUNET_SCHEDULER_Task *select_task_v6;
162 * Bandwidth tracker to limit global UDP traffic.
164 struct GNUNET_BANDWIDTH_Tracker tracker;
167 * Address we were told to bind to exclusively (IPv4).
172 * Address we were told to bind to exclusively (IPv6).
177 * Handle to NAT traversal support.
179 struct GNUNET_NAT_Handle *nat;
182 * Handle to NAT traversal support.
184 struct GNUNET_NAT_STUN_Handle *stun;
187 * The read socket for IPv4
189 struct GNUNET_NETWORK_Handle *sockv4;
192 * The read socket for IPv6
194 struct GNUNET_NETWORK_Handle *sockv6;
197 * Head of DLL of broadcast addresses
199 struct BroadcastAddress *broadcast_tail;
202 * Tail of DLL of broadcast addresses
204 struct BroadcastAddress *broadcast_head;
207 * Head of messages in IPv4 queue.
209 struct UDP_MessageWrapper *ipv4_queue_head;
212 * Tail of messages in IPv4 queue.
214 struct UDP_MessageWrapper *ipv4_queue_tail;
217 * Head of messages in IPv6 queue.
219 struct UDP_MessageWrapper *ipv6_queue_head;
222 * Tail of messages in IPv6 queue.
224 struct UDP_MessageWrapper *ipv6_queue_tail;
227 * Running pretty printers: head
229 struct PrettyPrinterContext *ppc_dll_head;
232 * Running pretty printers: tail
234 struct PrettyPrinterContext *ppc_dll_tail;
237 * Function to call about session status changes.
239 GNUNET_TRANSPORT_SessionInfoCallback sic;
242 * Closure for @e sic.
247 * IPv6 multicast address
249 struct sockaddr_in6 ipv6_multicast_address;
254 struct GNUNET_TIME_Relative broadcast_interval;
257 * Bytes currently in buffer
259 int64_t bytes_in_buffer;
267 * Is IPv6 enabled: #GNUNET_YES or #GNUNET_NO
272 * Is IPv4 enabled: #GNUNET_YES or #GNUNET_NO
277 * Is broadcasting enabled: #GNUNET_YES or #GNUNET_NO
279 int enable_broadcasting;
282 * Is receiving broadcasts enabled: #GNUNET_YES or #GNUNET_NO
284 int enable_broadcasting_receiving;
287 * Port we broadcasting on.
289 uint16_t broadcast_port;
297 * Port we advertise on.
304 * Function called for a quick conversion of the binary address to
305 * a numeric address. Note that the caller must not free the
306 * address and that the next call to this function is allowed
307 * to override the address again.
310 * @param addr binary address (a `union UdpAddress`)
311 * @param addrlen length of the @a addr
312 * @return string representing the same address
315 udp_address_to_string(void *cls,
321 * We received a broadcast message. Process it and all subsequent
322 * messages in the same packet.
324 * @param plugin the UDP plugin
325 * @param buf the buffer with the message(s)
326 * @param size number of bytes in @a buf
327 * @param udp_addr address of the sender
328 * @param udp_addr_len number of bytes in @a udp_addr
329 * @param network_type network type of the sender's address
332 udp_broadcast_receive(struct Plugin *plugin,
335 const union UdpAddress *udp_addr,
337 enum GNUNET_NetworkType network_type);
341 setup_broadcast(struct Plugin *plugin,
342 struct sockaddr_in6 *server_addrv6,
343 struct sockaddr_in *server_addrv4);
347 stop_broadcast(struct Plugin *plugin);
349 /*#ifndef PLUGIN_TRANSPORT_UDP_H*/
351 /* end of plugin_transport_udp.h */