Skip to content

Commit 053b2d3

Browse files
committed
Merge bitcoin/bitcoin#27264: p2p: Improve diversification of new connections
72e8ffd p2p: Account for MANUAL conns when diversifying persistent outbound conns (Gleb Naumenko) 3faae99 p2p: Diversify connections only w.r.t *persistent* outbound peers (Gleb Naumenko) Pull request description: Revives #19860. In order to make sure that our persistent outbound slots belong to different netgroups, distinct net groups of our peers are added to [`setConnected`](https://github.com/bitcoin/bitcoin/blob/8c4958bd4c06026dc108bc7f5f063d1f389d279b/src/net.cpp#L1716). We’d only open a persistent outbound connection to peers which have a different netgroup compared to those netgroups present in `setConnected`. **behaviour on master** we open persistent outbound connections to peers which have different netgroups compared to outbound full relay, block relay, addrfetch and feeler connection peers. **behaviour on PR** netgroup diversity is based on outbound full relay, block relay and manual connection peers. **rationale** - addrfetch and feeler connections are short lived connections and shouldn’t affect how we select outbound peers from addrman. - manual connections are like regular connections when viewed from addrman’s netgroup diversity point of view and should affect how we select outbound peers from addrman ACKs for top commit: amitiuttarwar: code review ACK 72e8ffd vasild: ACK 72e8ffd mzumsande: Code Review ACK 72e8ffd brunoerg: crACK 72e8ffd Tree-SHA512: 359451945a707b312ef6c2696a3a9d4256ab14dab9bd461cca4a52dae034db099012df6de3faef2f3fb38184b05996402ac280b681959483824419b6deb4db1a
2 parents 50171df + 72e8ffd commit 053b2d3

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/net.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1721,19 +1721,20 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
17211721
if (pnode->IsFullOutboundConn()) nOutboundFullRelay++;
17221722
if (pnode->IsBlockOnlyConn()) nOutboundBlockRelay++;
17231723

1724-
// Netgroups for inbound and manual peers are not excluded because our goal here
1725-
// is to not use multiple of our limited outbound slots on a single netgroup
1726-
// but inbound and manual peers do not use our outbound slots. Inbound peers
1727-
// also have the added issue that they could be attacker controlled and used
1728-
// to prevent us from connecting to particular hosts if we used them here.
1724+
// Make sure our persistent outbound slots belong to different netgroups.
17291725
switch (pnode->m_conn_type) {
1726+
// We currently don't take inbound connections into account. Since they are
1727+
// free to make, an attacker could make them to prevent us from connecting to
1728+
// certain peers.
17301729
case ConnectionType::INBOUND:
1731-
case ConnectionType::MANUAL:
1730+
// Short-lived outbound connections should not affect how we select outbound
1731+
// peers from addrman.
1732+
case ConnectionType::ADDR_FETCH:
1733+
case ConnectionType::FEELER:
17321734
break;
1735+
case ConnectionType::MANUAL:
17331736
case ConnectionType::OUTBOUND_FULL_RELAY:
17341737
case ConnectionType::BLOCK_RELAY:
1735-
case ConnectionType::ADDR_FETCH:
1736-
case ConnectionType::FEELER:
17371738
setConnected.insert(m_netgroupman.GetGroup(pnode->addr));
17381739
} // no default case, so the compiler can warn about missing cases
17391740
}

0 commit comments

Comments
 (0)