Skip to content

Add UDP Packet Mode endpoint#82

Open
Uxx0 wants to merge 9 commits intonarrowlink:mainfrom
Uxx0:udp-packet
Open

Add UDP Packet Mode endpoint#82
Uxx0 wants to merge 9 commits intonarrowlink:mainfrom
Uxx0:udp-packet

Conversation

@Uxx0
Copy link

@Uxx0 Uxx0 commented Feb 28, 2026

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 IpStackUdpPacketEndpoint to handle raw UDP datagrams (recv/send).

@SajjadPourali SajjadPourali self-assigned this Feb 28, 2026
@SajjadPourali SajjadPourali self-requested a review February 28, 2026 17:45
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 IpStackUdpPacketEndpoint with recv()/send() and a helper to build UDP packets.
  • Introduced IpStackConfig::udp_packet_mode and routed UDP packets through per-endpoint channels when enabled.
  • Updated IpStackStream and 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.

Comment on lines 54 to 58
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)),
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines 29 to 32
Udp(IpStackUdpStream),
/// UDP PACKET.
UdpEdp(IpStackUdpPacketEndpoint),
/// A stream for unknown transport protocols.
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +163 to +167
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}");

Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Uxx0 and others added 7 commits March 2, 2026 13:29
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants