Browse Source

twisterd 0.9.30: random listening port.

binds to a random port on init (unless specified by command line -port=28333 etc).
twisterd will memorize the port used last time so reinitializations/reboots won't mess with seeders' directories.
miguelfreitas
Miguel Freitas 10 years ago
parent
commit
92e2fb64b3
  1. 2
      src/clientversion.h
  2. 4
      src/init.cpp
  3. 11
      src/net.cpp
  4. 2
      src/net.h
  5. 35
      src/twister.cpp
  6. 1
      src/twister.h

2
src/clientversion.h

@ -8,7 +8,7 @@ @@ -8,7 +8,7 @@
// These need to be macros, as version.cpp's and bitcoin-qt.rc's voodoo requires it
#define CLIENT_VERSION_MAJOR 0
#define CLIENT_VERSION_MINOR 9
#define CLIENT_VERSION_REVISION 29
#define CLIENT_VERSION_REVISION 30
#define CLIENT_VERSION_BUILD 0
// Set to true for release, false for prerelease or test build

4
src/init.cpp

@ -576,6 +576,10 @@ bool AppInit2(boost::thread_group& threadGroup) @@ -576,6 +576,10 @@ bool AppInit2(boost::thread_group& threadGroup)
return InitError(_("twisterwallet.dat corrupt, salvage failed"));
}
// ********************************************************* Step 5 1/2: preinit twister/torrent before network
preinitSessionTorrent();
// ********************************************************* Step 6: network initialization
RegisterNodeSignals(GetNodeSignals());

11
src/net.cpp

@ -77,6 +77,8 @@ CCriticalSection cs_setservAddNodeAddresses; @@ -77,6 +77,8 @@ CCriticalSection cs_setservAddNodeAddresses;
vector<std::string> vAddedNodes;
CCriticalSection cs_vAddedNodes;
int portUsedLastTime = 0;
static CSemaphore *semOutbound = NULL;
// Signals for message handling
@ -91,7 +93,14 @@ void AddOneShot(string strDest) @@ -91,7 +93,14 @@ void AddOneShot(string strDest)
unsigned short GetListenPort()
{
return (unsigned short)(GetArg("-port", Params().GetDefaultPort()));
int64 portFromArg = GetArg("-port", 0);
if( portFromArg )
return (unsigned short)portFromArg;
if( !portUsedLastTime ) {
//portUsedLastTime = Params().GetDefaultPort();
portUsedLastTime = 1024 + GetRand(30000);
}
return (unsigned short)portUsedLastTime;
}
// find 'best' local address for a particular peer

2
src/net.h

@ -100,7 +100,7 @@ extern limitedmap<CInv, int64> mapAlreadyAskedFor; @@ -100,7 +100,7 @@ extern limitedmap<CInv, int64> mapAlreadyAskedFor;
extern std::vector<std::string> vAddedNodes;
extern CCriticalSection cs_vAddedNodes;
extern int portUsedLastTime;
class CNodeStats

35
src/twister.cpp

@ -71,6 +71,9 @@ static std::map<std::string,GroupChat> m_groups; @@ -71,6 +71,9 @@ static std::map<std::string,GroupChat> m_groups;
static CCriticalSection cs_seenHashtags;
static std::map<std::string,double> m_seenHashtags;
static bool generateOpt = 0;
static int genproclimit = 1;
const double hashtagHalfLife = 8*60*60; // Halve votes within 8 hours (sec)
const double hashtagExpiration = 7*24*60*60; // Remove a hashtag from the list after ~ hashtagExpiration*count (sec)
const int hashtagTimerInterval = 60; // Timer interval (sec)
@ -217,6 +220,7 @@ int saveGlobalData(std::string const& filename) @@ -217,6 +220,7 @@ int saveGlobalData(std::string const& filename)
int genproclimit = GetArg("-genproclimit", -1);
if( genproclimit > 0 )
globalDict["genproclimit"] = genproclimit;
globalDict["portUsedLastTime"] = GetListenPort();
std::vector<char> buf;
bencode(std::back_inserter(buf), globalDict);
@ -241,16 +245,9 @@ int loadGlobalData(std::string const& filename) @@ -241,16 +245,9 @@ int loadGlobalData(std::string const& filename)
if( sendSpamMsg.size() ) strSpamMessage = sendSpamMsg;
string sendSpamUser = userDict.dict_find_string_value("sendSpamUser");
if( sendSpamUser.size() ) strSpamUser = sendSpamUser;
bool generate = userDict.dict_find_int_value("generate");
int genproclimit = userDict.dict_find_int_value("genproclimit");
if( generate ) {
Array params;
params.push_back( generate );
if( genproclimit > 0 )
params.push_back( genproclimit );
setgenerate(params, false);
}
generateOpt = userDict.dict_find_int_value("generate");
genproclimit = userDict.dict_find_int_value("genproclimit");
portUsedLastTime = userDict.dict_find_int_value("portUsedLastTime");
return 0;
}
@ -267,7 +264,6 @@ void ThreadWaitExtIP() @@ -267,7 +264,6 @@ void ThreadWaitExtIP()
SimpleThreadCounter threadCounter(&cs_twister, &m_threadsToJoin, "wait-extip");
std::string ipStr;
// wait up to 10 seconds for bitcoin to get the external IP
for( int i = 0; i < 20; i++ ) {
const CNetAddr paddrPeer("8.8.8.8");
@ -397,9 +393,14 @@ void ThreadWaitExtIP() @@ -397,9 +393,14 @@ void ThreadWaitExtIP()
if( ss.dht_nodes )
break;
}
boost::filesystem::path globalDataPath = GetDataDir() / GLOBAL_DATA_FILE;
loadGlobalData(globalDataPath.string());
if( generateOpt ) {
Array params;
params.push_back( generateOpt );
if( genproclimit > 0 )
params.push_back( genproclimit );
setgenerate(params, false);
}
std::set<std::string> torrentsToStart;
{
@ -933,6 +934,12 @@ void ThreadHashtagsAging() @@ -933,6 +934,12 @@ void ThreadHashtagsAging()
}
}
void preinitSessionTorrent()
{
boost::filesystem::path globalDataPath = GetDataDir() / GLOBAL_DATA_FILE;
loadGlobalData(globalDataPath.string());
}
void startSessionTorrent(boost::thread_group& threadGroup)
{
printf("startSessionTorrent (waiting for external IP)\n");

1
src/twister.h

@ -29,6 +29,7 @@ public: @@ -29,6 +29,7 @@ public:
twister();
};
void preinitSessionTorrent();
void startSessionTorrent(boost::thread_group& threadGroup);
void stopSessionTorrent();

Loading…
Cancel
Save