-rps: proper cleaning/removing of peers
authorJulius Bünger <buenger@mytum.de>
Sun, 25 Sep 2016 15:08:59 +0000 (15:08 +0000)
committerJulius Bünger <buenger@mytum.de>
Sun, 25 Sep 2016 15:08:59 +0000 (15:08 +0000)
src/rps/gnunet-service-rps.c
src/rps/gnunet-service-rps_peers.c
src/rps/gnunet-service-rps_peers.h

index 974953ea09c74d0d522fb9ad2e7e203c3dc0046b..7d4b341033c371557393f17603d47f88b4f62836 100644 (file)
@@ -813,12 +813,15 @@ clean_peer (const struct GNUNET_PeerIdentity *peer)
        (GNUNET_NO == CustomPeerMap_contains_peer (push_map, peer)) &&
        (GNUNET_NO == CustomPeerMap_contains_peer (push_map, peer)) &&
        (0 == RPS_sampler_count_id (prot_sampler,   peer)) &&
-       (0 == RPS_sampler_count_id (client_sampler, peer)) )
-  { /* We can safely remov this peer */
+       (0 == RPS_sampler_count_id (client_sampler, peer)) &&
+       (GNUNET_NO != Peers_check_removable (peer)) )
+  { /* We can safely remove this peer */
+    LOG (GNUNET_ERROR_TYPE_DEBUG,
+        "Going to remove peer %s\n",
+        GNUNET_i2s (peer));
     remove_peer (peer);
     return;
   }
-  Peers_clean_peer (peer);
 }
 
 /**
@@ -826,6 +829,8 @@ clean_peer (const struct GNUNET_PeerIdentity *peer)
  *
  * Removes peer completely from our knowledge if the send_channel was destroyed
  * Otherwise simply delete the recv_channel
+ * Also check if the knowledge about this peer is still needed.
+ * If not, remove this peer from our knowledge.
  *
  * @param cls The closure
  * @param channel The channel being closed
@@ -1980,7 +1985,7 @@ do_round (void *cls)
       to_file (file_name_view_log,
                "-%s",
                GNUNET_i2s_full (&peers_to_clean[i]));
-      Peers_clean_peer (&peers_to_clean[i]);
+      clean_peer (&peers_to_clean[i]);
       //peer_destroy_channel_send (sender);
     }
 
@@ -2008,7 +2013,7 @@ do_round (void *cls)
          "Updating with peer %s from push list\n",
          GNUNET_i2s (update_peer));
     insert_in_sampler (NULL, update_peer);
-    Peers_clean_peer (update_peer); /* This cleans only if it is not in the view */
+    clean_peer (update_peer); /* This cleans only if it is not in the view */
     //peer_destroy_channel_send (sender);
   }
 
@@ -2019,7 +2024,7 @@ do_round (void *cls)
          GNUNET_i2s (CustomPeerMap_get_peer_by_index (pull_map, i)));
     insert_in_sampler (NULL, CustomPeerMap_get_peer_by_index (pull_map, i));
     /* This cleans only if it is not in the view */
-    Peers_clean_peer (CustomPeerMap_get_peer_by_index (pull_map, i));
+    clean_peer (CustomPeerMap_get_peer_by_index (pull_map, i));
     //peer_destroy_channel_send (sender);
   }
 
index d2a995c1de2351e6708be8a1f223da7fea7844d1..e0b278bd00225d9cfc85281cedfe4360409cde47 100644 (file)
@@ -1073,26 +1073,26 @@ Peers_issue_peer_liveliness_check (const struct GNUNET_PeerIdentity *peer)
 
 
 /**
- * @brief Remove unecessary data
+ * @brief Check if peer is removable.
  *
- * If the other peer is not intending to send messages, we have messages pending
- * to be sent to this peer and we are not waiting for a reply, remove the
- * information about it (its #PeerContext).
+ * Check if
+ *  - a recv channel exists
+ *  - there are pending messages
+ *  - there is no pending pull reply
  *
- * @param peer the peer to clean
- * @return #GNUNET_YES if peer was removed
- *         #GNUNET_NO  otherwise
+ * @param peer the peer in question
+ * @return #GNUNET_YES    if peer is removable
+ *         #GNUNET_NO     if peer is NOT removable
+ *         #GNUNET_SYSERR if peer is not known
  */
 int
-Peers_clean_peer (const struct GNUNET_PeerIdentity *peer)
+Peers_check_removable (const struct GNUNET_PeerIdentity *peer)
 {
   struct PeerContext *peer_ctx;
 
-  // TODO actually remove unnecessary data
-
   if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (peer_map, peer))
   {
-    return GNUNET_NO;
+    return GNUNET_SYSERR;
   }
 
   peer_ctx = get_peer_ctx (peer);
@@ -1102,7 +1102,6 @@ Peers_clean_peer (const struct GNUNET_PeerIdentity *peer)
   {
     return GNUNET_NO;
   }
-  Peers_remove_peer (peer);
   return GNUNET_YES;
 }
 
index c7b9ed265f3a7d73bac7fec3fbe292a2653bf6a6..bbac8600339c904119b36f5ce25615576e551858 100644 (file)
@@ -172,18 +172,20 @@ int
 Peers_issue_peer_liveliness_check (const struct GNUNET_PeerIdentity *peer);
 
 /**
- * @brief Remove unecessary data
+ * @brief Check if peer is removable.
  *
- * If the other peer is not intending to send messages, we have messages pending
- * to be sent to this peer and we are not waiting for a reply, remove the
- * information about it (its #PeerContext).
+ * Check if
+ *  - a recv channel exists
+ *  - there are pending messages
+ *  - there is no pending pull reply
  *
- * @param peer the peer to clean
- * @return #GNUNET_YES if peer was removed
- *         #GNUNET_NO  otherwise
+ * @param peer the peer in question
+ * @return #GNUNET_YES    if peer is removable
+ *         #GNUNET_NO     if peer is NOT removable
+ *         #GNUNET_SYSERR if peer is not known
  */
 int
-Peers_clean_peer (const struct GNUNET_PeerIdentity *peer);
+Peers_check_removable (const struct GNUNET_PeerIdentity *peer);
 
 /**
  * @brief Remove peer