diff --git a/src/clientversion.h b/src/clientversion.h index 1bcc5552..2027073f 100644 --- a/src/clientversion.h +++ b/src/clientversion.h @@ -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 diff --git a/src/init.cpp b/src/init.cpp index eed93598..790f9e77 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -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()); diff --git a/src/net.cpp b/src/net.cpp index 7d21646a..ce4fcf64 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -77,6 +77,8 @@ CCriticalSection cs_setservAddNodeAddresses; vector vAddedNodes; CCriticalSection cs_vAddedNodes; +int portUsedLastTime = 0; + static CSemaphore *semOutbound = NULL; // Signals for message handling @@ -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 diff --git a/src/net.h b/src/net.h index c286ea99..da84bf9c 100644 --- a/src/net.h +++ b/src/net.h @@ -100,7 +100,7 @@ extern limitedmap mapAlreadyAskedFor; extern std::vector vAddedNodes; extern CCriticalSection cs_vAddedNodes; - +extern int portUsedLastTime; class CNodeStats diff --git a/src/twister.cpp b/src/twister.cpp index 7429603c..4ac0c352 100644 --- a/src/twister.cpp +++ b/src/twister.cpp @@ -71,6 +71,9 @@ static std::map m_groups; static CCriticalSection cs_seenHashtags; static std::map 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) int genproclimit = GetArg("-genproclimit", -1); if( genproclimit > 0 ) globalDict["genproclimit"] = genproclimit; + globalDict["portUsedLastTime"] = GetListenPort(); std::vector buf; bencode(std::back_inserter(buf), globalDict); @@ -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() 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() 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 torrentsToStart; { @@ -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"); diff --git a/src/twister.h b/src/twister.h index cc8c3d4e..603c2b7e 100644 --- a/src/twister.h +++ b/src/twister.h @@ -29,6 +29,7 @@ public: twister(); }; +void preinitSessionTorrent(); void startSessionTorrent(boost::thread_group& threadGroup); void stopSessionTorrent();