mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-08-13 08:35:45 -04:00
Enforce main IPv4 usage for better retrocompatibility
This commit is contained in:
parent
f5160338ed
commit
ac8b56951c
2 changed files with 72 additions and 80 deletions
|
@ -692,11 +692,11 @@ void p3NetMgrIMPL::netExtCheck()
|
||||||
bool netSetupDone = false;
|
bool netSetupDone = false;
|
||||||
|
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
|
RS_STACK_MUTEX(mNetMtx);
|
||||||
bool isStable = false;
|
bool isStable = false;
|
||||||
struct sockaddr_storage tmpip ;
|
sockaddr_storage tmpip;
|
||||||
|
|
||||||
std::map<sockaddr_storage,ZeroInt> address_votes ;
|
std::map<sockaddr_storage,ZeroInt> address_votes;
|
||||||
|
|
||||||
/* check for External Address */
|
/* check for External Address */
|
||||||
/* in order of importance */
|
/* in order of importance */
|
||||||
|
@ -705,38 +705,30 @@ void p3NetMgrIMPL::netExtCheck()
|
||||||
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
|
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
|
||||||
std::cerr << "p3NetMgrIMPL::netExtCheck() Ext Not Ok" << std::endl;
|
std::cerr << "p3NetMgrIMPL::netExtCheck() Ext Not Ok" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* net Assist */
|
/* net Assist */
|
||||||
if (netAssistExtAddress(tmpip))
|
if ( netAssistExtAddress(tmpip) &&
|
||||||
|
sockaddr_storage_isValidNet(tmpip) &&
|
||||||
|
sockaddr_storage_ipv6_to_ipv4(tmpip) )
|
||||||
{
|
{
|
||||||
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
|
if( !rsBanList ||
|
||||||
std::cerr << "p3NetMgrIMPL::netExtCheck() Ext supplied from netAssistExternalAddress()" << std::endl;
|
rsBanList->isAddressAccepted(
|
||||||
#endif
|
tmpip, RSBANLIST_CHECKING_FLAGS_BLACKLIST ) )
|
||||||
if(sockaddr_storage_isValidNet(tmpip))
|
|
||||||
{
|
{
|
||||||
if( (rsBanList==NULL) || rsBanList->isAddressAccepted(tmpip,RSBANLIST_CHECKING_FLAGS_BLACKLIST))
|
// must be stable???
|
||||||
{
|
isStable = true;
|
||||||
// must be stable???
|
mNetFlags.mExtAddrOk = true;
|
||||||
isStable = true;
|
mNetFlags.mExtAddrStableOk = isStable;
|
||||||
//mNetFlags.mExtAddr = tmpip;
|
address_votes[tmpip].n++ ;
|
||||||
mNetFlags.mExtAddrOk = true;
|
std::cerr << __PRETTY_FUNCTION__ << " NetAssistAddress "
|
||||||
mNetFlags.mExtAddrStableOk = isStable;
|
<< " reported external address "
|
||||||
|
<< sockaddr_storage_iptostring(tmpip)
|
||||||
address_votes[tmpip].n++ ;
|
<< std::endl;
|
||||||
|
|
||||||
std::cerr << "NetAssistAddress reported external address " << sockaddr_storage_iptostring(tmpip) << std::endl;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
std::cerr << "(SS) netAssisExternalAddress returned banned own IP " << sockaddr_storage_iptostring(tmpip) << " (banned). Rejecting." << std::endl;
|
|
||||||
}
|
}
|
||||||
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
|
|
||||||
else
|
else
|
||||||
{
|
std::cerr << "(SS) netAssisExternalAddress returned banned "
|
||||||
std::cerr << "p3NetMgrIMPL::netExtCheck() Bad Address supplied from netAssistExternalAddress()" << std::endl;
|
<< "own IP " << sockaddr_storage_iptostring(tmpip)
|
||||||
}
|
<< " (banned). Rejecting." << std::endl;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ALLOW_DHT_STUNNER
|
#ifdef ALLOW_DHT_STUNNER
|
||||||
|
@ -780,7 +772,7 @@ void p3NetMgrIMPL::netExtCheck()
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* otherwise ask ExtAddrFinder */
|
/* ask ExtAddrFinder */
|
||||||
{
|
{
|
||||||
/* ExtAddrFinder */
|
/* ExtAddrFinder */
|
||||||
if (mUseExtAddrFinder)
|
if (mUseExtAddrFinder)
|
||||||
|
@ -789,7 +781,7 @@ void p3NetMgrIMPL::netExtCheck()
|
||||||
std::cerr << "p3NetMgrIMPL::netExtCheck() checking ExtAddrFinder" << std::endl;
|
std::cerr << "p3NetMgrIMPL::netExtCheck() checking ExtAddrFinder" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
bool extFinderOk = mExtAddrFinder->hasValidIP(tmpip);
|
bool extFinderOk = mExtAddrFinder->hasValidIP(tmpip);
|
||||||
if (extFinderOk)
|
if (extFinderOk && sockaddr_storage_ipv6_to_ipv4(tmpip))
|
||||||
{
|
{
|
||||||
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
|
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
|
||||||
std::cerr << "p3NetMgrIMPL::netExtCheck() Ext supplied by ExtAddrFinder" << std::endl;
|
std::cerr << "p3NetMgrIMPL::netExtCheck() Ext supplied by ExtAddrFinder" << std::endl;
|
||||||
|
@ -803,38 +795,41 @@ void p3NetMgrIMPL::netExtCheck()
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//mNetFlags.mExtAddr = tmpip;
|
|
||||||
mNetFlags.mExtAddrOk = true;
|
mNetFlags.mExtAddrOk = true;
|
||||||
|
|
||||||
address_votes[tmpip].n++ ;
|
address_votes[tmpip].n++ ;
|
||||||
|
|
||||||
/* XXX HACK TO FIX */
|
/* XXX HACK TO FIX drbob: ALLOWING
|
||||||
#warning drbob: ALLOWING ExtAddrFinder -> ExtAddrStableOk = true (which it is not normally)
|
* ExtAddrFinder -> ExtAddrStableOk = true
|
||||||
|
* (which it is not normally) */
|
||||||
mNetFlags.mExtAddrStableOk = true;
|
mNetFlags.mExtAddrStableOk = true;
|
||||||
|
|
||||||
std::cerr << "ExtAddrFinder reported external address " << sockaddr_storage_iptostring(tmpip) << std::endl;
|
std::cerr << __PRETTY_FUNCTION__ << " ExtAddrFinder "
|
||||||
|
<< " reported external address "
|
||||||
|
<< sockaddr_storage_iptostring(tmpip)
|
||||||
|
<< std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* also ask peer mgr. */
|
/* also ask peer mgr. */
|
||||||
|
|
||||||
if (mPeerMgr)
|
if (mPeerMgr)
|
||||||
{
|
{
|
||||||
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
|
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
|
||||||
std::cerr << "p3NetMgrIMPL::netExtCheck() checking mPeerMgr" << std::endl;
|
std::cerr << "p3NetMgrIMPL::netExtCheck() checking mPeerMgr" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
uint8_t isstable ; // unused
|
uint8_t isstable; // unused
|
||||||
sockaddr_storage tmpaddr ;
|
sockaddr_storage tmpaddr;
|
||||||
|
|
||||||
if (mPeerMgr->getExtAddressReportedByFriends(tmpaddr, isstable))
|
if ( mPeerMgr->getExtAddressReportedByFriends(tmpaddr, isstable) &&
|
||||||
|
sockaddr_storage_ipv6_to_ipv4(tmpaddr) )
|
||||||
{
|
{
|
||||||
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
|
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
|
||||||
std::cerr << "p3NetMgrIMPL::netExtCheck() Ext supplied by ExtAddrFinder" << std::endl;
|
std::cerr << "p3NetMgrIMPL::netExtCheck() Ext supplied by ExtAddrFinder" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
/* best guess at port */
|
/* best guess at port */
|
||||||
sockaddr_storage_setport(tmpaddr, sockaddr_storage_port(mLocalAddr));
|
sockaddr_storage_setport( tmpaddr,
|
||||||
|
sockaddr_storage_port(mLocalAddr) );
|
||||||
|
|
||||||
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
|
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
|
||||||
std::cerr << "p3NetMgrIMPL::netExtCheck() ";
|
std::cerr << "p3NetMgrIMPL::netExtCheck() ";
|
||||||
|
@ -842,17 +837,18 @@ void p3NetMgrIMPL::netExtCheck()
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//mNetFlags.mExtAddr = tmpaddr;
|
|
||||||
mNetFlags.mExtAddrOk = true;
|
mNetFlags.mExtAddrOk = true;
|
||||||
mNetFlags.mExtAddrStableOk = isstable;
|
mNetFlags.mExtAddrStableOk = isstable;
|
||||||
|
|
||||||
address_votes[tmpaddr].n++ ;
|
address_votes[tmpaddr].n++;
|
||||||
|
|
||||||
std::cerr << "PeerMgr reported external address " << sockaddr_storage_iptostring(tmpaddr) << std::endl;
|
std::cerr << __PRETTY_FUNCTION__ << " PeerMgr reported external"
|
||||||
|
<< " address "
|
||||||
|
<< sockaddr_storage_iptostring(tmpaddr) << std::endl;
|
||||||
}
|
}
|
||||||
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
|
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
|
||||||
else
|
else
|
||||||
std::cerr << " No reliable address returned." << std::endl;
|
std::cerr << " No reliable address returned." << std::endl;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -950,14 +946,6 @@ void p3NetMgrIMPL::netExtCheck()
|
||||||
#endif
|
#endif
|
||||||
netAssistSetAddress(mNetFlags.mLocalAddr, mNetFlags.mExtAddr, mNetMode);
|
netAssistSetAddress(mNetFlags.mLocalAddr, mNetFlags.mExtAddr, mNetMode);
|
||||||
}
|
}
|
||||||
#if 0
|
|
||||||
else
|
|
||||||
{
|
|
||||||
std::cerr << "p3NetMgrIMPL::netExtCheck() setting ERR netAssistSetAddress(0)" << std::endl;
|
|
||||||
/* mode = 0 for error */
|
|
||||||
netAssistSetAddress(mNetFlags.mLocalAddr, mNetFlags.mExtAddr, mNetMode);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* flag unreachables! */
|
/* flag unreachables! */
|
||||||
if ((mNetFlags.mExtAddrOk) && (!mNetFlags.mExtAddrStableOk))
|
if ((mNetFlags.mExtAddrOk) && (!mNetFlags.mExtAddrStableOk))
|
||||||
|
@ -966,9 +954,6 @@ void p3NetMgrIMPL::netExtCheck()
|
||||||
std::cerr << "p3NetMgrIMPL::netExtCheck() Ext Unstable - Unreachable Check" << std::endl;
|
std::cerr << "p3NetMgrIMPL::netExtCheck() Ext Unstable - Unreachable Check" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (netSetupDone)
|
if (netSetupDone)
|
||||||
|
@ -988,9 +973,9 @@ void p3NetMgrIMPL::netExtCheck()
|
||||||
RsPeerId fakeId;
|
RsPeerId fakeId;
|
||||||
netAssistKnownPeer(fakeId, mExtAddr, NETASSIST_KNOWN_PEER_SELF | NETASSIST_KNOWN_PEER_ONLINE);
|
netAssistKnownPeer(fakeId, mExtAddr, NETASSIST_KNOWN_PEER_SELF | NETASSIST_KNOWN_PEER_ONLINE);
|
||||||
|
|
||||||
rslog(RSL_WARNING, p3netmgrzone, "p3NetMgr::netExtCheck() Network Setup Complete");
|
std::cerr << __PRETTY_FUNCTION__ << " Network Setup Complete"
|
||||||
|
<< std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**********************************************************************************************
|
/**********************************************************************************************
|
||||||
|
@ -1021,6 +1006,9 @@ bool p3NetMgrIMPL::checkNetAddress()
|
||||||
* possible. It will require complete reenginering of the network layer
|
* possible. It will require complete reenginering of the network layer
|
||||||
* code. */
|
* code. */
|
||||||
|
|
||||||
|
/* For retro-compatibility strictly accept only IPv4 addresses here,
|
||||||
|
* IPv6 addresses are handled in a retro-compatible manner in
|
||||||
|
* p3PeerMgrIMPL::UpdateOwnAddress */
|
||||||
std::vector<sockaddr_storage> addrs;
|
std::vector<sockaddr_storage> addrs;
|
||||||
if (getLocalAddresses(addrs))
|
if (getLocalAddresses(addrs))
|
||||||
{
|
{
|
||||||
|
@ -1029,7 +1017,8 @@ bool p3NetMgrIMPL::checkNetAddress()
|
||||||
sockaddr_storage& addr(*it);
|
sockaddr_storage& addr(*it);
|
||||||
if( sockaddr_storage_isValidNet(addr) &&
|
if( sockaddr_storage_isValidNet(addr) &&
|
||||||
!sockaddr_storage_isLoopbackNet(addr) &&
|
!sockaddr_storage_isLoopbackNet(addr) &&
|
||||||
!sockaddr_storage_isLinkLocalNet(addr))
|
!sockaddr_storage_isLinkLocalNet(addr) &&
|
||||||
|
sockaddr_storage_ipv6_to_ipv4(addr) )
|
||||||
{
|
{
|
||||||
prefAddr = addr;
|
prefAddr = addr;
|
||||||
validAddr = true;
|
validAddr = true;
|
||||||
|
@ -1038,15 +1027,13 @@ bool p3NetMgrIMPL::checkNetAddress()
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If no satisfactory local address has been found yet relax and
|
/* If no satisfactory local address has been found yet relax and
|
||||||
* accept also IPv4 link local addresses, IPv6 link local is not
|
* accept also link local addresses */
|
||||||
* accepted because of sin6_scope_id that depends on the host using
|
|
||||||
* it as an outgoing connection endpoint */
|
|
||||||
if(!validAddr) for (auto it = addrs.begin(); it!=addrs.end(); ++it)
|
if(!validAddr) for (auto it = addrs.begin(); it!=addrs.end(); ++it)
|
||||||
{
|
{
|
||||||
sockaddr_storage& addr(*it);
|
sockaddr_storage& addr(*it);
|
||||||
if( sockaddr_storage_isValidNet(addr) &&
|
if( sockaddr_storage_isValidNet(addr) &&
|
||||||
!sockaddr_storage_isLoopbackNet(addr) &&
|
!sockaddr_storage_isLoopbackNet(addr) &&
|
||||||
!sockaddr_storage_ipv6_isLinkLocalNet(addr) )
|
sockaddr_storage_ipv6_to_ipv4(addr) )
|
||||||
{
|
{
|
||||||
prefAddr = addr;
|
prefAddr = addr;
|
||||||
validAddr = true;
|
validAddr = true;
|
||||||
|
@ -1072,7 +1059,7 @@ bool p3NetMgrIMPL::checkNetAddress()
|
||||||
/* check addresses */
|
/* check addresses */
|
||||||
|
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
|
RS_STACK_MUTEX(mNetMtx);
|
||||||
|
|
||||||
oldAddr = mLocalAddr;
|
oldAddr = mLocalAddr;
|
||||||
addrChanged = !sockaddr_storage_sameip(prefAddr, mLocalAddr);
|
addrChanged = !sockaddr_storage_sameip(prefAddr, mLocalAddr);
|
||||||
|
@ -1175,7 +1162,9 @@ bool p3NetMgrIMPL::checkNetAddress()
|
||||||
mPeerMgr->UpdateOwnAddress(mLocalAddr, mExtAddr);
|
mPeerMgr->UpdateOwnAddress(mLocalAddr, mExtAddr);
|
||||||
}
|
}
|
||||||
|
|
||||||
rslog(RSL_WARNING, p3netmgrzone, "p3NetMgr::checkNetAddress() local address changed, resetting network");
|
std::cerr << __PRETTY_FUNCTION__
|
||||||
|
<< " local address changed, resetting network" << std::endl;
|
||||||
|
|
||||||
netReset();
|
netReset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -119,17 +119,20 @@ class p3NetMgrIMPL;
|
||||||
|
|
||||||
class p3PeerMgr
|
class p3PeerMgr
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
p3PeerMgr() { return; }
|
p3PeerMgr() {}
|
||||||
virtual ~p3PeerMgr() { return; }
|
virtual ~p3PeerMgr() {}
|
||||||
|
|
||||||
virtual bool addFriend(const RsPeerId &ssl_id, const RsPgpId &gpg_id, uint32_t netMode = RS_NET_MODE_UDP,
|
virtual bool addFriend( const RsPeerId &ssl_id, const RsPgpId &gpg_id,
|
||||||
uint16_t vsDisc = RS_VS_DISC_FULL, uint16_t vsDht = RS_VS_DHT_FULL,
|
uint32_t netMode = RS_NET_MODE_UDP,
|
||||||
time_t lastContact = 0,ServicePermissionFlags = ServicePermissionFlags(RS_NODE_PERM_DEFAULT)) = 0;
|
uint16_t vsDisc = RS_VS_DISC_FULL,
|
||||||
virtual bool removeFriend(const RsPeerId &ssl_id, bool removePgpId) = 0;
|
uint16_t vsDht = RS_VS_DHT_FULL,
|
||||||
|
time_t lastContact = 0,
|
||||||
|
ServicePermissionFlags = ServicePermissionFlags(RS_NODE_PERM_DEFAULT) ) = 0;
|
||||||
|
|
||||||
virtual bool isFriend(const RsPeerId& ssl_id) = 0;
|
virtual bool removeFriend(const RsPeerId &ssl_id, bool removePgpId) = 0;
|
||||||
|
virtual bool isFriend(const RsPeerId& ssl_id) = 0;
|
||||||
|
|
||||||
virtual bool getAssociatedPeers(const RsPgpId &gpg_id, std::list<RsPeerId> &ids) = 0;
|
virtual bool getAssociatedPeers(const RsPgpId &gpg_id, std::list<RsPeerId> &ids) = 0;
|
||||||
virtual bool removeAllFriendLocations(const RsPgpId &gpgid) = 0;
|
virtual bool removeAllFriendLocations(const RsPgpId &gpgid) = 0;
|
||||||
|
@ -146,7 +149,7 @@ virtual bool getGroupInfoByName(const std::string& groupName, RsGroupInfo &gr
|
||||||
virtual bool getGroupInfoList(std::list<RsGroupInfo> &groupInfoList) = 0;
|
virtual bool getGroupInfoList(std::list<RsGroupInfo> &groupInfoList) = 0;
|
||||||
virtual bool assignPeersToGroup(const RsNodeGroupId &groupId, const std::list<RsPgpId> &peerIds, bool assign) = 0;
|
virtual bool assignPeersToGroup(const RsNodeGroupId &groupId, const std::list<RsPgpId> &peerIds, bool assign) = 0;
|
||||||
|
|
||||||
virtual bool resetOwnExternalAddressList() = 0 ;
|
virtual bool resetOwnExternalAddressList() = 0 ;
|
||||||
|
|
||||||
virtual ServicePermissionFlags servicePermissionFlags(const RsPgpId& gpg_id) =0;
|
virtual ServicePermissionFlags servicePermissionFlags(const RsPgpId& gpg_id) =0;
|
||||||
virtual ServicePermissionFlags servicePermissionFlags(const RsPeerId& ssl_id) =0;
|
virtual ServicePermissionFlags servicePermissionFlags(const RsPeerId& ssl_id) =0;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue