Skip to content

[codex] Add transport peer selection modes#7854

Open
prettyboyvic wants to merge 1 commit into
tari-project:developmentfrom
prettyboyvic:codex/tari-7830-transport-selection
Open

[codex] Add transport peer selection modes#7854
prettyboyvic wants to merge 1 commit into
tari-project:developmentfrom
prettyboyvic:codex/tari-7830-transport-selection

Conversation

@prettyboyvic
Copy link
Copy Markdown

Fixes #7830.

Summary

  • Replace the public peer TransportType modes with Tor, Tcp, TorTcp, and TcpTor, with TcpTor as the default.
  • Apply the mode protocol order when selecting dial addresses so Tor-only filters to onion, TCP-only filters to IP, and mixed modes preserve the requested preference.
  • Wire Tor-backed modes through hidden-service transport protocol ordering and keep legacy memory/SOCKS transports as internal TransportConfig overrides for existing tests/config compatibility.
  • Add unit coverage for transport mode protocol order and dial address ordering, plus a cucumber scenario outline for all four peer selection modes.

Validation

  • cargo test -p tari_p2p transport_type --no-default-features --features tari_common_sqlite/bundled
  • cargo test -p tari_comms dial_address_selection_filters_and_orders_transport_modes --no-default-features --features tari_common_sqlite/bundled
  • cargo check -p minotari_app_utilities --no-default-features
  • cargo check -p tari_libtor --no-default-features

Notes

  • cargo check -p minotari_node --no-default-features and cucumber compile-only were attempted locally but stopped before checking this patch because randomx-rs requires cmake, which is not installed in this Windows environment.

@github-actions
Copy link
Copy Markdown

⚠️ This PR contains unsigned commits. To get your PR merged, please sign those commits (git rebase --exec 'git commit -S --amend --no-edit -n' @{upstream}) and force push them to this branch (git push --force-with-lease).

If you're new to commit signing, there are different ways to set it up:

Sign commits with gpg

Follow the steps below to set up commit signing with gpg:

  1. Generate a GPG key
  2. Add the GPG key to your GitHub account
  3. Configure git to use your GPG key for commit signing
Sign commits with ssh-agent

Follow the steps below to set up commit signing with ssh-agent:

  1. Generate an SSH key and add it to ssh-agent
  2. Add the SSH key to your GitHub account
  3. Configure git to use your SSH key for commit signing
Sign commits with 1Password

You can also sign commits using 1Password, which lets you sign commits with biometrics without the signing key leaving the local 1Password process.

Learn how to use 1Password to sign your commits.

Watch the demo

@prettyboyvic prettyboyvic force-pushed the codex/tari-7830-transport-selection branch from 1870845 to 5297ef2 Compare May 25, 2026 17:02
@prettyboyvic prettyboyvic reopened this May 25, 2026
@prettyboyvic prettyboyvic marked this pull request as ready for review May 25, 2026 17:03
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 transport and peer selection configuration to support more flexible peer transport modes (such as preferring Tor or TCP/IP). It introduces new transport types (TorTcp and TcpTor), updates the address filtering logic, and deprecates the old tor_socks_address setting for TCP transport. The review feedback suggests fully removing the deprecated tor_socks_address handling from the TCP comms stack initialization since it is now dead code.

Comment on lines +238 to +239
let config = transport_config.tcp;
debug!(target: LOG_TARGET, "Building TCP comms stack");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Since tor_socks_address is deprecated and ignored for TransportType::Tcp, we should avoid implementing warning logic or other handling for it. Instead, consider removing the deprecated field and its associated code entirely, as it is now dead code.

Suggested change
let config = transport_config.tcp;
debug!(target: LOG_TARGET, "Building TCP comms stack");
debug!(target: LOG_TARGET, "Building TCP comms stack");
References
  1. Instead of implementing logic for a feature that relies on an unpopulated field, consider removing the feature and its associated code as it may be dead code.

Implements the four public TransportType peer-selection modes required by tari-project#7830:

- tor: onion only
- tcp: TCP only
- tor_tcp: onion preferred, TCP fallback
- tcp_tor: TCP preferred, onion fallback, and the default

Adds unit coverage for protocol ordering/address filtering and cucumber coverage for the four mode expectations.

Fixes tari-project#7830
@prettyboyvic prettyboyvic force-pushed the codex/tari-7830-transport-selection branch from dc6bede to e076b65 Compare May 25, 2026 17:05
@prettyboyvic prettyboyvic mentioned this pull request May 25, 2026
6 tasks
.await;

let comms = if p2p_config.transport.transport_type == TransportType::Tor {
let comms = if p2p_config.transport.uses_tor_hidden_service() {
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.

need to handle the cases above here as well

.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.

this nested if is very hard to follow

.spawn_with_transport(transport)
.await?
} else {
match transport_config.transport_type {
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.

you are not properly setting up tcp or tor here, look at the change diff

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