made init port random, depending on the SSL id

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4026 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2011-02-09 20:21:28 +00:00
parent e5385c533e
commit 081cfee461
2 changed files with 11 additions and 2 deletions

View File

@ -3306,7 +3306,16 @@ bool p3ConnectMgr::checkNetAddress()
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::checkNetAddress() Correcting Port to DEFAULT" << std::endl;
#endif
mOwnState.currentlocaladdr.sin_port = htons(PQI_DEFAULT_PORT);
// Generate a default port from SSL id. The port will always be the
// same, but appear random from peer to peer.
// Random port avoids clashes, improves anonymity.
//
uint32_t default_port_seed = 0 ;
for(uint i=0;i<mOwnState.id.size();++i)
default_port_seed = (0x473a8b74u * (unsigned int)(mOwnState.id[i]) + default_port_seed)^0x11837bea ;
mOwnState.currentlocaladdr.sin_port = htons(PQI_MIN_PORT + (default_port_seed % (PQI_MAX_PORT - PQI_MIN_PORT)));
addrChanged = true;
}

View File

@ -230,7 +230,7 @@ void RsInit::InitRsConfig()
RsInitConfig::load_trustedpeer = false;
RsInitConfig::firsttime_run = false;
RsInitConfig::port = (RSRandom::random_u32() & 0x1fff) + 7000 ; // random port between 7000 and 15191. Random port avoids clashes, improves anonymity.
RsInitConfig::port = 0 ;
RsInitConfig::forceLocalAddr = false;
RsInitConfig::haveLogFile = false;
RsInitConfig::outStderr = false;