- Add 7 registry tests (handler_registry_*) to registry.rs - Add 4 dispatch tests (build_auth_context_*, dispatch_decision_logic_*) to dispatch.rs - Add 6 endpoint tests to endpoint.rs: - debug_for_alknet_endpoint_is_implemented_without_panicking - endpoint_constructs_with_iroh_raw_key_identity (adapted for new API) - iroh_endpoint_runs_accept_loop_and_shutdown (adapted for new API) - with_iroh_sets_field (replaces has_iroh_identity_true_for_raw_key) - without_iroh_field_is_none (replaces has_iroh_identity_false_for_x509) - endpoint_works_without_iroh (replaces has_iroh_identity_false_when_no_identity) - Add async-trait as dev-dependency - All 17 tests pass with iroh feature - All 8 tests pass without features - Workspace tests all pass (no breakage) - Mark tasks 1-7 as completed
3.7 KiB
id, name, status, depends_on, scope, risk, impact, level
| id | name | status | depends_on | scope | risk | impact | level | |
|---|---|---|---|---|---|---|---|---|
| endpoint/registry | Extract HandlerRegistry from alknet-core/endpoint.rs into alknet-endpoint | completed |
|
narrow | low | component | implementation |
Description
Phase 2, Task 2 of the crate extraction. Extract the HandlerRegistry type from
crates/alknet-core/src/endpoint.rs (lines 66-116) into crates/alknet-endpoint/src/registry.rs.
The old code stays in endpoint.rs (duplicated) — no breakage. The new crate is
self-contained and builds standalone.
Types to extract
From endpoint.rs lines 66-116:
| Type/Function | Lines | Destination |
|---|---|---|
HandlerRegistry struct |
66-68 | registry.rs |
HandlerRegistry::new() |
71-75 | registry.rs |
HandlerRegistry::register() |
77-86 | registry.rs |
HandlerRegistry::get() |
88-90 | registry.rs |
HandlerRegistry::alpn_strings() |
92-94 | registry.rs |
impl Default for HandlerRegistry |
97-101 | registry.rs |
impl Debug for HandlerRegistry |
103-116 | registry.rs |
Adaptations
- Imports: Update
crate::types::ProtocolHandlertoalknet_core::types::ProtocolHandler. - No other changes: The
HandlerRegistryis a pure data structure with no transport deps. It maps ALPN byte strings toProtocolHandlerinstances. No feature gates needed — it's always available regardless of which transports are enabled.
Public API
// registry.rs
/// Maps ALPN byte strings to `ProtocolHandler` instances.
/// Registered statically at startup by the assembly layer; the endpoint
/// dispatches by looking up the negotiated ALPN.
pub struct HandlerRegistry {
handlers: HashMap<&'static [u8], Arc<dyn ProtocolHandler>>,
}
impl HandlerRegistry {
pub fn new() -> Self;
/// Insert a handler. Panics if the ALPN is already registered.
pub fn register(&mut self, handler: Arc<dyn ProtocolHandler>);
/// Look up a handler by ALPN string.
pub fn get(&self, alpn: &[u8]) -> Option<&Arc<dyn ProtocolHandler>>;
/// Return all registered ALPN strings.
pub fn alpn_strings(&self) -> Vec<Vec<u8>>;
}
What stays in core
The old HandlerRegistry in endpoint.rs lines 66-116 is not deleted — it stays as a
duplicate. The prune happens in Phase 4. This task only adds code to alknet-endpoint.
Acceptance Criteria
crates/alknet-endpoint/src/registry.rscontainsHandlerRegistrywith all methodsHandlerRegistry::new()creates an empty registryHandlerRegistry::register()inserts a handler, panics on duplicate ALPNHandlerRegistry::get()looks up by ALPN, returnsNonefor unknownHandlerRegistry::alpn_strings()returns all registered ALPNsDefaultimpl delegates tonew()Debugimpl lists ALPNs without exposing handler internals- All imports use
alknet_core::(notcrate::) - No feature gates (always available)
cargo check -p alknet-endpointsucceedscargo clippy -p alknet-endpointsucceeds with no warningscargo test -p alknet-corestill passes (old code untouched)
References
- docs/research/alknet-crate-extraction/findings.md — Phase 2, registry module
- docs/architecture/crates/endpoint/README.md — HandlerRegistry spec
- crates/alknet-core/src/endpoint.rs — lines 66-116 (source code to extract)
Notes
This is the simplest extraction in Phase 2 — ~50 lines of pure data structure.
HandlerRegistryhas no transport deps and no feature gates. It's extracted first becauseAlknetEndpoint::new()takes it as a parameter. The old code inendpoint.rsis NOT deleted — that's Phase 4.
Summary
To be filled on completion