From 00678bdb0aeb296456501f818faaa012a75ce18e Mon Sep 17 00:00:00 2001 From: Warren Togami Date: Mon, 9 May 2016 17:01:33 -0700 Subject: [PATCH 1/4] Make failures to connect via Socks5() more informative and less unnecessarily scary. * The "ERROR" was printed far too often during normal operation for what was not an error. * Makes the Socks5() connect failure similar to the IP connect failure in debug.log. Before: `2016-05-09 00:15:00 ERROR: Proxy error: host unreachable` After: `2016-05-09 00:15:00 Socks5() connect to t6xj6wilh4ytvcs7.onion:18333 failed: host unreachable"` --- src/netbase.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/netbase.cpp b/src/netbase.cpp index b44a8b16e20cc..6e81fdcac29b6 100644 --- a/src/netbase.cpp +++ b/src/netbase.cpp @@ -379,19 +379,21 @@ static bool Socks5(const std::string& strDest, int port, const ProxyCredentials return error("Proxy failed to accept request"); } if (pchRet2[1] != 0x00) { + // Failures to connect to a peer that are not proxy errors CloseSocket(hSocket); switch (pchRet2[1]) { - case 0x01: return error("Proxy error: general failure"); - case 0x02: return error("Proxy error: connection not allowed"); - case 0x03: return error("Proxy error: network unreachable"); - case 0x04: return error("Proxy error: host unreachable"); - case 0x05: return error("Proxy error: connection refused"); - case 0x06: return error("Proxy error: TTL expired"); - case 0x07: return error("Proxy error: protocol error"); - case 0x08: return error("Proxy error: address type not supported"); - default: return error("Proxy error: unknown"); + case 0x01: LogPrintf("Socks5() connect to %s:%d failed: general failure\n", strDest, port); break; + case 0x02: LogPrintf("Socks5() connect to %s:%d failed: connection not allowed\n", strDest, port); break; + case 0x03: LogPrintf("Socks5() connect to %s:%d failed: network unreachable\n", strDest, port); break; + case 0x04: LogPrintf("Socks5() connect to %s:%d failed: host unreachable\n", strDest, port); break; + case 0x05: LogPrintf("Socks5() connect to %s:%d failed: connection refused\n", strDest, port); break; + case 0x06: LogPrintf("Socks5() connect to %s:%d failed: TTL expired\n", strDest, port); break; + case 0x07: LogPrintf("Socks5() connect to %s:%d failed: protocol error\n", strDest, port); break; + case 0x08: LogPrintf("Socks5() connect to %s:%d failed: address type not supported\n", strDest, port); break; + default: LogPrintf("Socks5() connect to %s:%d failed: unknown\n", strDest, port); } + return false; } if (pchRet2[2] != 0x00) { CloseSocket(hSocket); From 0d9af79e5084dc2fb6a73abd9dd113dda4e993b4 Mon Sep 17 00:00:00 2001 From: Warren Togami Date: Mon, 9 May 2016 17:35:14 -0700 Subject: [PATCH 2/4] SOCKS5 connecting and connected messages with -debug=net. They were too noisy and not necessary for normal operation. --- src/netbase.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/netbase.cpp b/src/netbase.cpp index 6e81fdcac29b6..5ab12c9a7c43e 100644 --- a/src/netbase.cpp +++ b/src/netbase.cpp @@ -294,7 +294,7 @@ struct ProxyCredentials /** Connect using SOCKS5 (as described in RFC1928) */ static bool Socks5(const std::string& strDest, int port, const ProxyCredentials *auth, SOCKET& hSocket) { - LogPrintf("SOCKS5 connecting %s\n", strDest); + LogPrint("net", "SOCKS5 connecting %s\n", strDest); if (strDest.size() > 255) { CloseSocket(hSocket); return error("Hostname too long"); @@ -425,7 +425,7 @@ static bool Socks5(const std::string& strDest, int port, const ProxyCredentials CloseSocket(hSocket); return error("Error reading from proxy"); } - LogPrintf("SOCKS5 connected %s\n", strDest); + LogPrint("net", "SOCKS5 connected %s\n", strDest); return true; } From 94fd1d8d53adceb80e5a41cc6438c7704aeac0f7 Mon Sep 17 00:00:00 2001 From: Warren Togami Date: Tue, 17 May 2016 16:43:23 +0900 Subject: [PATCH 3/4] Make Socks5() InterruptibleRecv() timeout/failures informative. Before: 2016-05-16 06:10:45 ERROR: Error reading proxy response After: 2016-05-16 06:10:45 Socks5() connect to k7s5d6jqig4ej4v4.onion:18333 failed: InterruptibleRecv() timeout or other failure --- src/netbase.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/netbase.cpp b/src/netbase.cpp index 5ab12c9a7c43e..d2a4188ffcb54 100644 --- a/src/netbase.cpp +++ b/src/netbase.cpp @@ -318,7 +318,8 @@ static bool Socks5(const std::string& strDest, int port, const ProxyCredentials char pchRet1[2]; if (!InterruptibleRecv(pchRet1, 2, SOCKS5_RECV_TIMEOUT, hSocket)) { CloseSocket(hSocket); - return error("Error reading proxy response"); + LogPrintf("Socks5() connect to %s:%d failed: InterruptibleRecv() timeout or other failure\n", strDest, port); + return false; } if (pchRet1[0] != 0x05) { CloseSocket(hSocket); From bf9266e017b286c36e08fd09b91d9e39f14b2cf3 Mon Sep 17 00:00:00 2001 From: Warren Togami Date: Thu, 19 May 2016 14:19:08 +0900 Subject: [PATCH 4/4] Use Socks5ErrorString() to decode error responses from socks proxy. --- src/netbase.cpp | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/netbase.cpp b/src/netbase.cpp index d2a4188ffcb54..572ae70871d40 100644 --- a/src/netbase.cpp +++ b/src/netbase.cpp @@ -291,6 +291,21 @@ struct ProxyCredentials std::string password; }; +std::string Socks5ErrorString(int err) +{ + switch(err) { + case 0x01: return "general failure"; + case 0x02: return "connection not allowed"; + case 0x03: return "network unreachable"; + case 0x04: return "host unreachable"; + case 0x05: return "connection refused"; + case 0x06: return "TTL expired"; + case 0x07: return "protocol error"; + case 0x08: return "address type not supported"; + default: return "unknown"; + } +} + /** Connect using SOCKS5 (as described in RFC1928) */ static bool Socks5(const std::string& strDest, int port, const ProxyCredentials *auth, SOCKET& hSocket) { @@ -382,18 +397,7 @@ static bool Socks5(const std::string& strDest, int port, const ProxyCredentials if (pchRet2[1] != 0x00) { // Failures to connect to a peer that are not proxy errors CloseSocket(hSocket); - switch (pchRet2[1]) - { - case 0x01: LogPrintf("Socks5() connect to %s:%d failed: general failure\n", strDest, port); break; - case 0x02: LogPrintf("Socks5() connect to %s:%d failed: connection not allowed\n", strDest, port); break; - case 0x03: LogPrintf("Socks5() connect to %s:%d failed: network unreachable\n", strDest, port); break; - case 0x04: LogPrintf("Socks5() connect to %s:%d failed: host unreachable\n", strDest, port); break; - case 0x05: LogPrintf("Socks5() connect to %s:%d failed: connection refused\n", strDest, port); break; - case 0x06: LogPrintf("Socks5() connect to %s:%d failed: TTL expired\n", strDest, port); break; - case 0x07: LogPrintf("Socks5() connect to %s:%d failed: protocol error\n", strDest, port); break; - case 0x08: LogPrintf("Socks5() connect to %s:%d failed: address type not supported\n", strDest, port); break; - default: LogPrintf("Socks5() connect to %s:%d failed: unknown\n", strDest, port); - } + LogPrintf("Socks5() connect to %s:%d failed: %s\n", strDest, port, Socks5ErrorString(pchRet2[1])); return false; } if (pchRet2[2] != 0x00) {