-restructured cleaning of known peers
authorJulius Bünger <buenger@mytum.de>
Sat, 20 Jun 2015 13:48:19 +0000 (13:48 +0000)
committerJulius Bünger <buenger@mytum.de>
Sat, 20 Jun 2015 13:48:19 +0000 (13:48 +0000)
src/rps/gnunet-service-rps.c

index 63c9dcffaf0d7ce9c63e0f9c1b806d0e3127adc8..34501937dce5c7e3246da404ada10e3a063af96e 100644 (file)
@@ -923,8 +923,6 @@ insert_in_pull_list (void *cls, const struct GNUNET_PeerIdentity *peer)
 {
   if (GNUNET_NO == in_arr (pull_list, pull_list_size, peer))
     GNUNET_array_append (pull_list, pull_list_size, *peer);
-
-  peer_clean (peer);
 }
 
 /**
@@ -2349,29 +2347,6 @@ process_peerinfo_peers (void *cls,
 }
 
 
-/**
- * Clean the send channel of a peer
- */
-void
-peer_clean (const struct GNUNET_PeerIdentity *peer)
-{
-  struct PeerContext *peer_ctx;
-  struct GNUNET_CADET_Channel *channel;
-
-  if (GNUNET_YES != GNUNET_CONTAINER_multipeermap_contains (view, peer) &&
-      GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (peer_map, peer))
-  {
-    peer_ctx = get_peer_ctx (peer_map, peer);
-    if (NULL != peer_ctx->send_channel)
-    {
-      channel = peer_ctx->send_channel;
-      peer_ctx->send_channel = NULL;
-      GNUNET_CADET_channel_destroy (channel);
-    }
-  }
-}
-
-
 /**
  * Callback used to remove peers from the multipeermap.
  */
@@ -2453,6 +2428,32 @@ peer_remove_cb (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
 }
 
 
+/**
+ * Clean the send channel of a peer
+ * If there is also no channel to receive messages from that peer, remove it
+ * from the peermap.
+ */
+void
+peer_clean (const struct GNUNET_PeerIdentity *peer)
+{
+  struct PeerContext *peer_ctx;
+  /* struct GNUNET_CADET_Channel *channel; */
+
+  if (GNUNET_YES != GNUNET_CONTAINER_multipeermap_contains (view, peer) &&
+      GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (peer_map, peer))
+  {
+    peer_ctx = get_peer_ctx (peer_map, peer);
+    GNUNET_CADET_channel_destroy (peer_ctx->send_channel);
+    peer_ctx->send_channel = NULL;
+
+    if (NULL == peer_ctx->recv_channel)
+    {
+      peer_remove_cb (NULL, peer, peer_ctx);
+    }
+  }
+}
+
+
 /**
  * Task run during shutdown.
  *