2 This file is part of GNUnet
3 Copyright (C) 2010-2014 Christian Grothoff (and other contributing authors)
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., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, 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 * UDP Message-Packet header (after defragmentation).
131 struct GNUNET_MessageHeader header;
134 * Always zero for now.
139 * What is the identity of the sender
141 struct GNUNET_PeerIdentity sender;
145 struct UDP_MessageWrapper;
147 struct PrettyPrinterContext;
151 * Encapsulation of all of the state of the plugin.
159 struct GNUNET_TRANSPORT_PluginEnvironment *env;
162 * Session of peers with whom we are currently connected,
163 * map of peer identity to `struct Session *`.
165 struct GNUNET_CONTAINER_MultiPeerMap *sessions;
168 * Heap with all of our defragmentation activities.
170 struct GNUNET_CONTAINER_Heap *defrag_ctxs;
173 * ID of select task for IPv4
175 struct GNUNET_SCHEDULER_Task *select_task;
178 * ID of select task for IPv6
180 struct GNUNET_SCHEDULER_Task *select_task_v6;
183 * Tokenizer for inbound messages.
185 struct GNUNET_SERVER_MessageStreamTokenizer *mst;
188 * Bandwidth tracker to limit global UDP traffic.
190 struct GNUNET_BANDWIDTH_Tracker tracker;
193 * Address we were told to bind to exclusively (IPv4).
198 * Address we were told to bind to exclusively (IPv6).
203 * Handle to NAT traversal support.
205 struct GNUNET_NAT_Handle *nat;
210 struct GNUNET_NETWORK_FDSet *rs_v4;
215 struct GNUNET_NETWORK_FDSet *ws_v4;
218 * The read socket for IPv4
220 struct GNUNET_NETWORK_Handle *sockv4;
225 struct GNUNET_NETWORK_FDSet *rs_v6;
230 struct GNUNET_NETWORK_FDSet *ws_v6;
233 * The read socket for IPv6
235 struct GNUNET_NETWORK_Handle *sockv6;
238 * Tokenizer for inbound messages.
240 struct GNUNET_SERVER_MessageStreamTokenizer *broadcast_mst;
243 * Head of DLL of broadcast addresses
245 struct BroadcastAddress *broadcast_tail;
248 * Tail of DLL of broadcast addresses
250 struct BroadcastAddress *broadcast_head;
253 * Head of messages in IPv4 queue.
255 struct UDP_MessageWrapper *ipv4_queue_head;
258 * Tail of messages in IPv4 queue.
260 struct UDP_MessageWrapper *ipv4_queue_tail;
263 * Head of messages in IPv6 queue.
265 struct UDP_MessageWrapper *ipv6_queue_head;
268 * Tail of messages in IPv6 queue.
270 struct UDP_MessageWrapper *ipv6_queue_tail;
273 * Running pretty printers: head
275 struct PrettyPrinterContext *ppc_dll_head;
278 * Running pretty printers: tail
280 struct PrettyPrinterContext *ppc_dll_tail;
283 * Function to call about session status changes.
285 GNUNET_TRANSPORT_SessionInfoCallback sic;
288 * Closure for @e sic.
293 * IPv6 multicast address
295 struct sockaddr_in6 ipv6_multicast_address;
300 struct GNUNET_TIME_Relative broadcast_interval;
303 * Bytes currently in buffer
305 int64_t bytes_in_buffer;
313 * Is IPv6 enabled: #GNUNET_YES or #GNUNET_NO
318 * Is IPv4 enabled: #GNUNET_YES or #GNUNET_NO
323 * Is broadcasting enabled: #GNUNET_YES or #GNUNET_NO
325 int enable_broadcasting;
328 * Is receiving broadcasts enabled: #GNUNET_YES or #GNUNET_NO
330 int enable_broadcasting_receiving;
333 * Port we broadcasting on.
335 uint16_t broadcast_port;
343 * Port we advertise on.
351 udp_address_to_string (void *cls,
357 * We received a broadcast message. Process it and all subsequent
358 * messages in the same packet.
360 * @param plugin the UDP plugin
361 * @param buf the buffer with the message(s)
362 * @param size number of bytes in @a buf
363 * @param udp_addr address of the sender
364 * @param udp_addr_len number of bytes in @a udp_addr
365 * @param network_type network type of the sender's address
368 udp_broadcast_receive (struct Plugin *plugin,
371 const union UdpAddress *udp_addr,
373 enum GNUNET_ATS_Network_Type network_type);
377 setup_broadcast (struct Plugin *plugin,
378 struct sockaddr_in6 *server_addrv6,
379 struct sockaddr_in *server_addrv4);
383 stop_broadcast (struct Plugin *plugin);
385 /*#ifndef PLUGIN_TRANSPORT_UDP_H*/
387 /* end of plugin_transport_udp.h */