@@ -332,8 +332,7 @@ enum class IntrRecvError {
332
332
* @param data The buffer where the read bytes should be stored.
333
333
* @param len The number of bytes to read into the specified buffer.
334
334
* @param timeout The total timeout in milliseconds for this read.
335
- * @param hSocket The socket (has to be in non-blocking mode) from which to read
336
- * bytes.
335
+ * @param sock The socket (has to be in non-blocking mode) from which to read bytes.
337
336
*
338
337
* @returns An IntrRecvError indicating the resulting status of this read.
339
338
* IntrRecvError::OK only if all of the specified number of bytes were
@@ -343,15 +342,15 @@ enum class IntrRecvError {
343
342
* Sockets can be made non-blocking with SetSocketNonBlocking(const
344
343
* SOCKET&, bool).
345
344
*/
346
- static IntrRecvError InterruptibleRecv (uint8_t * data, size_t len, int timeout, const Sock& hSocket )
345
+ static IntrRecvError InterruptibleRecv (uint8_t * data, size_t len, int timeout, const Sock& sock )
347
346
{
348
347
int64_t curTime = GetTimeMillis ();
349
348
int64_t endTime = curTime + timeout;
350
349
// Maximum time to wait for I/O readiness. It will take up until this time
351
350
// (in millis) to break off in case of an interruption.
352
351
const int64_t maxWait = 1000 ;
353
352
while (len > 0 && curTime < endTime) {
354
- ssize_t ret = hSocket .Recv (data, len, 0 ); // Optimistically try the recv first
353
+ ssize_t ret = sock .Recv (data, len, 0 ); // Optimistically try the recv first
355
354
if (ret > 0 ) {
356
355
len -= ret;
357
356
data += ret;
@@ -363,7 +362,7 @@ static IntrRecvError InterruptibleRecv(uint8_t* data, size_t len, int timeout, c
363
362
// Only wait at most maxWait milliseconds at a time, unless
364
363
// we're approaching the end of the specified total timeout
365
364
int timeout_ms = std::min (endTime - curTime, maxWait);
366
- if (!hSocket .Wait (std::chrono::milliseconds{timeout_ms}, Sock::RECV)) {
365
+ if (!sock .Wait (std::chrono::milliseconds{timeout_ms}, Sock::RECV)) {
367
366
return IntrRecvError::NetworkError;
368
367
}
369
368
} else {
@@ -417,7 +416,7 @@ static std::string Socks5ErrorString(uint8_t err)
417
416
* @param port The destination port.
418
417
* @param auth The credentials with which to authenticate with the specified
419
418
* SOCKS5 proxy.
420
- * @param hSocket The SOCKS5 proxy socket.
419
+ * @param sock The SOCKS5 proxy socket.
421
420
*
422
421
* @returns Whether or not the operation succeeded.
423
422
*
@@ -427,7 +426,7 @@ static std::string Socks5ErrorString(uint8_t err)
427
426
* @see <a href="https://www.ietf.org/rfc/rfc1928.txt">RFC1928: SOCKS Protocol
428
427
* Version 5</a>
429
428
*/
430
- static bool Socks5 (const std::string& strDest, int port, const ProxyCredentials* auth, const Sock& hSocket )
429
+ static bool Socks5 (const std::string& strDest, int port, const ProxyCredentials* auth, const Sock& sock )
431
430
{
432
431
IntrRecvError recvr;
433
432
LogPrint (BCLog::NET, " SOCKS5 connecting %s\n " , strDest);
@@ -445,12 +444,12 @@ static bool Socks5(const std::string& strDest, int port, const ProxyCredentials*
445
444
vSocks5Init.push_back (0x01 ); // 1 method identifier follows...
446
445
vSocks5Init.push_back (SOCKS5Method::NOAUTH);
447
446
}
448
- ssize_t ret = hSocket .Send (vSocks5Init.data (), vSocks5Init.size (), MSG_NOSIGNAL);
447
+ ssize_t ret = sock .Send (vSocks5Init.data (), vSocks5Init.size (), MSG_NOSIGNAL);
449
448
if (ret != (ssize_t )vSocks5Init.size ()) {
450
449
return error (" Error sending to proxy" );
451
450
}
452
451
uint8_t pchRet1[2 ];
453
- if ((recvr = InterruptibleRecv (pchRet1, 2 , SOCKS5_RECV_TIMEOUT, hSocket )) != IntrRecvError::OK) {
452
+ if ((recvr = InterruptibleRecv (pchRet1, 2 , SOCKS5_RECV_TIMEOUT, sock )) != IntrRecvError::OK) {
454
453
LogPrintf (" Socks5() connect to %s:%d failed: InterruptibleRecv() timeout or other failure\n " , strDest, port);
455
454
return false ;
456
455
}
@@ -467,13 +466,13 @@ static bool Socks5(const std::string& strDest, int port, const ProxyCredentials*
467
466
vAuth.insert (vAuth.end (), auth->username .begin (), auth->username .end ());
468
467
vAuth.push_back (auth->password .size ());
469
468
vAuth.insert (vAuth.end (), auth->password .begin (), auth->password .end ());
470
- ret = hSocket .Send (vAuth.data (), vAuth.size (), MSG_NOSIGNAL);
469
+ ret = sock .Send (vAuth.data (), vAuth.size (), MSG_NOSIGNAL);
471
470
if (ret != (ssize_t )vAuth.size ()) {
472
471
return error (" Error sending authentication to proxy" );
473
472
}
474
473
LogPrint (BCLog::PROXY, " SOCKS5 sending proxy authentication %s:%s\n " , auth->username , auth->password );
475
474
uint8_t pchRetA[2 ];
476
- if ((recvr = InterruptibleRecv (pchRetA, 2 , SOCKS5_RECV_TIMEOUT, hSocket )) != IntrRecvError::OK) {
475
+ if ((recvr = InterruptibleRecv (pchRetA, 2 , SOCKS5_RECV_TIMEOUT, sock )) != IntrRecvError::OK) {
477
476
return error (" Error reading proxy authentication response" );
478
477
}
479
478
if (pchRetA[0 ] != 0x01 || pchRetA[1 ] != 0x00 ) {
@@ -493,12 +492,12 @@ static bool Socks5(const std::string& strDest, int port, const ProxyCredentials*
493
492
vSocks5.insert (vSocks5.end (), strDest.begin (), strDest.end ());
494
493
vSocks5.push_back ((port >> 8 ) & 0xFF );
495
494
vSocks5.push_back ((port >> 0 ) & 0xFF );
496
- ret = hSocket .Send (vSocks5.data (), vSocks5.size (), MSG_NOSIGNAL);
495
+ ret = sock .Send (vSocks5.data (), vSocks5.size (), MSG_NOSIGNAL);
497
496
if (ret != (ssize_t )vSocks5.size ()) {
498
497
return error (" Error sending to proxy" );
499
498
}
500
499
uint8_t pchRet2[4 ];
501
- if ((recvr = InterruptibleRecv (pchRet2, 4 , SOCKS5_RECV_TIMEOUT, hSocket )) != IntrRecvError::OK) {
500
+ if ((recvr = InterruptibleRecv (pchRet2, 4 , SOCKS5_RECV_TIMEOUT, sock )) != IntrRecvError::OK) {
502
501
if (recvr == IntrRecvError::Timeout) {
503
502
/* If a timeout happens here, this effectively means we timed out while connecting
504
503
* to the remote node. This is very common for Tor, so do not print an
@@ -522,24 +521,24 @@ static bool Socks5(const std::string& strDest, int port, const ProxyCredentials*
522
521
uint8_t pchRet3[256 ];
523
522
switch (pchRet2[3 ])
524
523
{
525
- case SOCKS5Atyp::IPV4: recvr = InterruptibleRecv (pchRet3, 4 , SOCKS5_RECV_TIMEOUT, hSocket ); break ;
526
- case SOCKS5Atyp::IPV6: recvr = InterruptibleRecv (pchRet3, 16 , SOCKS5_RECV_TIMEOUT, hSocket ); break ;
524
+ case SOCKS5Atyp::IPV4: recvr = InterruptibleRecv (pchRet3, 4 , SOCKS5_RECV_TIMEOUT, sock ); break ;
525
+ case SOCKS5Atyp::IPV6: recvr = InterruptibleRecv (pchRet3, 16 , SOCKS5_RECV_TIMEOUT, sock ); break ;
527
526
case SOCKS5Atyp::DOMAINNAME:
528
527
{
529
- recvr = InterruptibleRecv (pchRet3, 1 , SOCKS5_RECV_TIMEOUT, hSocket );
528
+ recvr = InterruptibleRecv (pchRet3, 1 , SOCKS5_RECV_TIMEOUT, sock );
530
529
if (recvr != IntrRecvError::OK) {
531
530
return error (" Error reading from proxy" );
532
531
}
533
532
int nRecv = pchRet3[0 ];
534
- recvr = InterruptibleRecv (pchRet3, nRecv, SOCKS5_RECV_TIMEOUT, hSocket );
533
+ recvr = InterruptibleRecv (pchRet3, nRecv, SOCKS5_RECV_TIMEOUT, sock );
535
534
break ;
536
535
}
537
536
default : return error (" Error: malformed proxy response" );
538
537
}
539
538
if (recvr != IntrRecvError::OK) {
540
539
return error (" Error reading from proxy" );
541
540
}
542
- if ((recvr = InterruptibleRecv (pchRet3, 2 , SOCKS5_RECV_TIMEOUT, hSocket )) != IntrRecvError::OK) {
541
+ if ((recvr = InterruptibleRecv (pchRet3, 2 , SOCKS5_RECV_TIMEOUT, sock )) != IntrRecvError::OK) {
543
542
return error (" Error reading from proxy" );
544
543
}
545
544
LogPrint (BCLog::NET, " SOCKS5 connected %s\n " , strDest);
@@ -764,18 +763,18 @@ bool IsProxy(const CNetAddr &addr) {
764
763
* @param proxy The SOCKS5 proxy.
765
764
* @param strDest The destination service to which to connect.
766
765
* @param port The destination port.
767
- * @param hSocket The socket on which to connect to the SOCKS5 proxy.
766
+ * @param sock The socket on which to connect to the SOCKS5 proxy.
768
767
* @param nTimeout Wait this many milliseconds for the connection to the SOCKS5
769
768
* proxy to be established.
770
769
* @param[out] outProxyConnectionFailed Whether or not the connection to the
771
770
* SOCKS5 proxy failed.
772
771
*
773
772
* @returns Whether or not the operation succeeded.
774
773
*/
775
- bool ConnectThroughProxy (const proxyType& proxy, const std::string& strDest, int port, const Sock& hSocket , int nTimeout, bool & outProxyConnectionFailed)
774
+ bool ConnectThroughProxy (const proxyType& proxy, const std::string& strDest, int port, const Sock& sock , int nTimeout, bool & outProxyConnectionFailed)
776
775
{
777
776
// first connect to proxy server
778
- if (!ConnectSocketDirectly (proxy.proxy , hSocket .Get (), nTimeout, true )) {
777
+ if (!ConnectSocketDirectly (proxy.proxy , sock .Get (), nTimeout, true )) {
779
778
outProxyConnectionFailed = true ;
780
779
return false ;
781
780
}
@@ -784,11 +783,11 @@ bool ConnectThroughProxy(const proxyType& proxy, const std::string& strDest, int
784
783
ProxyCredentials random_auth;
785
784
static std::atomic_int counter (0 );
786
785
random_auth.username = random_auth.password = strprintf (" %i" , counter++);
787
- if (!Socks5 (strDest, (uint16_t )port, &random_auth, hSocket )) {
786
+ if (!Socks5 (strDest, (uint16_t )port, &random_auth, sock )) {
788
787
return false ;
789
788
}
790
789
} else {
791
- if (!Socks5 (strDest, (uint16_t )port, 0 , hSocket )) {
790
+ if (!Socks5 (strDest, (uint16_t )port, 0 , sock )) {
792
791
return false ;
793
792
}
794
793
}
0 commit comments