Skip to content

Add transport peer selection modes#7855

Open
tzmWW wants to merge 8 commits into
tari-project:developmentfrom
tzmWW:bounty/7830-transport-peer-selection
Open

Add transport peer selection modes#7855
tzmWW wants to merge 8 commits into
tari-project:developmentfrom
tzmWW:bounty/7830-transport-peer-selection

Conversation

@tzmWW
Copy link
Copy Markdown

@tzmWW tzmWW commented May 25, 2026

Fixes #7830

Summary

  • Add the requested peer transport modes: tor, tcp, tor_tcp, and tcp_tor.
  • Make tcp_tor the default peer transport mode.
  • Apply the configured protocol order to both peer candidate selection and dial address selection.
  • Keep memory and SOCKS transports as internal TransportConfig overrides for existing test/internal transport support.
  • Add unit and cucumber coverage for all four modes, including limited peer queries with multiple addresses per peer.

Validation

  • git diff --check
  • rustfmt --check comms/core/src/peer_manager/storage/database.rs
  • cargo test -p tari_comms --lib --no-default-features --features tari_common_sqlite/bundled
  • cargo test -p tari_p2p --lib --no-default-features --features tari_common_sqlite/bundled
  • cargo test -p tari_integration_tests --test cucumber --no-run --no-default-features --features tari_common_sqlite/bundled

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the p2p transport configuration to support combined transport selection modes (Tor, Tcp, TorTcp, TcpTor) and updates peer selection and dialing logic to prioritize addresses based on these configured transport preferences. The review feedback identifies a critical issue where applying transport protocol preference ordering to random peer selection (get_n_random_peers) biases gossip and discovery, potentially isolating Tor-only nodes. It is recommended to keep random peer selection truly random and avoid sorting or truncating them by transport preference.

Comment thread comms/core/src/peer_manager/storage/database.rs Outdated
Comment thread comms/core/src/peer_manager/storage/database.rs Outdated
Comment thread base_layer/p2p/src/initialization.rs Outdated
.spawn_with_transport(transport)
.await?
},
let comms = if transport_config.is_memory_transport() {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dont use a nested if, its hard to follow, the setup here is also not correct, look at the change diff

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted. I applied that and other bug fixes in the latest commits.

  • TransportConfig::get_supported_protocols() only includes onion for tor_tcp/tcp_tor when tcp.tor_socks_address is configured. I interpreted “both enabled” in the bounty scope as “both actually dialable” not just both named in the enumeration.

@tzmWW tzmWW requested a review from SWvheerden May 26, 2026 22:59
Comment thread base_layer/p2p/src/transport.rs Outdated
Comment on lines +51 to +63
enum TransportOverride {
#[default]
None,
Memory,
Socks5,
}

#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub(crate) enum CommsTransport {
Memory,
Tcp,
TorHiddenService,
Socks5,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why add these?
Why not keep the original transaport type and just use them?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree it was an unnecessary over-abstraction. TransportType is again the main control flow for public modes, and the only remaining extra state is the private TransportOverride, which is there solely to preserve the existing internal new_memory / new_socks5 paths.

@tzmWW tzmWW requested a review from SWvheerden May 27, 2026 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Connection types

2 participants