From 0f498b21da0314edd8d35b419ea10ca25128bc83 Mon Sep 17 00:00:00 2001 From: Julius Bünger Date: Sun, 25 Sep 2016 15:08:59 +0000 Subject: -rps: proper cleaning/removing of peers --- src/rps/gnunet-service-rps.c | 17 +++++++++++------ src/rps/gnunet-service-rps_peers.c | 23 +++++++++++------------ src/rps/gnunet-service-rps_peers.h | 18 ++++++++++-------- 3 files changed, 32 insertions(+), 26 deletions(-) (limited to 'src/rps') diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c index 974953ea0..7d4b34103 100644 --- a/src/rps/gnunet-service-rps.c +++ b/src/rps/gnunet-service-rps.c @@ -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); } diff --git a/src/rps/gnunet-service-rps_peers.c b/src/rps/gnunet-service-rps_peers.c index d2a995c1d..e0b278bd0 100644 --- a/src/rps/gnunet-service-rps_peers.c +++ b/src/rps/gnunet-service-rps_peers.c @@ -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; } diff --git a/src/rps/gnunet-service-rps_peers.h b/src/rps/gnunet-service-rps_peers.h index c7b9ed265..bbac86003 100644 --- a/src/rps/gnunet-service-rps_peers.h +++ b/src/rps/gnunet-service-rps_peers.h @@ -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 -- cgit v1.2.3