From: Christian Grothoff Date: Thu, 16 Feb 2017 20:55:13 +0000 (+0100) Subject: properly clean up unbound channels X-Git-Tag: taler-0.2.1~167 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=dd5a385e16168f9d4fe43dde53e49b77a15afa6e;p=oweals%2Fgnunet.git properly clean up unbound channels --- diff --git a/src/cadet/gnunet-service-cadet-new.c b/src/cadet/gnunet-service-cadet-new.c index 55c7d1bdb..1f28745e1 100644 --- a/src/cadet/gnunet-service-cadet-new.c +++ b/src/cadet/gnunet-service-cadet-new.c @@ -1199,6 +1199,24 @@ GSC_handle_remote_channel_destroy (struct CadetClient *c, } +/** + * A client that created a loose channel that was not bound to a port + * disconnected, drop it from the #loose_channels list. + * + * @param port the port the channel was trying to bind to + * @param ch the channel that was lost + */ +void +GSC_drop_loose_channel (const struct GNUNET_HashCode *port, + struct CadetChannel *ch) +{ + GNUNET_assert (GNUNET_YES == + GNUNET_CONTAINER_multihashmap_remove (loose_channels, + port, + ch)); +} + + /** * Iterator for deleting each channel whose client endpoint disconnected. * diff --git a/src/cadet/gnunet-service-cadet-new.h b/src/cadet/gnunet-service-cadet-new.h index dff0d3c8c..bee5c67cc 100644 --- a/src/cadet/gnunet-service-cadet-new.h +++ b/src/cadet/gnunet-service-cadet-new.h @@ -264,6 +264,17 @@ GSC_handle_remote_channel_destroy (struct CadetClient *c, struct GNUNET_CADET_ClientChannelNumber ccn, struct CadetChannel *ch); +/** + * A client that created a loose channel that was not bound to a port + * disconnected, drop it from the #loose_channels list. + * + * @param port the port the channel was trying to bind to + * @param ch the channel that was lost + */ +void +GSC_drop_loose_channel (const struct GNUNET_HashCode *port, + struct CadetChannel *ch); + /** * Bind incoming channel to this client, and notify client diff --git a/src/cadet/gnunet-service-cadet-new_channel.c b/src/cadet/gnunet-service-cadet-new_channel.c index fe3faef5a..9d9edc28d 100644 --- a/src/cadet/gnunet-service-cadet-new_channel.c +++ b/src/cadet/gnunet-service-cadet-new_channel.c @@ -1044,7 +1044,10 @@ GCCH_channel_local_destroy (struct CadetChannel *ch, return; } /* If the we ever sent the CHANNEL_CREATE, we need to send a destroy message. */ - if (CADET_CHANNEL_NEW != ch->state) + if (CADET_CHANNEL_NEW == ch->state) + GSC_drop_loose_channel (&ch->port, + ch); + else GCT_send_channel_destroy (ch->t, ch->ctn); /* Nothing left to do, just finish destruction */ @@ -1710,6 +1713,11 @@ GCCH_handle_local_data (struct CadetChannel *ch, GNUNET_break (0); return GNUNET_SYSERR; } + if (GNUNET_YES == ch->destroy) + { + /* we are going down, drop messages */ + return GNUNET_OK; + } ch->pending_messages++; if (GNUNET_YES == ch->is_loopback) @@ -1722,19 +1730,25 @@ GCCH_handle_local_data (struct CadetChannel *ch, env = GNUNET_MQ_msg_extra (ld, buf_len, GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA); - if (sender_ccn.channel_of_client == - ch->owner->ccn.channel_of_client) + if ( (NULL != ch->owner) && + (sender_ccn.channel_of_client == + ch->owner->ccn.channel_of_client) ) { receiver = ch->dest; to_owner = GNUNET_NO; } - else + else if ( (NULL != ch->dest) && + (sender_ccn.channel_of_client == + ch->dest->ccn.channel_of_client) ) { - GNUNET_assert (sender_ccn.channel_of_client == - ch->dest->ccn.channel_of_client); receiver = ch->owner; to_owner = GNUNET_YES; } + else + { + GNUNET_break (0); + return GNUNET_SYSERR; + } ld->ccn = receiver->ccn; GNUNET_memcpy (&ld[1], buf,