Skip to content

feat(relay): embed the relay-tunnel receiver behind a tunnel feature (WIP) - #94

Draft
slinkydeveloper wants to merge 1 commit into
mainfrom
relay
Draft

slinkydeveloper wants to merge 1 commit into
mainfrom
relay

Conversation

@slinkydeveloper

Copy link
Copy Markdown
Collaborator

WIP / draft. Landing the Rust side of the embedded relay-tunnel receiver. Sibling PR on sdk-java (branch tunnel-client) consumes this branch as a git dependency.

What

Bring the SDK-side relay stack into shared-core so SDKs can act as relay receivers without reimplementing the protocol, and without the relay runtime owning the SDK's threads. Everything lives under src/relay/ behind #[cfg(feature = "tunnel")] (off by default), so the crate stays strictly sans-IO and WASM-compilable when the feature is off.

  • protocol/ — fork of relay-protocol (env/tunnel, path grammar, /whoami, h2 tuning). Sans-IO.
  • bridge.rs — fork of relay-bridge (the bidirectional h2 bridge; failpoints hooks stripped).
  • receiver/ — fork of relay-receiver (dial-out, role-flip, /whoami, redial, multi-homing R4 + instance-id affinity R5, InvokeHandler).
  • loopback.rs — new engine: owns a tokio runtime, runs the receiver with a LoopbackHandler that h2c-dials 127.0.0.1:<local_port> and bridges each forwarded stream, replaying the tail-only :path (preserves request-identity) + headers verbatim. Public API relay::{Config, Engine, Handle, Status} (Config is serde-JSON).

The tunnel feature pulls in optional tokio/h2/http/tokio-rustls/rustls-pki-types/async-trait/serde_json. http is now an explicit feature (a dep:http reference elsewhere would otherwise suppress its implicit feature and break #[cfg(feature = "http")] + external features=["http"]).

No cross-repo coupling

The three crates are copied in (forked), not shared with restatedev/relay — that repo keeps its own copies untouched. Independence over DRY, on purpose. See docs/relay-receiver-in-shared-core.md.

Verification

  • Default cargo tree has no tokio — the sans-IO / WASM invariant holds.
  • Default tests green; --features tunnel green + tests/relay_loopback.rs round-trips a forwarded request end-to-end (relay → engine → loopback → local h2c server → back, query preserved).
  • clippy -D warnings, rustfmt, rustdoc all clean on both feature sets.

Not in this PR

Live run against a real relay; TS/napi binding. v1 scope: /whoami mode, loopback TCP, no drain.

🤖 Generated with Claude Code

Bring the SDK-side relay stack into shared-core so SDKs can act as relay
receivers without reimplementing the protocol, and without the relay runtime
owning the SDK's threads. Everything lives under `src/relay/` gated by
`#[cfg(feature = "tunnel")]` (off by default), so the crate stays strictly
sans-IO and WASM-compilable when the feature is off.

Contents (a fork of the relay repo's crates + a new engine):
  * protocol/  — was relay-protocol: env/tunnel, path grammar, /whoami, h2
                 tuning. Sans-IO. Internal `crate::` refs rewritten to `super::`.
  * bridge.rs  — was relay-bridge: the bidirectional h2 bridge (failpoints
                 hooks stripped; shared-core has no `failpoints` feature).
  * receiver/  — was relay-receiver: dial-out, role-flip, /whoami, redial,
                 multi-homing (R4) + instance-id affinity (R5), InvokeHandler.
  * loopback.rs — new: the engine. Owns a tokio runtime, runs the receiver with
                 a LoopbackHandler that h2c-dials 127.0.0.1:<local_port> and
                 bridges each forwarded stream, replaying the tail-only `:path`
                 (preserves request-identity) + headers verbatim. JSON `Config`
                 (serde), `Engine::start` -> `Handle` (status/stop), `Status`.

The `tunnel` feature pulls in optional tokio/h2/http/tokio-rustls/
rustls-pki-types/async-trait/serde_json. `http` is now an explicit feature
(`dep:http` elsewhere would otherwise suppress its implicit feature and break
`#[cfg(feature = "http")]` in headers.rs + any external `features=["http"]`).

Verified: default `cargo tree` has no tokio (sans-IO preserved); default tests
green; `--features tunnel` builds, `tests/relay_loopback.rs` round-trips a
forwarded request end-to-end; clippy `-D warnings`, rustfmt, and rustdoc all
clean on both feature sets.

No cross-repo coupling: the relay repo keeps its own copies untouched (forked
at move time). Design + rationale in docs/relay-receiver-in-shared-core.md.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

1 participant