2 This file is part of GNUnet
3 (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
107 * UDP Message-Packet header (after defragmentation).
114 struct GNUNET_MessageHeader header;
117 * Always zero for now.
122 * What is the identity of the sender
124 struct GNUNET_PeerIdentity sender;
128 struct UDP_MessageWrapper;
130 struct PrettyPrinterContext;
134 * Encapsulation of all of the state of the plugin.
142 struct GNUNET_TRANSPORT_PluginEnvironment *env;
145 * Session of peers with whom we are currently connected,
146 * map of peer identity to `struct Session *`.
148 struct GNUNET_CONTAINER_MultiPeerMap *sessions;
151 * Heap with all of our defragmentation activities.
153 struct GNUNET_CONTAINER_Heap *defrag_ctxs;
156 * ID of select task for IPv4
158 struct GNUNET_SCHEDULER_Task * select_task;
161 * ID of select task for IPv6
163 struct GNUNET_SCHEDULER_Task * select_task_v6;
166 * Tokenizer for inbound messages.
168 struct GNUNET_SERVER_MessageStreamTokenizer *mst;
171 * Bandwidth tracker to limit global UDP traffic.
173 struct GNUNET_BANDWIDTH_Tracker tracker;
176 * Address we were told to bind to exclusively (IPv4).
181 * Address we were told to bind to exclusively (IPv6).
186 * Handle to NAT traversal support.
188 struct GNUNET_NAT_Handle *nat;
193 struct GNUNET_NETWORK_FDSet *rs_v4;
198 struct GNUNET_NETWORK_FDSet *ws_v4;
201 * The read socket for IPv4
203 struct GNUNET_NETWORK_Handle *sockv4;
208 struct GNUNET_NETWORK_FDSet *rs_v6;
213 struct GNUNET_NETWORK_FDSet *ws_v6;
216 * The read socket for IPv6
218 struct GNUNET_NETWORK_Handle *sockv6;
221 * Tokenizer for inbound IPv6 messages.
223 struct GNUNET_SERVER_MessageStreamTokenizer *broadcast_ipv6_mst;
226 * Tokenizer for inbound IPv4 messages.
228 struct GNUNET_SERVER_MessageStreamTokenizer *broadcast_ipv4_mst;
231 * Head of DLL of broadcast addresses
233 struct BroadcastAddress *broadcast_tail;
236 * Tail of DLL of broadcast addresses
238 struct BroadcastAddress *broadcast_head;
241 * Head of messages in IPv4 queue.
243 struct UDP_MessageWrapper *ipv4_queue_head;
246 * Tail of messages in IPv4 queue.
248 struct UDP_MessageWrapper *ipv4_queue_tail;
251 * Head of messages in IPv6 queue.
253 struct UDP_MessageWrapper *ipv6_queue_head;
256 * Tail of messages in IPv6 queue.
258 struct UDP_MessageWrapper *ipv6_queue_tail;
261 * Running pretty printers: head
263 struct PrettyPrinterContext *ppc_dll_head;
266 * Running pretty printers: tail
268 struct PrettyPrinterContext *ppc_dll_tail;
271 * Function to call about session status changes.
273 GNUNET_TRANSPORT_SessionInfoCallback sic;
276 * Closure for @e sic.
281 * IPv6 multicast address
283 struct sockaddr_in6 ipv6_multicast_address;
288 struct GNUNET_TIME_Relative broadcast_interval;
291 * Bytes currently in buffer
293 int64_t bytes_in_buffer;
301 * Is IPv6 enabled: #GNUNET_YES or #GNUNET_NO
306 * Is IPv4 enabled: #GNUNET_YES or #GNUNET_NO
311 * Is broadcasting enabled: #GNUNET_YES or #GNUNET_NO
313 int enable_broadcasting;
316 * Is receiving broadcasts enabled: #GNUNET_YES or #GNUNET_NO
318 int enable_broadcasting_receiving;
321 * Port we broadcasting on.
323 uint16_t broadcast_port;
331 * Port we advertise on.
339 udp_address_to_string (void *cls, const void *addr, size_t addrlen);
342 udp_broadcast_receive (struct Plugin *plugin,
345 const struct sockaddr *addr,
349 setup_broadcast (struct Plugin *plugin,
350 struct sockaddr_in6 *server_addrv6,
351 struct sockaddr_in *server_addrv4);
354 stop_broadcast (struct Plugin *plugin);
356 /*#ifndef PLUGIN_TRANSPORT_UDP_H*/
358 /* end of plugin_transport_udp.h */