Skip to content

feat(server): make run_connection generic over stream type#1180

Closed
Greg Lamberson (glamberson) wants to merge 1 commit intoDevolutions:masterfrom
glamberson:feat/generic-run-connection
Closed

feat(server): make run_connection generic over stream type#1180
Greg Lamberson (glamberson) wants to merge 1 commit intoDevolutions:masterfrom
glamberson:feat/generic-run-connection

Conversation

@glamberson
Copy link
Contributor

Summary

Make run_connection accept any AsyncRead + AsyncWrite stream instead of requiring TcpStream concretely.

  • run_connection<S>(&mut self, stream: S) where S: AsyncRead + AsyncWrite + Send + Sync + Unpin + 'static
  • Replace peer_addr() call in Hybrid/CredSSP path with local_addr fallback
  • Remove unused TcpStream import

Motivation

RDP servers may accept connections from transports other than TCP: Unix domain sockets (for local WebSocket relay), VSOCK (VM-to-host), or in-process streams (integration tests). The current TcpStream parameter prevents this, even though everything downstream of run_connection already operates generically (TokioFramed<S>, TLS accept, accept_finalize<S>, client_loop<R, W>).

Concrete use case: a QEMU display server that listens on both TCP (native RDP clients) and a Unix domain socket (browser clients via WebSocket relay) using the same RdpServer instance.

Changes

1 file, +8/-5 lines:

  • Generalize run_connection signature with AsyncRead + AsyncWrite + Send + Sync + Unpin + 'static bounds (matching accept_finalize)
  • Replace peer_addr() in the Hybrid/CredSSP path: the existing comment noted "doesn't seem to matter yet" for NTLM auth. Use local_addr as fallback since generic streams don't expose peer address
  • Remove now-unused TcpStream import (TcpListener remains for run())

Backward Compatibility

Fully backward compatible. Callers passing TcpStream continue to work unchanged via type inference. run() is unaffected.

Test Plan

  • cargo xtask check fmt -v passes
  • cargo xtask check lints -v passes
  • cargo xtask check tests -v passes
  • cargo xtask check typos -v passes
  • Verified run() compiles with inferred TcpStream
  • Verified UnixStream accepted via run_connection in downstream project

Make `run_connection` accept any `AsyncRead + AsyncWrite` stream instead
of requiring `TcpStream` concretely. This enables RDP servers to accept
connections from Unix domain sockets, VSOCK, in-process test streams, or
any other bidirectional byte stream.

Everything inside `run_connection` already operated generically:
`TokioFramed<S>`, TLS accept, and `accept_finalize` all use trait bounds
rather than concrete types. The only `TcpStream`-specific call was
`peer_addr()` in the CredSSP/Hybrid path, which the existing comment
noted "doesn't seem to matter yet" for NTLM auth. Replace it with
`local_addr` as a fallback client name.

Backward compatible: callers passing `TcpStream` continue to work
unchanged via type inference. `run()` is unaffected.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant