mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -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
@ -570,6 +570,18 @@ void p3ConnectMgr::tick()
|
|||||||
statusTick();
|
statusTick();
|
||||||
tickMonitors();
|
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 */
|
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 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 isDummyFriend(const std::string &ssl_id) = 0;
|
||||||
virtual bool removeFriend(const std::string &ssl_or_gpg_id) = 0;
|
virtual bool removeFriend(const std::string &ssl_or_gpg_id) = 0;
|
||||||
|
virtual bool cleanUnusedLocations() = 0 ;
|
||||||
|
|
||||||
/* Network Stuff */
|
/* Network Stuff */
|
||||||
virtual bool connectAttempt(const std::string &ssl_id) = 0;
|
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_EXT_IP = "--EXT--";
|
||||||
const std::string CERT_DYNDNS = "--DYNDNS--";
|
const std::string CERT_DYNDNS = "--DYNDNS--";
|
||||||
|
|
||||||
|
static const int MAX_TIME_KEEP_LOCATION_WITHOUT_CONTACT = 30*24*3600 ; // 30 days.
|
||||||
|
|
||||||
|
|
||||||
#include "pqi/authssl.h"
|
#include "pqi/authssl.h"
|
||||||
@ -526,28 +527,103 @@ bool p3Peers::getGPGAcceptedList(std::list<std::string> &ids)
|
|||||||
bool p3Peers::getSSLChildListOfGPGId(const std::string &gpg_id, std::list<std::string> &ids)
|
bool p3Peers::getSSLChildListOfGPGId(const std::string &gpg_id, std::list<std::string> &ids)
|
||||||
{
|
{
|
||||||
#ifdef P3PEERS_DEBUG
|
#ifdef P3PEERS_DEBUG
|
||||||
std::cerr << "p3Peers::getSSLChildListOfGPGId() for id : " << gpg_id << std::endl;
|
std::cerr << "p3Peers::getSSLChildListOfGPGId() for id : " << gpg_id << std::endl;
|
||||||
#endif
|
#endif
|
||||||
ids.clear();
|
ids.clear();
|
||||||
if (gpg_id == "" ) {
|
if (gpg_id == "" ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
//let's roll throush the friends
|
//let's roll throush the friends
|
||||||
std::list<std::string> friendsIds;
|
std::list<std::string> friendsIds;
|
||||||
mConnMgr->getFriendList(friendsIds);
|
mConnMgr->getFriendList(friendsIds);
|
||||||
peerConnectState pcs;
|
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
|
#ifdef P3PEERS_DEBUG
|
||||||
std::cerr << "p3Peers::getSSLChildListOfGPGId() iterating over friends id : " << *it << std::endl;
|
std::cerr << "p3Peers::getSSLChildListOfGPGId() iterating over friends id : " << *it << std::endl;
|
||||||
#endif
|
#endif
|
||||||
if (mConnMgr->getFriendNetStatus(*it, pcs) && pcs.gpg_id == gpg_id) {
|
if (mConnMgr->getFriendNetStatus(*it, pcs) && pcs.gpg_id == gpg_id) {
|
||||||
#ifdef P3PEERS_DEBUG
|
#ifdef P3PEERS_DEBUG
|
||||||
std::cerr << "p3Peers::getSSLChildListOfGPGId() adding ssl id : " << pcs.id << std::endl;
|
std::cerr << "p3Peers::getSSLChildListOfGPGId() adding ssl id : " << pcs.id << std::endl;
|
||||||
#endif
|
#endif
|
||||||
ids.push_back(pcs.id);
|
ids.push_back(pcs.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
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)
|
bool p3Peers::getGPGDetails(const std::string &id, RsPeerDetails &d)
|
||||||
|
@ -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 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 isDummyFriend(const std::string &ssl_id);
|
||||||
virtual bool removeFriend(const std::string &ssl_id);
|
virtual bool removeFriend(const std::string &ssl_id);
|
||||||
|
virtual bool cleanUnusedLocations() ;
|
||||||
|
|
||||||
/* Network Stuff */
|
/* Network Stuff */
|
||||||
virtual bool connectAttempt(const std::string &id);
|
virtual bool connectAttempt(const std::string &id);
|
||||||
|
@ -2711,8 +2711,7 @@ int RsServer::StartupRetroShare()
|
|||||||
helppage += configHelpName;
|
helppage += configHelpName;
|
||||||
|
|
||||||
/* Startup this thread! */
|
/* Startup this thread! */
|
||||||
createThread(*this);
|
createThread(*this);
|
||||||
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -392,56 +392,57 @@ RsDiscReply *p3disc::createDiscReply(const std::string &to, const std::string &a
|
|||||||
|
|
||||||
std::list<std::string>::iterator sslChildIt;
|
std::list<std::string>::iterator sslChildIt;
|
||||||
for (sslChildIt = sslChilds.begin(); sslChildIt != sslChilds.end(); 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;
|
|
||||||
std::cerr << std::endl;
|
|
||||||
#endif
|
|
||||||
if(sslChilds.size() == 1 || to != *sslChildIt) // We don't send info to a peer about itself, when there are more than one ssl children,
|
|
||||||
{ // but we allow sending info about peers with the same GPG id. When there is only one ssl child,
|
|
||||||
// we must send it to transfer the signers of the gpg key. The receiver is skipping the own id.
|
|
||||||
peerConnectState detail;
|
|
||||||
if (!mConnMgr->getFriendNetStatus(*sslChildIt, detail)
|
|
||||||
|| detail.visState & RS_VIS_STATE_NODISC)
|
|
||||||
{
|
|
||||||
#ifdef P3DISC_DEBUG
|
|
||||||
std::cerr << "p3disc::createDiscReply() Skipping cos No Details or NODISC flag";
|
|
||||||
std::cerr << std::endl;
|
|
||||||
#endif
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef P3DISC_DEBUG
|
|
||||||
std::cerr << "p3disc::createDiscReply() Adding Child SSL Id Details";
|
|
||||||
std::cerr << std::endl;
|
|
||||||
#endif
|
|
||||||
shouldWeSendGPGKey = true;
|
|
||||||
RsPeerNetItem *rsPeerNetItem = new RsPeerNetItem();
|
|
||||||
rsPeerNetItem->clear();
|
|
||||||
|
|
||||||
rsPeerNetItem->pid = detail.id;
|
|
||||||
rsPeerNetItem->gpg_id = detail.gpg_id;
|
|
||||||
rsPeerNetItem->location = detail.location;
|
|
||||||
rsPeerNetItem->netMode = detail.netMode;
|
|
||||||
rsPeerNetItem->visState = detail.visState;
|
|
||||||
rsPeerNetItem->lastContact = detail.lastcontact;
|
|
||||||
rsPeerNetItem->currentlocaladdr = detail.currentlocaladdr;
|
|
||||||
rsPeerNetItem->currentremoteaddr = detail.currentserveraddr;
|
|
||||||
rsPeerNetItem->dyndns = detail.dyndns;
|
|
||||||
detail.ipAddrs.mLocal.loadTlv(rsPeerNetItem->localAddrList);
|
|
||||||
detail.ipAddrs.mExt.loadTlv(rsPeerNetItem->extAddrList);
|
|
||||||
|
|
||||||
|
|
||||||
di->rsPeerList.push_back(*rsPeerNetItem);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
#ifdef P3DISC_DEBUG
|
#ifdef P3DISC_DEBUG
|
||||||
std::cerr << "p3disc::createDiscReply() Skipping cos \"to == sslChildId\"";
|
std::cerr << "p3disc::createDiscReply() Found Child SSL Id:" << *sslChildIt;
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
if(sslChilds.size() == 1 || to != *sslChildIt) // We don't send info to a peer about itself, when there are more than one ssl children,
|
||||||
|
{ // but we allow sending info about peers with the same GPG id. When there is only one ssl child,
|
||||||
|
// we must send it to transfer the signers of the gpg key. The receiver is skipping the own id.
|
||||||
|
peerConnectState detail;
|
||||||
|
if (!mConnMgr->getFriendNetStatus(*sslChildIt, detail)
|
||||||
|
|| detail.visState & RS_VIS_STATE_NODISC)
|
||||||
|
{
|
||||||
|
#ifdef P3DISC_DEBUG
|
||||||
|
std::cerr << "p3disc::createDiscReply() Skipping cos No Details or NODISC flag";
|
||||||
|
std::cerr << std::endl;
|
||||||
|
#endif
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef P3DISC_DEBUG
|
||||||
|
std::cerr << "p3disc::createDiscReply() Adding Child SSL Id Details";
|
||||||
|
std::cerr << std::endl;
|
||||||
|
#endif
|
||||||
|
shouldWeSendGPGKey = true;
|
||||||
|
RsPeerNetItem *rsPeerNetItem = new RsPeerNetItem();
|
||||||
|
rsPeerNetItem->clear();
|
||||||
|
|
||||||
|
rsPeerNetItem->pid = detail.id;
|
||||||
|
rsPeerNetItem->gpg_id = detail.gpg_id;
|
||||||
|
rsPeerNetItem->location = detail.location;
|
||||||
|
rsPeerNetItem->netMode = detail.netMode;
|
||||||
|
rsPeerNetItem->visState = detail.visState;
|
||||||
|
rsPeerNetItem->lastContact = detail.lastcontact;
|
||||||
|
rsPeerNetItem->currentlocaladdr = detail.currentlocaladdr;
|
||||||
|
rsPeerNetItem->currentremoteaddr = detail.currentserveraddr;
|
||||||
|
rsPeerNetItem->dyndns = detail.dyndns;
|
||||||
|
detail.ipAddrs.mLocal.loadTlv(rsPeerNetItem->localAddrList);
|
||||||
|
detail.ipAddrs.mExt.loadTlv(rsPeerNetItem->extAddrList);
|
||||||
|
|
||||||
|
|
||||||
|
di->rsPeerList.push_back(*rsPeerNetItem);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
#ifdef P3DISC_DEBUG
|
||||||
|
std::cerr << "p3disc::createDiscReply() Skipping cos \"to == sslChildId\"";
|
||||||
|
std::cerr << std::endl;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//send own details
|
//send own details
|
||||||
@ -613,113 +614,114 @@ void p3disc::recvPeerDetails(RsDiscReply *item, const std::string &certGpgId)
|
|||||||
bool should_notify_discovery = false ;
|
bool should_notify_discovery = false ;
|
||||||
|
|
||||||
for (std::list<RsPeerNetItem>::iterator pitem = item->rsPeerList.begin(); pitem != item->rsPeerList.end(); pitem++)
|
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);
|
|
||||||
|
|
||||||
if(new_info)
|
|
||||||
should_notify_discovery = true ;
|
|
||||||
|
|
||||||
#ifdef P3DISC_DEBUG
|
|
||||||
std::cerr << "p3disc::recvPeerFriendMsg() Peer Config Item:" << std::endl;
|
|
||||||
|
|
||||||
pitem->print(std::cerr, 10);
|
|
||||||
std::cerr << std::endl;
|
|
||||||
#endif
|
|
||||||
if (pitem->pid != rsPeers->getOwnId())
|
|
||||||
{
|
{
|
||||||
// Apparently, the connect manager won't add a friend if the gpg id is not
|
bool new_info ;
|
||||||
// trusted. However, this should be tested here for consistency and security
|
addDiscoveryData(item->PeerId(), pitem->pid,rsPeers->getGPGId(item->PeerId()),item->aboutId, pitem->currentlocaladdr, pitem->currentremoteaddr, 0, time(NULL),new_info);
|
||||||
// in case of modifications in mConnMgr.
|
|
||||||
//
|
if(new_info)
|
||||||
if(AuthGPG::getAuthGPG()->isGPGAccepted(pitem->gpg_id) || pitem->gpg_id == AuthGPG::getAuthGPG()->getGPGOwnId())
|
should_notify_discovery = true ;
|
||||||
|
|
||||||
|
#ifdef P3DISC_DEBUG
|
||||||
|
std::cerr << "p3disc::recvPeerFriendMsg() Peer Config Item:" << std::endl;
|
||||||
|
|
||||||
|
pitem->print(std::cerr, 10);
|
||||||
|
std::cerr << std::endl;
|
||||||
|
#endif
|
||||||
|
if (pitem->pid != rsPeers->getOwnId())
|
||||||
{
|
{
|
||||||
// Add with no disc by default. If friend already exists, it will do nothing
|
// Apparently, the connect manager won't add a friend if the gpg id is not
|
||||||
|
// trusted. However, this should be tested here for consistency and security
|
||||||
|
// in case of modifications in mConnMgr.
|
||||||
//
|
//
|
||||||
#ifdef P3DISC_DEBUG
|
if(AuthGPG::getAuthGPG()->isGPGAccepted(pitem->gpg_id) || pitem->gpg_id == AuthGPG::getAuthGPG()->getGPGOwnId())
|
||||||
std::cerr << "--> Adding to friends list " << pitem->pid << " - " << pitem->gpg_id << std::endl;
|
{
|
||||||
#endif
|
// Add with no disc by default. If friend already exists, it will do nothing
|
||||||
mConnMgr->addFriend(pitem->pid, pitem->gpg_id, pitem->netMode, 0, 0);
|
|
||||||
RsPeerDetails storedDetails;
|
|
||||||
|
|
||||||
// Update if know this peer
|
|
||||||
if(rsPeers->getPeerDetails(pitem->pid, storedDetails))
|
|
||||||
{
|
|
||||||
// Update if it's fresh info or if it's from the peer itself
|
|
||||||
// their info is fresher than ours, update ours
|
|
||||||
//
|
//
|
||||||
if(!(storedDetails.state & RS_PEER_CONNECTED))
|
|
||||||
{
|
|
||||||
#ifdef P3DISC_DEBUG
|
#ifdef P3DISC_DEBUG
|
||||||
std::cerr << "Friend is not connected -> updating info" << std::endl;
|
std::cerr << "--> Adding to friends list " << pitem->pid << " - " << pitem->gpg_id << std::endl;
|
||||||
std::cerr << " -> network mode: " << pitem->netMode << std::endl;
|
|
||||||
std::cerr << " -> location: " << pitem->location << std::endl;
|
|
||||||
#endif
|
#endif
|
||||||
mConnMgr->setNetworkMode(pitem->pid, pitem->netMode);
|
mConnMgr->addFriend(pitem->pid, pitem->gpg_id, pitem->netMode, 0, 0);
|
||||||
mConnMgr->setLocation(pitem->pid, pitem->location);
|
RsPeerDetails storedDetails;
|
||||||
|
|
||||||
|
// Update if know this peer
|
||||||
|
if(rsPeers->getPeerDetails(pitem->pid, storedDetails))
|
||||||
|
{
|
||||||
|
// Update if it's fresh info or if it's from the peer itself
|
||||||
|
// their info is fresher than ours, update ours
|
||||||
|
//
|
||||||
|
if(!(storedDetails.state & RS_PEER_CONNECTED))
|
||||||
|
{
|
||||||
|
#ifdef P3DISC_DEBUG
|
||||||
|
std::cerr << "Friend is not connected -> updating info" << std::endl;
|
||||||
|
std::cerr << " -> network mode: " << pitem->netMode << std::endl;
|
||||||
|
std::cerr << " -> location: " << pitem->location << std::endl;
|
||||||
|
#endif
|
||||||
|
mConnMgr->setNetworkMode(pitem->pid, pitem->netMode);
|
||||||
|
mConnMgr->setLocation(pitem->pid, pitem->location);
|
||||||
|
}
|
||||||
|
|
||||||
|
// The info from the peer itself is ultimately trustable, so we can override some info,
|
||||||
|
// such as:
|
||||||
|
// - local and global addresses
|
||||||
|
// - address list
|
||||||
|
//
|
||||||
|
// If we enter here, we're necessarily connected to this peer.
|
||||||
|
//
|
||||||
|
if (item->PeerId() == pitem->pid)
|
||||||
|
{
|
||||||
|
#ifdef P3DISC_DEBUG
|
||||||
|
std::cerr << "Info sent by the peer itself -> updating self info:" << std::endl;
|
||||||
|
std::cerr << " -> current local addr = " << pitem->currentlocaladdr << std::endl;
|
||||||
|
std::cerr << " -> current remote addr = " << pitem->currentremoteaddr << std::endl;
|
||||||
|
std::cerr << " -> clearing NODISC flag " << std::endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// When the peer sends his own list of IPs, the info replaces the existing info, because the
|
||||||
|
// peer is the primary source of his own IPs.
|
||||||
|
|
||||||
|
mConnMgr->setLocalAddress(pitem->pid, pitem->currentlocaladdr);
|
||||||
|
mConnMgr->setExtAddress(pitem->pid, pitem->currentremoteaddr);
|
||||||
|
pitem->visState &= ~RS_VIS_STATE_NODISC ;
|
||||||
|
mConnMgr->setVisState(pitem->pid, pitem->visState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cerr << "p3disc:: ERROR HOW DID WE GET HERE?" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
// The info from the peer itself is ultimately trustable, so we can override some info,
|
pqiIpAddrSet addrsFromPeer;
|
||||||
// such as:
|
addrsFromPeer.mLocal.extractFromTlv(pitem->localAddrList);
|
||||||
// - local and global addresses
|
addrsFromPeer.mExt.extractFromTlv(pitem->extAddrList);
|
||||||
// - address list
|
|
||||||
//
|
|
||||||
// If we enter here, we're necessarily connected to this peer.
|
|
||||||
//
|
|
||||||
if (item->PeerId() == pitem->pid)
|
|
||||||
{
|
|
||||||
#ifdef P3DISC_DEBUG
|
#ifdef P3DISC_DEBUG
|
||||||
std::cerr << "Info sent by the peer itself -> updating self info:" << std::endl;
|
std::cerr << "Setting address list to peer " << pitem->pid << ", to be:" << std::endl ;
|
||||||
std::cerr << " -> current local addr = " << pitem->currentlocaladdr << std::endl;
|
|
||||||
std::cerr << " -> current remote addr = " << pitem->currentremoteaddr << std::endl;
|
addrsFromPeer.printAddrs(std::cerr);
|
||||||
std::cerr << " -> clearing NODISC flag " << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
// allways update address list and dns, except if it's ours
|
||||||
|
if (pitem->dyndns != "")
|
||||||
|
mConnMgr->setDynDNS(pitem->pid, pitem->dyndns);
|
||||||
|
|
||||||
// When the peer sends his own list of IPs, the info replaces the existing info, because the
|
mConnMgr->updateAddressList(pitem->pid, addrsFromPeer);
|
||||||
// peer is the primary source of his own IPs.
|
|
||||||
|
|
||||||
mConnMgr->setLocalAddress(pitem->pid, pitem->currentlocaladdr);
|
|
||||||
mConnMgr->setExtAddress(pitem->pid, pitem->currentremoteaddr);
|
|
||||||
pitem->visState &= ~RS_VIS_STATE_NODISC ;
|
|
||||||
mConnMgr->setVisState(pitem->pid, pitem->visState);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
#ifdef P3DISC_DEBUG
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::cerr << "p3disc:: ERROR HOW DID WE GET HERE?" << std::endl;
|
std::cerr << " skipping unknown gpg id " << pitem->gpg_id << std::endl ;
|
||||||
}
|
}
|
||||||
|
|
||||||
pqiIpAddrSet addrsFromPeer;
|
|
||||||
addrsFromPeer.mLocal.extractFromTlv(pitem->localAddrList);
|
|
||||||
addrsFromPeer.mExt.extractFromTlv(pitem->extAddrList);
|
|
||||||
|
|
||||||
#ifdef P3DISC_DEBUG
|
|
||||||
std::cerr << "Setting address list to peer " << pitem->pid << ", to be:" << std::endl ;
|
|
||||||
|
|
||||||
addrsFromPeer.printAddrs(std::cerr);
|
|
||||||
std::cerr << std::endl;
|
|
||||||
#endif
|
#endif
|
||||||
// allways update address list and dns, except if it's ours
|
|
||||||
if (pitem->dyndns != "")
|
|
||||||
mConnMgr->setDynDNS(pitem->pid, pitem->dyndns);
|
|
||||||
|
|
||||||
mConnMgr->updateAddressList(pitem->pid, addrsFromPeer);
|
|
||||||
}
|
}
|
||||||
#ifdef P3DISC_DEBUG
|
#ifdef P3DISC_DEBUG
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::cerr << " skipping unknown gpg id " << pitem->gpg_id << std::endl ;
|
std::cerr << "Skipping info about own id " << pitem->pid << std::endl ;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
|
||||||
#ifdef P3DISC_DEBUG
|
|
||||||
else
|
|
||||||
{
|
|
||||||
std::cerr << "Skipping info about own id " << pitem->pid << std::endl ;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rsicontrol->getNotify().notifyListChange(NOTIFY_LIST_NEIGHBOURS, NOTIFY_TYPE_MOD);
|
rsicontrol->getNotify().notifyListChange(NOTIFY_LIST_NEIGHBOURS, NOTIFY_TYPE_MOD);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user