@@ -368,8 +368,10 @@ static CAddress GetBindAddress(SOCKET sock)
368
368
return addr_bind;
369
369
}
370
370
371
- CNode* CConnman::ConnectNode (CAddress addrConnect, const char *pszDest, bool fCountFailure , bool manual_connection , bool block_relay_only)
371
+ CNode* CConnman::ConnectNode (CAddress addrConnect, const char *pszDest, bool fCountFailure , ConnectionType conn_type , bool block_relay_only)
372
372
{
373
+ assert (conn_type != ConnectionType::INBOUND);
374
+
373
375
if (pszDest == nullptr ) {
374
376
if (IsLocal (addrConnect))
375
377
return nullptr ;
@@ -432,7 +434,7 @@ CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fCo
432
434
if (hSocket == INVALID_SOCKET) {
433
435
return nullptr ;
434
436
}
435
- connected = ConnectSocketDirectly (addrConnect, hSocket, nConnectTimeout, manual_connection );
437
+ connected = ConnectSocketDirectly (addrConnect, hSocket, nConnectTimeout, conn_type == ConnectionType::MANUAL );
436
438
}
437
439
if (!proxyConnectionFailed) {
438
440
// If a connection to the node was attempted, and failure (if any) is not caused by a problem connecting to
@@ -459,7 +461,7 @@ CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fCo
459
461
NodeId id = GetNewNodeId ();
460
462
uint64_t nonce = GetDeterministicRandomizer (RANDOMIZER_ID_LOCALHOSTNONCE).Write (id).Finalize ();
461
463
CAddress addr_bind = GetBindAddress (hSocket);
462
- CNode* pnode = new CNode (id, nLocalServices, GetBestHeight (), hSocket, addrConnect, CalculateKeyedNetGroup (addrConnect), nonce, addr_bind, pszDest ? pszDest : " " , ConnectionType::OUTBOUND , block_relay_only);
464
+ CNode* pnode = new CNode (id, nLocalServices, GetBestHeight (), hSocket, addrConnect, CalculateKeyedNetGroup (addrConnect), nonce, addr_bind, pszDest ? pszDest : " " , conn_type , block_relay_only);
463
465
pnode->AddRef ();
464
466
465
467
// We're making a new connection, harvest entropy from the time (and our peer count)
@@ -1705,17 +1707,6 @@ void CConnman::ThreadDNSAddressSeed()
1705
1707
LogPrintf (" %d addresses found from DNS seeds\n " , found);
1706
1708
}
1707
1709
1708
-
1709
-
1710
-
1711
-
1712
-
1713
-
1714
-
1715
-
1716
-
1717
-
1718
-
1719
1710
void CConnman::DumpAddresses ()
1720
1711
{
1721
1712
int64_t nStart = GetTimeMillis ();
@@ -1786,7 +1777,7 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
1786
1777
for (const std::string& strAddr : connect)
1787
1778
{
1788
1779
CAddress addr (CService (), NODE_NONE);
1789
- OpenNetworkConnection (addr, false , nullptr , strAddr.c_str (), false , false , true );
1780
+ OpenNetworkConnection (addr, false , nullptr , strAddr.c_str (), false , false , ConnectionType::MANUAL );
1790
1781
for (int i = 0 ; i < 10 && i < nLoop; i++)
1791
1782
{
1792
1783
if (!interruptNet.sleep_for (std::chrono::milliseconds (500 )))
@@ -1952,7 +1943,7 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
1952
1943
// well for sanity.)
1953
1944
bool block_relay_only = nOutboundBlockRelay < m_max_outbound_block_relay && !fFeeler && nOutboundFullRelay >= m_max_outbound_full_relay;
1954
1945
1955
- OpenNetworkConnection (addrConnect, (int )setConnected.size () >= std::min (nMaxConnections - 1 , 2 ), &grant, nullptr , false , fFeeler , false , block_relay_only);
1946
+ OpenNetworkConnection (addrConnect, (int )setConnected.size () >= std::min (nMaxConnections - 1 , 2 ), &grant, nullptr , false , fFeeler , ConnectionType::OUTBOUND , block_relay_only);
1956
1947
}
1957
1948
}
1958
1949
}
@@ -2027,7 +2018,7 @@ void CConnman::ThreadOpenAddedConnections()
2027
2018
}
2028
2019
tried = true ;
2029
2020
CAddress addr (CService (), NODE_NONE);
2030
- OpenNetworkConnection (addr, false , &grant, info.strAddedNode .c_str (), false , false , true );
2021
+ OpenNetworkConnection (addr, false , &grant, info.strAddedNode .c_str (), false , false , ConnectionType::MANUAL );
2031
2022
if (!interruptNet.sleep_for (std::chrono::milliseconds (500 )))
2032
2023
return ;
2033
2024
}
@@ -2039,8 +2030,10 @@ void CConnman::ThreadOpenAddedConnections()
2039
2030
}
2040
2031
2041
2032
// if successful, this moves the passed grant to the constructed node
2042
- void CConnman::OpenNetworkConnection (const CAddress& addrConnect, bool fCountFailure , CSemaphoreGrant *grantOutbound, const char *pszDest, bool m_addr_fetch, bool fFeeler , bool manual_connection , bool block_relay_only)
2033
+ void CConnman::OpenNetworkConnection (const CAddress& addrConnect, bool fCountFailure , CSemaphoreGrant *grantOutbound, const char *pszDest, bool m_addr_fetch, bool fFeeler , ConnectionType conn_type , bool block_relay_only)
2043
2034
{
2035
+ assert (conn_type != ConnectionType::INBOUND);
2036
+
2044
2037
//
2045
2038
// Initiate outbound network connection
2046
2039
//
@@ -2058,7 +2051,7 @@ void CConnman::OpenNetworkConnection(const CAddress& addrConnect, bool fCountFai
2058
2051
} else if (FindNode (std::string (pszDest)))
2059
2052
return ;
2060
2053
2061
- CNode* pnode = ConnectNode (addrConnect, pszDest, fCountFailure , manual_connection , block_relay_only);
2054
+ CNode* pnode = ConnectNode (addrConnect, pszDest, fCountFailure , conn_type , block_relay_only);
2062
2055
2063
2056
if (!pnode)
2064
2057
return ;
@@ -2068,8 +2061,6 @@ void CConnman::OpenNetworkConnection(const CAddress& addrConnect, bool fCountFai
2068
2061
pnode->m_addr_fetch = true ;
2069
2062
if (fFeeler )
2070
2063
pnode->fFeeler = true ;
2071
- if (manual_connection)
2072
- pnode->m_manual_connection = true ;
2073
2064
2074
2065
m_msgproc->InitializeNode (pnode);
2075
2066
{
@@ -2127,11 +2118,6 @@ void CConnman::ThreadMessageHandler()
2127
2118
}
2128
2119
}
2129
2120
2130
-
2131
-
2132
-
2133
-
2134
-
2135
2121
bool CConnman::BindListenPort (const CService& addrBind, bilingual_str& strError, NetPermissionFlags permissions)
2136
2122
{
2137
2123
int nOne = 1 ;
@@ -2390,7 +2376,7 @@ bool CConnman::Start(CScheduler& scheduler, const Options& connOptions)
2390
2376
else
2391
2377
threadDNSAddressSeed = std::thread (&TraceThread<std::function<void ()> >, " dnsseed" , std::function<void ()>(std::bind (&CConnman::ThreadDNSAddressSeed, this )));
2392
2378
2393
- // Initiate outbound connections from -addnode
2379
+ // Initiate manual connections
2394
2380
threadOpenAddedConnections = std::thread (&TraceThread<std::function<void ()> >, " addcon" , std::function<void ()>(std::bind (&CConnman::ThreadOpenAddedConnections, this )));
2395
2381
2396
2382
if (connOptions.m_use_addrman_outgoing && !connOptions.m_specified_outgoing .empty ()) {
@@ -2752,6 +2738,7 @@ CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn
2752
2738
: nTimeConnected(GetSystemTimeInSeconds()),
2753
2739
addr(addrIn),
2754
2740
addrBind(addrBindIn),
2741
+ m_manual_connection(conn_type_in == ConnectionType::MANUAL),
2755
2742
fInbound(conn_type_in == ConnectionType::INBOUND),
2756
2743
nKeyedNetGroup(nKeyedNetGroupIn),
2757
2744
// Don't relay addr messages to peers that we connect to as block-relay-only
0 commit comments