mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-04 20:59:05 -04:00
added auto-remove of unused and dummy locations every 10 minutes (still keeping at least one location for each GPG key). Suppressed exchange of p3disc info for dummy locations.
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3915 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
1495758d45
commit
98f471c56b
6 changed files with 239 additions and 148 deletions
|
@ -570,6 +570,18 @@ void p3ConnectMgr::tick()
|
|||
statusTick();
|
||||
tickMonitors();
|
||||
|
||||
static time_t last_friends_check = time(NULL) ;
|
||||
static const time_t INTERVAL_BETWEEN_LOCATION_CLEANING = 600 ; // Remove unused locations every 10 minutes.
|
||||
|
||||
time_t now = time(NULL) ;
|
||||
|
||||
if(now > last_friends_check + INTERVAL_BETWEEN_LOCATION_CLEANING && rsPeers != NULL)
|
||||
{
|
||||
std::cerr << "p3ConnectMgr::tick(): cleaning unused locations." << std::endl ;
|
||||
|
||||
rsPeers->cleanUnusedLocations() ;
|
||||
last_friends_check = now ;
|
||||
}
|
||||
}
|
||||
|
||||
bool p3ConnectMgr::shutdown() /* blocking shutdown call */
|
||||
|
|
|
@ -183,6 +183,7 @@ virtual bool addFriend(const std::string &ssl_id, const std::string &gpg_id)
|
|||
virtual bool addDummyFriend(const std::string &gpg_id) = 0; //we want to add a empty ssl friend for this gpg id
|
||||
virtual bool isDummyFriend(const std::string &ssl_id) = 0;
|
||||
virtual bool removeFriend(const std::string &ssl_or_gpg_id) = 0;
|
||||
virtual bool cleanUnusedLocations() = 0 ;
|
||||
|
||||
/* Network Stuff */
|
||||
virtual bool connectAttempt(const std::string &ssl_id) = 0;
|
||||
|
|
|
@ -44,6 +44,7 @@ const std::string CERT_LOCAL_IP = "--LOCAL--";
|
|||
const std::string CERT_EXT_IP = "--EXT--";
|
||||
const std::string CERT_DYNDNS = "--DYNDNS--";
|
||||
|
||||
static const int MAX_TIME_KEEP_LOCATION_WITHOUT_CONTACT = 30*24*3600 ; // 30 days.
|
||||
|
||||
|
||||
#include "pqi/authssl.h"
|
||||
|
@ -536,7 +537,8 @@ bool p3Peers::getSSLChildListOfGPGId(const std::string &gpg_id, std::list<std::s
|
|||
std::list<std::string> friendsIds;
|
||||
mConnMgr->getFriendList(friendsIds);
|
||||
peerConnectState pcs;
|
||||
for (std::list<std::string>::iterator it = friendsIds.begin(); it != friendsIds.end(); it++) {
|
||||
for (std::list<std::string>::iterator it = friendsIds.begin(); it != friendsIds.end(); it++)
|
||||
{
|
||||
#ifdef P3PEERS_DEBUG
|
||||
std::cerr << "p3Peers::getSSLChildListOfGPGId() iterating over friends id : " << *it << std::endl;
|
||||
#endif
|
||||
|
@ -550,6 +552,80 @@ bool p3Peers::getSSLChildListOfGPGId(const std::string &gpg_id, std::list<std::s
|
|||
return true;
|
||||
}
|
||||
|
||||
bool p3Peers::cleanUnusedLocations()
|
||||
{
|
||||
// Obtain all current locations of each GPG friend.
|
||||
//
|
||||
std::map<std::string,std::list<peerConnectState> > friends_info ;
|
||||
std::list<std::string> friendSSLIds ;
|
||||
|
||||
mConnMgr->getFriendList(friendSSLIds);
|
||||
|
||||
for(std::list<std::string>::const_iterator it(friendSSLIds.begin());it!=friendSSLIds.end();++it)
|
||||
{
|
||||
peerConnectState pcs;
|
||||
|
||||
if(mConnMgr->getFriendNetStatus(*it, pcs))
|
||||
friends_info[pcs.gpg_id].push_back(pcs) ;
|
||||
}
|
||||
|
||||
// Now sort them out
|
||||
//
|
||||
|
||||
std::cerr << "Examining Old/Unused locations." << std::endl ;
|
||||
time_t now = time(NULL) ;
|
||||
|
||||
std::list<std::string> locations_to_remove ;
|
||||
|
||||
for(std::map<std::string,std::list<peerConnectState> >::iterator it(friends_info.begin());it!=friends_info.end();++it)
|
||||
{
|
||||
std::list<peerConnectState>& locations_list(it->second) ;
|
||||
|
||||
int size = locations_list.size() ;
|
||||
|
||||
std::cerr << " GPG id: " << it->first << std::endl ;
|
||||
|
||||
for(std::list<peerConnectState>::const_iterator itloc(locations_list.begin());itloc!=locations_list.end();++itloc)
|
||||
std::cerr << " Location " << (*itloc).id << ", last contact " << now - (*itloc).lastcontact << " seconds ago" << std::endl ;
|
||||
|
||||
// Remove any location that is dummy. Update the list, such that we only look into non dummy friends later.
|
||||
//
|
||||
for(std::list<peerConnectState>::iterator itloc(locations_list.begin());itloc!=locations_list.end();)
|
||||
if(size > 1 && isDummyFriend((*itloc).id))
|
||||
{
|
||||
locations_to_remove.push_back((*itloc).id) ;
|
||||
--size ;
|
||||
|
||||
std::cerr << " Removing dummy location: " << (*itloc).id << std::endl ;
|
||||
|
||||
std::list<peerConnectState>::iterator tmp(itloc) ;
|
||||
++tmp ;
|
||||
locations_list.erase(itloc) ;
|
||||
itloc=tmp ;
|
||||
}
|
||||
else
|
||||
++itloc ;
|
||||
|
||||
for(std::list<peerConnectState>::const_iterator itloc(locations_list.begin());itloc!=locations_list.end();++itloc)
|
||||
if(size > 1 && now > (*itloc).lastcontact + MAX_TIME_KEEP_LOCATION_WITHOUT_CONTACT)
|
||||
{
|
||||
locations_to_remove.push_back((*itloc).id) ;
|
||||
--size ;
|
||||
std::cerr << " Removing unused location: " << (*itloc).id << std::endl ;
|
||||
}
|
||||
}
|
||||
|
||||
std::cerr << "Now removing unused locations:" << std::endl ;
|
||||
|
||||
for(std::list<std::string>::const_iterator it(locations_to_remove.begin());it!=locations_to_remove.end();++it)
|
||||
{
|
||||
std::cerr << " Removing unused friend location " << *it << std::endl ;
|
||||
removeFriend(*it) ;
|
||||
}
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
bool p3Peers::getGPGDetails(const std::string &id, RsPeerDetails &d)
|
||||
{
|
||||
#ifdef P3PEERS_DEBUG
|
||||
|
|
|
@ -70,6 +70,7 @@ virtual bool addFriend(const std::string &ssl_id, const std::string &gpg_id);
|
|||
virtual bool addDummyFriend(const std::string &gpg_id); //we want to add a empty ssl friend for this gpg id
|
||||
virtual bool isDummyFriend(const std::string &ssl_id);
|
||||
virtual bool removeFriend(const std::string &ssl_id);
|
||||
virtual bool cleanUnusedLocations() ;
|
||||
|
||||
/* Network Stuff */
|
||||
virtual bool connectAttempt(const std::string &id);
|
||||
|
|
|
@ -2713,6 +2713,5 @@ int RsServer::StartupRetroShare()
|
|||
/* Startup this thread! */
|
||||
createThread(*this);
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -392,6 +392,7 @@ RsDiscReply *p3disc::createDiscReply(const std::string &to, const std::string &a
|
|||
|
||||
std::list<std::string>::iterator sslChildIt;
|
||||
for (sslChildIt = sslChilds.begin(); sslChildIt != sslChilds.end(); sslChildIt++)
|
||||
if(!rsPeers->isDummyFriend(*sslChildIt))
|
||||
{
|
||||
#ifdef P3DISC_DEBUG
|
||||
std::cerr << "p3disc::createDiscReply() Found Child SSL Id:" << *sslChildIt;
|
||||
|
@ -613,6 +614,7 @@ void p3disc::recvPeerDetails(RsDiscReply *item, const std::string &certGpgId)
|
|||
bool should_notify_discovery = false ;
|
||||
|
||||
for (std::list<RsPeerNetItem>::iterator pitem = item->rsPeerList.begin(); pitem != item->rsPeerList.end(); pitem++)
|
||||
if(!rsPeers->isDummyFriend(pitem->pid))
|
||||
{
|
||||
bool new_info ;
|
||||
addDiscoveryData(item->PeerId(), pitem->pid,rsPeers->getGPGId(item->PeerId()),item->aboutId, pitem->currentlocaladdr, pitem->currentremoteaddr, 0, time(NULL),new_info);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue