diff options
author | Giel van Schijndel <me@mortis.eu> | 2012-06-17 14:30:37 +0200 |
---|---|---|
committer | Giel van Schijndel <me@mortis.eu> | 2012-06-17 14:30:37 +0200 |
commit | 07368a9e3c60bbef8452501d34bb8d3688cbca13 (patch) | |
tree | 963f2e56176451bfeb84e54d14bf726388407b7d /src/init.cpp | |
parent | fbf9df2ea32528c71b58160283b4eb2c52e30ccb (diff) | |
parent | fab7858a350d4650686b3aa07bd6277ce7c9685f (diff) |
Merge branch 'master' into async-ipv6-rpc
Conflicts:
src/bitcoinrpc.cpp
Signed-off-by: Giel van Schijndel <me@mortis.eu>
Diffstat (limited to 'src/init.cpp')
-rw-r--r-- | src/init.cpp | 139 |
1 files changed, 83 insertions, 56 deletions
diff --git a/src/init.cpp b/src/init.cpp index c01dc27086..08b594f56c 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -38,6 +38,17 @@ void ExitTimeout(void* parg) #endif } +void StartShutdown() +{ +#ifdef QT_GUI + // ensure we leave the Qt main loop for a clean GUI exit (Shutdown() is called in bitcoin.cpp afterwards) + uiInterface.QueueShutdown(); +#else + // Without UI, Shutdown() can simply be started in a new thread + CreateThread(Shutdown, NULL); +#endif +} + void Shutdown(void* parg) { static CCriticalSection cs_Shutdown; @@ -66,7 +77,10 @@ void Shutdown(void* parg) Sleep(50); printf("Bitcoin exited\n\n"); fExit = true; +#ifndef QT_GUI + // ensure non UI client get's exited here, but let Bitcoin-Qt reach return 0; in bitcoin.cpp exit(0); +#endif } else { @@ -182,12 +196,15 @@ bool static InitWarning(const std::string &str) } -bool static Bind(const CService &addr) { +bool static Bind(const CService &addr, bool fError = true) { if (IsLimited(addr)) return false; std::string strError; - if (!BindListenPort(addr, strError)) - return InitError(strError); + if (!BindListenPort(addr, strError)) { + if (fError) + return InitError(strError); + return false; + } return true; } @@ -204,20 +221,18 @@ std::string HelpMessage() " -dblogsize=<n> " + _("Set database disk log size in megabytes (default: 100)") + "\n" + " -timeout=<n> " + _("Specify connection timeout (in milliseconds)") + "\n" + " -proxy=<ip:port> " + _("Connect through socks proxy") + "\n" + - " -socks=<n> " + _("Select the version of socks proxy to use (4 or 5, 5 is default)") + "\n" + - " -noproxy=<net> " + _("Do not use proxy for connections to network <net> (IPv4 or IPv6)") + "\n" + + " -socks=<n> " + _("Select the version of socks proxy to use (4-5, default: 5)") + "\n" + " -dns " + _("Allow DNS lookups for -addnode, -seednode and -connect") + "\n" + - " -proxydns " + _("Pass DNS requests to (SOCKS5) proxy") + "\n" + " -port=<port> " + _("Listen for connections on <port> (default: 8333 or testnet: 18333)") + "\n" + " -maxconnections=<n> " + _("Maintain at most <n> connections to peers (default: 125)") + "\n" + " -addnode=<ip> " + _("Add a node to connect to and attempt to keep the connection open") + "\n" + - " -connect=<ip> " + _("Connect only to the specified node") + "\n" + + " -connect=<ip> " + _("Connect only to the specified node(s)") + "\n" + " -seednode=<ip> " + _("Connect to a node to retrieve peer addresses, and disconnect") + "\n" + " -externalip=<ip> " + _("Specify your own public address") + "\n" + " -onlynet=<net> " + _("Only connect to nodes in network <net> (IPv4 or IPv6)") + "\n" + - " -discover " + _("Try to discover public IP address (default: 1)") + "\n" + + " -discover " + _("Discover own IP address (default: 1 when listening and no -externalip)") + "\n" + " -irc " + _("Find peers using internet relay chat (default: 0)") + "\n" + - " -listen " + _("Accept connections from outside (default: 1)") + "\n" + + " -listen " + _("Accept connections from outside (default: 1 if no -proxy or -connect)") + "\n" + " -bind=<addr> " + _("Bind to given address. Use [host]:port notation for IPv6") + "\n" + " -dnsseed " + _("Find peers using DNS lookup (default: 1)") + "\n" + " -banscore=<n> " + _("Threshold for disconnecting misbehaving peers (default: 100)") + "\n" + @@ -226,9 +241,9 @@ std::string HelpMessage() " -maxsendbuffer=<n> " + _("Maximum per-connection send buffer, <n>*1000 bytes (default: 10000)") + "\n" + #ifdef USE_UPNP #if USE_UPNP - " -upnp " + _("Use Universal Plug and Play to map the listening port (default: 1)") + "\n" + + " -upnp " + _("Use UPnP to map the listening port (default: 1 when listening)") + "\n" + #else - " -upnp " + _("Use Universal Plug and Play to map the listening port (default: 0)") + "\n" + + " -upnp " + _("Use UPnP to map the listening port (default: 0)") + "\n" + #endif #endif " -detachdb " + _("Detach block and address databases. Increases shutdown time (default: 0)") + "\n" + @@ -308,30 +323,38 @@ bool AppInit2() // ********************************************************* Step 2: parameter interactions fTestNet = GetBoolArg("-testnet"); - if (fTestNet) - { + if (fTestNet) { SoftSetBoolArg("-irc", true); } - if (mapArgs.count("-connect")) - SoftSetBoolArg("-dnsseed", false); - - // even in Tor mode, if -bind is specified, you really want -listen - if (mapArgs.count("-bind")) + if (mapArgs.count("-bind")) { + // when specifying an explicit binding address, you want to listen on it + // even when -connect or -proxy is specified SoftSetBoolArg("-listen", true); + } - bool fTor = (fUseProxy && addrProxy.GetPort() == 9050); - if (fTor) - { - // Use SoftSetBoolArg here so user can override any of these if they wish. - // Note: the GetBoolArg() calls for all of these must happen later. + if (mapArgs.count("-connect")) { + // when only connecting to trusted nodes, do not seed via DNS, or listen by default + SoftSetBoolArg("-dnsseed", false); + SoftSetBoolArg("-listen", false); + } + + if (mapArgs.count("-proxy")) { + // to protect privacy, do not listen by default if a proxy server is specified SoftSetBoolArg("-listen", false); - SoftSetBoolArg("-irc", false); - SoftSetBoolArg("-proxydns", true); + } + + if (GetBoolArg("-listen", true)) { + // do not map ports or try to retrieve public IP when not listening (pointless) SoftSetBoolArg("-upnp", false); SoftSetBoolArg("-discover", false); } + if (mapArgs.count("-externalip")) { + // if an explicit public IP is specified, do not try to find others + SoftSetBoolArg("-discover", false); + } + // ********************************************************* Step 3: parameter-to-internal-flags fDebug = GetBoolArg("-debug"); @@ -414,7 +437,9 @@ bool AppInit2() ShrinkDebugFile(); printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); printf("Bitcoin version %s (%s)\n", FormatFullVersion().c_str(), CLIENT_DATE.c_str()); + printf("Startup time: %s\n", DateTimeStrFormat("%x %H:%M:%S", GetTime()).c_str()); printf("Default data directory %s\n", GetDefaultDataDir().string().c_str()); + printf("Used data directory %s\n", GetDataDir().string().c_str()); std::ostringstream strErrors; if (fDaemon) @@ -424,30 +449,8 @@ bool AppInit2() // ********************************************************* Step 5: network initialization - if (mapArgs.count("-proxy")) - { - fUseProxy = true; - addrProxy = CService(mapArgs["-proxy"], 9050); - if (!addrProxy.IsValid()) - return InitError(strprintf(_("Invalid -proxy address: '%s'"), mapArgs["-proxy"].c_str())); - } + int nSocksVersion = GetArg("-socks", 5); - if (mapArgs.count("-noproxy")) - { - BOOST_FOREACH(std::string snet, mapMultiArgs["-noproxy"]) { - enum Network net = ParseNetwork(snet); - if (net == NET_UNROUTABLE) - return InitError(strprintf(_("Unknown network specified in -noproxy: '%s'"), snet.c_str())); - SetNoProxy(net); - } - } - - fNameLookup = GetBoolArg("-dns"); - fProxyNameLookup = GetBoolArg("-proxydns"); - if (fProxyNameLookup) - fNameLookup = true; - fNoListen = !GetBoolArg("-listen", true); - nSocksVersion = GetArg("-socks", 5); if (nSocksVersion != 4 && nSocksVersion != 5) return InitError(strprintf(_("Unknown -socks proxy version requested: %i"), nSocksVersion)); @@ -466,8 +469,29 @@ bool AppInit2() } } - BOOST_FOREACH(string strDest, mapMultiArgs["-seednode"]) - AddOneShot(strDest); + if (mapArgs.count("-proxy")) { + CService addrProxy = CService(mapArgs["-proxy"], 9050); + if (!addrProxy.IsValid()) + return InitError(strprintf(_("Invalid -proxy address: '%s'"), mapArgs["-proxy"].c_str())); + + if (!IsLimited(NET_IPV4)) + SetProxy(NET_IPV4, addrProxy, nSocksVersion); + if (nSocksVersion > 4) { +#ifdef USE_IPV6 + if (!IsLimited(NET_IPV6)) + SetProxy(NET_IPV6, addrProxy, nSocksVersion); +#endif + SetNameProxy(addrProxy, nSocksVersion); + } + } + + // see Step 2: parameter interactions for more information about these + fNoListen = !GetBoolArg("-listen", true); + fDiscover = GetBoolArg("-discover", true); + fNameLookup = GetBoolArg("-dns", true); +#ifdef USE_UPNP + fUseUPnP = GetBoolArg("-upnp", USE_UPNP); +#endif bool fBound = false; if (!fNoListen) @@ -483,15 +507,15 @@ bool AppInit2() } else { struct in_addr inaddr_any; inaddr_any.s_addr = INADDR_ANY; - if (!IsLimited(NET_IPV4)) - fBound |= Bind(CService(inaddr_any, GetListenPort())); #ifdef USE_IPV6 if (!IsLimited(NET_IPV6)) - fBound |= Bind(CService(in6addr_any, GetListenPort())); + fBound |= Bind(CService(in6addr_any, GetListenPort()), false); #endif + if (!IsLimited(NET_IPV4)) + fBound |= Bind(CService(inaddr_any, GetListenPort()), !fBound); } if (!fBound) - return InitError(_("Not listening on any port")); + return InitError(_("Failed to listen on any port. Use -listen=0 if you want this.")); } if (mapArgs.count("-externalip")) @@ -504,6 +528,9 @@ bool AppInit2() } } + BOOST_FOREACH(string strDest, mapMultiArgs["-seednode"]) + AddOneShot(strDest); + // ********************************************************* Step 6: load blockchain if (GetBoolArg("-loadblockindextest")) @@ -604,11 +631,11 @@ bool AppInit2() // Create new keyUser and set as default key RandAddSeedPerfmon(); - std::vector<unsigned char> newDefaultKey; + CPubKey newDefaultKey; if (!pwalletMain->GetKeyFromPool(newDefaultKey, false)) strErrors << _("Cannot initialize keypool") << "\n"; pwalletMain->SetDefaultKey(newDefaultKey); - if (!pwalletMain->SetAddressBookName(CBitcoinAddress(pwalletMain->vchDefaultKey), "")) + if (!pwalletMain->SetAddressBookName(pwalletMain->vchDefaultKey.GetID(), "")) strErrors << _("Cannot write default address") << "\n"; } |