From 98e80df6a13b647258fedbb5f20658a582e255bf Mon Sep 17 00:00:00 2001 From: Bart Polot Date: Wed, 15 Oct 2014 00:55:51 +0000 Subject: [PATCH] - only try to pop messages if there are any, otherwise directly destory the connection --- src/cadet/gnunet-service-cadet_connection.c | 37 ++++++++++++++------- 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/src/cadet/gnunet-service-cadet_connection.c b/src/cadet/gnunet-service-cadet_connection.c index 147bf1e8e..2cf6d2dd9 100644 --- a/src/cadet/gnunet-service-cadet_connection.c +++ b/src/cadet/gnunet-service-cadet_connection.c @@ -1812,7 +1812,7 @@ GCC_handle_broken (void* cls, struct GNUNET_CADET_ConnectionBroken *msg; struct CadetConnection *c; struct CadetTunnel *t; - int destroyed; + int pending; int fwd; msg = (struct GNUNET_CADET_ConnectionBroken *) message; @@ -1848,24 +1848,37 @@ GCC_handle_broken (void* cls, endpoint = GCP_get_short (c->path->peers[c->path->length - 1]); path_invalidate (c->path); GCP_notify_broken_link (endpoint, &msg->peer1, &msg->peer2); + c->state = CADET_CONNECTION_BROKEN; GCT_remove_connection (t, c); c->t = NULL; - destroyed = GNUNET_NO; - /* GCP_connection_pop could destroy the connection! */ - while (NULL != (out_msg = GCP_connection_pop (neighbor, c, &destroyed))) + pending = c->pending_messages; + if (0 < pending) { - GCT_resend_message (out_msg, t); + int destroyed; + + destroyed = GNUNET_NO; + + /* GCP_connection_pop could destroy the connection! */ + while (NULL != (out_msg = GCP_connection_pop (neighbor, c, &destroyed))) + { + GCT_resend_message (out_msg, t); + } + + /* All pending messages should have been popped, + * and the connection destroyed by the continuation, + * except if the queue was empty. */ + if (GNUNET_YES != destroyed) + { + GNUNET_break (0); + GCC_debug (c, GNUNET_ERROR_TYPE_ERROR); + GCT_debug (t, GNUNET_ERROR_TYPE_ERROR); + GCC_destroy (c); + } } - /* All pending messages should have been popped, - * and the connection destroyed by the continuation. - */ - if (GNUNET_YES != destroyed) + else { - GNUNET_break (0); - GCC_debug (c, GNUNET_ERROR_TYPE_ERROR); - GCT_debug (t, GNUNET_ERROR_TYPE_ERROR); GCC_destroy (c); } } -- 2.25.1