aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-07-01 21:30:28 +0000
committerChristian Grothoff <christian@grothoff.org>2011-07-01 21:30:28 +0000
commite3f24011c0e95a67d673b43348202b7751574474 (patch)
tree89fff5172468c23f762c3db9c531b3e792da56dc
parent490cf7e092613f7c511b46332710187336eb3a6a (diff)
downloadgnunet-e3f24011c0e95a67d673b43348202b7751574474.tar.gz
gnunet-e3f24011c0e95a67d673b43348202b7751574474.zip
testcase for nat test code
-rw-r--r--contrib/defaults.conf3
-rw-r--r--src/nat/Makefile.am18
-rw-r--r--src/nat/gnunet-nat-server.c33
-rw-r--r--src/nat/nat.c4
-rw-r--r--src/nat/nat_test.c72
-rw-r--r--src/nat/test_nat_test.c133
-rw-r--r--src/nat/test_nat_test_data.conf43
-rw-r--r--src/util/client.c9
-rw-r--r--src/util/network.c7
-rw-r--r--src/util/program.c9
10 files changed, 302 insertions, 29 deletions
diff --git a/contrib/defaults.conf b/contrib/defaults.conf
index f5a0c8c7e..a634988a1 100644
--- a/contrib/defaults.conf
+++ b/contrib/defaults.conf
@@ -65,6 +65,9 @@ IFC_SCAN_FREQUENCY = 3000000
65# for our hostname (to get our own IP), in ms 65# for our hostname (to get our own IP), in ms
66DYNDNS_FREQUENCY = 140000 66DYNDNS_FREQUENCY = 140000
67 67
68[gnunet-nat-server]
69HOSTNAME = nat.gnunet.org
70PORT = 5724
68 71
69[transport-tcp] 72[transport-tcp]
70# Use 0 to ONLY advertise as a peer behind NAT (no port binding) 73# Use 0 to ONLY advertise as a peer behind NAT (no port binding)
diff --git a/src/nat/Makefile.am b/src/nat/Makefile.am
index 7b738df4e..5aafdb240 100644
--- a/src/nat/Makefile.am
+++ b/src/nat/Makefile.am
@@ -54,7 +54,8 @@ libgnunetnat_la_LDFLAGS = \
54 -version-info 0:0:0 54 -version-info 0:0:0
55 55
56check_PROGRAMS = \ 56check_PROGRAMS = \
57 test-nat 57 test_nat \
58 test_nat_test
58 59
59if ENABLE_TEST_RUN 60if ENABLE_TEST_RUN
60 TESTS = $(check_PROGRAMS) 61 TESTS = $(check_PROGRAMS)
@@ -62,11 +63,18 @@ endif
62 63
63test_nat_SOURCES = \ 64test_nat_SOURCES = \
64 test_nat.c 65 test_nat.c
65
66test_nat_LDADD = \ 66test_nat_LDADD = \
67 $(top_builddir)/src/nat/libgnunetnat.la \ 67 $(top_builddir)/src/nat/libgnunetnat.la \
68 $(top_builddir)/src/util/libgnunetutil.la \ 68 $(top_builddir)/src/util/libgnunetutil.la
69 @LIBCURL@ 69
70
71test_nat_test_SOURCES = \
72 test_nat_test.c
73test_nat_test_LDADD = \
74 $(top_builddir)/src/nat/libgnunetnat.la \
75 $(top_builddir)/src/util/libgnunetutil.la
76
70 77
71EXTRA_DIST = \ 78EXTRA_DIST = \
72 test_nat_data.conf 79 test_nat_data.conf \
80 test_nat_test_data.conf \ No newline at end of file
diff --git a/src/nat/gnunet-nat-server.c b/src/nat/gnunet-nat-server.c
index f2508a94a..f8951d4d2 100644
--- a/src/nat/gnunet-nat-server.c
+++ b/src/nat/gnunet-nat-server.c
@@ -39,6 +39,7 @@ static struct GNUNET_SERVER_Handle *server;
39 */ 39 */
40static const struct GNUNET_CONFIGURATION_Handle *cfg; 40static const struct GNUNET_CONFIGURATION_Handle *cfg;
41 41
42
42/** 43/**
43 * Try contacting the peer using autonomous 44 * Try contacting the peer using autonomous
44 * NAT traveral method. 45 * NAT traveral method.
@@ -55,12 +56,17 @@ try_anat (uint32_t dst_ipv4,
55 struct GNUNET_NAT_Handle *h; 56 struct GNUNET_NAT_Handle *h;
56 struct sockaddr_in sa; 57 struct sockaddr_in sa;
57 58
59 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
60 "Asking for connection reversal with %x and code %u\n",
61 (unsigned int) dst_ipv4,
62 (unsigned int) dport);
58 h = GNUNET_NAT_register (cfg, 63 h = GNUNET_NAT_register (cfg,
59 is_tcp, 64 is_tcp,
60 dport, 65 dport,
61 0, NULL, NULL, 66 0, NULL, NULL,
62 NULL, NULL, NULL); 67 NULL, NULL, NULL);
63 memset (&sa, 0, sizeof (sa)); 68 memset (&sa, 0, sizeof (sa));
69 sa.sin_family = AF_INET;
64#if HAVE_SOCKADDR_IN_SIN_LEN 70#if HAVE_SOCKADDR_IN_SIN_LEN
65 sa.sin_len = sizeof (sa); 71 sa.sin_len = sizeof (sa);
66#endif 72#endif
@@ -105,7 +111,7 @@ tcp_send (void *cls,
105 ctx->s)) ) 111 ctx->s)) )
106 { 112 {
107 if (-1 == GNUNET_NETWORK_socket_send (ctx->s, &ctx->data, sizeof (ctx->data))) 113 if (-1 == GNUNET_NETWORK_socket_send (ctx->s, &ctx->data, sizeof (ctx->data)))
108 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "send"); 114 GNUNET_log_strerror (GNUNET_ERROR_TYPE_DEBUG, "send");
109 GNUNET_NETWORK_socket_shutdown (ctx->s, SHUT_RDWR); 115 GNUNET_NETWORK_socket_shutdown (ctx->s, SHUT_RDWR);
110 } 116 }
111 GNUNET_NETWORK_socket_close (ctx->s); 117 GNUNET_NETWORK_socket_close (ctx->s);
@@ -130,18 +136,22 @@ try_send_tcp (uint32_t dst_ipv4,
130 struct sockaddr_in sa; 136 struct sockaddr_in sa;
131 struct TcpContext *ctx; 137 struct TcpContext *ctx;
132 138
133 s = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_STREAM, 0); 139 s = GNUNET_NETWORK_socket_create (AF_INET, SOCK_STREAM, 0);
134 if (NULL == s) 140 if (NULL == s)
135 { 141 {
136 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "socket"); 142 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "socket");
137 return; 143 return;
138 } 144 }
139 memset (&sa, 0, sizeof (sa)); 145 memset (&sa, 0, sizeof (sa));
146 sa.sin_family = AF_INET;
140#if HAVE_SOCKADDR_IN_SIN_LEN 147#if HAVE_SOCKADDR_IN_SIN_LEN
141 sa.sin_len = sizeof (sa); 148 sa.sin_len = sizeof (sa);
142#endif 149#endif
143 sa.sin_addr.s_addr = dst_ipv4; 150 sa.sin_addr.s_addr = dst_ipv4;
144 sa.sin_port = htons (dport); 151 sa.sin_port = htons (dport);
152 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
153 "Sending TCP message to `%s'\n",
154 GNUNET_a2s ((struct sockaddr*) &sa, sizeof (sa)));
145 if ( (GNUNET_OK != 155 if ( (GNUNET_OK !=
146 GNUNET_NETWORK_socket_connect (s, 156 GNUNET_NETWORK_socket_connect (s,
147 (const struct sockaddr*) &sa, sizeof (sa))) && 157 (const struct sockaddr*) &sa, sizeof (sa))) &&
@@ -176,19 +186,25 @@ try_send_udp (uint32_t dst_ipv4,
176 struct GNUNET_NETWORK_Handle *s; 186 struct GNUNET_NETWORK_Handle *s;
177 struct sockaddr_in sa; 187 struct sockaddr_in sa;
178 188
179 s = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_DGRAM, 0); 189 s = GNUNET_NETWORK_socket_create (AF_INET, SOCK_DGRAM, 0);
180 if (NULL == s) 190 if (NULL == s)
181 { 191 {
182 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "socket"); 192 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "socket");
183 return; 193 return;
184 } 194 }
185 memset (&sa, 0, sizeof (sa)); 195 memset (&sa, 0, sizeof (sa));
196 sa.sin_family = AF_INET;
186#if HAVE_SOCKADDR_IN_SIN_LEN 197#if HAVE_SOCKADDR_IN_SIN_LEN
187 sa.sin_len = sizeof (sa); 198 sa.sin_len = sizeof (sa);
188#endif 199#endif
189 sa.sin_addr.s_addr = dst_ipv4; 200 sa.sin_addr.s_addr = dst_ipv4;
190 sa.sin_port = htons (dport); 201 sa.sin_port = htons (dport);
191 if (-1 == GNUNET_NETWORK_socket_sendto (s, &data, sizeof(data), (const struct sockaddr*) &sa, sizeof (sa))) 202 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
203 "Sending UDP packet to `%s'\n",
204 GNUNET_a2s ((struct sockaddr*) &sa, sizeof (sa)));
205 if (-1 == GNUNET_NETWORK_socket_sendto (s,
206 &data, sizeof(data),
207 (const struct sockaddr*) &sa, sizeof (sa)))
192 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "sendto"); 208 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "sendto");
193 GNUNET_NETWORK_socket_close (s); 209 GNUNET_NETWORK_socket_close (s);
194} 210}
@@ -210,6 +226,8 @@ test (void *cls,
210 const struct GNUNET_NAT_TestMessage *tm; 226 const struct GNUNET_NAT_TestMessage *tm;
211 uint16_t dport; 227 uint16_t dport;
212 228
229 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
230 "Received test request\n");
213 tm = (const struct GNUNET_NAT_TestMessage*) msg; 231 tm = (const struct GNUNET_NAT_TestMessage*) msg;
214 dport = ntohs (tm->dport); 232 dport = ntohs (tm->dport);
215 if (0 == dport) 233 if (0 == dport)
@@ -279,15 +297,18 @@ run (void *cls,
279 if ( (args[0] == NULL) || 297 if ( (args[0] == NULL) ||
280 (1 != SSCANF (args[0], "%u", &port)) || 298 (1 != SSCANF (args[0], "%u", &port)) ||
281 (0 == port) || 299 (0 == port) ||
282 (65536 >= port) ) 300 (65536 <= port) )
283 { 301 {
284 fprintf (stderr, 302 fprintf (stderr,
285 _("Please pass valid port number as the first argument!\n")); 303 _("Please pass valid port number as the first argument! (got `%s')\n"),
304 args[0]);
286 return; 305 return;
287 } 306 }
288 memset (&in4, 0, sizeof (in4)); 307 memset (&in4, 0, sizeof (in4));
289 memset (&in6, 0, sizeof (in6)); 308 memset (&in6, 0, sizeof (in6));
309 in4.sin_family = AF_INET;
290 in4.sin_port = htons ((uint16_t) port); 310 in4.sin_port = htons ((uint16_t) port);
311 in6.sin6_family = AF_INET6;
291 in6.sin6_port = htons ((uint16_t) port); 312 in6.sin6_port = htons ((uint16_t) port);
292#if HAVE_SOCKADDR_IN_SIN_LEN 313#if HAVE_SOCKADDR_IN_SIN_LEN
293 in4.sin_len = sizeof (in); 314 in4.sin_len = sizeof (in);
diff --git a/src/nat/nat.c b/src/nat/nat.c
index 4e78c5d24..d62dc0408 100644
--- a/src/nat/nat.c
+++ b/src/nat/nat.c
@@ -51,9 +51,9 @@
51#define DYNDNS_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 7) 51#define DYNDNS_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 7)
52 52
53/** 53/**
54 * How long until we give up on transmitting the welcome message? 54 * How long until we give up trying to resolve our own hostname?
55 */ 55 */
56#define HOSTNAME_RESOLVE_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) 56#define HOSTNAME_RESOLVE_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
57 57
58 58
59/** 59/**
diff --git a/src/nat/nat_test.c b/src/nat/nat_test.c
index 74b2dddec..9b07b48f9 100644
--- a/src/nat/nat_test.c
+++ b/src/nat/nat_test.c
@@ -62,6 +62,29 @@ struct NatActivity
62 62
63 63
64/** 64/**
65 * Entry we keep for each connection to the gnunet-nat-service.
66 */
67struct ClientActivity
68{
69 /**
70 * This is a doubly-linked list.
71 */
72 struct ClientActivity *next;
73
74 /**
75 * This is a doubly-linked list.
76 */
77 struct ClientActivity *prev;
78
79 /**
80 * Socket of the incoming connection.
81 */
82 struct GNUNET_CLIENT_Connection *client;
83
84};
85
86
87/**
65 * Handle to a NAT test. 88 * Handle to a NAT test.
66 */ 89 */
67struct GNUNET_NAT_Test 90struct GNUNET_NAT_Test
@@ -95,12 +118,22 @@ struct GNUNET_NAT_Test
95 /** 118 /**
96 * Head of list of nat activities. 119 * Head of list of nat activities.
97 */ 120 */
98 struct NatActivity *head; 121 struct NatActivity *na_head;
99 122
100 /** 123 /**
101 * Tail of list of nat activities. 124 * Tail of list of nat activities.
102 */ 125 */
103 struct NatActivity *tail; 126 struct NatActivity *na_tail;
127
128 /**
129 * Head of list of client activities.
130 */
131 struct ClientActivity *ca_head;
132
133 /**
134 * Tail of list of client activities.
135 */
136 struct ClientActivity *ca_tail;
104 137
105 /** 138 /**
106 * Identity of task for the listen socket (if any) 139 * Identity of task for the listen socket (if any)
@@ -172,8 +205,8 @@ do_read (void *cls,
172 205
173 na->rtask = GNUNET_SCHEDULER_NO_TASK; 206 na->rtask = GNUNET_SCHEDULER_NO_TASK;
174 tst = na->h; 207 tst = na->h;
175 GNUNET_CONTAINER_DLL_remove (tst->head, 208 GNUNET_CONTAINER_DLL_remove (tst->na_head,
176 tst->tail, 209 tst->na_tail,
177 na); 210 na);
178 if ( (NULL != tc->write_ready) && 211 if ( (NULL != tc->write_ready) &&
179 (GNUNET_NETWORK_fdset_isset (tc->read_ready, 212 (GNUNET_NETWORK_fdset_isset (tc->read_ready,
@@ -234,8 +267,8 @@ do_accept (void *cls,
234 wl->sock, 267 wl->sock,
235 &do_read, 268 &do_read,
236 wl); 269 wl);
237 GNUNET_CONTAINER_DLL_insert (tst->head, 270 GNUNET_CONTAINER_DLL_insert (tst->na_head,
238 tst->tail, 271 tst->na_tail,
239 wl); 272 wl);
240} 273}
241 274
@@ -256,6 +289,7 @@ addr_cb (void *cls,
256 socklen_t addrlen) 289 socklen_t addrlen)
257{ 290{
258 struct GNUNET_NAT_Test *h = cls; 291 struct GNUNET_NAT_Test *h = cls;
292 struct ClientActivity *ca;
259 struct GNUNET_CLIENT_Connection *client; 293 struct GNUNET_CLIENT_Connection *client;
260 struct GNUNET_NAT_TestMessage msg; 294 struct GNUNET_NAT_TestMessage msg;
261 const struct sockaddr_in *sa; 295 const struct sockaddr_in *sa;
@@ -264,6 +298,9 @@ addr_cb (void *cls,
264 return; 298 return;
265 if (addrlen != sizeof (struct sockaddr_in)) 299 if (addrlen != sizeof (struct sockaddr_in))
266 return; /* ignore IPv6 here */ 300 return; /* ignore IPv6 here */
301 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
302 "Asking gnunet-nat-server to connect to `%s'\n",
303 GNUNET_a2s (addr, addrlen));
267 sa = (const struct sockaddr_in*) addr; 304 sa = (const struct sockaddr_in*) addr;
268 msg.header.size = htons (sizeof(struct GNUNET_NAT_TestMessage)); 305 msg.header.size = htons (sizeof(struct GNUNET_NAT_TestMessage));
269 msg.header.type = htons (GNUNET_MESSAGE_TYPE_NAT_TEST); 306 msg.header.type = htons (GNUNET_MESSAGE_TYPE_NAT_TEST);
@@ -274,13 +311,19 @@ addr_cb (void *cls,
274 311
275 client = GNUNET_CLIENT_connect ("gnunet-nat-server", 312 client = GNUNET_CLIENT_connect ("gnunet-nat-server",
276 h->cfg); 313 h->cfg);
314 if (NULL == client)
315 return;
316 ca = GNUNET_malloc (sizeof (struct ClientActivity));
317 ca->client = client;
318 GNUNET_CONTAINER_DLL_insert (h->ca_head,
319 h->ca_tail,
320 ca);
277 GNUNET_break (GNUNET_OK == 321 GNUNET_break (GNUNET_OK ==
278 GNUNET_CLIENT_transmit_and_get_response (client, 322 GNUNET_CLIENT_transmit_and_get_response (client,
279 &msg.header, 323 &msg.header,
280 GNUNET_TIME_UNIT_SECONDS, 324 GNUNET_TIME_UNIT_SECONDS,
281 GNUNET_YES, 325 GNUNET_YES,
282 NULL, NULL)); 326 NULL, NULL));
283 GNUNET_CLIENT_disconnect (client, GNUNET_YES);
284} 327}
285 328
286 329
@@ -369,11 +412,20 @@ void
369GNUNET_NAT_test_stop (struct GNUNET_NAT_Test *tst) 412GNUNET_NAT_test_stop (struct GNUNET_NAT_Test *tst)
370{ 413{
371 struct NatActivity *pos; 414 struct NatActivity *pos;
415 struct ClientActivity *cpos;
372 416
373 while (NULL != (pos = tst->head)) 417 while (NULL != (cpos = tst->ca_head))
418 {
419 GNUNET_CONTAINER_DLL_remove (tst->ca_head,
420 tst->ca_tail,
421 cpos);
422 GNUNET_CLIENT_disconnect (cpos->client, GNUNET_NO);
423 GNUNET_free (cpos);
424 }
425 while (NULL != (pos = tst->na_head))
374 { 426 {
375 GNUNET_CONTAINER_DLL_remove (tst->head, 427 GNUNET_CONTAINER_DLL_remove (tst->na_head,
376 tst->tail, 428 tst->na_tail,
377 pos); 429 pos);
378 GNUNET_SCHEDULER_cancel (pos->rtask); 430 GNUNET_SCHEDULER_cancel (pos->rtask);
379 GNUNET_NETWORK_socket_close (pos->sock); 431 GNUNET_NETWORK_socket_close (pos->sock);
diff --git a/src/nat/test_nat_test.c b/src/nat/test_nat_test.c
new file mode 100644
index 000000000..3b20a9abd
--- /dev/null
+++ b/src/nat/test_nat_test.c
@@ -0,0 +1,133 @@
1/*
2 This file is part of GNUnet.
3 (C) 2009, 2011 Christian Grothoff (and other contributing authors)
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., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/**
22 * Testcase for the NAT testing code.
23 *
24 * @file nat/test_nat_test.c
25 * @brief Testcase for NAT testing functions
26 * @author Christian Grothoff
27 */
28#include "platform.h"
29#include "gnunet_common.h"
30#include "gnunet_util_lib.h"
31#include "gnunet_nat_lib.h"
32
33
34#define VERBOSE GNUNET_YES
35
36
37/**
38 * Time to wait before stopping NAT test, in seconds
39 */
40#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15)
41
42
43static int ret = 1;
44
45static struct GNUNET_NAT_Test *tst;
46
47static GNUNET_SCHEDULER_TaskIdentifier end;
48
49static void
50end_test (void *cls,
51 const struct GNUNET_SCHEDULER_TaskContext *tc)
52{
53 GNUNET_NAT_test_stop (tst);
54}
55
56static void
57report_success (void *cls,
58 int success)
59{
60 GNUNET_assert (GNUNET_OK == success);
61 ret = 0;
62 GNUNET_SCHEDULER_cancel (end);
63 end = GNUNET_SCHEDULER_add_now (&end_test, NULL);
64}
65
66/**
67 * Main function run with scheduler.
68 */
69static void
70run (void *cls,
71 char *const *args,
72 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
73{
74 tst = GNUNET_NAT_test_start (cfg, GNUNET_YES,
75 1285, 1285,
76 &report_success, NULL);
77 if (NULL == tst)
78 return;
79 end = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
80 &end_test,
81 NULL);
82}
83
84
85int
86main (int argc, char *const argv[])
87{
88 struct GNUNET_GETOPT_CommandLineOption options[] = {
89 GNUNET_GETOPT_OPTION_END
90 };
91 struct GNUNET_OS_Process *gns;
92 char *const argv_prog[] = {
93 "test-nat-test",
94 "-c",
95 "test_nat_test_data.conf",
96 "-L",
97#if VERBOSE
98 "DEBUG",
99#else
100 "WARNING",
101#endif
102 NULL
103 };
104
105 GNUNET_log_setup ("test-nat-test",
106#if VERBOSE
107 "DEBUG",
108#else
109 "WARNING",
110#endif
111 NULL);
112 gns = GNUNET_OS_start_process (NULL, NULL,
113 "gnunet-nat-server",
114 "gnunet-nat-server",
115#if VERBOSE
116 "-L",
117 "DEBUG",
118#endif
119 "12345",
120 NULL);
121 GNUNET_assert (NULL != gns);
122 GNUNET_PROGRAM_run (5, argv_prog,
123 "test-nat-test", "nohelp",
124 options,
125 &run, NULL);
126 GNUNET_break (0 == GNUNET_OS_process_kill (gns, SIGTERM));
127 GNUNET_break (GNUNET_OK ==
128 GNUNET_OS_process_wait (gns));
129 GNUNET_OS_process_close (gns);
130 return ret;
131}
132
133/* end of test_nat_test.c */
diff --git a/src/nat/test_nat_test_data.conf b/src/nat/test_nat_test_data.conf
new file mode 100644
index 000000000..41324bb0a
--- /dev/null
+++ b/src/nat/test_nat_test_data.conf
@@ -0,0 +1,43 @@
1[PATHS]
2SERVICEHOME = /tmp/nat-test
3# SERVICEHOME = /var/lib/gnunet/
4# DEFAULTCONFIG = /etc/gnunet.conf
5# If 'DEFAULTCONFIG' is not defined, the current
6# configuration file is assumed to be the default,
7# which is what we want by default...
8
9[gnunet-nat-server]
10HOSTNAME = localhost
11PORT = 12345
12
13[nat]
14# Are we behind NAT?
15BEHIND_NAT = YES
16
17# Is the NAT hole-punched?
18PUNCHED_NAT = NO
19
20# Disable UPNP by default until it gets cleaner!
21ENABLE_UPNP = YES
22
23# Use addresses from the local network interfaces (inluding loopback, but also others)
24USE_LOCALADDR = YES
25
26# External IP address of the NAT box (if known); IPv4 dotted-decimal ONLY at this time (should allow DynDNS!)
27# normal interface IP address for non-NATed peers;
28# possibly auto-detected (using UPnP) if possible if not specified
29# EXTERNAL_ADDRESS =
30
31# Should we use ICMP-based NAT traversal to try connect to NATed peers
32# or, if we are behind NAT, to allow connections to us?
33ENABLE_ICMP_CLIENT = YES
34ENABLE_ICMP_SERVER = YES
35
36# IP address of the interface connected to the NAT box; IPv4 dotted-decimal ONLY;
37# normal interface IP address for non-NATed peers;
38# likely auto-detected (via interface list) if not specified (!)
39INTERNAL_ADDRESS = 127.0.0.1
40
41# Disable IPv6 support
42DISABLEV6 = YES
43x
diff --git a/src/util/client.c b/src/util/client.c
index c81c4eef0..b57b7bb4a 100644
--- a/src/util/client.c
+++ b/src/util/client.c
@@ -527,7 +527,8 @@ receive_helper (void *cls,
527 if (remaining.rel_value == 0) 527 if (remaining.rel_value == 0)
528 { 528 {
529 /* signal timeout! */ 529 /* signal timeout! */
530 conn->receiver_handler (conn->receiver_handler_cls, NULL); 530 if (NULL != conn->receiver_handler)
531 conn->receiver_handler (conn->receiver_handler_cls, NULL);
531 return; 532 return;
532 } 533 }
533 /* back to receive -- either for more data or to call callback! */ 534 /* back to receive -- either for more data or to call callback! */
@@ -593,7 +594,8 @@ GNUNET_CLIENT_receive (struct GNUNET_CLIENT_Connection *sock,
593 { 594 {
594 /* already disconnected, fail instantly! */ 595 /* already disconnected, fail instantly! */
595 GNUNET_break (0); /* this should not happen in well-written code! */ 596 GNUNET_break (0); /* this should not happen in well-written code! */
596 handler (handler_cls, NULL); 597 if (NULL != handler)
598 handler (handler_cls, NULL);
597 return; 599 return;
598 } 600 }
599 sock->receiver_handler = handler; 601 sock->receiver_handler = handler;
@@ -1009,7 +1011,8 @@ transmit_for_response (void *cls, size_t size, void *buf)
1009 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1011 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1010 _("Could not submit request, not expecting to receive a response.\n")); 1012 _("Could not submit request, not expecting to receive a response.\n"));
1011#endif 1013#endif
1012 tc->rn (tc->rn_cls, NULL); 1014 if (NULL != tc->rn)
1015 tc->rn (tc->rn_cls, NULL);
1013 GNUNET_free (tc); 1016 GNUNET_free (tc);
1014 return 0; 1017 return 0;
1015 } 1018 }
diff --git a/src/util/network.c b/src/util/network.c
index e51d7fdab..726e29511 100644
--- a/src/util/network.c
+++ b/src/util/network.c
@@ -219,7 +219,10 @@ GNUNET_NETWORK_socket_accept (const struct GNUNET_NETWORK_Handle *desc,
219 219
220 ret = GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle)); 220 ret = GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle));
221 ret->fd = accept (desc->fd, address, address_len); 221 ret->fd = accept (desc->fd, address, address_len);
222 ret->af = address->sa_family; 222 if (address != NULL)
223 ret->af = address->sa_family;
224 else
225 ret->af = desc->af;
223 if (ret->fd == INVALID_SOCKET) 226 if (ret->fd == INVALID_SOCKET)
224 { 227 {
225#ifdef MINGW 228#ifdef MINGW
@@ -256,7 +259,7 @@ GNUNET_NETWORK_socket_accept (const struct GNUNET_NETWORK_Handle *desc,
256 socket_set_nosigpipe (ret); 259 socket_set_nosigpipe (ret);
257#endif 260#endif
258#ifdef AF_UNIX 261#ifdef AF_UNIX
259 if (address->sa_family != AF_UNIX) 262 if (ret->af != AF_UNIX)
260#endif 263#endif
261 socket_set_nodelay (ret); 264 socket_set_nodelay (ret);
262 return ret; 265 return ret;
diff --git a/src/util/program.c b/src/util/program.c
index 8fd77637f..c5fe0b573 100644
--- a/src/util/program.c
+++ b/src/util/program.c
@@ -144,6 +144,8 @@ GNUNET_PROGRAM_run (int argc,
144 }; 144 };
145 struct GNUNET_GETOPT_CommandLineOption *allopts; 145 struct GNUNET_GETOPT_CommandLineOption *allopts;
146 const char *gargs; 146 const char *gargs;
147 char *lpfx;
148 char *spc;
147 149
148 logfile = NULL; 150 logfile = NULL;
149 gargs = getenv ("GNUNET_ARGS"); 151 gargs = getenv ("GNUNET_ARGS");
@@ -206,11 +208,14 @@ GNUNET_PROGRAM_run (int argc,
206 &cmd_sorter); 208 &cmd_sorter);
207 loglev = GNUNET_strdup ("WARNING"); 209 loglev = GNUNET_strdup ("WARNING");
208 cc.cfgfile = GNUNET_strdup (GNUNET_DEFAULT_USER_CONFIG_FILE); 210 cc.cfgfile = GNUNET_strdup (GNUNET_DEFAULT_USER_CONFIG_FILE);
211 lpfx = GNUNET_strdup (binaryName);
212 if (NULL != (spc = strstr (lpfx, " ")))
213 *spc = '\0';
209 if ((-1 == (ret = GNUNET_GETOPT_run (binaryName, 214 if ((-1 == (ret = GNUNET_GETOPT_run (binaryName,
210 allopts, 215 allopts,
211 (unsigned int) argc, argv))) || 216 (unsigned int) argc, argv))) ||
212 ((GNUNET_OK != 217 ((GNUNET_OK !=
213 GNUNET_log_setup (binaryName, 218 GNUNET_log_setup (lpfx,
214 loglev, 219 loglev,
215 logfile)) || 220 logfile)) ||
216 (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, cc.cfgfile)))) 221 (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, cc.cfgfile))))
@@ -219,9 +224,11 @@ GNUNET_PROGRAM_run (int argc,
219 GNUNET_free_non_null (cc.cfgfile); 224 GNUNET_free_non_null (cc.cfgfile);
220 GNUNET_free (loglev); 225 GNUNET_free (loglev);
221 GNUNET_free (allopts); 226 GNUNET_free (allopts);
227 GNUNET_free (lpfx);
222 return GNUNET_SYSERR; 228 return GNUNET_SYSERR;
223 } 229 }
224 GNUNET_free (allopts); 230 GNUNET_free (allopts);
231 GNUNET_free (lpfx);
225 232
226 /* run */ 233 /* run */
227 cc.args = &argv[ret]; 234 cc.args = &argv[ret];