From 1207b5793b4b4e92f5f26d18d77aebcc20563878 Mon Sep 17 00:00:00 2001 From: thunder2 Date: Fri, 8 Oct 2010 12:03:25 +0000 Subject: [PATCH] Changed p3Peers::getPeerCount to count also gpg id's only. Show count of friends in MainWindow, not the count of locations. Recompile of GUI needed. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3653 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/pqi/p3connmgr.cc | 63 ++++++++++++++++++++------ libretroshare/src/pqi/p3connmgr.h | 2 +- libretroshare/src/retroshare/rspeers.h | 2 +- libretroshare/src/rsserver/p3peers.cc | 4 +- libretroshare/src/rsserver/p3peers.h | 2 +- retroshare-gui/src/gui/MainWindow.cpp | 2 +- 6 files changed, 54 insertions(+), 21 deletions(-) diff --git a/libretroshare/src/pqi/p3connmgr.cc b/libretroshare/src/pqi/p3connmgr.cc index 6f52dd006..019719f89 100644 --- a/libretroshare/src/pqi/p3connmgr.cc +++ b/libretroshare/src/pqi/p3connmgr.cc @@ -473,10 +473,6 @@ void p3ConnectMgr::addNetListener(pqiNetListener *listener) mNetListeners.push_back(listener); } - - - - void p3ConnectMgr::netStatusReset_locked() { //std::cerr << "p3ConnectMgr::netStatusReset()" << std::endl;; @@ -1598,21 +1594,60 @@ void p3ConnectMgr::getOthersList(std::list &peers) #endif -void p3ConnectMgr::getPeerCount (unsigned int *pnFriendCount, unsigned int *pnOnlineCount) +bool p3ConnectMgr::getPeerCount (unsigned int *pnFriendCount, unsigned int *pnOnlineCount, bool ssl) { - RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/ + if (ssl) { + /* count ssl id's */ - if (pnFriendCount) *pnFriendCount = mFriendList.size(); - if (pnOnlineCount) { - *pnOnlineCount = 0; + RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/ - std::map::iterator it; - for(it = mFriendList.begin(); it != mFriendList.end(); it++) { - if (it->second.state & RS_PEER_S_CONNECTED) { - (*pnOnlineCount)++; + if (pnFriendCount) *pnFriendCount = mFriendList.size(); + if (pnOnlineCount) { + *pnOnlineCount = 0; + + std::map::iterator it; + for (it = mFriendList.begin(); it != mFriendList.end(); it++) { + if (it->second.state & RS_PEER_S_CONNECTED) { + (*pnOnlineCount)++; + } + } + } + } else { + /* count gpg id's */ + + if (pnFriendCount) *pnFriendCount = 0; + if (pnOnlineCount) *pnOnlineCount = 0; + + std::list gpgIds; + if (AuthGPG::getAuthGPG()->getGPGAcceptedList(gpgIds) == false) { + return false; + } + + if (pnFriendCount) *pnFriendCount = gpgIds.size(); + + if (pnOnlineCount) { + RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/ + + /* 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 (gpgIt != gpgIds.end()) { + (*pnOnlineCount)++; + gpgIds.erase(gpgIt); + + if (gpgIds.empty()) { + /* no more gpg id's to check */ + break; + } + } + } } } } + + return true; } @@ -2644,8 +2679,6 @@ bool p3ConnectMgr::addAddressIfUnique(std::list &addrList, * in the list */ - bool found = false; - std::list::iterator it; for(it = addrList.begin(); it != addrList.end(); it++) { diff --git a/libretroshare/src/pqi/p3connmgr.h b/libretroshare/src/pqi/p3connmgr.h index 56d7773ed..9410ca119 100644 --- a/libretroshare/src/pqi/p3connmgr.h +++ b/libretroshare/src/pqi/p3connmgr.h @@ -281,7 +281,7 @@ bool getOthersNetStatus(std::string id, peerConnectState &state); void getOnlineList(std::list &ssl_peers); void getFriendList(std::list &ssl_peers); //void getOthersList(std::list &peers); /deprecated -void getPeerCount (unsigned int *pnFriendCount, unsigned int *pnOnlineCount); +bool getPeerCount (unsigned int *pnFriendCount, unsigned int *pnOnlineCount, bool ssl); /**************** handle monitors *****************/ diff --git a/libretroshare/src/retroshare/rspeers.h b/libretroshare/src/retroshare/rspeers.h index 303645df8..95954d3c4 100644 --- a/libretroshare/src/retroshare/rspeers.h +++ b/libretroshare/src/retroshare/rspeers.h @@ -159,7 +159,7 @@ virtual std::string getOwnId() = 0; virtual bool getOnlineList(std::list &ssl_ids) = 0; virtual bool getFriendList(std::list &ssl_ids) = 0; //virtual bool getOthersList(std::list &ssl_ids) = 0; -virtual void getPeerCount (unsigned int *pnFriendCount, unsigned int *pnnOnlineCount) = 0; +virtual bool getPeerCount (unsigned int *pnFriendCount, unsigned int *pnnOnlineCount, bool ssl) = 0; virtual bool isOnline(std::string ssl_id) = 0; virtual bool isFriend(std::string ssl_id) = 0; diff --git a/libretroshare/src/rsserver/p3peers.cc b/libretroshare/src/rsserver/p3peers.cc index 26c7563b4..3b4d3017d 100644 --- a/libretroshare/src/rsserver/p3peers.cc +++ b/libretroshare/src/rsserver/p3peers.cc @@ -221,14 +221,14 @@ bool p3Peers::getFriendList(std::list &ids) // return true; //} -void p3Peers::getPeerCount (unsigned int *pnFriendCount, unsigned int *pnOnlineCount) +bool p3Peers::getPeerCount (unsigned int *pnFriendCount, unsigned int *pnOnlineCount, bool ssl) { #ifdef P3PEERS_DEBUG std::cerr << "p3Peers::getPeerCount()" << std::endl; #endif /* get from mConnectMgr */ - mConnMgr->getPeerCount(pnFriendCount, pnOnlineCount); + return mConnMgr->getPeerCount(pnFriendCount, pnOnlineCount, ssl); } bool p3Peers::isOnline(std::string id) diff --git a/libretroshare/src/rsserver/p3peers.h b/libretroshare/src/rsserver/p3peers.h index 0a5c7a319..40c12e6a8 100644 --- a/libretroshare/src/rsserver/p3peers.h +++ b/libretroshare/src/rsserver/p3peers.h @@ -46,7 +46,7 @@ virtual std::string getOwnId(); virtual bool getOnlineList(std::list &ids); virtual bool getFriendList(std::list &ids); //virtual bool getOthersList(std::list &ids); -virtual void getPeerCount (unsigned int *pnFriendCount, unsigned int *pnOnlineCount); +virtual bool getPeerCount (unsigned int *pnFriendCount, unsigned int *pnOnlineCount, bool ssl); virtual bool isOnline(std::string id); virtual bool isFriend(std::string id); diff --git a/retroshare-gui/src/gui/MainWindow.cpp b/retroshare-gui/src/gui/MainWindow.cpp index e81f88dc9..3f484878e 100644 --- a/retroshare-gui/src/gui/MainWindow.cpp +++ b/retroshare-gui/src/gui/MainWindow.cpp @@ -514,7 +514,7 @@ void MainWindow::updateStatus() unsigned int nFriendCount = 0; unsigned int nOnlineCount = 0; - rsPeers->getPeerCount (&nFriendCount, &nOnlineCount); + rsPeers->getPeerCount (&nFriendCount, &nOnlineCount, false); if (ratesstatus) ratesstatus->getRatesStatus();