aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2018-06-04 19:00:10 +0200
committerChristian Grothoff <christian@grothoff.org>2018-06-04 19:00:10 +0200
commit41cbe10b783a0741c75566232886f262cd779fbb (patch)
tree044c6277532cd0ade440915982a86745623da7a5 /src
parentfdf5283f5d5d603217748232941bafb60728aeb2 (diff)
downloadgnunet-41cbe10b783a0741c75566232886f262cd779fbb.tar.gz
gnunet-41cbe10b783a0741c75566232886f262cd779fbb.zip
add function for getopt uint16_t arguments
Diffstat (limited to 'src')
-rw-r--r--src/gns/gnunet-bcd.c22
-rw-r--r--src/gns/gnunet-gns-proxy.c16
-rw-r--r--src/include/gnunet_getopt_lib.h17
-rw-r--r--src/transport/Makefile.am7
-rw-r--r--src/transport/plugin_transport_xu.h273
-rw-r--r--src/util/getopt_helpers.c76
6 files changed, 391 insertions, 20 deletions
diff --git a/src/gns/gnunet-bcd.c b/src/gns/gnunet-bcd.c
index 0746d5c57..d7fd1a812 100644
--- a/src/gns/gnunet-bcd.c
+++ b/src/gns/gnunet-bcd.c
@@ -76,7 +76,7 @@ static char *resfile;
76/** 76/**
77 * Port number. 77 * Port number.
78 */ 78 */
79static unsigned int port = 8888; 79static uint16_t port = 8888;
80 80
81 81
82struct Entry 82struct Entry
@@ -351,7 +351,7 @@ prepare_daemon (struct MHD_Daemon *daemon_handle)
351static int 351static int
352server_start () 352server_start ()
353{ 353{
354 if ((0 == port) || (port > UINT16_MAX)) 354 if (0 == port)
355 { 355 {
356 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 356 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
357 _("Invalid port number %u. Exiting.\n"), 357 _("Invalid port number %u. Exiting.\n"),
@@ -362,7 +362,7 @@ server_start ()
362 _("Businesscard HTTP server starts on %u\n"), 362 _("Businesscard HTTP server starts on %u\n"),
363 port); 363 port);
364 daemon_handle = MHD_start_daemon (MHD_USE_DUAL_STACK | MHD_USE_DEBUG, 364 daemon_handle = MHD_start_daemon (MHD_USE_DUAL_STACK | MHD_USE_DEBUG,
365 (uint16_t) port, 365 port,
366 NULL /* accept_policy_callback */, NULL, 366 NULL /* accept_policy_callback */, NULL,
367 &access_handler_callback, NULL, 367 &access_handler_callback, NULL,
368 MHD_OPTION_CONNECTION_LIMIT, (unsigned int) 512, 368 MHD_OPTION_CONNECTION_LIMIT, (unsigned int) 512,
@@ -374,7 +374,7 @@ server_start ()
374 { 374 {
375 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 375 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
376 _("Could not start businesscard HTTP server on port %u\n"), 376 _("Could not start businesscard HTTP server on port %u\n"),
377 (unsigned short) port); 377 (unsigned int) port);
378 return GNUNET_SYSERR; 378 return GNUNET_SYSERR;
379 } 379 }
380 http_task = prepare_daemon (daemon_handle); 380 http_task = prepare_daemon (daemon_handle);
@@ -516,17 +516,17 @@ main (int argc, char *const *argv)
516{ 516{
517 struct GNUNET_GETOPT_CommandLineOption options[] = { 517 struct GNUNET_GETOPT_CommandLineOption options[] = {
518 518
519 GNUNET_GETOPT_option_uint ('p', 519 GNUNET_GETOPT_option_uint16 ('p',
520 "port", 520 "port",
521 "PORT", 521 "PORT",
522 gettext_noop ("Run HTTP serve on port PORT (default is 8888)"), 522 gettext_noop ("Run HTTP serve on port PORT (default is 8888)"),
523 &port), 523 &port),
524
525 GNUNET_GETOPT_OPTION_END 524 GNUNET_GETOPT_OPTION_END
526 }; 525 };
527 int ret; 526 int ret;
528 527
529 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 528 if (GNUNET_OK !=
529 GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
530 return 2; 530 return 2;
531 GNUNET_log_setup ("gnunet-bcd", "WARNING", NULL); 531 GNUNET_log_setup ("gnunet-bcd", "WARNING", NULL);
532 ret = 532 ret =
diff --git a/src/gns/gnunet-gns-proxy.c b/src/gns/gnunet-gns-proxy.c
index 02ebcf0f1..0d7d83b4b 100644
--- a/src/gns/gnunet-gns-proxy.c
+++ b/src/gns/gnunet-gns-proxy.c
@@ -636,7 +636,7 @@ struct Socks5Request
636/** 636/**
637 * The port the proxy is running on (default 7777) 637 * The port the proxy is running on (default 7777)
638 */ 638 */
639static unsigned long long port = GNUNET_GNS_PROXY_PORT; 639static uint16_t port = GNUNET_GNS_PROXY_PORT;
640 640
641/** 641/**
642 * The CA file (pem) to use for the proxy CA 642 * The CA file (pem) to use for the proxy CA
@@ -3399,8 +3399,8 @@ run (void *cls,
3399 return; 3399 return;
3400 } 3400 }
3401 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3401 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3402 "Proxy listens on port %llu\n", 3402 "Proxy listens on port %u\n",
3403 port); 3403 (unsigned int) port);
3404 3404
3405 /* start MHD daemon for HTTP */ 3405 /* start MHD daemon for HTTP */
3406 hd = GNUNET_new (struct MhdHttpList); 3406 hd = GNUNET_new (struct MhdHttpList);
@@ -3437,11 +3437,11 @@ int
3437main (int argc, char *const *argv) 3437main (int argc, char *const *argv)
3438{ 3438{
3439 struct GNUNET_GETOPT_CommandLineOption options[] = { 3439 struct GNUNET_GETOPT_CommandLineOption options[] = {
3440 GNUNET_GETOPT_option_ulong ('p', 3440 GNUNET_GETOPT_option_uint16 ('p',
3441 "port", 3441 "port",
3442 NULL, 3442 NULL,
3443 gettext_noop ("listen on specified port (default: 7777)"), 3443 gettext_noop ("listen on specified port (default: 7777)"),
3444 &port), 3444 &port),
3445 GNUNET_GETOPT_option_string ('a', 3445 GNUNET_GETOPT_option_string ('a',
3446 "authority", 3446 "authority",
3447 NULL, 3447 NULL,
diff --git a/src/include/gnunet_getopt_lib.h b/src/include/gnunet_getopt_lib.h
index e38925f14..88c7825d0 100644
--- a/src/include/gnunet_getopt_lib.h
+++ b/src/include/gnunet_getopt_lib.h
@@ -287,6 +287,23 @@ GNUNET_GETOPT_option_uint (char shortName,
287 287
288 288
289/** 289/**
290 * Allow user to specify an uint16_t.
291 *
292 * @param shortName short name of the option
293 * @param name long name of the option
294 * @param argumentHelp help text for the option argument
295 * @param description long help text for the option
296 * @param[out] val set to the value specified at the command line
297 */
298struct GNUNET_GETOPT_CommandLineOption
299GNUNET_GETOPT_option_uint16 (char shortName,
300 const char *name,
301 const char *argumentHelp,
302 const char *description,
303 uint16_t *val);
304
305
306/**
290 * Allow user to specify an `unsigned long long`. 307 * Allow user to specify an `unsigned long long`.
291 * 308 *
292 * @param shortName short name of the option 309 * @param shortName short name of the option
diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am
index 286f03c4d..8697d0941 100644
--- a/src/transport/Makefile.am
+++ b/src/transport/Makefile.am
@@ -280,7 +280,6 @@ gnunet_service_transport_CFLAGS = \
280 280
281plugin_LTLIBRARIES = \ 281plugin_LTLIBRARIES = \
282 libgnunet_plugin_transport_tcp.la \ 282 libgnunet_plugin_transport_tcp.la \
283 libgnunet_plugin_transport_xt.la \
284 libgnunet_plugin_transport_udp.la \ 283 libgnunet_plugin_transport_udp.la \
285 $(UNIX_PLUGIN_LA) \ 284 $(UNIX_PLUGIN_LA) \
286 $(HTTP_CLIENT_PLUGIN_LA) \ 285 $(HTTP_CLIENT_PLUGIN_LA) \
@@ -290,6 +289,12 @@ plugin_LTLIBRARIES = \
290 $(WLAN_PLUGIN_LA) \ 289 $(WLAN_PLUGIN_LA) \
291 $(BT_PLUGIN_LA) 290 $(BT_PLUGIN_LA)
292 291
292if HAVE_EXPERIMENTAL
293plugin_LTLIBRARIES += \
294 libgnunet_plugin_transport_xt.la \
295 libgnunet_plugin_transport_xu.la
296endif
297
293# Note: real plugins of course need to be added 298# Note: real plugins of course need to be added
294# to the plugin_LTLIBRARIES above 299# to the plugin_LTLIBRARIES above
295noinst_LTLIBRARIES = \ 300noinst_LTLIBRARIES = \
diff --git a/src/transport/plugin_transport_xu.h b/src/transport/plugin_transport_xu.h
new file mode 100644
index 000000000..1884f92e8
--- /dev/null
+++ b/src/transport/plugin_transport_xu.h
@@ -0,0 +1,273 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2010-2014 GNUnet e.V.
4
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.
9
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.
14
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., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/
20
21/**
22 * @file transport/plugin_transport_xu.h
23 * @brief Implementation of the XU transport protocol
24 * @author Christian Grothoff
25 * @author Nathan Evans
26 * @author Matthias Wachs
27 */
28#ifndef PLUGIN_TRANSPORT_XU_H
29#define PLUGIN_TRANSPORT_XU_H
30
31#include "platform.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"
43
44#define LOG(kind,...) GNUNET_log_from (kind, "transport-xu", __VA_ARGS__)
45
46#define PLUGIN_NAME "xu"
47
48#define DEBUG_XU GNUNET_NO
49
50#define DEBUG_XU_BROADCASTING GNUNET_NO
51
52/**
53 * MTU for fragmentation subsystem. Should be conservative since
54 * all communicating peers MUST work with this MTU.
55 */
56#define XU_MTU 1400
57
58
59GNUNET_NETWORK_STRUCT_BEGIN
60/**
61 * Network format for IPv4 addresses.
62 */
63struct IPv4XuAddress
64{
65 /**
66 * Optional options and flags for this address
67 */
68 uint32_t options GNUNET_PACKED;
69
70 /**
71 * IPv4 address, in network byte order.
72 */
73 uint32_t ipv4_addr GNUNET_PACKED;
74
75 /**
76 * Port number, in network byte order.
77 */
78 uint16_t u4_port GNUNET_PACKED;
79};
80
81
82/**
83 * Network format for IPv6 addresses.
84 */
85struct IPv6XuAddress
86{
87 /**
88 * Optional options and flags for this address
89 */
90 uint32_t options GNUNET_PACKED;
91
92 /**
93 * IPv6 address.
94 */
95 struct in6_addr ipv6_addr GNUNET_PACKED;
96
97 /**
98 * Port number, in network byte order.
99 */
100 uint16_t u6_port GNUNET_PACKED;
101};
102GNUNET_NETWORK_STRUCT_END
103
104/**
105 * Either an IPv4 or IPv6 XU address. Note that without a "length",
106 * one cannot tell which one of the two types this address represents.
107 */
108union XuAddress
109{
110 /**
111 * IPv4 case.
112 */
113 struct IPv4XuAddress v4;
114
115 /**
116 * IPv6 case.
117 */
118 struct IPv6XuAddress v6;
119};
120
121
122/**
123 * Information we track for each message in the queue.
124 */
125struct XU_MessageWrapper;
126
127
128/**
129 * Closure for #append_port().
130 */
131struct PrettyPrinterContext;
132
133
134/**
135 * Encapsulation of all of the state of the plugin.
136 */
137struct Plugin
138{
139
140 /**
141 * Our environment.
142 */
143 struct GNUNET_TRANSPORT_PluginEnvironment *env;
144
145 /**
146 * Session of peers with whom we are currently connected,
147 * map of peer identity to `struct GNUNET_ATS_Session *`.
148 */
149 struct GNUNET_CONTAINER_MultiPeerMap *sessions;
150
151 /**
152 * ID of select task for IPv4
153 */
154 struct GNUNET_SCHEDULER_Task *select_task_v4;
155
156 /**
157 * ID of select task for IPv6
158 */
159 struct GNUNET_SCHEDULER_Task *select_task_v6;
160
161 /**
162 * Address we were told to bind to exclusively (IPv4).
163 */
164 char *bind4_address;
165
166 /**
167 * Address we were told to bind to exclusively (IPv6).
168 */
169 char *bind6_address;
170
171 /**
172 * Handle to NAT traversal support.
173 */
174 struct GNUNET_NAT_Handle *nat;
175
176 /**
177 * Handle to NAT traversal support.
178 */
179 struct GNUNET_NAT_STUN_Handle *stun;
180
181 /**
182 * The read socket for IPv4
183 */
184 struct GNUNET_NETWORK_Handle *sockv4;
185
186 /**
187 * The read socket for IPv6
188 */
189 struct GNUNET_NETWORK_Handle *sockv6;
190
191 /**
192 * Running pretty printers: head
193 */
194 struct PrettyPrinterContext *ppc_dll_head;
195
196 /**
197 * Running pretty printers: tail
198 */
199 struct PrettyPrinterContext *ppc_dll_tail;
200
201 /**
202 * Function to call about session status changes.
203 */
204 GNUNET_TRANSPORT_SessionInfoCallback sic;
205
206 /**
207 * Closure for @e sic.
208 */
209 void *sic_cls;
210
211 /**
212 * IPv6 multicast address
213 */
214 struct sockaddr_in6 ipv6_multicast_address;
215
216 /**
217 * Broadcast interval
218 */
219 struct GNUNET_TIME_Relative broadcast_interval;
220
221 /**
222 * Bytes currently in buffer
223 */
224 int64_t bytes_in_buffer;
225
226 /**
227 * Address options
228 */
229 uint32_t myoptions;
230
231 /**
232 * Is IPv6 enabled: #GNUNET_YES or #GNUNET_NO
233 */
234 int enable_ipv6;
235
236 /**
237 * Is IPv4 enabled: #GNUNET_YES or #GNUNET_NO
238 */
239 int enable_ipv4;
240
241 /**
242 * Port we listen on.
243 */
244 uint16_t port;
245
246 /**
247 * Port we advertise on.
248 */
249 uint16_t aport;
250
251};
252
253
254/**
255 * Function called for a quick conversion of the binary address to
256 * a numeric address. Note that the caller must not free the
257 * address and that the next call to this function is allowed
258 * to override the address again.
259 *
260 * @param cls closure
261 * @param addr binary address (a `union XuAddress`)
262 * @param addrlen length of the @a addr
263 * @return string representing the same address
264 */
265const char *
266xu_address_to_string (void *cls,
267 const void *addr,
268 size_t addrlen);
269
270
271/*#ifndef PLUGIN_TRANSPORT_XU_H*/
272#endif
273/* end of plugin_transport_xu.h */
diff --git a/src/util/getopt_helpers.c b/src/util/getopt_helpers.c
index c836c9055..f9341f528 100644
--- a/src/util/getopt_helpers.c
+++ b/src/util/getopt_helpers.c
@@ -793,6 +793,82 @@ GNUNET_GETOPT_option_uint (char shortName,
793} 793}
794 794
795 795
796
797/**
798 * Set an option of type 'uint16_t' from the command line.
799 * A pointer to this function should be passed as part of the
800 * 'struct GNUNET_GETOPT_CommandLineOption' array to initialize options
801 * of this type. It should be followed by a pointer to a value of
802 * type 'uint16_t'.
803 *
804 * @param ctx command line processing context
805 * @param scls additional closure (will point to the 'unsigned int')
806 * @param option name of the option
807 * @param value actual value of the option as a string.
808 * @return #GNUNET_OK if parsing the value worked
809 */
810static int
811set_uint16 (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
812 void *scls,
813 const char *option,
814 const char *value)
815{
816 uint16_t *val = scls;
817 unsigned int v;
818
819 (void) ctx;
820 if (1 != SSCANF (value,
821 "%u",
822 v))
823 {
824 FPRINTF (stderr,
825 _("You must pass a number to the `%s' option.\n"),
826 option);
827 return GNUNET_SYSERR;
828 }
829 if (v > UINT16_MAX)
830 {
831 FPRINTF (stderr,
832 _("You must pass a number below %u to the `%s' option.\n"),
833 (unsigned int) UINT16_MAX,
834 option);
835 return GNUNET_SYSERR;
836 }
837 *val = (uint16_t) v;
838 return GNUNET_OK;
839}
840
841
842/**
843 * Allow user to specify an uint16_t.
844 *
845 * @param shortName short name of the option
846 * @param name long name of the option
847 * @param argumentHelp help text for the option argument
848 * @param description long help text for the option
849 * @param[out] val set to the value specified at the command line
850 */
851struct GNUNET_GETOPT_CommandLineOption
852GNUNET_GETOPT_option_uint16 (char shortName,
853 const char *name,
854 const char *argumentHelp,
855 const char *description,
856 uint16_t *val)
857{
858 struct GNUNET_GETOPT_CommandLineOption clo = {
859 .shortName = shortName,
860 .name = name,
861 .argumentHelp = argumentHelp,
862 .description = description,
863 .require_argument = 1,
864 .processor = &set_uint16,
865 .scls = (void *) val
866 };
867
868 return clo;
869}
870
871
796/** 872/**
797 * Closure for #set_base32(). 873 * Closure for #set_base32().
798 */ 874 */