aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-02-09 14:27:59 +0000
committerChristian Grothoff <christian@grothoff.org>2015-02-09 14:27:59 +0000
commit6806f421c1164921cfa265ddc7009c08986bc915 (patch)
tree9c1de8556bae9ee459bbf5ec13814cbbcc95c144 /src
parent336a09367ceb678108a4bd13aeb852d90b8776e5 (diff)
downloadgnunet-6806f421c1164921cfa265ddc7009c08986bc915.tar.gz
gnunet-6806f421c1164921cfa265ddc7009c08986bc915.zip
-tolerateNAT instant reporting
Diffstat (limited to 'src')
-rw-r--r--src/transport/test_plugin_transport.c227
1 files changed, 128 insertions, 99 deletions
diff --git a/src/transport/test_plugin_transport.c b/src/transport/test_plugin_transport.c
index bad07f7fb..1bd0a2dcd 100644
--- a/src/transport/test_plugin_transport.c
+++ b/src/transport/test_plugin_transport.c
@@ -129,8 +129,12 @@ struct AddressWrapper
129 struct GNUNET_HELLO_Address *address; 129 struct GNUNET_HELLO_Address *address;
130 130
131 char *addrstring; 131 char *addrstring;
132
133 struct GNUNET_SCHEDULER_Task *test_task;
134
132}; 135};
133 136
137
134static void 138static void
135end () 139end ()
136{ 140{
@@ -149,8 +153,9 @@ end ()
149 while (NULL != head) 153 while (NULL != head)
150 { 154 {
151 w = head; 155 w = head;
152 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Plugin did not remove address `%s'\n", 156 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
153 w->addrstring); 157 "Plugin did not remove address `%s'\n",
158 w->addrstring);
154 GNUNET_CONTAINER_DLL_remove(head, tail, w); 159 GNUNET_CONTAINER_DLL_remove(head, tail, w);
155 c++; 160 c++;
156 GNUNET_HELLO_address_free(w->address); 161 GNUNET_HELLO_address_free(w->address);
@@ -177,6 +182,7 @@ end ()
177 } 182 }
178} 183}
179 184
185
180static void 186static void
181end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 187end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
182{ 188{
@@ -221,6 +227,8 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
221 GNUNET_CONTAINER_DLL_remove(head, tail, w); 227 GNUNET_CONTAINER_DLL_remove(head, tail, w);
222 c++; 228 c++;
223 GNUNET_HELLO_address_free(w->address); 229 GNUNET_HELLO_address_free(w->address);
230 if (NULL != w->test_task)
231 GNUNET_SCHEDULER_cancel (w->test_task);
224 GNUNET_free(w->addrstring); 232 GNUNET_free(w->addrstring);
225 GNUNET_free(w); 233 GNUNET_free(w);
226 } 234 }
@@ -317,20 +325,117 @@ address_pretty_printer_cb (void *cls, const char *address, int res)
317 325
318 326
319static void 327static void
328test_addr_string (void *cls,
329 const struct GNUNET_SCHEDULER_TaskContext *tc)
330{
331 struct AddressWrapper *w = cls;
332 void *s2a;
333 size_t s2a_len;
334
335 w->test_task = NULL;
336
337 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
338 "Testing: address_to_string \n");
339 w->addrstring = GNUNET_strdup (api->address_to_string (api,
340 w->address->address,
341 w->address->address_length));
342 if (NULL == w->addrstring)
343 {
344 GNUNET_break(0);
345 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
346 "Plugin cannot convert address to string!\n");
347 end_badly_now ();
348 return;
349 }
350 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
351 "Plugin added address `%s'\n",
352 w->addrstring);
353 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
354 "Testing address_to_string: OK\n");
355 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
356 "Testing: string_to_address \n");
357 s2a = NULL;
358 s2a_len = 0;
359 if ((GNUNET_OK !=
360 api->string_to_address (api, w->addrstring,
361 strlen (w->addrstring) + 1,
362 &s2a, &s2a_len)) ||
363 (NULL == s2a))
364 {
365 GNUNET_break(0);
366 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
367 "Plugin cannot convert string to address!\n");
368 end_badly_now ();
369 return;
370 }
371
372 /*
373 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
374 "Plugin creates `%s' %u\n",api->address_to_string (api, s2a, s2a_len), s2a_len);
375
376 int c1;
377 for (c1 = 0; c1 < s2a_len; c1++ )
378 fprintf (stderr, "%u == %u\n", ((char *) s2a)[c1], ((char *) w->addr)[c1]);
379 */
380 if (s2a_len != w->address->address_length)
381 {
382 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
383 "Plugin creates different address length when converting address->string->address: %u != %u\n",
384 w->address->address_length, s2a_len);
385 }
386 else if (0 != memcmp (s2a, w->address->address, s2a_len))
387 {
388 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
389 "Plugin creates different address length when converting back and forth %i!\n",
390 memcmp (s2a, w->address->address, s2a_len));
391 }
392 else
393 {
394 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
395 "Testing string_to_address: OK\n");
396 }
397 GNUNET_free(s2a);
398
399 pretty_printers_running++;
400 api->address_pretty_printer (api->cls,
401 w->address->transport_name,
402 w->address->address,
403 w->address->address_length,
404 GNUNET_YES,
405 GNUNET_TIME_UNIT_MINUTES,
406 &address_pretty_printer_cb, w);
407
408 if (GNUNET_OK !=
409 api->check_address (api->cls, w->address->address, w->address->address_length))
410 {
411 GNUNET_break(0);
412 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Plugin refuses added address!\n");
413 end_badly_now ();
414 return;
415 }
416 if (NULL != timeout_wait)
417 {
418 GNUNET_SCHEDULER_cancel (timeout_wait);
419 timeout_wait = NULL;
420 }
421 timeout_wait = GNUNET_SCHEDULER_add_delayed (WAIT, &wait_end, NULL);
422}
423
424
425static void
320env_notify_address (void *cls, 426env_notify_address (void *cls,
321 int add_remove, 427 int add_remove,
322 const struct GNUNET_HELLO_Address *address) 428 const struct GNUNET_HELLO_Address *address)
323{ 429{
324 struct AddressWrapper *w; 430 struct AddressWrapper *w;
325 struct AddressWrapper *wtmp; 431 struct AddressWrapper *wtmp;
326 void *s2a;
327 size_t s2a_len;
328 432
329 if (GNUNET_YES == add_remove) 433 if (GNUNET_YES == add_remove)
330 { 434 {
331 addresses_reported++; 435 addresses_reported++;
332 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Adding address of length %u\n", 436 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
333 address->address_length); 437 "Adding address of length %u\n",
438 address->address_length);
334 439
335 for (wtmp = head; NULL != wtmp; wtmp = wtmp->next) 440 for (wtmp = head; NULL != wtmp; wtmp = wtmp->next)
336 { 441 {
@@ -338,100 +443,25 @@ env_notify_address (void *cls,
338 (0 == memcmp (address->address, wtmp->address->address, address->address_length))) 443 (0 == memcmp (address->address, wtmp->address->address, address->address_length)))
339 { 444 {
340 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 445 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
341 "Duplicate address notification .... \n"); 446 "Duplicate address notification .... \n");
342 return; 447 return;
343 } 448 }
344 } 449 }
345 450
346 w = GNUNET_new (struct AddressWrapper); 451 w = GNUNET_new (struct AddressWrapper);
347 w->address = GNUNET_HELLO_address_copy (address); 452 w->address = GNUNET_HELLO_address_copy (address);
348 GNUNET_CONTAINER_DLL_insert(head, tail, w); 453 GNUNET_CONTAINER_DLL_insert (head, tail, w);
349 got_reply = GNUNET_NO; 454 got_reply = GNUNET_NO;
350 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Testing: address_to_string \n"); 455 w->test_task = GNUNET_SCHEDULER_add_now (&test_addr_string,
351 w->addrstring = GNUNET_strdup ( 456 w);
352 api->address_to_string (api, w->address->address, 457 return;
353 w->address->address_length));
354 if (NULL == w->addrstring)
355 {
356 GNUNET_break(0);
357 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
358 "Plugin cannot convert address to string!\n");
359 end_badly_now ();
360 return;
361 }
362 else
363 {
364 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Plugin added address `%s'\n",
365 w->addrstring);
366 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Testing address_to_string: OK\n");
367 }
368
369 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Testing: string_to_address \n");
370 s2a = NULL;
371 s2a_len = 0;
372 if ((GNUNET_OK
373 != api->string_to_address (api, w->addrstring,
374 strlen (w->addrstring) + 1, &s2a, &s2a_len)) || (NULL == s2a))
375 {
376 GNUNET_break(0);
377 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
378 "Plugin cannot convert string to address!\n");
379 end_badly_now ();
380 return;
381 }
382
383 /*
384 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
385 "Plugin creates `%s' %u\n",api->address_to_string (api, s2a, s2a_len), s2a_len);
386
387 int c1;
388 for (c1 = 0; c1 < s2a_len; c1++ )
389 fprintf (stderr, "%u == %u\n", ((char *) s2a)[c1], ((char *) w->addr)[c1]);
390 */
391 if (s2a_len != w->address->address_length)
392 {
393 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
394 "Plugin creates different address length when converting address->string->address: %u != %u\n",
395 w->address->address_length, s2a_len);
396 }
397 else if (0 != memcmp (s2a, w->address->address, s2a_len))
398 {
399 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
400 "Plugin creates different address length when converting back and forth %i!\n",
401 memcmp (s2a, w->address->address, s2a_len));
402 }
403 else
404 {
405 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Testing string_to_address: OK\n");
406 }
407 GNUNET_free(s2a);
408
409 pretty_printers_running++;
410 api->address_pretty_printer (api->cls, address->transport_name,
411 address->address, address->address_length, GNUNET_YES,
412 GNUNET_TIME_UNIT_MINUTES, &address_pretty_printer_cb, w);
413
414 if (GNUNET_OK != api->check_address (api->cls, w->address->address, w->address->address_length))
415 {
416 GNUNET_break(0);
417 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Plugin refuses added address!\n");
418 end_badly_now ();
419 return;
420 }
421 if (NULL != timeout_wait)
422 {
423 GNUNET_SCHEDULER_cancel (timeout_wait);
424 timeout_wait = NULL;
425 }
426
427 timeout_wait = GNUNET_SCHEDULER_add_delayed (WAIT, &wait_end, NULL );
428
429 } 458 }
430 else if (GNUNET_NO == add_remove)
431 {
432 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Removing address of length %u\n",
433 address->address_length);
434 459
460 if (GNUNET_NO == add_remove)
461 {
462 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
463 "Removing address of length %u\n",
464 address->address_length);
435 w = head; 465 w = head;
436 while (NULL != w) 466 while (NULL != w)
437 { 467 {
@@ -443,7 +473,7 @@ env_notify_address (void *cls,
443 w = w->next; 473 w = w->next;
444 } 474 }
445 475
446 if (w == NULL ) 476 if (w == NULL)
447 { 477 {
448 GNUNET_break(0); 478 GNUNET_break(0);
449 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 479 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
@@ -456,14 +486,13 @@ env_notify_address (void *cls,
456 GNUNET_HELLO_address_free (w->address); 486 GNUNET_HELLO_address_free (w->address);
457 GNUNET_free(w->addrstring); 487 GNUNET_free(w->addrstring);
458 GNUNET_free(w); 488 GNUNET_free(w);
459 }
460 else
461 {
462 GNUNET_break(0);
463 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Invalid operation: %u\n", add_remove);
464 end_badly_now ();
465 return; 489 return;
466 } 490 }
491 GNUNET_break(0);
492 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
493 "Invalid operation: %u\n",
494 add_remove);
495 end_badly_now ();
467} 496}
468 497
469 498
@@ -642,7 +671,7 @@ run (void *cls, char * const *args, const char *cfgfile,
642 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Loading transport plugin %s\n", plugin); 671 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Loading transport plugin %s\n", plugin);
643 GNUNET_asprintf (&libname, "libgnunet_plugin_transport_%s", plugin); 672 GNUNET_asprintf (&libname, "libgnunet_plugin_transport_%s", plugin);
644 api = GNUNET_PLUGIN_load (libname, &env); 673 api = GNUNET_PLUGIN_load (libname, &env);
645 if (api == NULL ) 674 if (NULL == api)
646 { 675 {
647 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 676 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
648 "Failed to load transport plugin for %s\n", plugin); 677 "Failed to load transport plugin for %s\n", plugin);