Allow custom RelayMode via XS_RELAY_URL env var#139
Open
joeblew999 wants to merge 1 commit into
Open
Conversation
xs currently hardcodes `iroh::RelayMode::Default` in three places (the iroh listener bind, the listener's outbound dial, and the client connect path). RelayMode::Default routes through n0's public relay infrastructure (use1, euw1, apse-1). This is the right default, but operators have legitimate reasons to override: - **Regions where n0's defaults aren't reachable.** The Asia-Pacific regional relay (apse-1.relay.iroh.network) currently has no public DNS A record, so iroh nodes in that region hang indefinitely on `home_relay().initialized().await`. A laptop in Thailand cannot bind an iroh:// endpoint at all. The workaround is to self-host an iroh-relay (e.g. on Hetzner Singapore) and point xs at it — but that is impossible today without source-patching xs. - **Compliance / air-gapped networks** that don't allow outbound to relay.iroh.network. - **Local development** against a self-hosted dev relay. This commit introduces a small `relay` module that resolves the iroh `RelayMode` from an `XS_RELAY_URL` environment variable: - empty / unset → RelayMode::Default (preserved default; strict superset) - "disabled" (any case) → RelayMode::Disabled - any other value → parsed as RelayUrl → RelayMode::Custom(map) - parse failure → falls back to RelayMode::Default + warn log The three call sites in listener.rs and client/connect.rs now call `relay_mode_from_env()` instead of using the hardcoded constant. No behavior change for anyone who doesn't set the env var. Includes unit tests for all five paths (unset, empty, whitespace, disabled keyword, valid URL, malformed URL fallback). Verified end-to-end against a self-hosted iroh-relay v1.0.0-rc.0 on Hetzner Singapore from a Thai laptop — bind completes in ~3s where previously it hung forever.
2561b57 to
d45fca9
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
xscurrently hardcodesiroh::RelayMode::Defaultin three places (listener.rs:303,listener.rs:374,client/connect.rs:74).RelayMode::Defaultroutes via n0's public relay infrastructure (use1,euw1,apse-1).That's the right default, but operators have legitimate reasons to override:
apse-1.relay.iroh.networkhas no public DNS A record. Iroh nodes in Asia hang indefinitely onhome_relay().initialized().await— a laptop in Thailand cannot bind aniroh://endpoint at all. Self-hosting aniroh-relay(e.g. on a Hetzner Singapore VM) is the workaround, but today it requires source-patchingxs.relay.iroh.networkisn't permitted.What
Introduces
src/relay.rsexportingrelay_mode_from_env() -> RelayMode:XS_RELAY_URLvalueRelayMode::Default(preserves existing behavior — strict superset)"disabled"(case-insensitive)RelayMode::Disablediroh_base::RelayUrl→RelayMode::Custom(RelayMap)RelayMode::Defaultwith atracing::warn!The three iroh endpoint builders in
listener.rsandclient/connect.rsnow call this helper instead of using the hardcoded constant.Backward compatibility
Strict superset. Users who don't set
XS_RELAY_URLget exactly the prior behavior.Tests
6 unit tests in
src/relay::testscover: unset, empty, whitespace,"DISABLED"keyword, valid URL →Custom, malformed URL →Defaultfallback.All existing tests pass (
cargo test --lib).Verification
Built locally and run from a Thai laptop against a self-hosted
iroh-relay 1.0.0-rc.0on Hetzner Singapore (5.223.94.174 in--devmode):Without the patch, the bind hangs forever in that environment.
Naming alternative
Happy to rename the env var (e.g.
XS_RELAYorCROSSTREAM_RELAY_URL) if there's a project convention I should follow.