mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-06 21:58:57 -04:00
improved voting for extr address, and make sure DHTStunner does not return a banned IP
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@8408 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
b9a620ee39
commit
91bf1d6cb2
1 changed files with 93 additions and 75 deletions
|
@ -44,6 +44,7 @@ const int p3netmgrzone = 7563;
|
|||
#include "serialiser/rsconfigitems.h"
|
||||
#include "retroshare/rsiface.h"
|
||||
#include "retroshare/rsconfig.h"
|
||||
#include "retroshare/rsbanlist.h"
|
||||
|
||||
/* Network setup States */
|
||||
|
||||
|
@ -713,6 +714,8 @@ void p3NetMgrIMPL::netExtCheck()
|
|||
std::cerr << "p3NetMgrIMPL::netExtCheck() Ext supplied from netAssistExternalAddress()" << std::endl;
|
||||
#endif
|
||||
if(sockaddr_storage_isValidNet(tmpip))
|
||||
{
|
||||
if(rsBanList->isAddressAccepted(tmpip,RSBANLIST_CHECKING_FLAGS_BLACKLIST))
|
||||
{
|
||||
// must be stable???
|
||||
isStable = true;
|
||||
|
@ -723,11 +726,14 @@ void p3NetMgrIMPL::netExtCheck()
|
|||
address_votes[tmpip].n++ ;
|
||||
}
|
||||
else
|
||||
{
|
||||
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
|
||||
std::cerr << "p3NetMgrIMPL::netExtCheck() Bad Address supplied from netAssistExternalAddress()" << std::endl;
|
||||
#endif
|
||||
std::cerr << "(SS) netAssisExternalAddress returned wrong own IP " << sockaddr_storage_iptostring(tmpip) << " (banned). Rejecting." << std::endl;
|
||||
}
|
||||
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
|
||||
else
|
||||
{
|
||||
std::cerr << "p3NetMgrIMPL::netExtCheck() Bad Address supplied from netAssistExternalAddress()" << std::endl;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -745,6 +751,8 @@ void p3NetMgrIMPL::netExtCheck()
|
|||
{
|
||||
/* input network bits */
|
||||
if (mDhtStunner->getExternalAddr(tmpaddr, isstable))
|
||||
{
|
||||
if(rsBanList->isAddressAccepted(tmpaddr,RSBANLIST_CHECKING_FLAGS_BLACKLIST))
|
||||
{
|
||||
// must be stable???
|
||||
isStable = (isstable == 1);
|
||||
|
@ -759,6 +767,9 @@ void p3NetMgrIMPL::netExtCheck()
|
|||
std::cerr << " Stable: " << (uint32_t) isstable;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
std::cerr << "(SS) DHTStunner returned wrong own IP " << sockaddr_storage_iptostring(tmpaddr) << " (banned). Rejecting." << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -788,7 +799,6 @@ void p3NetMgrIMPL::netExtCheck()
|
|||
|
||||
mNetFlags.mExtAddr = tmpip;
|
||||
mNetFlags.mExtAddrOk = true;
|
||||
mNetFlags.mExtAddrStableOk = isStable;
|
||||
|
||||
address_votes[tmpip].n++ ;
|
||||
|
||||
|
@ -808,13 +818,21 @@ void p3NetMgrIMPL::netExtCheck()
|
|||
// look at votes.
|
||||
|
||||
std::cerr << "Figuring out ext addr from voting:" << std::endl;
|
||||
uint32_t max = 0 ;
|
||||
uint32_t admax = 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;
|
||||
std::cerr << " Vote: " << sockaddr_storage_iptostring(it->first) << " : " << it->second.n << " votes." ;
|
||||
|
||||
if(it->second.n > max)
|
||||
if(it->second.n > admax)
|
||||
{
|
||||
mNetFlags.mExtAddr = it->first ;
|
||||
admax = it->second.n ;
|
||||
|
||||
std::cerr << " Kept!" << std::endl;
|
||||
}
|
||||
else
|
||||
std::cerr << " Discarded." << std::endl;
|
||||
}
|
||||
|
||||
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue