Skip to content

refactor(endpoint): split EndpointInner god-object into named subsystems #171

Description

@momics

Summary

crates/iroh-http-core/src/endpoint.rs#L29-71 defines EndpointInner as a 17-field god struct holding pool, handles, serve_handle, stats atomics, event subscribers, path subscribers, compression options, etc. ADR-014 D1 named four named subsystems: Transport, HttpRuntime, SessionRuntime, FfiBridge. The split was deferred. Land it now.

Follow-up to the post-rework review at reviews/2026-04-30-post-rework-review.md §5.3.

Evidence

  • EndpointInner has 17 fields covering five distinct concerns.
  • Adding a new concern (a metrics export, a discovery hook) means another field on the same struct.
  • Tests that need only the handle store have to construct or mock the full inner.

Impact

  • High cognitive load — a reader touching one concern must scan 17 fields.
  • Discourages independent unit testing of subsystems.
  • Couples the lifetimes/visibility of unrelated state.

Remediation

  1. Extract Transport (raw iroh Endpoint, node_addr, bound sockets, relay state).
  2. Extract HttpRuntime (pool, max_header_size, max_response_body_bytes, request/connection counters, compression options).
  3. Extract SessionRuntime (session registry, session events).
  4. Extract FfiBridge (handle store, fetch tokens, drain/sweep).
  5. IrohEndpoint becomes a thin façade composing the four; inner becomes Arc<EndpointInner> with one field per subsystem.
  6. Public API of IrohEndpoint unchanged — the split is purely internal.

Acceptance criteria

  • Four subsystem structs in their own modules (transport.rs, http_runtime.rs, session_runtime.rs, ffi_bridge.rs).
  • endpoint.rs is the façade only — no business logic.
  • Each subsystem is independently testable (an #[cfg(test)] new_for_test() helper per subsystem).
  • All 92 interop pairs pass.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Low priorityenhancementNew feature or requestrustPull requests that update rust code

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions