From 469af5f00bfb33005f4243b8ec69eba5ad1f13b0 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Fri, 2 Oct 2009 13:02:40 +0000 Subject: [PATCH] misc bugfixes --- src/transport/gnunet-service-transport.c | 92 +++++++++++++++------ src/transport/plugin_transport_tcp.c | 57 +++++++------ src/transport/test_transport_api.c | 5 +- src/transport/test_transport_api_peer1.conf | 5 +- src/transport/test_transport_api_peer2.conf | 3 + src/transport/transport_api.c | 4 + 6 files changed, 114 insertions(+), 52 deletions(-) diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c index 09f87d444..49ed6f468 100644 --- a/src/transport/gnunet-service-transport.c +++ b/src/transport/gnunet-service-transport.c @@ -67,8 +67,13 @@ /** * How long until a HELLO verification attempt should time out? + * Must be rather small, otherwise a partially successful HELLO + * validation (some addresses working) might not be available + * before a client's request for a connection fails for good. + * Besides, if a single request to an address takes a long time, + * then the peer is unlikely worthwhile anyway. */ -#define HELLO_VERIFICATION_TIMEOUT GNUNET_TIME_UNIT_MINUTES +#define HELLO_VERIFICATION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3) /** * How often do we re-add (cheaper) plugins to our list of plugins @@ -692,6 +697,11 @@ transmit_to_client_callback (void *cls, size_t size, void *buf) msize = ntohs (msg->size); if (msize + tsize > size) break; +#if DEBUG_TRANSPORT + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Transmitting message of type %u to client.\n", + ntohs (msg->type)); +#endif client->message_queue_head = q->next; if (q->next == NULL) client->message_queue_tail = NULL; @@ -1451,6 +1461,7 @@ cleanup_validation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) struct ValidationList *pos; struct ValidationList *prev; struct GNUNET_TIME_Absolute now; + struct GNUNET_TIME_Absolute first; struct GNUNET_HELLO_Message *hello; struct GNUNET_PeerIdentity pid; struct NeighbourList *n; @@ -1506,16 +1517,22 @@ cleanup_validation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) /* finally, reschedule cleanup if needed; list is ordered by timeout, so we need the last element... */ - pos = pending_validations; - while ((pos != NULL) && (pos->next != NULL)) - pos = pos->next; - if (NULL != pos) - GNUNET_SCHEDULER_add_delayed (sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_IDLE, - GNUNET_SCHEDULER_NO_TASK, - GNUNET_TIME_absolute_get_remaining - (pos->timeout), &cleanup_validation, NULL); + if (NULL != pending_validations) + { + first = pos->timeout; + pos = pending_validations; + while (pos != NULL) + { + first = GNUNET_TIME_absolute_min (first, pos->timeout); + pos = pos->next; + } + GNUNET_SCHEDULER_add_delayed (sched, + GNUNET_NO, + GNUNET_SCHEDULER_PRIORITY_IDLE, + GNUNET_SCHEDULER_NO_TASK, + GNUNET_TIME_absolute_get_remaining (first), + &cleanup_validation, NULL); + } } @@ -1543,7 +1560,7 @@ plugin_env_notify_validation (void *cls, uint32_t challenge, const char *sender_addr) { - int all_done; + unsigned int not_done; int matched; struct ValidationList *pos; struct ValidationAddress *va; @@ -1570,7 +1587,7 @@ plugin_env_notify_validation (void *cls, GNUNET_i2s(peer)); return; } - all_done = GNUNET_YES; + not_done = 0; matched = GNUNET_NO; va = pos->addresses; while (va != NULL) @@ -1579,7 +1596,10 @@ plugin_env_notify_validation (void *cls, { #if DEBUG_TRANSPORT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Confirmed validity of peer address.\n"); + "Confirmed validity of address, peer `%4s' has address `%s'.\n", + GNUNET_i2s (peer), + GNUNET_a2s ((const struct sockaddr*) &va[1], + va->addr_len)); #endif GNUNET_log (GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK, _("Another peer saw us using the address `%s' via `%s'. If this is not plausible, this address should be listed in the configuration as implausible to avoid MiM attacks.\n"), @@ -1591,7 +1611,7 @@ plugin_env_notify_validation (void *cls, matched = GNUNET_YES; } if (va->ok != GNUNET_YES) - all_done = GNUNET_NO; + not_done++; va = va->next; } if (GNUNET_NO == matched) @@ -1602,8 +1622,14 @@ plugin_env_notify_validation (void *cls, ("Received `%s' message but have no record of a matching `%s' message. Ignoring.\n"), "PONG", "PING"); } - if (GNUNET_YES == all_done) + if (0 == not_done) { +#if DEBUG_TRANSPORT + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "All addresses validated, will now construct `%s' for `%4s'.\n", + "HELLO", + GNUNET_i2s (peer)); +#endif pos->timeout.value = 0; GNUNET_SCHEDULER_add_delayed (sched, GNUNET_NO, @@ -1612,6 +1638,17 @@ plugin_env_notify_validation (void *cls, GNUNET_TIME_UNIT_ZERO, &cleanup_validation, NULL); } + else + { +#if DEBUG_TRANSPORT + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Still waiting for %u additional `%s' messages before constructing `%s' for `%4s'.\n", + not_done, + "PONG", + "HELLO", + GNUNET_i2s (peer)); +#endif + } } @@ -1731,14 +1768,21 @@ check_hello_validated (void *cls, GNUNET_assert (GNUNET_OK == GNUNET_HELLO_get_id (chvc->hello, &apeer)); +#if DEBUG_TRANSPORT + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Ready to validate addresses from `%s' message for peer `%4s'\n", + "HELLO", GNUNET_i2s (&apeer)); +#endif va = chvc->e->addresses; while (va != NULL) { #if DEBUG_TRANSPORT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Establishing `%s' connection to validate `%s' of `%4s'\n", + "Establishing `%s' connection to validate `%s' address `%s' of `%4s'\n", va->transport_name, "HELLO", + GNUNET_a2s ((const struct sockaddr*) &va[1], + va->addr_len), GNUNET_i2s (&apeer)); #endif tp = find_transport (va->transport_name); @@ -1753,14 +1797,12 @@ check_hello_validated (void *cls, va->ok = GNUNET_SYSERR; va = va->next; } - if (chvc->e->next == NULL) - GNUNET_SCHEDULER_add_delayed (sched, - GNUNET_NO, - GNUNET_SCHEDULER_PRIORITY_IDLE, - GNUNET_SCHEDULER_NO_TASK, - GNUNET_TIME_absolute_get_remaining - (chvc->e->timeout), &cleanup_validation, - NULL); + GNUNET_SCHEDULER_add_delayed (sched, + GNUNET_NO, + GNUNET_SCHEDULER_PRIORITY_IDLE, + GNUNET_SCHEDULER_NO_TASK, + GNUNET_TIME_absolute_get_remaining (chvc->e->timeout), + &cleanup_validation, NULL); GNUNET_free (chvc); } diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c index bfa17d275..15afeab3d 100644 --- a/src/transport/plugin_transport_tcp.c +++ b/src/transport/plugin_transport_tcp.c @@ -39,7 +39,7 @@ #include "plugin_transport.h" #include "transport.h" -#define DEBUG_TCP GNUNET_NO +#define DEBUG_TCP GNUNET_YES /** * After how long do we expire an address that we @@ -1490,8 +1490,17 @@ handle_tcp_ping (void *cls, void *addr; #if DEBUG_TRANSPORT - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, - "Processing PING\n"); + if (GNUNET_OK == + GNUNET_SERVER_client_get_address (client, + (void **) &addr, + &addrlen)) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, + "Processing `%s' from `%s'\n", + "PING", + GNUNET_a2s (addr, addrlen)); + GNUNET_free (addr); + } #endif msize = ntohs (message->size); if (msize < sizeof (struct ValidationChallengeMessage)) @@ -1570,23 +1579,10 @@ handle_tcp_ping (void *cls, /** - * Handle PING-message. If the plugin that gave us the message is - * able to queue the PONG immediately, we only queue one PONG. - * Otherwise we send at most TWO PONG messages, one via an unconfirmed - * transport and one via a confirmed transport. Both addresses are - * selected randomly among those available. - * - * @param plugin plugin that gave us the message - * @param sender claimed sender of the PING - * @param plugin_context context that might be used to send response - * @param message the actual message - */ -/** - * We've received a PING from this peer via TCP. - * Send back our PONG. + * Handle PONG-message. * - * @param cls closure - * @param client identification of the client + * @param plugin handle for this plugin + * @param sender claimed sender of the PONG * @param message the actual message */ static void @@ -1604,8 +1600,19 @@ handle_tcp_pong (void *cls, struct sockaddr_in6 v6; #if DEBUG_TRANSPORT - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, - "Processing PONG\n"); + struct sockaddr *claddr; + + if (GNUNET_OK == + GNUNET_SERVER_client_get_address (client, + (void**) &claddr, + &addrlen)) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, + "Processing `%s' from `%s'\n", + "PONG", + GNUNET_a2s (claddr, addrlen)); + GNUNET_free (claddr); + } #endif if (ntohs(message->size) < sizeof(struct ValidationChallengeResponse)) { @@ -2002,9 +2009,11 @@ process_hostname_ips (void *cls, if (addr == NULL) return; - plugin->env->notify_address (plugin->env->cls, - "tcp", - addr, addrlen, GNUNET_TIME_UNIT_FOREVER_REL); + process_interfaces (plugin, + "", + GNUNET_YES, + addr, + addrlen); } diff --git a/src/transport/test_transport_api.c b/src/transport/test_transport_api.c index 2aa12bcbd..881c75019 100644 --- a/src/transport/test_transport_api.c +++ b/src/transport/test_transport_api.c @@ -223,7 +223,8 @@ exchange_hello (void *cls, GNUNET_assert (GNUNET_OK == GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) message, &me->id)); - GNUNET_TRANSPORT_get_hello (p2.th, GNUNET_TIME_UNIT_MINUTES, + GNUNET_TRANSPORT_get_hello (p2.th, + TIMEOUT, &exchange_hello_last, &p2); } @@ -241,7 +242,7 @@ run (void *cls, setup_peer (&p1, "test_transport_api_peer1.conf"); setup_peer (&p2, "test_transport_api_peer2.conf"); GNUNET_TRANSPORT_get_hello (p1.th, - GNUNET_TIME_UNIT_MINUTES, &exchange_hello, &p1); + TIMEOUT, &exchange_hello, &p1); } diff --git a/src/transport/test_transport_api_peer1.conf b/src/transport/test_transport_api_peer1.conf index 2957ec3e7..606ab8224 100644 --- a/src/transport/test_transport_api_peer1.conf +++ b/src/transport/test_transport_api_peer1.conf @@ -9,7 +9,10 @@ HOSTNAME = localhost [transport] PORT = 12365 PLUGINS = tcp -#DEBUG = YES +DEBUG = YES +#PREFIX = xterm -T t1 -e gdb -x cmd --args +#BINARY = /home/grothoff/bin/gnunet-service-transport +#PREFIX = valgrind --tool=memcheck [arm] PORT = 12366 diff --git a/src/transport/test_transport_api_peer2.conf b/src/transport/test_transport_api_peer2.conf index 7f98ba3cf..ea746f9c1 100644 --- a/src/transport/test_transport_api_peer2.conf +++ b/src/transport/test_transport_api_peer2.conf @@ -10,6 +10,9 @@ HOSTNAME = localhost PORT = 22365 PLUGINS = tcp #DEBUG = YES +#PREFIX = xterm -T t2 -e gdb -x cmd --args +#BINARY = /home/grothoff/bin/gnunet-service-transport +#PREFIX = valgrind --tool=memcheck [arm] PORT = 22366 diff --git a/src/transport/transport_api.c b/src/transport/transport_api.c index aa1a3f9a1..49462fd5d 100644 --- a/src/transport/transport_api.c +++ b/src/transport/transport_api.c @@ -1108,6 +1108,10 @@ remove_neighbour (struct GNUNET_TRANSPORT_Handle *h, } else { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + _("Connection with `%4s' failed, will keep trying for %llu ms to deliver message\n"), + GNUNET_i2s (peer), + GNUNET_TIME_absolute_get_remaining (th->timeout).value); /* try again in a bit */ GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == th->notify_delay_task); th->notify_delay_task -- 2.25.1