From 7f082ef1cd69b48984b05ae72f3c124493fdd86e Mon Sep 17 00:00:00 2001 From: Matthias Wachs Date: Tue, 16 Nov 2010 11:51:20 +0000 Subject: [PATCH] Basic problem fixed: Line 477: Timeout for GNUNET_CORE_peer_request_connect with 1 sec. too short to connect to other peer --- src/core/test_core_quota_compliance.c | 180 ++++++++++++++------------ 1 file changed, 96 insertions(+), 84 deletions(-) diff --git a/src/core/test_core_quota_compliance.c b/src/core/test_core_quota_compliance.c index 88a735736..2fbe8dcc5 100644 --- a/src/core/test_core_quota_compliance.c +++ b/src/core/test_core_quota_compliance.c @@ -39,7 +39,7 @@ #define VERBOSE GNUNET_YES #define START_ARM GNUNET_YES -#define DEBUG_CONNECTIONS GNUNET_NO +#define DEBUG_CONNECTIONS GNUNET_YES /** * Note that this value must not significantly exceed @@ -157,63 +157,6 @@ terminate_task_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) ok = 42; } -static void connect_notify (void *cls, - const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_TRANSPORT_ATS_Information *atsi) -{ - struct PeerContext *pc = cls; - GNUNET_assert (pc->connect_status == 0); - pc->connect_status = 1; -#if DEBUG_CONNECTIONS - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Encrypted connection established to peer `%4s'\n", - GNUNET_i2s (peer)); -#endif -} - - -static void -disconnect_notify (void *cls, - const struct GNUNET_PeerIdentity *peer) -{ - struct PeerContext *pc = cls; - pc->connect_status = 0; -#if DEBUG_CONNECTIONS - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Encrypted connection to `%4s' cut\n", GNUNET_i2s (peer)); -#endif -} - - -static int -inbound_notify (void *cls, - const struct GNUNET_PeerIdentity *other, - const struct GNUNET_MessageHeader *message, - const struct GNUNET_TRANSPORT_ATS_Information *atsi) -{ - total_bytes_recv += ntohs (message->size); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Core provides inbound data from `%4s' size %u.\n", GNUNET_i2s (other), ntohs (message->size)); -#if DEBUG_CONNECTIONS - #endif - return GNUNET_OK; -} - - -static int -outbound_notify (void *cls, - const struct GNUNET_PeerIdentity *other, - const struct GNUNET_MessageHeader *message, - const struct GNUNET_TRANSPORT_ATS_Information *atsi) -{ -#if DEBUG_CONNECTIONS - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Core notifies about outbound data for `%4s'.\n", - GNUNET_i2s (other)); -#endif - return GNUNET_OK; -} - static void next_fin (void *cls, int success) { @@ -230,26 +173,43 @@ check_2 (void *cls, return GNUNET_OK; } +static size_t +transmit_ready (void *cls, size_t size, void *buf); + +static void +send_tsk (void *cls, + const struct GNUNET_SCHEDULER_TaskContext *tc) +{ + send_task = GNUNET_SCHEDULER_NO_TASK; + + ch = GNUNET_CORE_notify_transmit_ready (p1.ch, + 0, + FAST_TIMEOUT, + &p2.id, + sizeof (struct TestMessage) + MEASUREMENT_MSG_SIZE, + &transmit_ready, &p1); +} + static void measurement_end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct GNUNET_TIME_Relative duration; - + measure_task = GNUNET_SCHEDULER_NO_TASK; if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) return; - + if (err_task != GNUNET_SCHEDULER_NO_TASK) GNUNET_SCHEDULER_cancel (err_task); if (send_task != GNUNET_SCHEDULER_NO_TASK) GNUNET_SCHEDULER_cancel (send_task); - + GNUNET_STATISTICS_get(p1.stats,"core","# discarded CORE_SEND requests",GNUNET_TIME_UNIT_SECONDS, &next_fin, &check_2, &p1); GNUNET_STATISTICS_get(p1.stats,"core","# discarded CORE_SEND requests",GNUNET_TIME_UNIT_SECONDS, &next_fin, &check_2, &p2); GNUNET_STATISTICS_get(p1.stats,"core","# discarded lower priority CORE_SEND requests",GNUNET_TIME_UNIT_SECONDS, &next_fin, &check_2, &p1); GNUNET_STATISTICS_get(p1.stats,"core","# discarded lower priority CORE_SEND requests",GNUNET_TIME_UNIT_SECONDS, &next_fin, &check_2, &p2); - + GNUNET_STATISTICS_get(p1.stats,"core","# discarded CORE_SEND request bytes",GNUNET_TIME_UNIT_SECONDS, &next_fin, &check_2, &p1); GNUNET_STATISTICS_get(p1.stats,"core","# discarded CORE_SEND request bytes",GNUNET_TIME_UNIT_SECONDS, &next_fin, &check_2, &p2); GNUNET_STATISTICS_get(p1.stats,"core","# discarded lower priority CORE_SEND request bytes",GNUNET_TIME_UNIT_SECONDS, &next_fin, &check_2, &p1); @@ -267,25 +227,8 @@ measurement_end (void *cls, GNUNET_SCHEDULER_add_now (&terminate_task, NULL); } -static size_t -transmit_ready (void *cls, size_t size, void *buf); static void -send_tsk (void *cls, - const struct GNUNET_SCHEDULER_TaskContext *tc) -{ - send_task = GNUNET_SCHEDULER_NO_TASK; - - ch = GNUNET_CORE_notify_transmit_ready (p1.ch, - 0, - FAST_TIMEOUT, - &p2.id, - sizeof (struct TestMessage) + MEASUREMENT_MSG_SIZE, - &transmit_ready, &p1); -} - - -static void measure (unsigned long long quota_p1, unsigned long long quota_p2) { #if VERBOSE @@ -320,6 +263,70 @@ measure (unsigned long long quota_p1, unsigned long long quota_p2) &transmit_ready, &p1); } +static void connect_notify (void *cls, + const struct GNUNET_PeerIdentity *peer, + const struct GNUNET_TRANSPORT_ATS_Information *atsi) +{ + struct PeerContext *pc = cls; + + GNUNET_assert (pc->connect_status == 0); + pc->connect_status = 1; + if (pc == &p1) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Encrypted connection established to peer `%4s'\n", + GNUNET_i2s (peer)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Asking core (1) for transmission to peer `%4s'\n", + GNUNET_i2s (&p2.id)); + measure (MEASUREMENT_MIN_QUOTA, MEASUREMENT_MIN_QUOTA); + } +} + + +static void +disconnect_notify (void *cls, + const struct GNUNET_PeerIdentity *peer) +{ + struct PeerContext *pc = cls; + pc->connect_status = 0; +#if DEBUG_CONNECTIONS + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Encrypted connection to `%4s' cut\n", GNUNET_i2s (peer)); +#endif +} + + +static int +inbound_notify (void *cls, + const struct GNUNET_PeerIdentity *other, + const struct GNUNET_MessageHeader *message, + const struct GNUNET_TRANSPORT_ATS_Information *atsi) +{ + total_bytes_recv += ntohs (message->size); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Core provides inbound data from `%4s' size %u.\n", GNUNET_i2s (other), ntohs (message->size)); +#if DEBUG_CONNECTIONS + #endif + return GNUNET_OK; +} + + +static int +outbound_notify (void *cls, + const struct GNUNET_PeerIdentity *other, + const struct GNUNET_MessageHeader *message, + const struct GNUNET_TRANSPORT_ATS_Information *atsi) +{ +#if DEBUG_CONNECTIONS + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Core notifies about outbound data for `%4s'.\n", + GNUNET_i2s (other)); +#endif + return GNUNET_OK; +} + + static int tr_n; @@ -369,7 +376,7 @@ transmit_ready (void *cls, size_t size, void *buf) if (measurement_running != GNUNET_YES) return 0; - GNUNET_assert (size <= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE); + GNUNET_assert (size <= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE); if (buf == NULL) { if (p1.ch != NULL) @@ -414,7 +421,7 @@ transmit_ready (void *cls, size_t size, void *buf) while (size - ret >= s); GNUNET_SCHEDULER_cancel (err_task); err_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, - &terminate_task_error, + &terminate_task_error, NULL); total_bytes += ret; @@ -453,7 +460,7 @@ init_notify (void *cls, &init_notify, &connect_notify, &disconnect_notify, - NULL, + NULL, &inbound_notify, GNUNET_YES, &outbound_notify, GNUNET_YES, handlers); @@ -463,8 +470,13 @@ init_notify (void *cls, GNUNET_assert (ok == 3); OKPP; GNUNET_assert (cls == &p2); - - measure (MEASUREMENT_MIN_QUOTA, MEASUREMENT_MIN_QUOTA); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Asking core (1) to connect to peer `%4s'\n", + GNUNET_i2s (&p2.id)); + GNUNET_CORE_peer_request_connect (p1.ch, + GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5), + &p2.id, + NULL, NULL); } } -- 2.25.1