Conversation
There was a problem hiding this comment.
Pull request overview
Adds an optional “UDP packet mode” to the IP stack so UDP traffic can be delivered to the application as raw datagrams (src, dst, payload) via a new endpoint type, rather than as an AsyncRead/AsyncWrite UDP stream.
Changes:
- Added
IpStackUdpPacketEndpointwithrecv()/send()and a helper to build UDP packets. - Introduced
IpStackConfig::udp_packet_modeand routed UDP packets through per-endpoint channels when enabled. - Updated
IpStackStreamand examples to include a new UDP packet endpoint stream variant.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 16 comments.
Show a summary per file
| File | Description |
|---|---|
| src/stream/udp.rs | Adds the packet endpoint type and UDP packet builder helper. |
| src/stream/mod.rs | Exposes the new endpoint and adds a new IpStackStream variant. |
| src/lib.rs | Implements packet-mode dispatch, endpoint lifecycle/timeout, and config flag. |
| examples/tun.rs | Adds an example match arm for the new stream variant. |
| examples/tun_wintun.rs | Adds an example match arm for the new stream variant (Windows). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| match self { | ||
| IpStackStream::Tcp(tcp) => tcp.local_addr(), | ||
| IpStackStream::Udp(udp) => udp.local_addr(), | ||
| IpStackStream::UdpEdp(udp_edp) => udp_edp.local_addr(), | ||
| IpStackStream::UnknownNetwork(_) => SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::UNSPECIFIED, 0)), |
There was a problem hiding this comment.
The IpStackStream docs for local_addr()/peer_addr() currently describe behavior only for TCP/UDP/unknown variants, but UdpEdp has different semantics (and peer_addr() returns an unspecified address). Update the doc comments to include the new variant so API behavior is accurately documented.
| Udp(IpStackUdpStream), | ||
| /// UDP PACKET. | ||
| UdpEdp(IpStackUdpPacketEndpoint), | ||
| /// A stream for unknown transport protocols. |
There was a problem hiding this comment.
IpStackStream::UdpEdp is an unclear/abbreviated variant name and the doc comment "UDP PACKET." is not descriptive. Consider renaming the variant to something aligned with the type name (e.g., UdpPacketEndpoint) and updating the enum docs accordingly to keep the public API self-explanatory.
| IpStackStream::UdpEdp(mut endpoint) => { | ||
| let c = count.fetch_add(1, std::sync::atomic::Ordering::Relaxed) + 1; | ||
| let number2 = number; | ||
| log::info!("#{number2} UDP Packet Endpoint starting, session count {c}"); | ||
|
|
There was a problem hiding this comment.
This example adds a UdpEdp match arm, but the example never enables IpStackConfig::udp_packet_mode(true), so this branch will never be hit with the default config. Either enable packet mode in the example configuration or remove/guard this branch so the example remains accurate.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
I think it is better for gamers like me to have the udp packet mode, so I add the udp packet for P2P game.
I have tested the mode. it works well, but please review the code.
Key changes:
Added
IpStackUdpPacketEndpointto handle raw UDP datagrams (recv/send).