From 38203704f03681d5b79b7196bf08140d672f077b Mon Sep 17 00:00:00 2001 From: thunder2 Date: Sun, 5 Dec 2010 00:20:11 +0000 Subject: [PATCH] Count the own gpg id as friend, when another location exists. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3896 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/pqi/p3connmgr.cc | 34 +++++++++++++++++++----------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/libretroshare/src/pqi/p3connmgr.cc b/libretroshare/src/pqi/p3connmgr.cc index de31c5b5b..02bae85d5 100644 --- a/libretroshare/src/pqi/p3connmgr.cc +++ b/libretroshare/src/pqi/p3connmgr.cc @@ -1630,28 +1630,38 @@ bool p3ConnectMgr::getPeerCount (unsigned int *pnFriendCount, unsigned int *pnOn if (pnFriendCount) *pnFriendCount = 0; if (pnOnlineCount) *pnOnlineCount = 0; - std::list gpgIds; - if (AuthGPG::getAuthGPG()->getGPGAcceptedList(gpgIds) == false) { - return false; - } + if (pnFriendCount || pnOnlineCount) { + std::list gpgIds; + if (AuthGPG::getAuthGPG()->getGPGAcceptedList(gpgIds) == false) { + return false; + } - if (pnFriendCount) *pnFriendCount = gpgIds.size(); + /* add own id */ + gpgIds.push_back(AuthGPG::getAuthGPG()->getGPGOwnId()); + + std::list gpgOnlineIds = gpgIds; - if (pnOnlineCount) { RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/ + std::list::iterator gpgIt; + /* check ssl id's */ std::map::iterator it; for (it = mFriendList.begin(); it != mFriendList.end(); it++) { - if (it->second.state & RS_PEER_S_CONNECTED) { - std::list::iterator gpgIt = std::find(gpgIds.begin(), gpgIds.end(), it->second.gpg_id); + if (pnFriendCount && gpgIds.size()) { + gpgIt = std::find(gpgIds.begin(), gpgIds.end(), it->second.gpg_id); if (gpgIt != gpgIds.end()) { - (*pnOnlineCount)++; + (*pnFriendCount)++; gpgIds.erase(gpgIt); + } + } - if (gpgIds.empty()) { - /* no more gpg id's to check */ - break; + if (pnOnlineCount && gpgOnlineIds.size()) { + if (it->second.state & RS_PEER_S_CONNECTED) { + gpgIt = std::find(gpgOnlineIds.begin(), gpgOnlineIds.end(), it->second.gpg_id); + if (gpgIt != gpgOnlineIds.end()) { + (*pnOnlineCount)++; + gpgOnlineIds.erase(gpgIt); } } }