From f2e6b8befbb984e01847eefce835dfafe1a4c6d1 Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Sat, 11 Jul 2026 04:31:56 +0000 Subject: [PATCH] transport: promote FMP stream framing to transport::framing The FMP frame-boundary reader lived in transport/tcp/stream.rs, but the Tor and Nym transports both reached across module boundaries to 'use crate::transport::tcp::stream::read_fmp_packet', a layering smell: the reader is a shared stream-framing utility, not a TCP-private one. Move the file to transport/framing.rs and repoint the tcp/tor/nym use sites, removing the tor->tcp and nym->tcp dependencies. Behavior unchanged. --- src/transport/{tcp/stream.rs => framing.rs} | 4 ++-- src/transport/mod.rs | 2 ++ src/transport/nym/mod.rs | 4 ++-- src/transport/tcp/mod.rs | 3 +-- src/transport/tor/mod.rs | 6 +++--- 5 files changed, 10 insertions(+), 9 deletions(-) rename src/transport/{tcp/stream.rs => framing.rs} (99%) diff --git a/src/transport/tcp/stream.rs b/src/transport/framing.rs similarity index 99% rename from src/transport/tcp/stream.rs rename to src/transport/framing.rs index 4323fdc..4fe0f24 100644 --- a/src/transport/tcp/stream.rs +++ b/src/transport/framing.rs @@ -3,8 +3,8 @@ //! Recovers FIPS packet boundaries from a TCP byte stream using the //! existing 4-byte FMP common prefix `[ver+phase:1][flags:1][payload_len:2 LE]`. //! -//! This module is deliberately separate from the TCP transport so it can -//! be reused by the future Tor transport. +//! This module is deliberately separate from any single transport so it can +//! be shared by the stream-oriented transports (TCP, Tor, Nym). use tokio::io::{AsyncRead, AsyncReadExt}; diff --git a/src/transport/mod.rs b/src/transport/mod.rs index 9dacc17..1176215 100644 --- a/src/transport/mod.rs +++ b/src/transport/mod.rs @@ -34,6 +34,8 @@ use tor::TorTransport; use tor::control::TorMonitoringInfo; use udp::UdpTransport; +pub(crate) mod framing; + mod stats_common; pub(crate) use stats_common::PoolCounters; diff --git a/src/transport/nym/mod.rs b/src/transport/nym/mod.rs index 4996664..053677f 100644 --- a/src/transport/nym/mod.rs +++ b/src/transport/nym/mod.rs @@ -9,7 +9,7 @@ //! //! Outbound-only: connects to remote TCP peers through the local //! nym-socks5-client SOCKS5 proxy. Like the Tor transport, reuses FMP -//! stream framing from `tcp::stream` and follows the same connection +//! stream framing from `transport::framing` and follows the same connection //! pool pattern. No inbound service is supported. pub mod stats; @@ -22,7 +22,7 @@ use super::{ TransportError, TransportId, TransportState, TransportType, }; use crate::config::NymConfig; -use crate::transport::tcp::stream::read_fmp_packet; +use crate::transport::framing::read_fmp_packet; use stats::NymStats; use futures::FutureExt; diff --git a/src/transport/tcp/mod.rs b/src/transport/tcp/mod.rs index 350c879..b1975b8 100644 --- a/src/transport/tcp/mod.rs +++ b/src/transport/tcp/mod.rs @@ -23,7 +23,6 @@ //! TCP stream and the receiver uses phase-dependent size computation. pub mod stats; -pub mod stream; use super::resolve_socket_addr; use super::{ @@ -31,8 +30,8 @@ use super::{ TransportError, TransportId, TransportState, TransportType, }; use crate::config::TcpConfig; +use crate::transport::framing::read_fmp_packet; use stats::TcpStats; -use stream::read_fmp_packet; use futures::FutureExt; use socket2::TcpKeepalive; diff --git a/src/transport/tor/mod.rs b/src/transport/tor/mod.rs index 5c2b8a9..e183632 100644 --- a/src/transport/tor/mod.rs +++ b/src/transport/tor/mod.rs @@ -14,8 +14,8 @@ //! ## Architecture //! //! Like TCP, each peer has its own connection. The transport reuses FMP -//! stream framing from `tcp::stream` and follows the same connection pool -//! pattern as the TCP transport. Inbound connections arrive via a local +//! stream framing from `transport::framing` and follows the same connection +//! pool pattern as the TCP transport. Inbound connections arrive via a local //! TCP listener that the Tor daemon forwards onion service traffic to. pub mod control; @@ -31,7 +31,7 @@ use super::{ TransportError, TransportId, TransportState, TransportType, }; use crate::config::TorConfig; -use crate::transport::tcp::stream::read_fmp_packet; +use crate::transport::framing::read_fmp_packet; use control::{ControlAuth, TorControlClient, TorMonitoringInfo}; use stats::TorStats;