From 6ca3d645119db22bea49e7111970cc5ab8e7d33c Mon Sep 17 00:00:00 2001 From: csoler Date: Tue, 8 Mar 2022 21:28:42 +0100 Subject: [PATCH] added list of already received peers from FS so that we do not request them again --- libbitdht | 2 +- libretroshare | 2 +- retroshare-friendserver/src/friendserver.cc | 26 +++++++++++++-------- retroshare-friendserver/src/friendserver.h | 2 +- 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/libbitdht b/libbitdht index 6abbec950..659423769 160000 --- a/libbitdht +++ b/libbitdht @@ -1 +1 @@ -Subproject commit 6abbec95073f3c1eb5059cbf8441111ef4a317a7 +Subproject commit 659423769541169457c41f71c8a038e2d64ba079 diff --git a/libretroshare b/libretroshare index 59ebd8136..ac742c869 160000 --- a/libretroshare +++ b/libretroshare @@ -1 +1 @@ -Subproject commit 59ebd813697eda75b188ea5a8cc5d650c5602700 +Subproject commit ac742c869a7187de467c38e73c0ea7b87e09ffdb diff --git a/retroshare-friendserver/src/friendserver.cc b/retroshare-friendserver/src/friendserver.cc index 523a76640..e63156ae6 100644 --- a/retroshare-friendserver/src/friendserver.cc +++ b/retroshare-friendserver/src/friendserver.cc @@ -88,7 +88,7 @@ void FriendServer::handleClientPublish(const RsFriendServerClientPublishItem *it std::map friends; sr_item.nonce = pi->second.last_nonce; - sr_item.friend_invites = computeListOfFriendInvites(item->n_requested_friends,pi->first,friends); + sr_item.friend_invites = computeListOfFriendInvites(item->n_requested_friends,item->already_received_peers,pi->first,friends); sr_item.PeerId(item->PeerId()); // Update the have_added_as_friend for the list of each peer. We do that before sending because sending destroys @@ -142,7 +142,10 @@ void FriendServer::handleClientPublish(const RsFriendServerClientPublishItem *it } } -std::map FriendServer::computeListOfFriendInvites(uint32_t nb_reqs_invites, const RsPeerId &pid, std::map& friends) +std::map FriendServer::computeListOfFriendInvites(uint32_t nb_reqs_invites, + const std::set& already_known_peers, + const RsPeerId &pid, + std::map& friends) { // Strategy: we want to return the same set of friends for a given PGP profile key. // Still, using some closest distance strategy, the n-closest peers for profile A is not the @@ -168,17 +171,20 @@ std::map FriendServer::computeListOfFriendInvites(uint32_t nb std::map res; - auto add_from = [&res,&friends,nb_reqs_invites,this](bool added,const std::map& lst) -> bool + auto add_from = [&res,&friends,nb_reqs_invites,already_known_peers,this](bool added, + const std::map& lst) -> bool { for(const auto& pid:lst) - { - const auto p = mCurrentClientPeers.find(pid.second); - res.insert(std::make_pair(p->second.short_certificate,added)); - friends.insert(std::make_pair(p->first,p->second.pgp_fingerprint)); + if(already_known_peers.find(pid.second) == already_known_peers.end()) + { + const auto p = mCurrentClientPeers.find(pid.second); + res.insert(std::make_pair(p->second.short_certificate,added)); + friends.insert(std::make_pair(p->first,p->second.pgp_fingerprint)); + + if(res.size() + already_known_peers.size() >= nb_reqs_invites) + return true; + } - if(res.size() >= nb_reqs_invites) - return true; - } return false; }; diff --git a/retroshare-friendserver/src/friendserver.h b/retroshare-friendserver/src/friendserver.h index 4f46bebdc..7b688147a 100644 --- a/retroshare-friendserver/src/friendserver.h +++ b/retroshare-friendserver/src/friendserver.h @@ -69,7 +69,7 @@ private: std::map::iterator handleIncomingClientData(const std::string& pgp_public_key_b64,const std::string& short_invite_b64); // Computes the appropriate list of short invites to send to a given peer. - std::map computeListOfFriendInvites(uint32_t nb_reqs_invites, const RsPeerId &pid, std::map& friends); + std::map computeListOfFriendInvites(uint32_t nb_reqs_invites, const std::set &already_received_peers, const RsPeerId &pid, std::map& friends); // Compute the distance between peers using the random bias (It's not really a distance though. I'm not sure about the triangular inequality). PeerInfo::PeerDistance computePeerDistance(const RsPgpFingerprint &p1, const RsPgpFingerprint &p2);