Enforce the relay scheme policy in the Rust relay pool, not only in the add-relay dialog

Open
#834 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
dart, rust

Research direction

Start in rust/src/api/nostr.rs, where initialize_in, add_relay and apply_relay_list_event reach RelayPool::sync_discovered, and read _validateRelayUrl in lib/features/settings/screens/relays_screen.dart to see the current Dart-only check. The issue asks for one scheme policy in the Rust pool, applied at all three entry points, with persisted ws:// rows deactivated rather than deleted. Done means a release-mode cargo test case shows a ws:// relay is neither connected nor added, while debug and Mortsom behaviour is unchanged.

Written by the indexing model from the issue text.

Description

area: relays area: rust-core enhancement

Problem

The wss:// requirement for relays is enforced only by the add-relay dialog in Dart (_validateRelayUrl in lib/features/settings/screens/relays_screen.dart). The Rust relay pool never checks the scheme:

  • initialize_in (rust/src/api/nostr.rs) reconnects every persisted active URL.
  • add_relay persists whatever URL it is given.
  • apply_relay_list_event → RelayPool::sync_discovered auto-adds whatever a Mostro node announces in its kind 10002 list.

So a release build connects over plaintext ws:// to any relay a node announces, and keeps any ws:// row already in its database. #833 makes the dialog accept ws:// in debug builds, which adds one more way for such a row to exist (a release build reusing a debug build's data directory on the same machine), but the gap predates it. Raised by Codex on #833: https://github.com/MostroP2P/app/pull/833#discussion_r4295512614

Per AGENTS.md, Rust owns relays, so the policy belongs in the pool, not in a dialog.

Proposal

  1. Define the scheme policy once in the Rust core: which schemes a build accepts. Release and profile builds accept wss:// only; debug builds (cfg(debug_assertions)) and the Mortsom test environment accept ws:// as well.
  2. Pass the test-environment allowance down from Dart at initialize (the Mortsom entry point is the only one that can grant it), so a Mortsom release build keeps its ws:// relays from MORTSOM_RELAYS.
  3. Apply the policy at every entry point: initialize_in (persisted rows and seeds), add_relay, and sync_discovered (announced relays). A rejected announced relay is logged, not blacklisted, so a node that later announces it over wss:// is still picked up.
  4. Rows that no longer qualify on load: deactivate them rather than delete them, and log it, so a developer switching back to a debug build gets them back.
  5. The dialog keeps its early check for the error message, but the Rust result is what decides.

Acceptance

  • A release build with a persisted ws:// row does not connect to it and marks the row inactive.
  • A release build whose node announces a ws:// relay in its kind 10002 does not add it.
  • A debug build and a Mortsom build behave as today.
  • Tests at the pool level for the three entry points, and a cfg(debug_assertions)-independent seam so the release case is testable under cargo test.
Dominant language
Dart
Stars
11
Forks
9
Avg merge
2d 1h
Merged PRs (30d)
16

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from MostroP2P/app

All issues in MostroP2P/app

Similar issues

More Dart issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.