From 7cc01327be9a215ed817c462c3ee44c3db131398 Mon Sep 17 00:00:00 2001 From: Bart Polot Date: Wed, 10 Jun 2015 12:08:20 +0000 Subject: [PATCH] - refactor connection timeout into one implementation - always send CONNECTION_BROKEN to alert of the timeout --- src/cadet/gnunet-service-cadet_connection.c | 79 +++++++++++---------- 1 file changed, 42 insertions(+), 37 deletions(-) diff --git a/src/cadet/gnunet-service-cadet_connection.c b/src/cadet/gnunet-service-cadet_connection.c index b257ab53d..969a307cc 100644 --- a/src/cadet/gnunet-service-cadet_connection.c +++ b/src/cadet/gnunet-service-cadet_connection.c @@ -1375,39 +1375,42 @@ resend_messages_and_destroy (struct CadetConnection *c, int fwd) /** - * Timeout function due to lack of keepalive/traffic from the owner. + * Generic connection timeout implementation. + * + * Timeout function due to lack of keepalive/traffic from an endpoint. * Destroys connection if called. * - * @param cls Closure (connection to destroy). - * @param tc TaskContext. + * @param c Connection to destroy. + * @param fwd Was the timeout from the origin? (FWD timeout) */ static void -connection_fwd_timeout (void *cls, - const struct GNUNET_SCHEDULER_TaskContext *tc) +connection_timeout (struct CadetConnection *c, int fwd) { - struct CadetConnection *c = cls; + struct CadetFlowControl *reverse_fc; - c->fwd_maintenance_task = NULL; - if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) - return; + reverse_fc = fwd ? c->bck_fc : c->fwd_fc; LOG (GNUNET_ERROR_TYPE_INFO, - "Connection %s FWD timed out. Destroying.\n", - GCC_2s (c)); + "Connection %s %s timed out. Destroying.\n", + GCC_2s (c), + GC_f2s (fwd)); GCC_debug (c, GNUNET_ERROR_TYPE_DEBUG); - if (GCC_is_origin (c, GNUNET_YES)) /* If local, leave. */ + if (GCC_is_origin (c, fwd)) /* Loopback? Something is wrong! */ { GNUNET_break (0); return; } /* If dest, salvage queued traffic. */ - if (GCC_is_origin (c, GNUNET_NO) && 0 < c->bck_fc.queue_n) + if (GCC_is_origin (c, !fwd)) { - send_broken_unknown (&c->id, &my_full_id, NULL, - GCP_get_id( get_prev_hop (c))); - resend_messages_and_destroy (c, GNUNET_NO); + struct GNUNET_PeerIdentity *next_hop; + + next_hop = fwd ? get_prev_hop (c) : get_next_hop (c); + send_broken_unknown (&c->id, &my_full_id, NULL, GCP_get_id (next_hop)); + if (0 < reverse_fc->queue_n) + resend_messages_and_destroy (c, !fwd); return; } @@ -1416,43 +1419,45 @@ connection_fwd_timeout (void *cls, /** - * Timeout function due to lack of keepalive/traffic from the destination. + * Timeout function due to lack of keepalive/traffic from the owner. * Destroys connection if called. * - * FIXME refactor and merge with connection_fwd_timeout. - * * @param cls Closure (connection to destroy). - * @param tc TaskContext + * @param tc TaskContext. */ static void -connection_bck_timeout (void *cls, +connection_fwd_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct CadetConnection *c = cls; + struct CadetFlowControl *fc; - c->bck_maintenance_task = NULL; + c->fwd_maintenance_task = NULL; if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) return; - LOG (GNUNET_ERROR_TYPE_INFO, "Connection %s BCK timed out. Destroying.\n", - GCC_2s (c)); + connection_timeout (c, GNUNET_YES); +} - if (GCC_is_origin (c, GNUNET_NO)) /* If local, leave. */ - { - GNUNET_break (0); - return; - } - /* If dest, salvage queued traffic. */ - if (GCC_is_origin (c, GNUNET_YES) && 0 < c->fwd_fc.queue_n) - { - send_broken_unknown (&c->id, &my_full_id, NULL, - GCP_get_id (get_next_hop (c))); - resend_messages_and_destroy (c, GNUNET_YES); +/** + * Timeout function due to lack of keepalive/traffic from the destination. + * Destroys connection if called. + * + * @param cls Closure (connection to destroy). + * @param tc TaskContext + */ +static void +connection_bck_timeout (void *cls, + const struct GNUNET_SCHEDULER_TaskContext *tc) +{ + struct CadetConnection *c = cls; + + c->bck_maintenance_task = NULL; + if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) return; - } - GCC_destroy (c); + connection_timeout (c, GNUNET_NO); } -- 2.25.1