2 This file is part of GNUnet
3 (C) 2010, 2011 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
29 #include "gnunet_hello_lib.h"
30 #include "gnunet_util_lib.h"
31 #include "gnunet_fragmentation_lib.h"
32 #include "gnunet_nat_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 DEBUG_UDP GNUNET_NO
45 #define DEBUG_UDP_BROADCASTING GNUNET_NO
48 * MTU for fragmentation subsystem. Should be conservative since
49 * all communicating peers MUST work with this MTU.
54 GNUNET_NETWORK_STRUCT_BEGIN
56 * Network format for IPv4 addresses.
61 * Optional options and flags for this address
63 uint32_t options GNUNET_PACKED;
66 * IPv4 address, in network byte order.
68 uint32_t ipv4_addr GNUNET_PACKED;
71 * Port number, in network byte order.
73 uint16_t u4_port GNUNET_PACKED;
78 * Network format for IPv6 addresses.
83 * Optional options and flags for this address
85 uint32_t options GNUNET_PACKED;
90 struct in6_addr ipv6_addr GNUNET_PACKED;
93 * Port number, in network byte order.
95 uint16_t u6_port GNUNET_PACKED;
97 GNUNET_NETWORK_STRUCT_END
101 * UDP Message-Packet header (after defragmentation).
108 struct GNUNET_MessageHeader header;
111 * Always zero for now.
116 * What is the identity of the sender
118 struct GNUNET_PeerIdentity sender;
124 * Encapsulation of all of the state of the plugin.
132 struct GNUNET_TRANSPORT_PluginEnvironment *env;
135 * Session of peers with whom we are currently connected,
136 * map of peer identity to 'struct PeerSession'.
138 struct GNUNET_CONTAINER_MultiHashMap *sessions;
141 * Heap with all of our defragmentation activities.
143 struct GNUNET_CONTAINER_Heap *defrag_ctxs;
148 GNUNET_SCHEDULER_TaskIdentifier select_task;
149 GNUNET_SCHEDULER_TaskIdentifier select_task_v6;
152 * Tokenizer for inbound messages.
154 struct GNUNET_SERVER_MessageStreamTokenizer *mst;
157 * Bandwidth tracker to limit global UDP traffic.
159 struct GNUNET_BANDWIDTH_Tracker tracker;
162 * Address we were told to bind to exclusively (IPv4).
167 * Address we were told to bind to exclusively (IPv6).
173 * Bytes currently in buffer
175 int64_t bytes_in_buffer;
178 * Handle to NAT traversal support.
180 struct GNUNET_NAT_Handle *nat;
185 struct GNUNET_NETWORK_FDSet *rs_v4;
190 struct GNUNET_NETWORK_FDSet *ws_v4;
194 * The read socket for IPv4
196 struct GNUNET_NETWORK_Handle *sockv4;
202 struct GNUNET_NETWORK_FDSet *rs_v6;
207 struct GNUNET_NETWORK_FDSet *ws_v6;
210 * The read socket for IPv6
212 struct GNUNET_NETWORK_Handle *sockv6;
215 * Beacon broadcasting
216 * -------------------
222 struct GNUNET_TIME_Relative broadcast_interval;
225 * Broadcast with IPv4
230 * Broadcast with IPv6
236 * Tokenizer for inbound messages.
238 struct GNUNET_SERVER_MessageStreamTokenizer *broadcast_ipv6_mst;
239 struct GNUNET_SERVER_MessageStreamTokenizer *broadcast_ipv4_mst;
242 * ID of select broadcast task
244 GNUNET_SCHEDULER_TaskIdentifier send_ipv4_broadcast_task;
247 * ID of select broadcast task
249 GNUNET_SCHEDULER_TaskIdentifier send_ipv6_broadcast_task;
252 * IPv6 multicast address
254 struct sockaddr_in6 ipv6_multicast_address;
257 * DLL of IPv4 broadcast addresses
259 struct BroadcastAddress *ipv4_broadcast_tail;
260 struct BroadcastAddress *ipv4_broadcast_head;
263 * Is IPv6 enabled: GNUNET_YES or GNUNET_NO
268 * Is IPv4 enabled: GNUNET_YES or GNUNET_NO
273 * Port we broadcasting on.
275 uint16_t broadcast_port;
283 * Port we advertise on.
287 struct UDP_MessageWrapper *ipv4_queue_head;
288 struct UDP_MessageWrapper *ipv4_queue_tail;
290 struct UDP_MessageWrapper *ipv6_queue_head;
291 struct UDP_MessageWrapper *ipv6_queue_tail;
296 udp_address_to_string (void *cls, const void *addr, size_t addrlen);
299 udp_broadcast_receive ();
302 setup_broadcast (struct Plugin *plugin, struct sockaddr_in6 *serverAddrv6, struct sockaddr_in *serverAddrv4);
305 stop_broadcast (struct Plugin *plugin);
307 /* end of plugin_transport_udp.h */