From 6ebea190877edfd857ee8c75dfdbd3a2aa70219a Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 25 Jan 2021 21:13:37 +0100 Subject: [PATCH] added check for group/friends consistency at loadign time --- libretroshare/src/pqi/p3peermgr.cc | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/libretroshare/src/pqi/p3peermgr.cc b/libretroshare/src/pqi/p3peermgr.cc index b072a55de..1b5fc0684 100644 --- a/libretroshare/src/pqi/p3peermgr.cc +++ b/libretroshare/src/pqi/p3peermgr.cc @@ -1066,8 +1066,7 @@ bool p3PeerMgrIMPL::addFriend(const RsPeerId& input_id, const RsPgpId& input_gpg } -bool p3PeerMgrIMPL::addSslOnlyFriend( - const RsPeerId& sslId, const RsPgpId& pgp_id, const RsPeerDetails& dt ) +bool p3PeerMgrIMPL::addSslOnlyFriend( const RsPeerId& sslId, const RsPgpId& pgp_id, const RsPeerDetails& dt ) { constexpr auto fname = __PRETTY_FUNCTION__; const auto failure = [&](const std::string& err) @@ -2435,7 +2434,6 @@ void p3PeerMgrIMPL::saveDone() bool p3PeerMgrIMPL::loadList(std::list& load) { - // DEFAULTS. bool useExtAddrFinder = true; std::string proxyIpAddressTor = kConfigDefaultProxyServerIpAddr; @@ -2684,13 +2682,31 @@ bool p3PeerMgrIMPL::loadList(std::list& load) groupList[info.id] = info; } + + // Also filter out profiles in groups that are not friends. Normally this shouldn't be needed, but it's a precaution + + for(auto group_pair:groupList) + { + for(auto profileIdIt(group_pair.second.peerIds.begin());profileIdIt!=group_pair.second.peerIds.end();) + if(AuthGPG::getAuthGPG()->isGPGAccepted(*profileIdIt) || *profileIdIt == AuthGPG::getAuthGPG()->getGPGOwnId()) + ++profileIdIt; + else + { + std::cerr << "(WW) filtering out profile " << profileIdIt->toStdString() << " from group " << group_pair.first.toStdString() << " because it is not a friend anymore" << std::endl; + + auto tmp = profileIdIt; + ++tmp; + group_pair.second.peerIds.erase(profileIdIt); + profileIdIt=tmp; + + IndicateConfigChanged(); + } + } } // If we are hidden - don't want ExtAddrFinder - ever! if (isHidden()) - { useExtAddrFinder = false; - } mNetMgr->setIPServersEnabled(useExtAddrFinder);