@@ -1856,28 +1856,32 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
1856
1856
}
1857
1857
}
1858
1858
1859
- // Feeler Connections
1860
- //
1861
- // Design goals:
1862
- // * Increase the number of connectable addresses in the tried table.
1863
- //
1864
- // Method:
1865
- // * Choose a random address from new and attempt to connect to it if we can connect
1866
- // successfully it is added to tried.
1867
- // * Start attempting feeler connections only after node finishes making outbound
1868
- // connections.
1869
- // * Only make a feeler connection once every few minutes.
1870
- //
1859
+ ConnectionType conn_type = ConnectionType::OUTBOUND_FULL_RELAY;
1860
+ int64_t nTime = GetTimeMicros ();
1871
1861
bool fFeeler = false ;
1872
1862
1873
- if (nOutboundFullRelay >= m_max_outbound_full_relay && nOutboundBlockRelay >= m_max_outbound_block_relay && !GetTryNewOutboundPeer ()) {
1874
- int64_t nTime = GetTimeMicros (); // The current time right now (in microseconds).
1875
- if (nTime > nNextFeeler) {
1876
- nNextFeeler = PoissonNextSend (nTime, FEELER_INTERVAL);
1877
- fFeeler = true ;
1878
- } else {
1879
- continue ;
1880
- }
1863
+ // Determine what type of connection to open. Opening
1864
+ // OUTBOUND_FULL_RELAY connections gets the highest priority until we
1865
+ // meet our full-relay capacity. Then we open BLOCK_RELAY connection
1866
+ // until we hit our block-relay-only peer limit.
1867
+ // GetTryNewOutboundPeer() gets set when a stale tip is detected, so we
1868
+ // try opening an additional OUTBOUND_FULL_RELAY connection. If none of
1869
+ // these conditions are met, check the nNextFeeler timer to decide if
1870
+ // we should open a FEELER.
1871
+
1872
+ if (nOutboundFullRelay < m_max_outbound_full_relay) {
1873
+ // OUTBOUND_FULL_RELAY
1874
+ } else if (nOutboundBlockRelay < m_max_outbound_block_relay) {
1875
+ conn_type = ConnectionType::BLOCK_RELAY;
1876
+ } else if (GetTryNewOutboundPeer ()) {
1877
+ // OUTBOUND_FULL_RELAY
1878
+ } else if (nTime > nNextFeeler) {
1879
+ nNextFeeler = PoissonNextSend (nTime, FEELER_INTERVAL);
1880
+ conn_type = ConnectionType::FEELER;
1881
+ fFeeler = true ;
1882
+ } else {
1883
+ // skip to next iteration of while loop
1884
+ continue ;
1881
1885
}
1882
1886
1883
1887
addrman.ResolveCollisions ();
@@ -1944,23 +1948,6 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
1944
1948
LogPrint (BCLog::NET, " Making feeler connection to %s\n " , addrConnect.ToString ());
1945
1949
}
1946
1950
1947
- ConnectionType conn_type;
1948
- // Determine what type of connection to open. If fFeeler is not
1949
- // set, open OUTBOUND connections until we meet our full-relay
1950
- // capacity. Then open BLOCK_RELAY connections until we hit our
1951
- // block-relay peer limit. Otherwise, default to opening an
1952
- // OUTBOUND connection.
1953
- if (fFeeler ) {
1954
- conn_type = ConnectionType::FEELER;
1955
- } else if (nOutboundFullRelay < m_max_outbound_full_relay) {
1956
- conn_type = ConnectionType::OUTBOUND_FULL_RELAY;
1957
- } else if (nOutboundBlockRelay < m_max_outbound_block_relay) {
1958
- conn_type = ConnectionType::BLOCK_RELAY;
1959
- } else {
1960
- // GetTryNewOutboundPeer() is true
1961
- conn_type = ConnectionType::OUTBOUND_FULL_RELAY;
1962
- }
1963
-
1964
1951
OpenNetworkConnection (addrConnect, (int )setConnected.size () >= std::min (nMaxConnections - 1 , 2 ), &grant, nullptr , conn_type);
1965
1952
}
1966
1953
}
0 commit comments