properly clean up unbound channels
authorChristian Grothoff <christian@grothoff.org>
Thu, 16 Feb 2017 20:55:13 +0000 (21:55 +0100)
committerChristian Grothoff <christian@grothoff.org>
Thu, 16 Feb 2017 20:55:13 +0000 (21:55 +0100)
src/cadet/gnunet-service-cadet-new.c
src/cadet/gnunet-service-cadet-new.h
src/cadet/gnunet-service-cadet-new_channel.c

index 55c7d1bdb128b9cc6641be840b3bf3c636c0cd6c..1f28745e118a88008e30156fe18635ff5ced5378 100644 (file)
@@ -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.
  *
index dff0d3c8c0c9368e735abb8d97d78000731e6aa8..bee5c67cc0b5dc4853ce9a2f058adbdf151a9614 100644 (file)
@@ -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
index fe3faef5aefcab60e4c080c4f4d955daa5a2abcd..9d9edc28dae8b5db3303288c9845b7533e3d9180 100644 (file)
@@ -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,