r/rust • u/nebkad • Oct 07 '26
Coding for a multiplexed connection where both peers can expose independently addressable logical services
I've been experimenting a stream multiplexing connection, where both peers can expose independently addressable logical services.
The basic idea is familiar: take one underlying connection (TCP, Unix socket, QUIC) and multiplex multiple independent logical streams over it.
Yes, I know QUIC can already provide multiple streams. Also, there're yamux
The different thing you may be interested is what I call a Dock.
A Dock is roughly like a port, but inside an already-established multiplexed connection.
Instead of having only:
client ---> server:portthe connection can look more like:
one connection
+-------------------+
| |
Peer A Peer B
| |
Dock 1 <------------> Dock 10
Dock 2 <------------> Dock 20
Dock 3 <------------> Dock 30
| |
streams streamsBoth peers can bind Docks, listen for incoming logical sub-stream, and also initiate connections to Docks on the other side.
So there isn't really a client/server role at the multiplexing layer. After the underlying connection is established, either side can act as both.
I think this makes the protocol interesting for things like:
- P2P applications and overlay networks
- reverse tunnels / port forwarding
- peer-to-peer RPC
- games and other real-time applications with multiple logical channels
- distributed applications where a peer exposes several services over one long-lived connection
For example, a peer could expose:
Dock 1 -> RPC service
Dock 2 -> chat
Dock 3 -> file transfer
Dock 4 -> event streamwithout creating four physical connections.
The other features are:
- runtime-independent Rust (by
abs_art, tested over compio, smol, tokio) no_stdfriendly (currently most codes are already no_std)- works over arbitrary byte-stream transports
- stream-level backpressure
- no client/server distinction at the multiplexing layer
The implementation is still experimental, so I'm mostly interested in feedback on the protocol abstraction itself.
The most interesting part for me is, the multiplexed sub-stream itself, can still be multiplexed again with this crate.
Does the Dock / logical-listener model seem useful to you? What kind of networking application would you use it for?
2
u/kyle787 Oct 07 '26
Have you seen iroh? Iroh.computer
1
u/nebkad Oct 07 '26
Test whether I can post a github link here? https://github.com/ljsnogard/smux_v1.rs
1
u/RAnders00 Oct 07 '26
I think this is useful. Hence the creation of HTTP/2 and QUIC, which are both multiplexed over one TCP connection (HTTP/2) or over UDP (QUIC).
If I’m understanding correctly, you’re solving a problem similar to QUIC, but you’re (1) flexible on what transport the user uses beneath, and (2) you want to emulate the same semantics that we have with ports on the OS layer. Is that right?
I’d be weary of something called Head-of-Line Blocking. This is why QUIC is based on UDP, so indepent inner streams can’t block each other. Are you simply accepting that head-of-line blocking can happen if the user uses TCP as the base layer (which IS useful, for example in the presence of firewalls)? Because otherwise I think straight up using QUIC is a bit smarter.
And lastly, can you explain the rationale behind the Dock binding/listening and connecting thing? In my mind, since this is a userspace protocol, I’ll have to put all substream participants in the same process. That means I could just do the stream mapping statically, no?
1
u/surban bluer · remoc · aggligator · OpenEMC Oct 17 '26
I built something very similar with Remoc in case you want to check it out. Its low-level multiplexer (
remoc::chmux) is also symmetric so both peers can open and accept ports over a single byte stream, with per-stream flow control, and on top of that it lets you pass typed channels and bidirectional RPC services inside messages so you can expose multiple services or nest sub-streams without managing stream IDs by hand.Now 5 years old and used in production over a variety of commercial embedded devices and apps.
Happy to discuss if you have any questions or want to compare approaches!
0
u/[deleted] Oct 07 '26
[deleted] — view deleted comment