diff options
author | Luke Dashjr <luke-jr+git@utopios.org> | 2012-01-03 12:23:09 -0500 |
---|---|---|
committer | Luke Dashjr <luke-jr+git@utopios.org> | 2012-01-03 12:23:09 -0500 |
commit | a2e9767225d3c3fa55f31c2494a3a2f54a65f87f (patch) | |
tree | 67460aca4b75a21357f4906ded77c346d0181d50 | |
parent | 20e3f2aefc6071af1d4e0754053f2fb88061ee9a (diff) | |
parent | fb88f1cc97d52d8cd5bc49169a1bcd4df735fc52 (diff) |
Merge branch '0.5.0.x' into 0.5.x
-rw-r--r-- | src/init.cpp | 67 | ||||
-rw-r--r-- | src/irc.cpp | 17 | ||||
-rw-r--r-- | src/net.cpp | 61 | ||||
-rw-r--r-- | src/qt/locale/bitcoin_es.ts | 2 | ||||
-rw-r--r-- | src/qt/locale/bitcoin_es_CL.ts | 2 | ||||
-rw-r--r-- | src/util.cpp | 17 | ||||
-rw-r--r-- | src/util.h | 25 |
7 files changed, 120 insertions, 71 deletions
diff --git a/src/init.cpp b/src/init.cpp index dd8bdf5598..fc171cd48e 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -190,6 +190,7 @@ bool AppInit2(int argc, char* argv[]) " -maxconnections=<n>\t " + _("Maintain at most <n> connections to peers (default: 125)\n") + " -addnode=<ip> \t " + _("Add a node to connect to\n") + " -connect=<ip> \t\t " + _("Connect only to the specified node\n") + + " -noirc \t " + _("Don't find peers using internet relay chat\n") + " -nolisten \t " + _("Don't accept connections from outside\n") + " -nodnsseed \t " + _("Don't bootstrap list of peers using DNS\n") + " -banscore=<n> \t " + _("Threshold for disconnecting misbehaving peers (default: 100)\n") + @@ -243,8 +244,8 @@ bool AppInit2(int argc, char* argv[]) return false; } + fTestNet = GetBoolArg("-testnet"); fDebug = GetBoolArg("-debug"); - fAllowDNS = GetBoolArg("-dns"); #ifndef WIN32 fDaemon = GetBoolArg("-daemon"); @@ -263,10 +264,6 @@ bool AppInit2(int argc, char* argv[]) #endif fPrintToConsole = GetBoolArg("-printtoconsole"); fPrintToDebugger = GetBoolArg("-printtodebugger"); - - fTestNet = GetBoolArg("-testnet"); - bool fTOR = (fUseProxy && addrProxy.port == htons(9050)); - fNoListen = GetBoolArg("-nolisten") || fTOR; fLogTimestamps = GetBoolArg("-logtimestamps"); #ifndef QT_GUI @@ -328,16 +325,7 @@ bool AppInit2(int argc, char* argv[]) return false; } - // Bind to the port early so we can tell if another instance is already running. string strErrors; - if (!fNoListen) - { - if (!BindListenPort(strErrors)) - { - wxMessageBox(strErrors, "Bitcoin"); - return false; - } - } // // Load data files @@ -424,6 +412,10 @@ bool AppInit2(int argc, char* argv[]) // Add wallet transactions that aren't already in a block to mapTransactions pwalletMain->ReacceptWalletTransactions(); + // Note: Bitcoin-QT stores several settings in the wallet, so we want + // to load the wallet BEFORE parsing command-line arguments, so + // the command-line/bitcoin.conf settings override GUI setting. + // // Parameters // @@ -476,6 +468,42 @@ bool AppInit2(int argc, char* argv[]) } } + bool fTor = (fUseProxy && addrProxy.port == htons(9050)); + if (fTor) + { + // Use SoftSetArg here so user can override any of these if they wish. + // Note: the GetBoolArg() calls for all of these must happen later. + SoftSetArg("-nolisten", true); + SoftSetArg("-noirc", true); + SoftSetArg("-nodnsseed", true); + SoftSetArg("-noupnp", true); + SoftSetArg("-upnp", false); + SoftSetArg("-dns", false); + } + + fAllowDNS = GetBoolArg("-dns"); + fNoListen = GetBoolArg("-nolisten"); + + if (fHaveUPnP) + { +#if USE_UPNP + if (GetBoolArg("-noupnp")) + fUseUPnP = false; +#else + if (GetBoolArg("-upnp")) + fUseUPnP = true; +#endif + } + + if (!fNoListen) + { + if (!BindListenPort(strErrors)) + { + wxMessageBox(strErrors, "Bitcoin"); + return false; + } + } + if (mapArgs.count("-addnode")) { BOOST_FOREACH(string strAddr, mapMultiArgs["-addnode"]) @@ -498,17 +526,6 @@ bool AppInit2(int argc, char* argv[]) wxMessageBox(_("Warning: -paytxfee is set very high. This is the transaction fee you will pay if you send a transaction."), "Bitcoin", wxOK | wxICON_EXCLAMATION); } - if (fHaveUPnP) - { -#if USE_UPNP - if (GetBoolArg("-noupnp")) - fUseUPnP = false; -#else - if (GetBoolArg("-upnp")) - fUseUPnP = true; -#endif - } - // // Start the node // diff --git a/src/irc.cpp b/src/irc.cpp index 5278488dcd..fe96a90a1c 100644 --- a/src/irc.cpp +++ b/src/irc.cpp @@ -264,19 +264,14 @@ void ThreadIRCSeed2(void* parg) int nErrorWait = 10; int nRetryWait = 10; bool fNameInUse = false; - bool fTOR = (fUseProxy && addrProxy.port == htons(9050)); while (!fShutdown) { - //CAddress addrConnect("216.155.130.130:6667"); // chat.freenode.net CAddress addrConnect("92.243.23.21", 6667); // irc.lfnet.org - if (!fTOR) - { - //struct hostent* phostent = gethostbyname("chat.freenode.net"); - CAddress addrIRC("irc.lfnet.org", 6667, true); - if (addrIRC.IsValid()) - addrConnect = addrIRC; - } + + CAddress addrIRC("irc.lfnet.org", 6667, true); + if (addrIRC.IsValid()) + addrConnect = addrIRC; SOCKET hSocket; if (!ConnectSocket(addrConnect, hSocket)) @@ -406,10 +401,6 @@ void ThreadIRCSeed2(void* parg) closesocket(hSocket); hSocket = INVALID_SOCKET; - // IRC usually blocks TOR, so only try once - if (fTOR) - return; - if (GetTime() - nStart > 20 * 60) { nErrorWait /= 3; diff --git a/src/net.cpp b/src/net.cpp index 50d28913e0..8fe7e2a389 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -496,21 +496,25 @@ bool AddAddress(CAddress addr, int64 nTimePenalty, CAddrDB *pAddrDB) void AddressCurrentlyConnected(const CAddress& addr) { + CAddress *paddrFound = NULL; + CRITICAL_BLOCK(cs_mapAddresses) { // Only if it's been published already map<vector<unsigned char>, CAddress>::iterator it = mapAddresses.find(addr.GetKey()); if (it != mapAddresses.end()) + paddrFound = &(*it).second; + } + + if (paddrFound) + { + int64 nUpdateInterval = 20 * 60; + if (paddrFound->nTime < GetAdjustedTime() - nUpdateInterval) { - CAddress& addrFound = (*it).second; - int64 nUpdateInterval = 20 * 60; - if (addrFound.nTime < GetAdjustedTime() - nUpdateInterval) - { - // Periodically update most recently seen time - addrFound.nTime = GetAdjustedTime(); - CAddrDB addrdb; - addrdb.WriteAddress(addrFound); - } + // Periodically update most recently seen time + paddrFound->nTime = GetAdjustedTime(); + CAddrDB addrdb; + addrdb.WriteAddress(*paddrFound); } } } @@ -1256,13 +1260,13 @@ void ThreadDNSAddressSeed2(void* parg) if (!fTestNet) { printf("Loading addresses from DNS seeds (could take a while)\n"); - CAddrDB addrDB; - addrDB.TxnBegin(); for (int seed_idx = 0; seed_idx < ARRAYLEN(strDNSSeed); seed_idx++) { vector<CAddress> vaddr; if (Lookup(strDNSSeed[seed_idx], vaddr, NODE_NETWORK, -1, true)) { + CAddrDB addrDB; + addrDB.TxnBegin(); BOOST_FOREACH (CAddress& addr, vaddr) { if (addr.GetByte(3) != 127) @@ -1272,10 +1276,9 @@ void ThreadDNSAddressSeed2(void* parg) found++; } } + addrDB.TxnCommit(); // Save addresses (it's ok if this fails) } } - - addrDB.TxnCommit(); // Save addresses (it's ok if this fails) } printf("%d addresses found from DNS seeds\n", found); @@ -1447,28 +1450,32 @@ void ThreadOpenConnections2(void* parg) if (fShutdown) return; + bool fAddSeeds = false; + CRITICAL_BLOCK(cs_mapAddresses) { // Add seed nodes if IRC isn't working bool fTOR = (fUseProxy && addrProxy.port == htons(9050)); - if (mapAddresses.empty() && (GetTime() - nStart > 60 || fTOR) && !fTestNet) + if (mapAddresses.empty() && (GetTime() - nStart > 60 || fUseProxy) && !fTestNet) + fAddSeeds = true; + } + + if (fAddSeeds) + { + for (int i = 0; i < ARRAYLEN(pnSeed); i++) { - for (int i = 0; i < ARRAYLEN(pnSeed); i++) - { - // It'll only connect to one or two seed nodes because once it connects, - // it'll get a pile of addresses with newer timestamps. - // Seed nodes are given a random 'last seen time' of between one and two - // weeks ago. - const int64 nOneWeek = 7*24*60*60; - CAddress addr; - addr.ip = pnSeed[i]; - addr.nTime = GetTime()-GetRand(nOneWeek)-nOneWeek; - AddAddress(addr); - } + // It'll only connect to one or two seed nodes because once it connects, + // it'll get a pile of addresses with newer timestamps. + // Seed nodes are given a random 'last seen time' of between one and two + // weeks ago. + const int64 nOneWeek = 7*24*60*60; + CAddress addr; + addr.ip = pnSeed[i]; + addr.nTime = GetTime()-GetRand(nOneWeek)-nOneWeek; + AddAddress(addr); } } - // // Choose an address to connect to based on most recently seen // diff --git a/src/qt/locale/bitcoin_es.ts b/src/qt/locale/bitcoin_es.ts index df62780c4f..3956097a4f 100644 --- a/src/qt/locale/bitcoin_es.ts +++ b/src/qt/locale/bitcoin_es.ts @@ -2339,4 +2339,4 @@ pero la información de los comentarios quedará en blanco.</translation> <translation>Bitcoin Qt</translation> </message> </context> -</TS>
\ No newline at end of file +</TS> diff --git a/src/qt/locale/bitcoin_es_CL.ts b/src/qt/locale/bitcoin_es_CL.ts index d7e110cb13..878ca050b1 100644 --- a/src/qt/locale/bitcoin_es_CL.ts +++ b/src/qt/locale/bitcoin_es_CL.ts @@ -2339,4 +2339,4 @@ pero la información de los comentarios quedará en blanco.</translation> <translation>Bitcoin Qt</translation> </message> </context> -</TS>
\ No newline at end of file +</TS> diff --git a/src/util.cpp b/src/util.cpp index 236c7f7c44..3472111bb1 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -469,6 +469,23 @@ void ParseParameters(int argc, char* argv[]) } } +bool SoftSetArg(const std::string& strArg, const std::string& strValue) +{ + if (mapArgs.count(strArg)) + return false; + mapArgs[strArg] = strValue; + return true; +} + +bool SoftSetArg(const std::string& strArg, bool fValue) +{ + if (fValue) + return SoftSetArg(strArg, std::string("1")); + else + return SoftSetArg(strArg, std::string("0")); +} + + string EncodeBase64(const unsigned char* pch, size_t len) { static const char *pbase64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; diff --git a/src/util.h b/src/util.h index dcf060e3e8..d42b572c6b 100644 --- a/src/util.h +++ b/src/util.h @@ -459,7 +459,7 @@ inline int64 GetArg(const std::string& strArg, int64 nDefault) return nDefault; } -inline bool GetBoolArg(const std::string& strArg) +inline bool GetBoolArg(const std::string& strArg, bool fDefault=false) { if (mapArgs.count(strArg)) { @@ -467,9 +467,26 @@ inline bool GetBoolArg(const std::string& strArg) return true; return (atoi(mapArgs[strArg]) != 0); } - return false; -} - + return fDefault; +} + +/** + * Set an argument if it doesn't already have a value + * + * @param strArg Argument to set (e.g. "-foo") + * @param strValue Value (e.g. "1") + * @return true if argument gets set, false if it already had a value + */ +bool SoftSetArg(const std::string& strArg, const std::string& strValue); + +/** + * Set a boolean argument if it doesn't already have a value + * + * @param strArg Argument to set (e.g. "-foo") + * @param fValue Value (e.g. false) + * @return true if argument gets set, false if it already had a value + */ +bool SoftSetArg(const std::string& strArg, bool fValue); |