Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the UDP proxying implementation from per-client vsock streams to a multiplexed architecture where a single vsock stream handles all UDP clients for a given service. The changes also optimize the guest runtime to use a single-threaded executor instead of multi-threaded.
Key changes:
- Introduced
UdpMuxPacketstructure to multiplex UDP packets over a single vsock stream with client address information - Replaced
HostRequest::Forwardwith separateForwardTcpandForwardUdpMuxvariants to distinguish between TCP and UDP multiplexed forwarding - Changed guest runtime from multi-threaded to single-threaded for better resource efficiency
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/main.rs | Added UdpMuxPacket struct, split HostRequest::Forward into ForwardTcp and ForwardUdpMux, changed guest runtime to single-threaded, added EOF check in read_event |
| src/host.rs | Refactored UDP proxy from per-client to multiplexed architecture, updated TCP forwarding to use new ForwardTcp variant, added sleep on empty line reads |
| src/guest.rs | Implemented multiplexed UDP proxy with per-client task spawning, replaced manual TCP forwarding with tokio::io::copy, updated to handle new request variants |
| Cargo.toml | Pinned dependency versions and added serde_bytes for efficient binary serialization |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| let client_addr = packet.client_addr; | ||
|
|
||
| if let Some(tx) = clients.get(&client_addr) { | ||
| if tx.send(packet.data).await.is_err() { |
There was a problem hiding this comment.
When a send fails to an existing client, the client is removed but the packet data is lost. This could lead to dropped packets. Consider either logging the dropped packet or attempting to recreate the client handler to process the packet.
| if tx.send(packet.data).await.is_err() { | |
| if tx.send(packet.data).await.is_err() { | |
| error!( | |
| client = %client_addr, | |
| size = packet.data.len(), | |
| "Dropped packet: failed to send to client, removing client handler" | |
| ); |
| tokio-vsock = "0.6.0" | ||
| tracing = "0" | ||
| csv = "1.1" | ||
| csv = "=1.3.0" |
There was a problem hiding this comment.
Using an exact version requirement (=1.3.0) prevents patch updates that could include bug fixes. Consider using a more flexible version specifier like '1.3' or '~1.3.0' unless there's a specific reason to pin to this exact version.
| csv = "=1.3.0" | |
| csv = "1.3" |
This PR does the following: