Skip to content

Commit

Permalink
Add some comments to the timeout value.
Browse files Browse the repository at this point in the history
  • Loading branch information
sbruens committed Dec 20, 2024
1 parent d14ea20 commit eef630a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
10 changes: 6 additions & 4 deletions service/udp_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ import (
)

type udpListener struct {
natTimeout time.Duration
// NAT mapping timeout is the default time a mapping will stay active
// without packets traversing the NAT, applied to non-DNS packets.
timeout time.Duration
// fwmark can be used in conjunction with other Linux networking features like cgroups, network
// namespaces, and TC (Traffic Control) for sophisticated network management.
// Value of 0 disables fwmark (SO_MARK) (Linux only)
Expand All @@ -35,8 +37,8 @@ type udpListener struct {

// NewPacketListener creates a new PacketListener that listens on UDP
// and optionally sets a firewall mark on the socket (Linux only).
func MakeTargetUDPListener(natTimeout time.Duration, fwmark uint) transport.PacketListener {
return &udpListener{natTimeout: natTimeout, fwmark: fwmark}
func MakeTargetUDPListener(timeout time.Duration, fwmark uint) transport.PacketListener {
return &udpListener{timeout: timeout, fwmark: fwmark}
}

func (ln *udpListener) ListenPacket(ctx context.Context) (net.PacketConn, error) {
Expand All @@ -59,5 +61,5 @@ func (ln *udpListener) ListenPacket(ctx context.Context) (net.PacketConn, error)

}
}
return &timedPacketConn{PacketConn: conn, defaultTimeout: ln.natTimeout}, nil
return &timedPacketConn{PacketConn: conn, defaultTimeout: ln.timeout}, nil
}
9 changes: 6 additions & 3 deletions service/udp_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,15 @@ import (

type udpListener struct {
*transport.UDPListener
natTimeout time.Duration

// NAT mapping timeout is the default time a mapping will stay active
// without packets traversing the NAT, applied to non-DNS packets.
timeout time.Duration
}

// fwmark can be used in conjunction with other Linux networking features like cgroups, network namespaces, and TC (Traffic Control) for sophisticated network management.
// Value of 0 disables fwmark (SO_MARK)
func MakeTargetUDPListener(natTimeout time.Duration, fwmark uint) transport.PacketListener {
func MakeTargetUDPListener(timeout time.Duration, fwmark uint) transport.PacketListener {
if fwmark != 0 {
panic("fwmark is linux-specific feature and should be 0")
}
Expand All @@ -43,5 +46,5 @@ func (ln *udpListener) ListenPacket(ctx context.Context) (net.PacketConn, error)
if err != nil {
return nil, err
}
return &timedPacketConn{PacketConn: conn, defaultTimeout: ln.natTimeout}, nil
return &timedPacketConn{PacketConn: conn, defaultTimeout: ln.timeout}, nil
}

0 comments on commit eef630a

Please sign in to comment.