9
9
#include < sync.h>
10
10
#include < uint256.h>
11
11
#include < random.h>
12
+ #include < tinyformat.h>
12
13
#include < util.h>
13
14
#include < utilstrencodings.h>
14
15
@@ -468,7 +469,17 @@ SOCKET CreateSocket(const CService &addrConnect)
468
469
return hSocket;
469
470
}
470
471
471
- bool ConnectSocketDirectly (const CService &addrConnect, const SOCKET& hSocket, int nTimeout)
472
+ template <typename ... Args>
473
+ static void LogConnectFailure (bool manual_connection, const char * fmt, const Args&... args) {
474
+ std::string error_message = tfm::format (fmt, args...);
475
+ if (manual_connection) {
476
+ LogPrintf (" %s\n " , error_message);
477
+ } else {
478
+ LogPrint (BCLog::NET, " %s\n " , error_message);
479
+ }
480
+ }
481
+
482
+ bool ConnectSocketDirectly (const CService &addrConnect, const SOCKET& hSocket, int nTimeout, bool manual_connection)
472
483
{
473
484
struct sockaddr_storage sockaddr;
474
485
socklen_t len = sizeof (sockaddr);
@@ -513,7 +524,7 @@ bool ConnectSocketDirectly(const CService &addrConnect, const SOCKET& hSocket, i
513
524
}
514
525
if (nRet != 0 )
515
526
{
516
- LogPrintf ( " connect() to %s failed after select(): %s\n " , addrConnect.ToString (), NetworkErrorString (nRet));
527
+ LogConnectFailure (manual_connection, " connect() to %s failed after select(): %s" , addrConnect.ToString (), NetworkErrorString (nRet));
517
528
return false ;
518
529
}
519
530
}
@@ -523,7 +534,7 @@ bool ConnectSocketDirectly(const CService &addrConnect, const SOCKET& hSocket, i
523
534
else
524
535
#endif
525
536
{
526
- LogPrintf ( " connect() to %s failed: %s\n " , addrConnect.ToString (), NetworkErrorString (WSAGetLastError ()));
537
+ LogConnectFailure (manual_connection, " connect() to %s failed: %s" , addrConnect.ToString (), NetworkErrorString (WSAGetLastError ()));
527
538
return false ;
528
539
}
529
540
}
@@ -581,7 +592,7 @@ bool IsProxy(const CNetAddr &addr) {
581
592
bool ConnectThroughProxy (const proxyType &proxy, const std::string& strDest, int port, const SOCKET& hSocket, int nTimeout, bool *outProxyConnectionFailed)
582
593
{
583
594
// first connect to proxy server
584
- if (!ConnectSocketDirectly (proxy.proxy , hSocket, nTimeout)) {
595
+ if (!ConnectSocketDirectly (proxy.proxy , hSocket, nTimeout, true )) {
585
596
if (outProxyConnectionFailed)
586
597
*outProxyConnectionFailed = true ;
587
598
return false ;
@@ -601,6 +612,7 @@ bool ConnectThroughProxy(const proxyType &proxy, const std::string& strDest, int
601
612
}
602
613
return true ;
603
614
}
615
+
604
616
bool LookupSubNet (const char * pszName, CSubNet& ret)
605
617
{
606
618
std::string strSubnet (pszName);
0 commit comments