From 841299d07751dd33ce5494d2c531f3c27e53e3fd Mon Sep 17 00:00:00 2001 From: sehraf Date: Tue, 16 Feb 2016 20:20:41 +0100 Subject: [PATCH] discovery: don't remove new added locations too soon was: removed after 10 min. or less - when no connection is established now: removed after 1 day - when no connection is established --- libretroshare/src/pqi/p3peermgr.cc | 4 +--- libretroshare/src/pqi/p3peermgr.h | 3 +++ libretroshare/src/services/p3discovery2.cc | 6 +++++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/libretroshare/src/pqi/p3peermgr.cc b/libretroshare/src/pqi/p3peermgr.cc index e99d302c6..db2e2fdb3 100644 --- a/libretroshare/src/pqi/p3peermgr.cc +++ b/libretroshare/src/pqi/p3peermgr.cc @@ -64,8 +64,6 @@ const uint32_t MIN_TIME_BETWEEN_NET_RESET = 5; const uint32_t PEER_IP_CONNECT_STATE_MAX_LIST_SIZE = 4; -#define VERY_OLD_PEER (90 * 24 * 3600) // 90 days. - /**** * #define PEER_DEBUG 1 ***/ @@ -2751,7 +2749,7 @@ bool p3PeerMgrIMPL::removeUnusedLocations() std::map::iterator it; for(it = mFriendList.begin(); it != mFriendList.end(); ++it) { - if (now - it->second.lastcontact > VERY_OLD_PEER) + if (now - it->second.lastcontact > RS_PEER_OLD_PEER) { toRemove.push_back(it->first); diff --git a/libretroshare/src/pqi/p3peermgr.h b/libretroshare/src/pqi/p3peermgr.h index 78be4a6cb..acd7c8a06 100644 --- a/libretroshare/src/pqi/p3peermgr.h +++ b/libretroshare/src/pqi/p3peermgr.h @@ -65,6 +65,9 @@ const uint32_t RS_NET_FLAGS_EXTERNAL_ADDR = 0x0008; const uint32_t RS_NET_FLAGS_STABLE_UDP = 0x0010; const uint32_t RS_NET_FLAGS_TRUSTS_ME = 0x0020; +/* remove locations offline since 90 days */ +const time_t RS_PEER_OLD_PEER = (90 * 24 * 3600); + class peerState { public: diff --git a/libretroshare/src/services/p3discovery2.cc b/libretroshare/src/services/p3discovery2.cc index 0b95d2134..d1bccdd9e 100644 --- a/libretroshare/src/services/p3discovery2.cc +++ b/libretroshare/src/services/p3discovery2.cc @@ -24,6 +24,7 @@ */ #include "services/p3discovery2.h" +#include "pqi/p3peermgr.h" #include "util/rsversioninfo.h" #include "retroshare/rsiface.h" @@ -930,7 +931,10 @@ void p3discovery2::processContactInfo(const SSLID &fromId, const RsDiscContactIt // We pass RS_NODE_PERM_ALL because the PGP id is already a friend, so we should keep the existing // permission flags. Therefore the mask needs to be 0xffff. - mPeerMgr->addFriend(item->sslId, item->pgpId, item->netMode, RS_VS_DISC_OFF, RS_VS_DHT_FULL,(time_t)0,RS_NODE_PERM_ALL); + // set last seen to RS_PEER_OLD_PEER minus 1 day so that the DHT has a fair chance to establish a connection + // before the location gets automatically removed again + + mPeerMgr->addFriend(item->sslId, item->pgpId, item->netMode, RS_VS_DISC_OFF, RS_VS_DHT_FULL, time(NULL) - RS_PEER_OLD_PEER + (24 * 3600), RS_NODE_PERM_ALL); updatePeerAddresses(item); } }