aboutsummaryrefslogtreecommitdiff
path: root/src/init.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/init.cpp')
-rw-r--r--src/init.cpp171
1 files changed, 111 insertions, 60 deletions
diff --git a/src/init.cpp b/src/init.cpp
index 687cb9a9d..5c87af911 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,31 +221,30 @@ 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" +
+ " -tor=<ip:port> " + _("Use proxy to reach tor hidden services (default: same as -proxy)") + "\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" +
+ " -onlynet=<net> " + _("Only connect to nodes in network <net> (IPv4, IPv6 or Tor)") + "\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" +
+ " -dnsseed " + _("Find peers using DNS lookup (default: 1 unless -connect)") + "\n" +
" -banscore=<n> " + _("Threshold for disconnecting misbehaving peers (default: 100)") + "\n" +
" -bantime=<n> " + _("Number of seconds to keep misbehaving peers from reconnecting (default: 86400)") + "\n" +
- " -maxreceivebuffer=<n> " + _("Maximum per-connection receive buffer, <n>*1000 bytes (default: 10000)") + "\n" +
- " -maxsendbuffer=<n> " + _("Maximum per-connection send buffer, <n>*1000 bytes (default: 10000)") + "\n" +
+ " -maxreceivebuffer=<n> " + _("Maximum per-connection receive buffer, <n>*1000 bytes (default: 5000)") + "\n" +
+ " -maxsendbuffer=<n> " + _("Maximum per-connection send buffer, <n>*1000 bytes (default: 1000)") + "\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" +
@@ -240,7 +256,8 @@ std::string HelpMessage()
" -daemon " + _("Run in the background as a daemon and accept commands") + "\n" +
#endif
" -testnet " + _("Use the test network") + "\n" +
- " -debug " + _("Output extra debugging information") + "\n" +
+ " -debug " + _("Output extra debugging information. Implies all other -debug* options") + "\n" +
+ " -debugnet " + _("Output extra network debugging information") + "\n" +
" -logtimestamps " + _("Prepend debug output with timestamp") + "\n" +
" -printtoconsole " + _("Send trace/debug info to console instead of debug.log file") + "\n" +
#ifdef WIN32
@@ -308,33 +325,48 @@ 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);
- SoftSetBoolArg("-irc", false);
- SoftSetBoolArg("-proxydns", true);
+ }
+
+ if (mapArgs.count("-proxy")) {
+ // to protect privacy, do not listen by default if a proxy server is specified
+ SoftSetBoolArg("-listen", false);
+ }
+
+ 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");
+
+ // -debug implies fDebug*
+ if (fDebug)
+ fDebugNet = true;
+ else
+ fDebugNet = GetBoolArg("-debugnet");
+
bitdb.SetDetach(GetBoolArg("-detachdb", false));
#if !defined(WIN32) && !defined(QT_GUI)
@@ -416,6 +448,7 @@ bool AppInit2()
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)
@@ -425,30 +458,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));
@@ -467,8 +478,45 @@ bool AppInit2()
}
}
- BOOST_FOREACH(string strDest, mapMultiArgs["-seednode"])
- AddOneShot(strDest);
+ CService addrProxy;
+ bool fProxy = false;
+ if (mapArgs.count("-proxy")) {
+ 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);
+ }
+ fProxy = true;
+ }
+
+ // -tor can override normal proxy, -notor disables tor entirely
+ if (!(mapArgs.count("-tor") && mapArgs["-tor"] == "0") && (fProxy || mapArgs.count("-tor"))) {
+ CService addrOnion;
+ if (!mapArgs.count("-tor"))
+ addrOnion = addrProxy;
+ else
+ addrOnion = CService(mapArgs["-tor"], 9050);
+ if (!addrOnion.IsValid())
+ return InitError(strprintf(_("Invalid -tor address: '%s'"), mapArgs["-tor"].c_str()));
+ SetProxy(NET_TOR, addrOnion, 5);
+ SetReachable(NET_TOR);
+ }
+
+ // 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)
@@ -484,15 +532,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"))
@@ -505,6 +553,9 @@ bool AppInit2()
}
}
+ BOOST_FOREACH(string strDest, mapMultiArgs["-seednode"])
+ AddOneShot(strDest);
+
// ********************************************************* Step 6: load blockchain
if (GetBoolArg("-loadblockindextest"))
@@ -587,7 +638,7 @@ bool AppInit2()
if (GetBoolArg("-upgradewallet", fFirstRun))
{
int nMaxVersion = GetArg("-upgradewallet", 0);
- if (nMaxVersion == 0) // the -walletupgrade without argument case
+ if (nMaxVersion == 0) // the -upgradewallet without argument case
{
printf("Performing wallet upgrade to %i\n", FEATURE_LATEST);
nMaxVersion = CLIENT_VERSION;