@@ -291,10 +291,25 @@ struct ProxyCredentials
291
291
std::string password;
292
292
};
293
293
294
+ std::string Socks5ErrorString (int err)
295
+ {
296
+ switch (err) {
297
+ case 0x01 : return " general failure" ;
298
+ case 0x02 : return " connection not allowed" ;
299
+ case 0x03 : return " network unreachable" ;
300
+ case 0x04 : return " host unreachable" ;
301
+ case 0x05 : return " connection refused" ;
302
+ case 0x06 : return " TTL expired" ;
303
+ case 0x07 : return " protocol error" ;
304
+ case 0x08 : return " address type not supported" ;
305
+ default : return " unknown" ;
306
+ }
307
+ }
308
+
294
309
/* * Connect using SOCKS5 (as described in RFC1928) */
295
310
static bool Socks5 (const std::string& strDest, int port, const ProxyCredentials *auth, SOCKET& hSocket)
296
311
{
297
- LogPrintf ( " SOCKS5 connecting %s\n " , strDest);
312
+ LogPrint ( " net " , " SOCKS5 connecting %s\n " , strDest);
298
313
if (strDest.size () > 255 ) {
299
314
CloseSocket (hSocket);
300
315
return error (" Hostname too long" );
@@ -318,7 +333,8 @@ static bool Socks5(const std::string& strDest, int port, const ProxyCredentials
318
333
char pchRet1[2 ];
319
334
if (!InterruptibleRecv (pchRet1, 2 , SOCKS5_RECV_TIMEOUT, hSocket)) {
320
335
CloseSocket (hSocket);
321
- return error (" Error reading proxy response" );
336
+ LogPrintf (" Socks5() connect to %s:%d failed: InterruptibleRecv() timeout or other failure\n " , strDest, port);
337
+ return false ;
322
338
}
323
339
if (pchRet1[0 ] != 0x05 ) {
324
340
CloseSocket (hSocket);
@@ -379,19 +395,10 @@ static bool Socks5(const std::string& strDest, int port, const ProxyCredentials
379
395
return error (" Proxy failed to accept request" );
380
396
}
381
397
if (pchRet2[1 ] != 0x00 ) {
398
+ // Failures to connect to a peer that are not proxy errors
382
399
CloseSocket (hSocket);
383
- switch (pchRet2[1 ])
384
- {
385
- case 0x01 : return error (" Proxy error: general failure" );
386
- case 0x02 : return error (" Proxy error: connection not allowed" );
387
- case 0x03 : return error (" Proxy error: network unreachable" );
388
- case 0x04 : return error (" Proxy error: host unreachable" );
389
- case 0x05 : return error (" Proxy error: connection refused" );
390
- case 0x06 : return error (" Proxy error: TTL expired" );
391
- case 0x07 : return error (" Proxy error: protocol error" );
392
- case 0x08 : return error (" Proxy error: address type not supported" );
393
- default : return error (" Proxy error: unknown" );
394
- }
400
+ LogPrintf (" Socks5() connect to %s:%d failed: %s\n " , strDest, port, Socks5ErrorString (pchRet2[1 ]));
401
+ return false ;
395
402
}
396
403
if (pchRet2[2 ] != 0x00 ) {
397
404
CloseSocket (hSocket);
@@ -423,7 +430,7 @@ static bool Socks5(const std::string& strDest, int port, const ProxyCredentials
423
430
CloseSocket (hSocket);
424
431
return error (" Error reading from proxy" );
425
432
}
426
- LogPrintf ( " SOCKS5 connected %s\n " , strDest);
433
+ LogPrint ( " net " , " SOCKS5 connected %s\n " , strDest);
427
434
return true ;
428
435
}
429
436
0 commit comments