From 4253dace949ef4d4480b26d091046ff08fa1b6bc Mon Sep 17 00:00:00 2001 From: Bart Polot Date: Mon, 15 Dec 2014 07:17:55 +0000 Subject: [PATCH] Fix connection count to count only ESTABLISHED connections, use DEFINE instead of hardcoded number --- src/cadet/gnunet-service-cadet_connection.c | 4 +++- src/cadet/gnunet-service-cadet_peer.c | 15 +++++++------- src/cadet/gnunet-service-cadet_tunnel.c | 23 ++++++++++++--------- src/cadet/gnunet-service-cadet_tunnel.h | 2 ++ 4 files changed, 25 insertions(+), 19 deletions(-) diff --git a/src/cadet/gnunet-service-cadet_connection.c b/src/cadet/gnunet-service-cadet_connection.c index ee96dddf8..fe4a22747 100644 --- a/src/cadet/gnunet-service-cadet_connection.c +++ b/src/cadet/gnunet-service-cadet_connection.c @@ -1833,6 +1833,7 @@ GCC_handle_broken (void* cls, } t = c->t; + fwd = is_fwd (c, id); c->destroy = GNUNET_YES; if (GCC_is_terminal (c, fwd)) @@ -2699,7 +2700,8 @@ GCC_get_allowed (struct CadetConnection *c, int fwd) struct CadetFlowControl *fc; fc = fwd ? &c->fwd_fc : &c->bck_fc; - if (GC_is_pid_bigger (fc->last_pid_recv, fc->last_ack_sent)) + if (CADET_CONNECTION_READY != c->state + || GC_is_pid_bigger (fc->last_pid_recv, fc->last_ack_sent)) { return 0; } diff --git a/src/cadet/gnunet-service-cadet_peer.c b/src/cadet/gnunet-service-cadet_peer.c index b57c77e11..838a2d3de 100644 --- a/src/cadet/gnunet-service-cadet_peer.c +++ b/src/cadet/gnunet-service-cadet_peer.c @@ -941,8 +941,8 @@ search_handler (void *cls, const struct CadetPeerPath *path) /* Count connections */ connection_count = GCT_count_connections (peer->tunnel); - /* If we already have 3 (or more (?!)) connections, it's enough */ - if (3 <= connection_count) + /* If we already have our minimum (or more) connections, it's enough */ + if (CONNECTIONS_PER_TUNNEL <= connection_count) return; if (CADET_TUNNEL_SEARCHING == GCT_get_cstate (peer->tunnel)) @@ -1914,11 +1914,7 @@ GCP_add_path (struct CadetPeer *peer, struct CadetPeerPath *path, LOG (GNUNET_ERROR_TYPE_DEBUG, " added\n"); GNUNET_CONTAINER_DLL_insert_before (peer->path_head, peer->path_tail, aux, path); - if (NULL != peer->tunnel && 3 < GCT_count_connections (peer->tunnel)) - { - GCP_connect (peer); - } - return path; + goto finish; } else { @@ -1933,7 +1929,10 @@ GCP_add_path (struct CadetPeer *peer, struct CadetPeerPath *path, GNUNET_CONTAINER_DLL_insert_tail (peer->path_head, peer->path_tail, path); LOG (GNUNET_ERROR_TYPE_DEBUG, " added last\n"); - if (NULL != peer->tunnel && 3 < GCT_count_connections (peer->tunnel)) + +finish: + if (NULL != peer->tunnel + && CONNECTIONS_PER_TUNNEL < GCT_count_connections (peer->tunnel)) { GCP_connect (peer); } diff --git a/src/cadet/gnunet-service-cadet_tunnel.c b/src/cadet/gnunet-service-cadet_tunnel.c index 44b9f3153..cab5809a3 100644 --- a/src/cadet/gnunet-service-cadet_tunnel.c +++ b/src/cadet/gnunet-service-cadet_tunnel.c @@ -37,8 +37,6 @@ #define REKEY_WAIT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5) -#define CONNECTIONS_PER_TUNNEL 3 - #if !defined(GNUNET_CULL_LOGGING) #define DUMP_KEYS_TO_STDERR GNUNET_YES #else @@ -2332,7 +2330,7 @@ trim_connections (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) for (c = iter = t->connection_head; NULL != iter; iter = iter->next) { - if ((NULL == c || iter->created.abs_value_us > c->created.abs_value_us) + if ((iter->created.abs_value_us > c->created.abs_value_us) && GNUNET_NO == GCC_is_direct (iter->c)) { c = iter; @@ -2788,7 +2786,7 @@ GCT_count_connections (struct CadetTunnel *t) return 0; for (count = 0, iter = t->connection_head; NULL != iter; iter = iter->next) - if (CADET_CONNECTION_DESTROYED != GCC_get_state (iter->c)) + if (CADET_CONNECTION_READY == GCC_get_state (iter->c)) count++; return count; @@ -3065,24 +3063,29 @@ GCT_send_connection_acks (struct CadetTunnel *t) } /* Authorize connections to send more data */ - to_allow = buffer; /* - allowed; */ + to_allow = buffer; /* FIXME (- allowed;) */ for (iter = t->connection_head; NULL != iter && to_allow > 0; iter = iter->next) { - allow_per_connection = to_allow/cs; - to_allow -= allow_per_connection; - cs--; - if (get_connection_allowed (iter) > 64 / 3) + if (CADET_CONNECTION_READY != GCC_get_state (iter->c) + || get_connection_allowed (iter) > 64 / 3) { continue; } + allow_per_connection = to_allow/cs; + to_allow -= allow_per_connection; + cs--; GCC_allow (iter->c, allow_per_connection, GCC_is_origin (iter->c, GNUNET_NO)); } - GNUNET_break (to_allow == 0); //FIXME tripped + if (0 != to_allow) + { + GNUNET_break (0); + LOG (GNUNET_ERROR_TYPE_WARNING, " reminding to_allow: %u\n", to_allow); + } } diff --git a/src/cadet/gnunet-service-cadet_tunnel.h b/src/cadet/gnunet-service-cadet_tunnel.h index 3c57896d5..12be8a032 100644 --- a/src/cadet/gnunet-service-cadet_tunnel.h +++ b/src/cadet/gnunet-service-cadet_tunnel.h @@ -40,6 +40,8 @@ extern "C" #include "platform.h" #include "gnunet_util_lib.h" +#define CONNECTIONS_PER_TUNNEL 3 + /** * All the connectivity states a tunnel can be in. */ -- 2.25.1