aboutsummaryrefslogtreecommitdiff
path: root/src/netbase.cpp
diff options
context:
space:
mode:
authorpracticalswift <practicalswift@users.noreply.github.com>2018-02-28 21:15:01 +0100
committerpracticalswift <practicalswift@users.noreply.github.com>2018-03-11 10:49:04 +0100
commitcba2800e8c4e73c2eddff76880b55d930c5010f6 (patch)
tree02c5d5d8590e4a923765b1f7ee5fee5a2bb08407 /src/netbase.cpp
parent29fad97c320c892ab6a480c81e2078ec22ab354b (diff)
downloadbitcoin-cba2800e8c4e73c2eddff76880b55d930c5010f6.tar.xz
Increase signal-to-noise ratio in debug.log by adjusting log level when logging failed non-manual connect():s
Before this patch: ``` $ src/bitcoind -printtoconsole … 2018-02-28 18:42:51 UpdateTip: new best=0000000000005448b10a219683d34b770a28044e1cc421032dea1a79ff548948 height=1286903 version=0x20000000 log2_work=69.791313 tx=17408546 date='2018-02-28 18:42:46' progress=1.000000 cache=0.0MiB(173txo) 2018-02-28T18:37:52Z connect() 10.11.21.34:18333 failed after select(): Connection refused (111) 2018-02-28 18:43:22 connect() to 10.11.43.14:18333 failed after select(): Network is unreachable (101) 2018-02-28 18:44:49 UpdateTip: new best=000000000000029a521ff2803e1441b09413b876accff5084a4cccf7747d798b height=1286904 version=0x20000000 log2_work=69.791345 tx=17408559 date='2018-02-28 18:44:51' progress=1.000000 cache=0.1MiB(502txo) 2018-02-28 18:46:54 connect() to [2001:0:9d38:78ff:1234:1234:1234:1234]:18333 failed: Network is unreachable (101) 2018-02-28 18:48:56 connect() to [2001:0:9d38:6aff:1234:1234:1234:1234]:18333 failed: Network is unreachable (101) 2018-02-28 18:49:11 UpdateTip: new best=000000000000000206b79eb235e5dd907b6369de0e5d764330bf40ec0d460311 height=1286905 version=0x20000000 log2_work=69.791377 tx=17408577 date='2018-02-28 18:49:12' progress=1.000000 cache=1.0MiB(5245txo) ``` After this patch: ``` $ src/bitcoind -printtoconsole … 2018-02-28 18:42:51 UpdateTip: new best=0000000000005448b10a219683d34b770a28044e1cc421032dea1a79ff548948 height=1286903 version=0x20000000 log2_work=69.791313 tx=17408546 date='2018-02-28 18:42:46' progress=1.000000 cache=0.0MiB(173txo) 2018-02-28 18:44:49 UpdateTip: new best=000000000000029a521ff2803e1441b09413b876accff5084a4cccf7747d798b height=1286904 version=0x20000000 log2_work=69.791345 tx=17408559 date='2018-02-28 18:44:51' progress=1.000000 cache=0.1MiB(502txo) 2018-02-28 18:49:11 UpdateTip: new best=000000000000000206b79eb235e5dd907b6369de0e5d764330bf40ec0d460311 height=1286905 version=0x20000000 log2_work=69.791377 tx=17408577 date='2018-02-28 18:49:12' progress=1.000000 cache=1.0MiB(5245txo) ``` Please note that "manual connect():s" (invoked via `-connect`, `-proxy` or `addnode`) are still reported as usual: ``` $ src/bitcoind -printtoconsole -connect=10.11.12.13 … 2018-02-28 18:33:13 connect() to 10.11.12.13:18333 failed after select(): Connection refused (111) $ src/bitcoind -printtoconsole -proxy=10.11.12.13 … 2018-02-28 18:32:32 connect() to 10.11.12.13:9050 failed after select(): Connection refused (111) $ src/bitcoind -printtoconsole & $ src/bitcoin-cli addnode "10.11.12.13" onetry … 2018-02-28 18:34:40 connect() to 10.11.12.13:18333 failed after select(): Connection refused (111) ```
Diffstat (limited to 'src/netbase.cpp')
-rw-r--r--src/netbase.cpp20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/netbase.cpp b/src/netbase.cpp
index 3ea3141d5e..dd32110932 100644
--- a/src/netbase.cpp
+++ b/src/netbase.cpp
@@ -9,6 +9,7 @@
#include <sync.h>
#include <uint256.h>
#include <random.h>
+#include <tinyformat.h>
#include <util.h>
#include <utilstrencodings.h>
@@ -468,7 +469,17 @@ SOCKET CreateSocket(const CService &addrConnect)
return hSocket;
}
-bool ConnectSocketDirectly(const CService &addrConnect, const SOCKET& hSocket, int nTimeout)
+template<typename... Args>
+static void LogConnectFailure(bool manual_connection, const char* fmt, const Args&... args) {
+ std::string error_message = tfm::format(fmt, args...);
+ if (manual_connection) {
+ LogPrintf("%s\n", error_message);
+ } else {
+ LogPrint(BCLog::NET, "%s\n", error_message);
+ }
+}
+
+bool ConnectSocketDirectly(const CService &addrConnect, const SOCKET& hSocket, int nTimeout, bool manual_connection)
{
struct sockaddr_storage sockaddr;
socklen_t len = sizeof(sockaddr);
@@ -513,7 +524,7 @@ bool ConnectSocketDirectly(const CService &addrConnect, const SOCKET& hSocket, i
}
if (nRet != 0)
{
- LogPrintf("connect() to %s failed after select(): %s\n", addrConnect.ToString(), NetworkErrorString(nRet));
+ LogConnectFailure(manual_connection, "connect() to %s failed after select(): %s", addrConnect.ToString(), NetworkErrorString(nRet));
return false;
}
}
@@ -523,7 +534,7 @@ bool ConnectSocketDirectly(const CService &addrConnect, const SOCKET& hSocket, i
else
#endif
{
- LogPrintf("connect() to %s failed: %s\n", addrConnect.ToString(), NetworkErrorString(WSAGetLastError()));
+ LogConnectFailure(manual_connection, "connect() to %s failed: %s", addrConnect.ToString(), NetworkErrorString(WSAGetLastError()));
return false;
}
}
@@ -581,7 +592,7 @@ bool IsProxy(const CNetAddr &addr) {
bool ConnectThroughProxy(const proxyType &proxy, const std::string& strDest, int port, const SOCKET& hSocket, int nTimeout, bool *outProxyConnectionFailed)
{
// first connect to proxy server
- if (!ConnectSocketDirectly(proxy.proxy, hSocket, nTimeout)) {
+ if (!ConnectSocketDirectly(proxy.proxy, hSocket, nTimeout, true)) {
if (outProxyConnectionFailed)
*outProxyConnectionFailed = true;
return false;
@@ -601,6 +612,7 @@ bool ConnectThroughProxy(const proxyType &proxy, const std::string& strDest, int
}
return true;
}
+
bool LookupSubNet(const char* pszName, CSubNet& ret)
{
std::string strSubnet(pszName);