mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 20:12:57 +01:00
Merge #8033: Fix Socks5() connect failures to be less noisy and less unnecessarily scary
bf9266e
Use Socks5ErrorString() to decode error responses from socks proxy. (Warren Togami)94fd1d8
Make Socks5() InterruptibleRecv() timeout/failures informative. (Warren Togami)0d9af79
SOCKS5 connecting and connected messages with -debug=net. (Warren Togami)00678bd
Make failures to connect via Socks5() more informative and less unnecessarily scary. (Warren Togami)
This commit is contained in:
parent
0450dfdeb8
commit
1897ccc646
@ -300,10 +300,25 @@ struct ProxyCredentials
|
|||||||
std::string password;
|
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) */
|
/** Connect using SOCKS5 (as described in RFC1928) */
|
||||||
static bool Socks5(const std::string& strDest, int port, const ProxyCredentials *auth, SOCKET& hSocket)
|
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) {
|
if (strDest.size() > 255) {
|
||||||
CloseSocket(hSocket);
|
CloseSocket(hSocket);
|
||||||
return error("Hostname too long");
|
return error("Hostname too long");
|
||||||
@ -327,7 +342,8 @@ static bool Socks5(const std::string& strDest, int port, const ProxyCredentials
|
|||||||
char pchRet1[2];
|
char pchRet1[2];
|
||||||
if (!InterruptibleRecv(pchRet1, 2, SOCKS5_RECV_TIMEOUT, hSocket)) {
|
if (!InterruptibleRecv(pchRet1, 2, SOCKS5_RECV_TIMEOUT, hSocket)) {
|
||||||
CloseSocket(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) {
|
if (pchRet1[0] != 0x05) {
|
||||||
CloseSocket(hSocket);
|
CloseSocket(hSocket);
|
||||||
@ -388,19 +404,10 @@ static bool Socks5(const std::string& strDest, int port, const ProxyCredentials
|
|||||||
return error("Proxy failed to accept request");
|
return error("Proxy failed to accept request");
|
||||||
}
|
}
|
||||||
if (pchRet2[1] != 0x00) {
|
if (pchRet2[1] != 0x00) {
|
||||||
|
// Failures to connect to a peer that are not proxy errors
|
||||||
CloseSocket(hSocket);
|
CloseSocket(hSocket);
|
||||||
switch (pchRet2[1])
|
LogPrintf("Socks5() connect to %s:%d failed: %s\n", strDest, port, Socks5ErrorString(pchRet2[1]));
|
||||||
{
|
return false;
|
||||||
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");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (pchRet2[2] != 0x00) {
|
if (pchRet2[2] != 0x00) {
|
||||||
CloseSocket(hSocket);
|
CloseSocket(hSocket);
|
||||||
@ -432,7 +439,7 @@ static bool Socks5(const std::string& strDest, int port, const ProxyCredentials
|
|||||||
CloseSocket(hSocket);
|
CloseSocket(hSocket);
|
||||||
return error("Error reading from proxy");
|
return error("Error reading from proxy");
|
||||||
}
|
}
|
||||||
LogPrintf("SOCKS5 connected %s\n", strDest);
|
LogPrint("net", "SOCKS5 connected %s\n", strDest);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user