From 281d5b7680f9b1d2adce9f69c75b38f1b1e7f177 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Mon, 31 May 2010 11:25:31 +0000 Subject: fixes --- src/transport/gnunet-service-transport.c | 105 ++++++++++++++++-------- src/transport/plugin_transport_tcp.c | 2 +- src/transport/test_transport_api_reliability.c | 49 +++++++++-- src/transport/test_transport_api_tcp_peer1.conf | 5 +- src/transport/test_transport_api_tcp_peer2.conf | 5 +- src/transport/transport.h | 6 +- src/transport/transport_api.c | 2 + 7 files changed, 123 insertions(+), 51 deletions(-) (limited to 'src/transport') diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c index 44d2ff726..7d3691696 100644 --- a/src/transport/gnunet-service-transport.c +++ b/src/transport/gnunet-service-transport.c @@ -58,9 +58,12 @@ * messages, so the number should be chosen rather generously. * * The expectation here is that most of the time the queue is large - * enough so that a drop is virtually never required. + * enough so that a drop is virtually never required. Note that + * this value must be about as large as 'TOTAL_MSGS' in the + * 'test_transport_api_reliability.c', otherwise that testcase may + * fail. */ -#define MAX_PENDING 128 +#define MAX_PENDING (128 * 1024) /** * Size of the per-transport blacklist hash maps. @@ -1224,6 +1227,32 @@ transmit_to_client_callback (void *cls, size_t size, void *buf) } +/** + * Convert an address to a string. + * + * @param plugin name of the plugin responsible for the address + * @param addr binary address + * @param addr_len number of bytes in addr + * @return NULL on error, otherwise address string + */ +static const char* +a2s (const char *plugin, + const void *addr, + uint16_t addr_len) +{ + struct TransportPlugin *p; + + if (plugin == NULL) + return NULL; + p = find_transport (plugin); + if (p == NULL) + return NULL; + return p->api->address_to_string (p->api->cls, + addr, + addr_len); +} + + /** * Mark the given FAL entry as 'connected' (and hence preferred for * sending); also mark all others for the same peer as 'not connected' @@ -1246,9 +1275,20 @@ mark_address_connected (struct ForeignAddressList *fal) { if (GNUNET_YES == pos->connected) { +#if DEBUG_TRANSPORT + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Marking address `%s' as no longer connected (due to connect on other address)\n", + a2s (pos->ready_list->plugin->short_name, + pos->addr, + pos->addrlen)); +#endif GNUNET_break (cnt == GNUNET_YES); cnt = GNUNET_NO; pos->connected = GNUNET_NO; + GNUNET_STATISTICS_update (stats, + gettext_noop ("# connected addresses"), + -1, + GNUNET_NO); } pos = pos->next; } @@ -1284,9 +1324,15 @@ transmit_to_client (struct TransportClient *client, { GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ - ("Dropping message, have %u messages pending (%u is the soft limit)\n"), - client->message_count, MAX_PENDING); - /* TODO: call to statistics... */ + ("Dropping message of type %u and size %u, have %u messages pending (%u is the soft limit)\n"), + ntohs (msg->type), + ntohs (msg->size), + client->message_count, + MAX_PENDING); + GNUNET_STATISTICS_update (stats, + gettext_noop ("# messages dropped due to slow client"), + 1, + GNUNET_NO); return; } msize = ntohs (msg->size); @@ -1390,6 +1436,13 @@ transmit_send_continuation (void *cls, { if (mq->specific_address->connected != GNUNET_NO) { +#if DEBUG_TRANSPORT + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Marking address `%s' as no longer connected (due to transmission problem)\n", + a2s (mq->specific_address->ready_list->plugin->short_name, + mq->specific_address->addr, + mq->specific_address->addrlen)); +#endif GNUNET_STATISTICS_update (stats, gettext_noop ("# connected addresses"), -1, @@ -1407,32 +1460,6 @@ transmit_send_continuation (void *cls, } -/** - * Convert an address to a string. - * - * @param plugin name of the plugin responsible for the address - * @param addr binary address - * @param addr_len number of bytes in addr - * @return NULL on error, otherwise address string - */ -static const char* -a2s (const char *plugin, - const void *addr, - uint16_t addr_len) -{ - struct TransportPlugin *p; - - if (plugin == NULL) - return NULL; - p = find_transport (plugin); - if (p == NULL) - return NULL; - return p->api->address_to_string (p->api->cls, - addr, - addr_len); -} - - /** * Find an address in any of the available transports for * the given neighbour that would be good for message @@ -1508,7 +1535,10 @@ find_ready_address(struct NeighbourList *neighbour) { #if DEBUG_TRANSPORT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Best address found has latency of %llu ms.\n", + "Best address found (`%s') has latency of %llu ms.\n", + a2s (best_address->ready_list->plugin->short_name, + best_address->addr, + best_address->addrlen), best_address->latency.value); #endif } @@ -3228,8 +3258,9 @@ handle_payload_message (const struct GNUNET_MessageHeader *message, } #if DEBUG_TRANSPORT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received message of type %u from `%4s', sending to all clients.\n", + "Received message of type %u and size %u from `%4s', sending to all clients.\n", ntohs (message->type), + ntohs (message->size), GNUNET_i2s (&n->id)); #endif if (GNUNET_YES == GNUNET_BANDWIDTH_tracker_consume (&n->in_tracker, @@ -3718,7 +3749,7 @@ check_hello_validated (void *cls, NULL); GNUNET_PEERINFO_add_peer (peerinfo, plain_hello); GNUNET_free (plain_hello); -#if DEBUG_TRANSPORT || 1 +#if DEBUG_TRANSPORT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "PEERINFO had no `%s' message for peer `%4s', full validation needed.\n", "HELLO", @@ -4248,8 +4279,10 @@ plugin_env_receive (void *cls, const struct GNUNET_PeerIdentity *peer, } #if DEBUG_PING_PONG GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received message of type %u from `%4s', sending to all clients.\n", - ntohs (message->type), GNUNET_i2s (peer)); + "Received message of type %u and size %u from `%4s', sending to all clients.\n", + ntohs (message->type), + ntohs (message->size), + GNUNET_i2s (peer)); #endif switch (ntohs (message->type)) { diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c index 865ca325a..f6ba584eb 100644 --- a/src/transport/plugin_transport_tcp.c +++ b/src/transport/plugin_transport_tcp.c @@ -37,7 +37,7 @@ #include "plugin_transport.h" #include "transport.h" -#define DEBUG_TCP GNUNET_YES +#define DEBUG_TCP GNUNET_NO /** * How long until we give up on transmitting the welcome message? diff --git a/src/transport/test_transport_api_reliability.c b/src/transport/test_transport_api_reliability.c index 9b2c167cb..fe7b6590e 100644 --- a/src/transport/test_transport_api_reliability.c +++ b/src/transport/test_transport_api_reliability.c @@ -35,12 +35,17 @@ #include "gnunet_transport_service.h" #include "transport.h" -#define VERBOSE GNUNET_YES +#define VERBOSE GNUNET_NO #define VERBOSE_ARM GNUNET_NO #define START_ARM GNUNET_YES +/** + * Note that this value must not significantly exceed + * 'MAX_PENDING' in 'gnunet-service-transport.c', otherwise + * messages may be dropped even for a reliable transport. + */ #define TOTAL_MSGS (60000 * 2) /** @@ -72,6 +77,10 @@ static int is_tcp; static int is_http; +static unsigned long long total_bytes; + +static struct GNUNET_TIME_Absolute start_time; + static GNUNET_SCHEDULER_TaskIdentifier die_task; #if VERBOSE @@ -84,15 +93,23 @@ static GNUNET_SCHEDULER_TaskIdentifier die_task; static void end () { - GNUNET_assert (ok == 6); + unsigned long long delta; + GNUNET_SCHEDULER_cancel (sched, die_task); + die_task = GNUNET_SCHEDULER_NO_TASK; +#if VERBOSE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from transports!\n"); +#endif GNUNET_TRANSPORT_disconnect (p1.th); GNUNET_TRANSPORT_disconnect (p2.th); - - die_task = GNUNET_SCHEDULER_NO_TASK; +#if VERBOSE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transports disconnected, returning success!\n"); +#endif + delta = GNUNET_TIME_absolute_get_duration (start_time).value; + fprintf (stderr, + "\nThroughput was %llu kb/s\n", + total_bytes * 1000 / 1024 / delta); ok = 0; } @@ -175,11 +192,15 @@ notify_receive (void *cls, die_task = GNUNET_SCHEDULER_add_now (sched, &end_badly, NULL); return; } +#if VERBOSE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got message %u of size %u\n", ntohl (hdr->num), ntohs (message->size)); +#endif n++; + if (0 == (n % (TOTAL_MSGS/100))) + fprintf (stderr, "."); if (n == TOTAL_MSGS) end (); } @@ -214,10 +235,12 @@ notify_ready (void *cls, size_t size, void *buf) ret += sizeof (struct TestMessage); memset (&cbuf[ret], n, s - sizeof (struct TestMessage)); ret += s - sizeof (struct TestMessage); +#if VERBOSE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending message %u of size %u\n", n, s); +#endif n++; s = get_size (n); if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16)) @@ -233,6 +256,7 @@ notify_ready (void *cls, size_t size, void *buf) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Returning total message block of size %u\n", ret); + total_bytes += ret; return ret; } @@ -251,6 +275,7 @@ notify_connect (void *cls, GNUNET_BANDWIDTH_value_init (1024 * 1024 * 1024), GNUNET_TIME_UNIT_FOREVER_REL, NULL, NULL); + start_time = GNUNET_TIME_absolute_get (); GNUNET_TRANSPORT_notify_transmit_ready (p1.th, &p2.id, get_size (0), 0, TIMEOUT, @@ -266,17 +291,21 @@ notify_connect (void *cls, GNUNET_TIME_UNIT_FOREVER_REL, NULL, NULL); } +#if VERBOSE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%4s' connected to us (%p)!\n", GNUNET_i2s (peer), cls); +#endif } static void notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) { +#if VERBOSE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%4s' disconnected (%p)!\n", GNUNET_i2s (peer), cls); +#endif } @@ -310,8 +339,10 @@ exchange_hello_last (void *cls, struct PeerContext *me = cls; GNUNET_TRANSPORT_get_hello_cancel (p2.th, &exchange_hello_last, me); +#if VERBOSE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Exchanging HELLO with peer (%p)!\n", cls); +#endif GNUNET_assert (ok >= 3); OKPP; GNUNET_assert (message != NULL); @@ -331,8 +362,10 @@ exchange_hello (void *cls, struct PeerContext *me = cls; GNUNET_TRANSPORT_get_hello_cancel (p1.th, &exchange_hello, me); +#if VERBOSE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Exchanging HELLO with peer (%p)!\n", cls); +#endif GNUNET_assert (ok >= 2); OKPP; GNUNET_assert (message != NULL); @@ -340,9 +373,11 @@ exchange_hello (void *cls, GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) message, &me->id)); +#if VERBOSE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received HELLO size %d\n", GNUNET_HELLO_size((const struct GNUNET_HELLO_Message *)message)); - + "Received HELLO size %d\n", + GNUNET_HELLO_size((const struct GNUNET_HELLO_Message *)message)); +#endif GNUNET_TRANSPORT_offer_hello (p2.th, message); GNUNET_TRANSPORT_get_hello (p2.th, &exchange_hello_last, &p2); } @@ -399,7 +434,7 @@ check () #endif ok = 1; GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, - argv, "test-transport-api", "nohelp", + argv, "test-transport-api-reliability", "nohelp", options, &run, &ok); stop_arm (&p1); stop_arm (&p2); diff --git a/src/transport/test_transport_api_tcp_peer1.conf b/src/transport/test_transport_api_tcp_peer1.conf index 719dc1c79..97e2111c8 100644 --- a/src/transport/test_transport_api_tcp_peer1.conf +++ b/src/transport/test_transport_api_tcp_peer1.conf @@ -1,5 +1,6 @@ [transport-tcp] PORT = 12368 +BINDTO = 127.0.0.1 [fs] AUTOSTART = NO @@ -31,7 +32,7 @@ MINIMUM-FRIENDS = 0 [transport] PLUGINS = tcp -#DEBUG = YES +DEBUG = NO #PREFIX = xterm -T transport2 -e gdb --command=cmd --args #PREFIX = valgrind --leak-check=full ACCEPT_FROM6 = ::1; @@ -73,7 +74,7 @@ HOSTNAME = localhost PORT = 12367 [arm] -DEFAULTSERVICES = +DEFAULTSERVICES = transport statistics ACCEPT_FROM6 = ::1; ACCEPT_FROM = 127.0.0.1; BINARY = gnunet-service-arm diff --git a/src/transport/test_transport_api_tcp_peer2.conf b/src/transport/test_transport_api_tcp_peer2.conf index cddce5926..f6ab6c231 100644 --- a/src/transport/test_transport_api_tcp_peer2.conf +++ b/src/transport/test_transport_api_tcp_peer2.conf @@ -1,5 +1,6 @@ [transport-tcp] PORT = 22368 +BINDTO = 127.0.0.1 [core] AUTOSTART = NO @@ -31,7 +32,7 @@ MINIMUM-FRIENDS = 0 [transport] PLUGINS = tcp -#DEBUG = YES +DEBUG = NO # PREFIX = ACCEPT_FROM6 = ::1; ACCEPT_FROM = 127.0.0.1; @@ -74,7 +75,7 @@ HOSTNAME = localhost PORT = 22367 [arm] -DEFAULTSERVICES = +DEFAULTSERVICES = transport statistics ACCEPT_FROM6 = ::1; ACCEPT_FROM = 127.0.0.1; BINARY = gnunet-service-arm diff --git a/src/transport/transport.h b/src/transport/transport.h index b2ef01bb5..6cdbaae77 100644 --- a/src/transport/transport.h +++ b/src/transport/transport.h @@ -30,9 +30,9 @@ #include "gnunet_time_lib.h" #include "gnunet_transport_service.h" -#define DEBUG_TRANSPORT GNUNET_YES -#define DEBUG_TRANSPORT_TIMEOUT GNUNET_YES -#define DEBUG_TRANSPORT_DISCONNECT GNUNET_YES +#define DEBUG_TRANSPORT GNUNET_NO +#define DEBUG_TRANSPORT_TIMEOUT GNUNET_NO +#define DEBUG_TRANSPORT_DISCONNECT GNUNET_NO /** * For how long do we allow unused bandwidth diff --git a/src/transport/transport_api.c b/src/transport/transport_api.c index 22f6eee51..8007c6d8e 100644 --- a/src/transport/transport_api.c +++ b/src/transport/transport_api.c @@ -548,10 +548,12 @@ transport_notify_ready (void *cls, size_t size, void *buf) h->control_tail, cm); nret = cm->notify (cm->notify_cls, size, &cbuf[ret]); +#if DEBUG_TRANSPORT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Added %u bytes of control message at %u\n", nret, ret); +#endif GNUNET_free (cm); ret += nret; size -= nret; -- cgit v1.2.3