mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
added hability to disconnect friends which report our own IP as something different than what we know. Removed a test in discovery2 that prevented sending info to a peer about himself. Not active yet since it needs some testing
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@8340 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
ab62eaee32
commit
96cccbbc75
@ -2218,6 +2218,39 @@ int p3LinkMgrIMPL::removeFriend(const RsPeerId &id)
|
||||
return 1;
|
||||
}
|
||||
|
||||
void p3LinkMgrIMPL::disconnectFriend(const RsPeerId& id)
|
||||
{
|
||||
std::list<pqiMonitor*> disconnect_clients ;
|
||||
|
||||
{
|
||||
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
|
||||
|
||||
disconnect_clients = clients ;
|
||||
|
||||
std::cerr << "Disconnecting friend " << id << std::endl;
|
||||
|
||||
std::map<RsPeerId, peerConnectState>::iterator it;
|
||||
it = mFriendList.find(id);
|
||||
|
||||
if (it == mFriendList.end())
|
||||
{
|
||||
std::cerr << "p3LinkMgrIMPL::removeFriend() ERROR, friend not there : " << id;
|
||||
std::cerr << std::endl;
|
||||
return ;
|
||||
}
|
||||
|
||||
/* Move to OthersList (so remove can be handled via the action) */
|
||||
peerConnectState peer = it->second;
|
||||
|
||||
peer.state &= (~RS_PEER_S_CONNECTED);
|
||||
peer.state &= (~RS_PEER_S_ONLINE);
|
||||
peer.actions = RS_PEER_DISCONNECTED;
|
||||
peer.inConnAttempt = false;
|
||||
}
|
||||
|
||||
for(std::list<pqiMonitor*>::const_iterator it(disconnect_clients.begin());it!=disconnect_clients.end();++it)
|
||||
(*it)->disconnectPeer(id) ;
|
||||
}
|
||||
|
||||
void p3LinkMgrIMPL::printPeerLists(std::ostream &out)
|
||||
{
|
||||
|
@ -264,6 +264,8 @@ void tick();
|
||||
/* THIS COULD BE ADDED TO INTERFACE */
|
||||
void setFriendVisibility(const RsPeerId &id, bool isVisible);
|
||||
|
||||
void disconnectFriend(const RsPeerId& id) ;
|
||||
|
||||
/* add/remove friends */
|
||||
virtual int addFriend(const RsPeerId &ssl_id, bool isVisible);
|
||||
int removeFriend(const RsPeerId &ssl_id);
|
||||
|
@ -677,6 +677,12 @@ void p3NetMgrIMPL::netUpnpCheck()
|
||||
|
||||
}
|
||||
|
||||
class ZeroInt
|
||||
{
|
||||
public:
|
||||
ZeroInt() { n=0; }
|
||||
uint32_t n ;
|
||||
};
|
||||
|
||||
void p3NetMgrIMPL::netExtCheck()
|
||||
{
|
||||
@ -690,10 +696,11 @@ void p3NetMgrIMPL::netExtCheck()
|
||||
bool isStable = false;
|
||||
struct sockaddr_storage tmpip ;
|
||||
|
||||
std::map<sockaddr_storage,ZeroInt> address_votes ;
|
||||
|
||||
/* check for External Address */
|
||||
/* in order of importance */
|
||||
/* (1) UPnP -> which handles itself */
|
||||
if (!mNetFlags.mExtAddrOk)
|
||||
{
|
||||
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
|
||||
std::cerr << "p3NetMgrIMPL::netExtCheck() Ext Not Ok" << std::endl;
|
||||
@ -712,6 +719,8 @@ void p3NetMgrIMPL::netExtCheck()
|
||||
mNetFlags.mExtAddr = tmpip;
|
||||
mNetFlags.mExtAddrOk = true;
|
||||
mNetFlags.mExtAddrStableOk = isStable;
|
||||
|
||||
address_votes[tmpip].n++ ;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -724,7 +733,6 @@ void p3NetMgrIMPL::netExtCheck()
|
||||
}
|
||||
|
||||
/* Next ask the DhtStunner */
|
||||
if (!mNetFlags.mExtAddrOk)
|
||||
{
|
||||
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
|
||||
std::cerr << "p3NetMgrIMPL::netExtCheck() Ext Not Ok, Checking DhtStunner" << std::endl;
|
||||
@ -744,6 +752,7 @@ void p3NetMgrIMPL::netExtCheck()
|
||||
mNetFlags.mExtAddrOk = true;
|
||||
mNetFlags.mExtAddrStableOk = isStable;
|
||||
|
||||
address_votes[tmpaddr].n++ ;
|
||||
#ifdef NETMGR_DEBUG_STATEBOX
|
||||
std::cerr << "p3NetMgrIMPL::netExtCheck() From DhtStunner: ";
|
||||
std::cerr << sockaddr_storage_tostring(tmpaddr);
|
||||
@ -755,7 +764,6 @@ void p3NetMgrIMPL::netExtCheck()
|
||||
}
|
||||
|
||||
/* otherwise ask ExtAddrFinder */
|
||||
if (!mNetFlags.mExtAddrOk)
|
||||
{
|
||||
/* ExtAddrFinder */
|
||||
if (mUseExtAddrFinder)
|
||||
@ -782,6 +790,8 @@ void p3NetMgrIMPL::netExtCheck()
|
||||
mNetFlags.mExtAddrOk = true;
|
||||
mNetFlags.mExtAddrStableOk = isStable;
|
||||
|
||||
address_votes[tmpip].n++ ;
|
||||
|
||||
/* XXX HACK TO FIX */
|
||||
#warning "ALLOWING ExtAddrFinder -> ExtAddrStableOk = true (which it is not normally)"
|
||||
mNetFlags.mExtAddrStableOk = true;
|
||||
@ -795,6 +805,17 @@ void p3NetMgrIMPL::netExtCheck()
|
||||
/* finalise address */
|
||||
if (mNetFlags.mExtAddrOk)
|
||||
{
|
||||
// look at votes.
|
||||
|
||||
std::cerr << "Figuring out ext addr from voting:" << std::endl;
|
||||
uint32_t max = 0 ;
|
||||
for(std::map<sockaddr_storage,ZeroInt>::const_iterator it(address_votes.begin());it!=address_votes.end();++it)
|
||||
{
|
||||
std::cerr << " Vote 1: " << sockaddr_storage_iptostring(it->first) << " : " << it->second.n << " votes." << std::endl;
|
||||
|
||||
if(it->second.n > max)
|
||||
mNetFlags.mExtAddr = it->first ;
|
||||
}
|
||||
|
||||
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
|
||||
std::cerr << "p3NetMgrIMPL::netExtCheck() ";
|
||||
@ -1096,6 +1117,18 @@ bool p3NetMgrIMPL::setLocalAddress(const struct sockaddr_storage &addr)
|
||||
}
|
||||
return true;
|
||||
}
|
||||
bool p3NetMgrIMPL::getExtAddress(struct sockaddr_storage& addr)
|
||||
{
|
||||
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
|
||||
|
||||
if(mNetFlags.mExtAddrOk)
|
||||
{
|
||||
addr = mExtAddr ;
|
||||
return true ;
|
||||
}
|
||||
else
|
||||
return false ;
|
||||
}
|
||||
|
||||
bool p3NetMgrIMPL::setExtAddress(const struct sockaddr_storage &addr)
|
||||
{
|
||||
|
@ -216,6 +216,7 @@ void tick();
|
||||
// THESE MIGHT BE ADDED TO INTERFACE.
|
||||
bool setLocalAddress(const struct sockaddr_storage &addr);
|
||||
bool setExtAddress(const struct sockaddr_storage &addr);
|
||||
bool getExtAddress(sockaddr_storage &addr);
|
||||
|
||||
/*************** Setup ***************************/
|
||||
void addNetAssistConnect(uint32_t type, pqiNetAssistConnect *);
|
||||
@ -226,7 +227,6 @@ void addNetListener(pqiNetListener *listener);
|
||||
// SHOULD MAKE THIS PROTECTED.
|
||||
bool checkNetAddress(); /* check our address is sensible */
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
void slowTick();
|
||||
|
@ -1225,6 +1225,25 @@ bool p3PeerMgrIMPL::setDynDNS(const RsPeerId &id, const std::string &dyndns)
|
||||
return changed;
|
||||
}
|
||||
|
||||
bool p3PeerMgrIMPL::addCandidateForOwnExternalAddress(const RsPeerId &from, const sockaddr_storage &addr)
|
||||
{
|
||||
//#ifdef PEER_DEBUG
|
||||
std::cerr << "Own external address is " << sockaddr_storage_iptostring(addr) << ", as reported by friend " << from << std::endl;
|
||||
//#endif
|
||||
|
||||
// disconnect every friend that has reported a wrong external address
|
||||
|
||||
sockaddr_storage own_addr ;
|
||||
|
||||
if(mNetMgr->getExtAddress(own_addr) && !sockaddr_storage_sameip(own_addr,addr))
|
||||
{
|
||||
std::cerr << "(WW) peer reports an address that is not our current external address. This is weird." << std::endl;
|
||||
|
||||
//mLinkMgr->disconnectFriend(from) ;
|
||||
}
|
||||
return true ;
|
||||
}
|
||||
|
||||
bool p3PeerMgrIMPL::updateAddressList(const RsPeerId& id, const pqiIpAddrSet &addrs)
|
||||
{
|
||||
#ifdef PEER_DEBUG
|
||||
|
@ -152,6 +152,7 @@ virtual bool assignPeersToGroup(const std::string &groupId, const std::list<R
|
||||
virtual bool setLocalAddress(const RsPeerId &id, const struct sockaddr_storage &addr) = 0;
|
||||
virtual bool setExtAddress(const RsPeerId &id, const struct sockaddr_storage &addr) = 0;
|
||||
virtual bool setDynDNS(const RsPeerId &id, const std::string &dyndns) = 0;
|
||||
virtual bool addCandidateForOwnExternalAddress(const RsPeerId& from, const struct sockaddr_storage &addr) = 0;
|
||||
|
||||
virtual bool setNetworkMode(const RsPeerId &id, uint32_t netMode) = 0;
|
||||
virtual bool setVisState(const RsPeerId &id, uint16_t vs_disc, uint16_t vs_dht) = 0;
|
||||
@ -254,6 +255,7 @@ virtual bool assignPeersToGroup(const std::string &groupId, const std::list<R
|
||||
virtual bool setLocalAddress(const RsPeerId &id, const struct sockaddr_storage &addr);
|
||||
virtual bool setExtAddress(const RsPeerId &id, const struct sockaddr_storage &addr);
|
||||
virtual bool setDynDNS(const RsPeerId &id, const std::string &dyndns);
|
||||
virtual bool addCandidateForOwnExternalAddress(const RsPeerId& from, const struct sockaddr_storage &addr) ;
|
||||
|
||||
virtual bool setNetworkMode(const RsPeerId &id, uint32_t netMode);
|
||||
virtual bool setVisState(const RsPeerId &id, uint16_t vs_disc, uint16_t vs_dht);
|
||||
|
@ -71,6 +71,11 @@ void pqiConnectCbDummy::peerConnectRequest(const RsPeerId& id,
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
|
||||
void pqiMonitor::disconnectPeer(const RsPeerId &peer)
|
||||
{
|
||||
std::cerr << "(EE) pqiMonitor::disconnectPeer() shouldn't be called!!!"<< std::endl;
|
||||
}
|
||||
|
||||
#if 0
|
||||
void pqiConnectCbDummy::stunStatus(std::string id, const struct sockaddr_storage *raddr,
|
||||
uint32_t type, uint32_t flags)
|
||||
|
@ -133,6 +133,10 @@ virtual ~pqiMonitor() { return; }
|
||||
*/
|
||||
virtual void statusChange(const std::list<pqipeer> &plist) = 0;
|
||||
|
||||
// This is used to force disconnection of a peer, if e.g. something suspicious happenned.
|
||||
|
||||
virtual void disconnectPeer(const RsPeerId& peer) ;
|
||||
|
||||
#ifdef WINDOWS_SYS
|
||||
///////////////////////////////////////////////////////////
|
||||
// hack for too many connections
|
||||
|
@ -135,6 +135,16 @@ pqiperson * pqisslpersongrp::locked_createPerson(const RsPeerId& id, pqilistener
|
||||
return pqip;
|
||||
}
|
||||
|
||||
void pqisslpersongrp::disconnectPeer(const RsPeerId &peer)
|
||||
{
|
||||
std::map<RsPeerId,pqissl*>::iterator it = ssl_tunnels.find(peer) ;
|
||||
|
||||
if(it != ssl_tunnels.end())
|
||||
it->second->disconnect() ;
|
||||
else
|
||||
std::cerr << "pqisslpersongrp::cannot find peer " << peer << ". cannot disconnect!" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
/********************************** SSL Specific features ***************************/
|
||||
|
||||
|
@ -47,6 +47,8 @@ virtual pqilistener *locked_createListener(const struct sockaddr_storage &laddr)
|
||||
virtual pqiperson *locked_createPerson(const RsPeerId& id, pqilistener *listener);
|
||||
/********* FUNCTIONS to OVERLOAD for specialisation ********/
|
||||
|
||||
virtual void disconnectPeer(const RsPeerId& peer) ;
|
||||
|
||||
private:
|
||||
|
||||
p3PeerMgr *mPeerMgr;
|
||||
|
@ -797,10 +797,12 @@ void p3discovery2::sendContactInfo_locked(const PGPID &aboutId, const SSLID &toI
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
if ((sit->first == rsPeers->getOwnId()) || (sit->first == toId))
|
||||
if (sit->first == rsPeers->getOwnId())
|
||||
{
|
||||
// sending info of toId to himself will be used by toId to check that the IP it is connected as is the same
|
||||
// as its external IP.
|
||||
#ifdef P3DISC_DEBUG
|
||||
std::cerr << "p3discovery2::processContactInfo() not sending info on self or theirself";
|
||||
std::cerr << "p3discovery2::processContactInfo() not sending info on self";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
continue;
|
||||
@ -848,6 +850,7 @@ void p3discovery2::processContactInfo(const SSLID &fromId, const RsDiscContactIt
|
||||
|
||||
if (item->sslId == rsPeers->getOwnId())
|
||||
{
|
||||
mPeerMgr->addCandidateForOwnExternalAddress(item->PeerId(), item->extAddrV4.addr) ;
|
||||
#ifdef P3DISC_DEBUG
|
||||
std::cerr << "p3discovery2::processContactInfo(" << fromId << ") PGPID: ";
|
||||
std::cerr << item->pgpId << " Ignoring Info on self";
|
||||
|
Loading…
Reference in New Issue
Block a user