refactor(core,http,tty,call): unify stream leaf — BiStream as the handler leaf (Phase 6)
Implement ADR-092 across the workspace: accept_bi/open_bi return BiStream (a concrete AsyncRead + AsyncWrite + Send + Unpin newtype), not the split (SendStream, RecvStream) pair. The join moves into core's BidiStreamSource impls (quinn/iroh via tokio::io::join, single-stream via boxed AsyncReadWrite); handlers receive the joined BiStream and never see the pair. Core (alknet-core/src/types.rs): - Add concrete BiStream struct boxing Box<dyn AsyncReadWrite + Unpin>, with AsyncRead + AsyncWrite impls. from_joined (pub, for downstream crates that produce split halves naturally — channels reassembly, tests) and from_bidi (pub(crate), for Connection::from_bidi) constructors. - Change BidiStreamSource::accept_bi/open_bi return types from (SendStream, RecvStream) to BiStream. Update QuinnBidiStreamSource, IrohBidiStreamSource, StreamBidiStreamSource impls to do the join once. - Collapse SendStream/RecvStream to thin newtypes over Box<dyn Async* + Send + Unpin>. Remove SendStreamKind/RecvStreamKind enums and the quinn/iroh per-call dispatch (the join happens once in the BidiStreamSource impl now). Keep SendStream::from_stream / RecvStream::from_stream per-half boxing for into_sub_streams() (ADR-074) and the future channels reassembly path. - Remove Connection::from_stream (split-pair constructor). Promote Connection::from_bidi to the only public stream constructor (the rule: the split never crosses a crate boundary as part of a constructor). - Update Connection::accept_bi/open_bi to return BiStream. Update from_source_tests and tests modules to use from_bidi and BiStream; add a SinkEmpty test helper (AsyncRead EOF + AsyncWrite discard) for Connection-level-only test connections. alknet-http (server/adapter.rs): - Drop the 44-line QuicStream wrapper — accept_bi returns BiStream which is already AsyncRead + AsyncWrite. HttpAdapter::handle becomes 4 lines. - Drop the 38-line QuicStreamDuplex test helper — tests use a single tokio::io::duplex whose ends are each AsyncRead + AsyncWrite natively. - Remove unused std::io / std::pin::Pin imports. alknet-tty (adapter.rs): - TtyAdapter::handle splits the BiStream from accept_bi via tokio::io::split for drive_session's separate AsyncWrite/AsyncRead args (the stdlib idiom for TcpStream-style duplex streams). alknet-call (protocol/*, client/*): - Dispatcher::run_loop accept_bi site: take BiStream, pass to handle_stream. - Dispatcher::handle_stream signature: take BiStream, split internally via tokio::io::split (was: take SendStream + RecvStream separately). - CallConnection::call_with_payload / subscribe_with_payload / write_envelope: split the BiStream from open_bi via tokio::io::split at the call site. - write_request / read_stream_until_closed: generic over AsyncWrite/AsyncRead (were: concrete SendStream/RecvStream) — accepts the ReadHalf/WriteHalf from tokio::io::split directly. - Add protocol/test_support.rs with sink_empty_connection() (replaces the 5 duplicated stub_connection() fns that used Connection::from_stream). - Update all test stubs (call_client.rs, protocol/connection.rs, protocol/dispatch.rs, protocol/adapter.rs, client/from_call.rs) to use Connection::from_bidi + the shared sink_empty_connection() helper. - Test handle_stream call sites: build BiStream::from_joined(recv, send) from the existing BufReader<Cursor> + duplex pair. Workspace test status: all 9 crates pass (116 + 307 + 18 + 3 + 17 + 301 + 34 + 61 + 23 + 5 + 6 + 8 + 82 + 4 + 3 + 6 + 12 + 1 = 1007 tests pass). One pre-existing failure remains in alknet-http (adapters::to_mcp::tests::search_returns_access_control_filtered_ops_excluding_subscriptions — handler kind mismatch, unrelated to Phase 6, fails on develop baseline).
This commit is contained in:
1 parent
249370345f
commit
b60a5844ba
10 files changed
+412
-403
No files matched your search
@@ -118,8 +118,8 @@ impl ProtocolHandler for TtyAdapter {
|
||||
let _ = connection.set_identity(identity);
|
||||
}
|
||||
loop {
|
||||
let (send, recv) = match connection.accept_bi().await {
|
||||
Ok(pair) => pair,
|
||||
let stream = match connection.accept_bi().await {
|
||||
Ok(stream) => stream,
|
||||
Err(StreamError::ConnectionClosed) => break,
|
||||
Err(StreamError::StreamClosed) => break,
|
||||
Err(e) => return Err(HandlerError::from(e)),
|
||||
@@ -128,7 +128,14 @@ impl ProtocolHandler for TtyAdapter {
|
||||
let ownership = self.ownership.clone();
|
||||
let identity = auth.identity.clone();
|
||||
tokio::spawn(async move {
|
||||
let _ = drive_session(send, recv, backends, ownership, identity).await;
|
||||
// `stream` is a `BiStream` (ADR-092) — `AsyncRead + AsyncWrite
|
||||
// + Send + Unpin`. Split into halves for `drive_session`
|
||||
// (which takes separate `AsyncWrite` + `AsyncRead` args). The
|
||||
// split is the stdlib idiom for `TcpStream`-style duplex
|
||||
// streams; no per-handler wrapper.
|
||||
let (client_read, client_write) = tokio::io::split(stream);
|
||||
let _ =
|
||||
drive_session(client_write, client_read, backends, ownership, identity).await;
|
||||
});
|
||||
}
|
||||
Ok(())
|
||||
@@ -164,10 +171,10 @@ async fn send_negotiation_error<W: AsyncWrite + Unpin>(
|
||||
|
||||
/// Drive a `alknet/tty` session end-to-end over a bidi stream.
|
||||
///
|
||||
/// `client_send` / `client_recv` are the two halves of the bidi stream (QUIC
|
||||
/// `SendStream` / `RecvStream`). Returns when the session is complete (exit
|
||||
/// chunk sent, stream closed) or when the stream is reset (cancel-cleanup
|
||||
/// path — no exit chunk sent).
|
||||
/// `client_send` / `client_recv` are the two halves of the bidi stream
|
||||
/// (split from the `BiStream` yielded by `accept_bi` via `tokio::io::split`).
|
||||
/// Returns when the session is complete (exit chunk sent, stream closed) or
|
||||
/// when the stream is reset (cancel-cleanup path — no exit chunk sent).
|
||||
///
|
||||
/// This is the per-stream session driver — the counterpart to the POC's
|
||||
/// `session::drive_session` (`/workspace/alknet-tty-poc/src/session.rs`),
|
||||
|
||||
Reference in new issue
Block a user