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
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
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.
66 * Optional options and flags for this address
68 uint32_t options GNUNET_PACKED;
71 * IPv4 address, in network byte order.
73 uint32_t ipv4_addr GNUNET_PACKED;
76 * Port number, in network byte order.
78 uint16_t u4_port GNUNET_PACKED;
83 * Network format for IPv6 addresses.
88 * Optional options and flags for this address
90 uint32_t options GNUNET_PACKED;
95 struct in6_addr ipv6_addr GNUNET_PACKED;
98 * Port number, in network byte order.
100 uint16_t u6_port GNUNET_PACKED;
102 GNUNET_NETWORK_STRUCT_END
106 * UDP Message-Packet header (after defragmentation).
113 struct GNUNET_MessageHeader header;
116 * Always zero for now.
121 * What is the identity of the sender
123 struct GNUNET_PeerIdentity sender;
127 struct UDP_MessageWrapper;
131 * Encapsulation of all of the state of the plugin.
139 struct GNUNET_TRANSPORT_PluginEnvironment *env;
142 * Session of peers with whom we are currently connected,
143 * map of peer identity to 'struct PeerSession'.
145 struct GNUNET_CONTAINER_MultiPeerMap *sessions;
148 * Heap with all of our defragmentation activities.
150 struct GNUNET_CONTAINER_Heap *defrag_ctxs;
155 GNUNET_SCHEDULER_TaskIdentifier select_task;
156 GNUNET_SCHEDULER_TaskIdentifier select_task_v6;
159 * Tokenizer for inbound messages.
161 struct GNUNET_SERVER_MessageStreamTokenizer *mst;
164 * Bandwidth tracker to limit global UDP traffic.
166 struct GNUNET_BANDWIDTH_Tracker tracker;
169 * Address we were told to bind to exclusively (IPv4).
174 * Address we were told to bind to exclusively (IPv6).
180 * Bytes currently in buffer
182 int64_t bytes_in_buffer;
185 * Handle to NAT traversal support.
187 struct GNUNET_NAT_Handle *nat;
192 struct GNUNET_NETWORK_FDSet *rs_v4;
197 struct GNUNET_NETWORK_FDSet *ws_v4;
201 * The read socket for IPv4
203 struct GNUNET_NETWORK_Handle *sockv4;
209 struct GNUNET_NETWORK_FDSet *rs_v6;
214 struct GNUNET_NETWORK_FDSet *ws_v6;
217 * The read socket for IPv6
219 struct GNUNET_NETWORK_Handle *sockv6;
222 * Beacon broadcasting
223 * -------------------
229 struct GNUNET_TIME_Relative broadcast_interval;
232 * Tokenizer for inbound messages.
234 struct GNUNET_SERVER_MessageStreamTokenizer *broadcast_ipv6_mst;
235 struct GNUNET_SERVER_MessageStreamTokenizer *broadcast_ipv4_mst;
238 * IPv6 multicast address
240 struct sockaddr_in6 ipv6_multicast_address;
243 * DLL of broadcast addresses
245 struct BroadcastAddress *broadcast_tail;
246 struct BroadcastAddress *broadcast_head;
249 * Is IPv6 enabled: GNUNET_YES or GNUNET_NO
254 * Is IPv4 enabled: GNUNET_YES or GNUNET_NO
259 * Is broadcasting enabled: GNUNET_YES or GNUNET_NO
261 int enable_broadcasting;
264 * Is receiving broadcasts enabled: GNUNET_YES or GNUNET_NO
266 int enable_broadcasting_receiving;
269 * Port we broadcasting on.
271 uint16_t broadcast_port;
279 * Port we advertise on.
283 struct UDP_MessageWrapper *ipv4_queue_head;
284 struct UDP_MessageWrapper *ipv4_queue_tail;
286 struct UDP_MessageWrapper *ipv6_queue_head;
287 struct UDP_MessageWrapper *ipv6_queue_tail;
292 udp_address_to_string (void *cls, const void *addr, size_t addrlen);
295 udp_broadcast_receive (struct Plugin *plugin,
298 const struct sockaddr *addr,
302 setup_broadcast (struct Plugin *plugin,
303 struct sockaddr_in6 *server_addrv6,
304 struct sockaddr_in *server_addrv4);
307 stop_broadcast (struct Plugin *plugin);
309 /*#ifndef PLUGIN_TRANSPORT_UDP_H*/
311 /* end of plugin_transport_udp.h */