From b26be4db08a07798b65fc7c58019ab6116f9e1a6 Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 19 Aug 2019 22:56:49 +0200 Subject: [PATCH] added more checks against inconsistencies --- .../src/gui/common/FriendListModel.cpp | 74 +++++++++---------- .../src/gui/common/FriendListModel.h | 4 + 2 files changed, 41 insertions(+), 37 deletions(-) diff --git a/retroshare-gui/src/gui/common/FriendListModel.cpp b/retroshare-gui/src/gui/common/FriendListModel.cpp index 645ff7da1..d90dbedd3 100644 --- a/retroshare-gui/src/gui/common/FriendListModel.cpp +++ b/retroshare-gui/src/gui/common/FriendListModel.cpp @@ -931,6 +931,30 @@ RsFriendListModel::EntryType RsFriendListModel::getType(const QModelIndex& i) co return e.type; } +std::map::const_iterator RsFriendListModel::checkProfileIndex(const RsPgpId& pgp_id,std::map& pgp_indices,std::vector& mProfiles,bool create) +{ + auto it2 = pgp_indices.find(pgp_id); + + if(it2 == pgp_indices.end()) + { + if(!create) + { + std::cerr << "(EE) trying to display profile " << pgp_id <<" that is actually not a friend." << std::endl; + return it2; + } + HierarchicalProfileInformation hprof ; + rsPeers->getGPGDetails(pgp_id,hprof.profile_info); + + pgp_indices[pgp_id] = mProfiles.size(); + mProfiles.push_back(hprof); + + it2 = pgp_indices.find(pgp_id); + + RsDbg() << " Creating profile pgp id = " << pgp_id << " (" << hprof.profile_info.name << ")" << std::endl; + } + return it2; +} + void RsFriendListModel::updateInternalData() { preMods(); @@ -945,11 +969,17 @@ void RsFriendListModel::updateInternalData() mTopLevel.clear(); // create a map of profiles and groups - std::map pgp_indices; + std::map pgp_indices; - // we start from the base and fill all locations in an array + // parse PGP friends that may or may not have a known location. Create the associated data. - // peer ids + std::list pgp_friends; + rsPeers->getGPGAcceptedList(pgp_friends); + + for(auto it(pgp_friends.begin());it!=pgp_friends.end();++it) + checkProfileIndex(*it,pgp_indices,mProfiles,true); + + // Now parse peer ids and look for the associated PGP id. If not found, raise an error. RsDbg() << "Updating Nodes information: " << std::endl; @@ -963,45 +993,15 @@ void RsFriendListModel::updateInternalData() HierarchicalNodeInformation hnode ; rsPeers->getPeerDetails(*it,hnode.node_info); - auto it2 = pgp_indices.find(hnode.node_info.gpg_id); + auto it2 = checkProfileIndex(hnode.node_info.gpg_id,pgp_indices,mProfiles,false); if(it2 == pgp_indices.end()) - { - HierarchicalProfileInformation hprof ; - rsPeers->getGPGDetails(hnode.node_info.gpg_id,hprof.profile_info); + continue; - pgp_indices[hnode.node_info.gpg_id] = mProfiles.size(); - mProfiles.push_back(hprof); - - it2 = pgp_indices.find(hnode.node_info.gpg_id); - - RsDbg() << " Profile " << *it << " pgp id = " << hnode.node_info.gpg_id << " (" << hprof.profile_info.name << ")" << std::endl; - } mProfiles[it2->second].child_node_indices.push_back(mLocations.size()); - mLocations.push_back(hnode); } - // also parse PGP friends that may not have a known location - - std::list pgp_friends; - rsPeers->getGPGAcceptedList(pgp_friends); - - for(auto it(pgp_friends.begin());it!=pgp_friends.end();++it) - { - auto it2 = pgp_indices.find(*it); - - if(it2 != pgp_indices.end()) - continue; - - HierarchicalProfileInformation hprof ; - rsPeers->getGPGDetails(*it,hprof.profile_info); - - RsDbg() << " Profile (without nodes) " << *it << " (" << hprof.profile_info.name << ")" << std::endl; - - pgp_indices[*it] = mProfiles.size(); - mProfiles.push_back(hprof); - } // finally, parse groups @@ -1027,10 +1027,10 @@ void RsFriendListModel::updateInternalData() { // Then for each peer in this group, make sure that the peer is already known, and if not create it - auto it3 = pgp_indices.find(*it2); + auto it3 = checkProfileIndex(*it2,pgp_indices,mProfiles,false); if(it3 == pgp_indices.end())// not found - RsErr() << "Inconsistency error!" << std::endl; + continue; hgroup.child_profile_indices.push_back(it3->second); } diff --git a/retroshare-gui/src/gui/common/FriendListModel.h b/retroshare-gui/src/gui/common/FriendListModel.h index d479f216d..2418aed9e 100644 --- a/retroshare-gui/src/gui/common/FriendListModel.h +++ b/retroshare-gui/src/gui/common/FriendListModel.h @@ -153,6 +153,10 @@ private: const HierarchicalNodeInformation *getNodeInfo(const EntryIndex&) const; bool getPeerOnlineStatus(const EntryIndex& e) const; + std::map::const_iterator checkProfileIndex(const RsPgpId& pgp_id, + std::map& pgp_indices, + std::vector& mProfiles, + bool create); QVariant sizeHintRole (const EntryIndex& e, int col) const; QVariant displayRole (const EntryIndex& e, int col) const;