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 9 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. 33
      src/twister.cpp
  6. 1
      src/twister.h

2
src/clientversion.h

@ -8,7 +8,7 @@
// These need to be macros, as version.cpp's and bitcoin-qt.rc's voodoo requires it // 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_MAJOR 0
#define CLIENT_VERSION_MINOR 9 #define CLIENT_VERSION_MINOR 9
#define CLIENT_VERSION_REVISION 29 #define CLIENT_VERSION_REVISION 30
#define CLIENT_VERSION_BUILD 0 #define CLIENT_VERSION_BUILD 0
// Set to true for release, false for prerelease or test build // 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)
return InitError(_("twisterwallet.dat corrupt, salvage failed")); return InitError(_("twisterwallet.dat corrupt, salvage failed"));
} }
// ********************************************************* Step 5 1/2: preinit twister/torrent before network
preinitSessionTorrent();
// ********************************************************* Step 6: network initialization // ********************************************************* Step 6: network initialization
RegisterNodeSignals(GetNodeSignals()); RegisterNodeSignals(GetNodeSignals());

11
src/net.cpp

@ -77,6 +77,8 @@ CCriticalSection cs_setservAddNodeAddresses;
vector<std::string> vAddedNodes; vector<std::string> vAddedNodes;
CCriticalSection cs_vAddedNodes; CCriticalSection cs_vAddedNodes;
int portUsedLastTime = 0;
static CSemaphore *semOutbound = NULL; static CSemaphore *semOutbound = NULL;
// Signals for message handling // Signals for message handling
@ -91,7 +93,14 @@ void AddOneShot(string strDest)
unsigned short GetListenPort() 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 // find 'best' local address for a particular peer

2
src/net.h

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

33
src/twister.cpp

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

1
src/twister.h

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

Loading…
Cancel
Save