Skip to content

Max/socks5 autodiscovery#6920

Open
mfahampshire wants to merge 6 commits into
developfrom
max/socks5-to-socks-plus-autodiscovery
Open

Max/socks5 autodiscovery#6920
mfahampshire wants to merge 6 commits into
developfrom
max/socks5-to-socks-plus-autodiscovery

Conversation

@mfahampshire

@mfahampshire mfahampshire commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

The name of this branch is misleading - the socks5 -> socks changes touch a lot of stuff, so I'm going to do that on a different branch. This branch just covers the addition of autodiscovery + country-based selection, + docs

Summary by CodeRabbit

  • New Features
    • Added Rust SOCKS5 mixnet auto-discovery with country-restricted requester selection and a new helper for connecting using a discovered network requester.
    • Added a Rust SOCKS5 autodiscovery example.
  • Documentation
    • Expanded SOCKS5 developer documentation and updated Rust module listings; clarified the “Exit Gateway” model across relevant pages.
    • Refreshed multiple CLI help pages and developer docs formatting.
  • Bug Fixes
    • Updated published API-scraping outputs and token/current-time reference values.

@vercel

vercel Bot commented Jun 29, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
docs-nextra Ready Ready Preview, Comment Jun 29, 2026 5:51pm
nym-explorer-v2 Ready Ready Preview, Comment Jun 29, 2026 5:51pm
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
nym-node-status Ignored Ignored Preview Jun 29, 2026 5:51pm

Request Review

@coderabbitai

coderabbitai Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds country-aware SOCKS5 auto-discovery in nym-sdk, updates SOCKS5 and exit-gateway documentation, and refreshes generated API-scraping and CLI help outputs.

Changes

SOCKS5 Auto-Discovery Feature

Layer / File(s) Summary
Discovery types and selection logic
sdk/rust/nym-sdk/src/error.rs, sdk/rust/nym-sdk/src/mixnet/socks5_discovery.rs
Adds country-selection error variants, requester performance data, metadata retrieval, and weighted requester selection with country filtering.
Builder wiring and exports
sdk/rust/nym-sdk/Cargo.toml, sdk/rust/nym-sdk/src/mixnet.rs, sdk/rust/nym-sdk/src/mixnet/socks5_client.rs, sdk/rust/nym-sdk/examples/socks5_autodiscover.rs
Adds the discovery submodule, mixnet re-export, discovery-based client construction, workspace dependency, and autodiscovery example.
SOCKS5 docs and navigation
documentation/docs/pages/developers/rust/socks5.mdx, documentation/docs/pages/developers/rust/_meta.json, documentation/docs/pages/developers/rust.mdx, documentation/docs/pages/developers/index.mdx, documentation/docs/pages/developers/clients/socks5.mdx, documentation/docs/pages/developers/_meta.json, documentation/docs/pages/developers/concepts/exit-security.mdx, documentation/docs/pages/network/infrastructure/exit-services.mdx
Adds the SOCKS5 module page, wires it into navigation, updates related developer references, and rewrites exit-security guidance for exit-gateway usage.
Scraped outputs and CLI help
documentation/docs/components/outputs/api-scraping-outputs/*, documentation/docs/components/outputs/command-outputs/*
Updates tokenomics and node-count snapshots, refreshes the current-time doc, and reflows several CLI help pages.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • nymtech/nym#6827: Also updates generated documentation outputs including nodes-count.json and time-now.md.
  • nymtech/nym#6890: Overlaps on the same generated documentation/help output area, including nodes-count.json and multiple CLI help pages.

Suggested labels

documentation

Suggested reviewers

  • simonwicky
  • jstuczyn

Poem

A bunny built a SOCKS5 trail,
Through mixnet hops and country pail 🐇
Docs now point the way so clear,
And outputs twinkle bright and near.
Hop-hop—new routes are in the air!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and points to the main change: SOCKS5 autodiscovery.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch max/socks5-to-socks-plus-autodiscovery

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 2

🧹 Nitpick comments (1)
sdk/rust/nym-sdk/src/mixnet/socks5_discovery.rs (1)

74-79: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

get_best_network_requester* is a weighted random pick, not “best”.

These helpers can legitimately return a lower-performance requester because choose_weighted is probabilistic. Please rename them before this lands in the public API, or make the summary/docs lead with “weighted random selection” instead of “best”.

Also applies to: 81-88, 127-129

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@sdk/rust/nym-sdk/src/mixnet/socks5_discovery.rs` around lines 74 - 79, The
public helpers named get_best_network_requester, get_best_network_requester_in,
and get_best_network_requester_from are described as selecting the “best”
requester, but their behavior uses choose_weighted and is only a weighted random
selection. Update the API to either rename these functions and their related
docs/comments to reflect weighted random selection, or revise the
summaries/docstrings to avoid claiming “best” and instead clearly describe the
probabilistic selection behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@documentation/docs/pages/developers/concepts/exit-security.mdx`:
- Around line 65-66: The guidance in the Exit Security callout should not
recommend `preferredIpr` to SOCKS5 users, since that knob is IPR-specific and
not available for Network Requester flows. Update the wording in the
exit-security callout so it applies only to IPR-backed clients, or add the
SOCKS5 equivalent using `Socks5MixnetClient::connect_new(...)` and the
`discover().country(...)` / `.countries(...)` filters. Keep the recommendation
aligned with the client type mentioned in the surrounding docs.

In `@sdk/rust/nym-sdk/src/mixnet/socks5_discovery.rs`:
- Around line 54-68: The requester discovery logic in `socks5_discovery.rs` is
silently skipping invalid entries, which hides metadata issues and makes pool
shrinkage hard to diagnose. Update the `NetworkRequesterWithPerformance`
collection flow in this loop to emit warnings when `all_nodes.get(...)` misses a
described node and when `nr_info.address.parse()` fails, including the exit
identity and offending address in the log. Keep the existing filtering behavior,
but ensure malformed or missing requester records are observable instead of
being dropped without context.

---

Nitpick comments:
In `@sdk/rust/nym-sdk/src/mixnet/socks5_discovery.rs`:
- Around line 74-79: The public helpers named get_best_network_requester,
get_best_network_requester_in, and get_best_network_requester_from are described
as selecting the “best” requester, but their behavior uses choose_weighted and
is only a weighted random selection. Update the API to either rename these
functions and their related docs/comments to reflect weighted random selection,
or revise the summaries/docstrings to avoid claiming “best” and instead clearly
describe the probabilistic selection behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2e1036cf-b1f1-46cf-8133-5943768464be

📥 Commits

Reviewing files that changed from the base of the PR and between ae8af31 and 30fb410.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (27)
  • documentation/docs/components/outputs/api-scraping-outputs/circulating-supply.json
  • documentation/docs/components/outputs/api-scraping-outputs/nodes-count.json
  • documentation/docs/components/outputs/api-scraping-outputs/nyx-outputs/circulating-supply.md
  • documentation/docs/components/outputs/api-scraping-outputs/nyx-outputs/epoch-reward-budget.md
  • documentation/docs/components/outputs/api-scraping-outputs/nyx-outputs/stake-saturation.md
  • documentation/docs/components/outputs/api-scraping-outputs/nyx-outputs/staking-target.md
  • documentation/docs/components/outputs/api-scraping-outputs/nyx-outputs/staking_supply.md
  • documentation/docs/components/outputs/api-scraping-outputs/nyx-outputs/token-table.md
  • documentation/docs/components/outputs/api-scraping-outputs/reward-params.json
  • documentation/docs/components/outputs/api-scraping-outputs/time-now.md
  • documentation/docs/components/outputs/command-outputs/nym-api-help.md
  • documentation/docs/components/outputs/command-outputs/nym-node-help.md
  • documentation/docs/components/outputs/command-outputs/nym-node-run-help.md
  • documentation/docs/components/outputs/command-outputs/nymvisor-help.md
  • documentation/docs/pages/developers/_meta.json
  • documentation/docs/pages/developers/clients/socks5.mdx
  • documentation/docs/pages/developers/concepts/exit-security.mdx
  • documentation/docs/pages/developers/index.mdx
  • documentation/docs/pages/developers/rust.mdx
  • documentation/docs/pages/developers/rust/_meta.json
  • documentation/docs/pages/developers/rust/socks5.mdx
  • sdk/rust/nym-sdk/Cargo.toml
  • sdk/rust/nym-sdk/examples/socks5_autodiscover.rs
  • sdk/rust/nym-sdk/src/error.rs
  • sdk/rust/nym-sdk/src/mixnet.rs
  • sdk/rust/nym-sdk/src/mixnet/socks5_client.rs
  • sdk/rust/nym-sdk/src/mixnet/socks5_discovery.rs

Comment thread documentation/docs/pages/developers/concepts/exit-security.mdx Outdated
Comment thread sdk/rust/nym-sdk/src/mixnet/socks5_discovery.rs

@serinko serinko left a comment

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.

I have a same comment over a few places, I leave it up to you how to handle that, just let me know to sync up with the Operators Guide

Comment thread documentation/docs/pages/developers/concepts/exit-security.mdx Outdated
Comment thread documentation/docs/pages/developers/concepts/exit-security.mdx Outdated
Comment thread documentation/docs/pages/developers/concepts/exit-security.mdx Outdated
use nym_task::ShutdownTracker;
use tokio::sync::RwLockReadGuard;

use celes::Country;

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.

nittest nit : How about grouping the imports? One group nym stuff, on crate stuff and one with the rest. We're so close

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@sdk/rust/nym-sdk/src/mixnet/socks5_discovery.rs`:
- Around line 93-98: The resolve logic in Recipient/NetworkRequester currently
treats InCountries with an empty list the same as Any, which lets callers bypass
the country restriction. Update resolve() so the InCountries branch enforces the
non-empty invariant directly, either by rejecting empty vectors with an error or
by delegating to the same validation used by in_countries(), while keeping Exact
and Any behavior unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2cc8c203-89cb-41b2-bc6e-55502430d64e

📥 Commits

Reviewing files that changed from the base of the PR and between d78b28d and bea3242.

📒 Files selected for processing (6)
  • documentation/docs/pages/developers/rust/socks5.mdx
  • sdk/rust/nym-sdk/examples/socks5_autodiscover.rs
  • sdk/rust/nym-sdk/src/error.rs
  • sdk/rust/nym-sdk/src/mixnet.rs
  • sdk/rust/nym-sdk/src/mixnet/socks5_client.rs
  • sdk/rust/nym-sdk/src/mixnet/socks5_discovery.rs
✅ Files skipped from review due to trivial changes (1)
  • documentation/docs/pages/developers/rust/socks5.mdx
🚧 Files skipped from review as they are similar to previous changes (2)
  • sdk/rust/nym-sdk/examples/socks5_autodiscover.rs
  • sdk/rust/nym-sdk/src/error.rs

Comment on lines +93 to +98
pub async fn resolve(&self) -> Result<Recipient, Error> {
match self {
Self::Exact(addr) => Ok((**addr).clone()),
Self::Any => discover(&[]).await,
Self::InCountries(countries) => discover(countries).await,
}

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.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Enforce the non-empty country invariant in resolve() too.

Lines 96-97 currently turn NetworkRequester::InCountries(vec![]) into an any-country discovery. Because the enum variants are public, callers can bypass in_countries() and silently lose the country restriction this PR is supposed to guarantee.

Proposed fix
 pub async fn resolve(&self) -> Result<Recipient, Error> {
     match self {
         Self::Exact(addr) => Ok((**addr).clone()),
         Self::Any => discover(&[]).await,
+        Self::InCountries(countries) if countries.is_empty() => {
+            Err(Error::NoCountriesSpecified)
+        }
         Self::InCountries(countries) => discover(countries).await,
     }
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
pub async fn resolve(&self) -> Result<Recipient, Error> {
match self {
Self::Exact(addr) => Ok((**addr).clone()),
Self::Any => discover(&[]).await,
Self::InCountries(countries) => discover(countries).await,
}
pub async fn resolve(&self) -> Result<Recipient, Error> {
match self {
Self::Exact(addr) => Ok((**addr).clone()),
Self::Any => discover(&[]).await,
Self::InCountries(countries) if countries.is_empty() => {
Err(Error::NoCountriesSpecified)
}
Self::InCountries(countries) => discover(countries).await,
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@sdk/rust/nym-sdk/src/mixnet/socks5_discovery.rs` around lines 93 - 98, The
resolve logic in Recipient/NetworkRequester currently treats InCountries with an
empty list the same as Any, which lets callers bypass the country restriction.
Update resolve() so the InCountries branch enforces the non-empty invariant
directly, either by rejecting empty vectors with an error or by delegating to
the same validation used by in_countries(), while keeping Exact and Any behavior
unchanged.

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.

3 participants