Make the connection handler transport-generic (serve over TLS / any AsyncRead+AsyncWrite)#46
Open
rockwotj wants to merge 2 commits into
Open
Make the connection handler transport-generic (serve over TLS / any AsyncRead+AsyncWrite)#46rockwotj wants to merge 2 commits into
rockwotj wants to merge 2 commits into
Conversation
set_nodelay is TcpStream-specific. Moving it to NFSTcpListener::handle_forever, right before process_socket is spawned, keeps the per-connection handler free of TcpStream-only calls (a prerequisite for making it transport-generic) while the existing TCP path keeps nodelay behavior unchanged.
…syncRead+AsyncWrite) process_socket and write_fragment were concretely typed to tokio::net::TcpStream, so callers couldn't serve NFS over anything else. Genericize the per-connection handler over AsyncRead + AsyncWrite + Send + 'static so callers can hand it a plaintext TcpStream, an already-handshaked TLS stream (tokio_rustls), a unix socket, etc. — without nfsserve taking a TLS dependency. - write_fragment is now generic over W: AsyncWrite + Unpin (body unchanged). - process_socket is generic over the stream and is now pub, so external callers can serve a pre-established stream. It uses tokio::io::split + AsyncReadExt::read (cancel-safe in select!) instead of the TcpStream-specific readable()/try_read(). - Replies are flushed after writing: a buffering transport (TLS) only encrypts and sends on flush; without it the reply never leaves the server. No-op for raw TCP. - Added a test driving a MOUNTPROC3_NULL RPC through process_socket over an in-memory tokio::io::duplex stream (not a TcpStream), proving the genericization. No new dependency required. NFSTcpListener behavior is unchanged and remains backward-compatible.
9cce6ff to
549577a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
We want to serve NFS over connections that aren't a raw
TcpStream— specifically an already-handshaked TLS stream (tokio_rustls::server::TlsStream). Two concrete cases drive this:tokio-rustls.Both need to hand
nfsservea stream that isn't aTcpStream. Todayprocess_socketandwrite_fragmentare concretely typed totokio::net::TcpStream, which blocks this. This PR genericizes the per-connection handler over the stream type so callers can bring their own transport, withoutnfsserveitself taking a TLS dependency.Changes
write_fragmentis now generic overW: AsyncWrite + Unpin(body unchanged — it only usedwrite_all).process_socketis now generic overS: AsyncRead + AsyncWrite + Send + 'staticand is nowpub, so external callers can serve a pre-established stream. It usestokio::io::split+AsyncReadExt::read(cancel-safe inselect!) in place of theTcpStream-specificreadable()/try_read(). (splitreturnsUnpinhalves, soSneeds noUnpinbound.)set_nodelaymoved fromprocess_socketintoNFSTcpListener::handle_forever(it'sTcpStream-specific). The TCP path keepsnodelaybehavior unchanged.MOUNTPROC3_NULLRPC throughprocess_socketover an in-memorytokio::io::duplexstream (which isAsyncRead + AsyncWrite + Send + 'static, not aTcpStream) and asserts a well-formed reply comes back. This proves the genericization and adds no new dependency (norustls), keeping the PR dependency-free.Compatibility
NFSTcpListenerbehavior is unchanged and fully backward-compatible — it uses the now-genericprocess_socketinternally for plaintext TCP.