diff options
Diffstat (limited to 'src/nat/nat_test.c')
-rw-r--r-- | src/nat/nat_test.c | 95 |
1 files changed, 47 insertions, 48 deletions
diff --git a/src/nat/nat_test.c b/src/nat/nat_test.c index 30db00803..74bb758dd 100644 --- a/src/nat/nat_test.c +++ b/src/nat/nat_test.c | |||
@@ -178,8 +178,7 @@ reversal_cb (void *cls, const struct sockaddr *addr, socklen_t addrlen) | |||
178 | if (h->data != sa->sin_port) | 178 | if (h->data != sa->sin_port) |
179 | { | 179 | { |
180 | #if DEBUG_NAT | 180 | #if DEBUG_NAT |
181 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 181 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "nat", |
182 | "nat", | ||
183 | "Received connection reversal request for wrong port\n"); | 182 | "Received connection reversal request for wrong port\n"); |
184 | #endif | 183 | #endif |
185 | return; /* wrong port */ | 184 | return; /* wrong port */ |
@@ -202,11 +201,11 @@ do_udp_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
202 | struct GNUNET_NAT_Test *tst = cls; | 201 | struct GNUNET_NAT_Test *tst = cls; |
203 | uint16_t data; | 202 | uint16_t data; |
204 | 203 | ||
205 | tst->ltask = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, | 204 | tst->ltask = |
206 | tst->lsock, &do_udp_read, tst); | 205 | GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, tst->lsock, |
206 | &do_udp_read, tst); | ||
207 | if ((NULL != tc->write_ready) && | 207 | if ((NULL != tc->write_ready) && |
208 | (GNUNET_NETWORK_fdset_isset (tc->read_ready, | 208 | (GNUNET_NETWORK_fdset_isset (tc->read_ready, tst->lsock)) && |
209 | tst->lsock)) && | ||
210 | (sizeof (data) == | 209 | (sizeof (data) == |
211 | GNUNET_NETWORK_socket_recv (tst->lsock, &data, sizeof (data)))) | 210 | GNUNET_NETWORK_socket_recv (tst->lsock, &data, sizeof (data)))) |
212 | { | 211 | { |
@@ -214,14 +213,14 @@ do_udp_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
214 | tst->report (tst->report_cls, GNUNET_OK); | 213 | tst->report (tst->report_cls, GNUNET_OK); |
215 | #if DEBUG_NAT | 214 | #if DEBUG_NAT |
216 | else | 215 | else |
217 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 216 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "nat", |
218 | "nat", "Received data mismatches expected value\n"); | 217 | "Received data mismatches expected value\n"); |
219 | #endif | 218 | #endif |
220 | } | 219 | } |
221 | #if DEBUG_NAT | 220 | #if DEBUG_NAT |
222 | else | 221 | else |
223 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 222 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "nat", |
224 | "nat", "Failed to receive data from inbound connection\n"); | 223 | "Failed to receive data from inbound connection\n"); |
225 | #endif | 224 | #endif |
226 | } | 225 | } |
227 | 226 | ||
@@ -244,8 +243,7 @@ do_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
244 | tst = na->h; | 243 | tst = na->h; |
245 | GNUNET_CONTAINER_DLL_remove (tst->na_head, tst->na_tail, na); | 244 | GNUNET_CONTAINER_DLL_remove (tst->na_head, tst->na_tail, na); |
246 | if ((NULL != tc->write_ready) && | 245 | if ((NULL != tc->write_ready) && |
247 | (GNUNET_NETWORK_fdset_isset (tc->read_ready, | 246 | (GNUNET_NETWORK_fdset_isset (tc->read_ready, na->sock)) && |
248 | na->sock)) && | ||
249 | (sizeof (data) == | 247 | (sizeof (data) == |
250 | GNUNET_NETWORK_socket_recv (na->sock, &data, sizeof (data)))) | 248 | GNUNET_NETWORK_socket_recv (na->sock, &data, sizeof (data)))) |
251 | { | 249 | { |
@@ -259,8 +257,8 @@ do_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
259 | } | 257 | } |
260 | #if DEBUG_NAT | 258 | #if DEBUG_NAT |
261 | else | 259 | else |
262 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 260 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "nat", |
263 | "nat", "Failed to receive data from inbound connection\n"); | 261 | "Failed to receive data from inbound connection\n"); |
264 | #endif | 262 | #endif |
265 | GNUNET_NETWORK_socket_close (na->sock); | 263 | GNUNET_NETWORK_socket_close (na->sock); |
266 | GNUNET_free (na); | 264 | GNUNET_free (na); |
@@ -284,8 +282,9 @@ do_accept (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
284 | tst->ltask = GNUNET_SCHEDULER_NO_TASK; | 282 | tst->ltask = GNUNET_SCHEDULER_NO_TASK; |
285 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 283 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
286 | return; | 284 | return; |
287 | tst->ltask = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, | 285 | tst->ltask = |
288 | tst->lsock, &do_accept, tst); | 286 | GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, tst->lsock, |
287 | &do_accept, tst); | ||
289 | s = GNUNET_NETWORK_socket_accept (tst->lsock, NULL, NULL); | 288 | s = GNUNET_NETWORK_socket_accept (tst->lsock, NULL, NULL); |
290 | if (NULL == s) | 289 | if (NULL == s) |
291 | { | 290 | { |
@@ -293,14 +292,15 @@ do_accept (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
293 | return; /* odd error */ | 292 | return; /* odd error */ |
294 | } | 293 | } |
295 | #if DEBUG_NAT | 294 | #if DEBUG_NAT |
296 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 295 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "nat", |
297 | "nat", "Got an inbound connection, waiting for data\n"); | 296 | "Got an inbound connection, waiting for data\n"); |
298 | #endif | 297 | #endif |
299 | wl = GNUNET_malloc (sizeof (struct NatActivity)); | 298 | wl = GNUNET_malloc (sizeof (struct NatActivity)); |
300 | wl->sock = s; | 299 | wl->sock = s; |
301 | wl->h = tst; | 300 | wl->h = tst; |
302 | wl->rtask = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, | 301 | wl->rtask = |
303 | wl->sock, &do_read, wl); | 302 | GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, wl->sock, |
303 | &do_read, wl); | ||
304 | GNUNET_CONTAINER_DLL_insert (tst->na_head, tst->na_tail, wl); | 304 | GNUNET_CONTAINER_DLL_insert (tst->na_head, tst->na_tail, wl); |
305 | } | 305 | } |
306 | 306 | ||
@@ -315,8 +315,8 @@ do_accept (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
315 | * @param addrlen actual lenght of the address | 315 | * @param addrlen actual lenght of the address |
316 | */ | 316 | */ |
317 | static void | 317 | static void |
318 | addr_cb (void *cls, | 318 | addr_cb (void *cls, int add_remove, const struct sockaddr *addr, |
319 | int add_remove, const struct sockaddr *addr, socklen_t addrlen) | 319 | socklen_t addrlen) |
320 | { | 320 | { |
321 | struct GNUNET_NAT_Test *h = cls; | 321 | struct GNUNET_NAT_Test *h = cls; |
322 | struct ClientActivity *ca; | 322 | struct ClientActivity *ca; |
@@ -329,8 +329,7 @@ addr_cb (void *cls, | |||
329 | if (addrlen != sizeof (struct sockaddr_in)) | 329 | if (addrlen != sizeof (struct sockaddr_in)) |
330 | return; /* ignore IPv6 here */ | 330 | return; /* ignore IPv6 here */ |
331 | #if DEBUG_NAT | 331 | #if DEBUG_NAT |
332 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 332 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "nat", |
333 | "nat", | ||
334 | "Asking gnunet-nat-server to connect to `%s'\n", | 333 | "Asking gnunet-nat-server to connect to `%s'\n", |
335 | GNUNET_a2s (addr, addrlen)); | 334 | GNUNET_a2s (addr, addrlen)); |
336 | #endif | 335 | #endif |
@@ -353,11 +352,10 @@ addr_cb (void *cls, | |||
353 | ca->client = client; | 352 | ca->client = client; |
354 | GNUNET_CONTAINER_DLL_insert (h->ca_head, h->ca_tail, ca); | 353 | GNUNET_CONTAINER_DLL_insert (h->ca_head, h->ca_tail, ca); |
355 | GNUNET_break (GNUNET_OK == | 354 | GNUNET_break (GNUNET_OK == |
356 | GNUNET_CLIENT_transmit_and_get_response (client, | 355 | GNUNET_CLIENT_transmit_and_get_response (client, &msg.header, |
357 | &msg.header, | ||
358 | GNUNET_TIME_UNIT_SECONDS, | 356 | GNUNET_TIME_UNIT_SECONDS, |
359 | GNUNET_YES, | 357 | GNUNET_YES, NULL, |
360 | NULL, NULL)); | 358 | NULL)); |
361 | } | 359 | } |
362 | 360 | ||
363 | 361 | ||
@@ -375,9 +373,7 @@ addr_cb (void *cls, | |||
375 | */ | 373 | */ |
376 | struct GNUNET_NAT_Test * | 374 | struct GNUNET_NAT_Test * |
377 | GNUNET_NAT_test_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | 375 | GNUNET_NAT_test_start (const struct GNUNET_CONFIGURATION_Handle *cfg, |
378 | int is_tcp, | 376 | int is_tcp, uint16_t bnd_port, uint16_t adv_port, |
379 | uint16_t bnd_port, | ||
380 | uint16_t adv_port, | ||
381 | GNUNET_NAT_TestCallback report, void *report_cls) | 377 | GNUNET_NAT_TestCallback report, void *report_cls) |
382 | { | 378 | { |
383 | struct GNUNET_NAT_Test *ret; | 379 | struct GNUNET_NAT_Test *ret; |
@@ -401,19 +397,21 @@ GNUNET_NAT_test_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
401 | ret->report_cls = report_cls; | 397 | ret->report_cls = report_cls; |
402 | if (bnd_port == 0) | 398 | if (bnd_port == 0) |
403 | { | 399 | { |
404 | ret->nat = GNUNET_NAT_register (cfg, is_tcp, | 400 | ret->nat = |
405 | 0, | 401 | GNUNET_NAT_register (cfg, is_tcp, 0, 0, NULL, NULL, &addr_cb, |
406 | 0, NULL, NULL, &addr_cb, &reversal_cb, ret); | 402 | &reversal_cb, ret); |
407 | } | 403 | } |
408 | else | 404 | else |
409 | { | 405 | { |
410 | ret->lsock = GNUNET_NETWORK_socket_create (AF_INET, | 406 | ret->lsock = |
411 | (is_tcp == GNUNET_YES) | 407 | GNUNET_NETWORK_socket_create (AF_INET, |
412 | ? SOCK_STREAM : SOCK_DGRAM, 0); | 408 | (is_tcp == |
409 | GNUNET_YES) ? SOCK_STREAM : SOCK_DGRAM, | ||
410 | 0); | ||
413 | if ((ret->lsock == NULL) || | 411 | if ((ret->lsock == NULL) || |
414 | (GNUNET_OK != GNUNET_NETWORK_socket_bind (ret->lsock, | 412 | (GNUNET_OK != |
415 | (const struct sockaddr *) &sa, | 413 | GNUNET_NETWORK_socket_bind (ret->lsock, (const struct sockaddr *) &sa, |
416 | sizeof (sa)))) | 414 | sizeof (sa)))) |
417 | { | 415 | { |
418 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 416 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
419 | _ | 417 | _ |
@@ -428,18 +426,19 @@ GNUNET_NAT_test_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
428 | if (GNUNET_YES == is_tcp) | 426 | if (GNUNET_YES == is_tcp) |
429 | { | 427 | { |
430 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_listen (ret->lsock, 5)); | 428 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_listen (ret->lsock, 5)); |
431 | ret->ltask = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, | 429 | ret->ltask = |
432 | ret->lsock, &do_accept, ret); | 430 | GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, |
431 | ret->lsock, &do_accept, ret); | ||
433 | } | 432 | } |
434 | else | 433 | else |
435 | { | 434 | { |
436 | ret->ltask = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, | 435 | ret->ltask = |
437 | ret->lsock, | 436 | GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, |
438 | &do_udp_read, ret); | 437 | ret->lsock, &do_udp_read, ret); |
439 | } | 438 | } |
440 | ret->nat = GNUNET_NAT_register (cfg, is_tcp, | 439 | ret->nat = |
441 | adv_port, | 440 | GNUNET_NAT_register (cfg, is_tcp, adv_port, 1, addrs, addrlens, |
442 | 1, addrs, addrlens, &addr_cb, NULL, ret); | 441 | &addr_cb, NULL, ret); |
443 | } | 442 | } |
444 | return ret; | 443 | return ret; |
445 | } | 444 | } |