Documentation
¶
Index ¶
- func NewListener(conn net.PacketConn, cfg *ListenConfig) net.Listener
- type Conn
- type ListenConfig
- type ReadUDP
- type Relay
- func (r *Relay) Run(ctx context.Context) (err error)
- func (r *Relay) WithBufferSize(n int) *Relay
- func (r *Relay) WithBypass(bp bypass.Bypass) *Relay
- func (r *Relay) WithLogger(logger logger.Logger) *Relay
- func (r *Relay) WithReadTimeout(d time.Duration) *Relay
- func (r *Relay) WithService(service string) *Relay
- type WriteUDP
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewListener ¶ added in v0.0.3
func NewListener(conn net.PacketConn, cfg *ListenConfig) net.Listener
NewListener creates a net.Listener from a net.PacketConn by demultiplexing UDP datagrams into per-client net.Conn streams. Idle connections are cleaned up according to cfg.TTL.
When cfg.Stateless is true, the listener operates in raw datagram mode: no connPool, no listenLoop goroutine, no per-client session tracking. Each Accept call blocks on a ReadFrom and returns a lightweight datagramConn wrapping a single packet.
Types ¶
type Conn ¶
type Conn interface {
net.PacketConn
io.Reader
io.Writer
ReadUDP
WriteUDP
xnet.SetBuffer
xnet.SyscallConn
xnet.RemoteAddr
}
Conn is a net.PacketConn that also supports io.Reader, io.Writer, buffer sizing, syscall access, and remote address exposure.
type ListenConfig ¶ added in v0.0.3
type ListenConfig struct {
Addr net.Addr
Backlog int
ReadQueueSize int
ReadBufferSize int
TTL time.Duration
Keepalive bool
Stateless bool
Logger logger.Logger
}
ListenConfig configures a UDP-to-TCP-stream listener.
type ReadUDP ¶
type ReadUDP interface {
ReadFromUDP(b []byte) (n int, addr *net.UDPAddr, err error)
ReadMsgUDP(b, oob []byte) (n, oobn, flags int, addr *net.UDPAddr, err error)
}
ReadUDP supports reading UDP datagrams with metadata.
type Relay ¶
type Relay struct {
// contains filtered or unexported fields
}
Relay copies UDP datagrams between two net.PacketConns bidirectionally.
func NewRelay ¶
func NewRelay(pc1, pc2 net.PacketConn) *Relay
NewRelay creates a Relay that copies datagrams between pc1 and pc2.
func (*Relay) Run ¶
Run starts the relay. It blocks until an error occurs or ctx is cancelled. Both packet conns are closed before returning so the underlying sockets are released and the pending read in either direction is unblocked.
func (*Relay) WithBufferSize ¶ added in v0.0.3
WithBufferSize sets the buffer size for copy operations.
func (*Relay) WithBypass ¶
WithBypass sets the bypass matcher to skip certain addresses.
func (*Relay) WithLogger ¶
WithLogger sets the logger.
func (*Relay) WithReadTimeout ¶ added in v0.28.1
WithReadTimeout sets an idle read timeout for both relay directions. When a read blocks for longer than d the relay terminates and closes both packet conns. A value of 0 disables the timeout, relying on ctx cancellation to detect dead associations.
func (*Relay) WithService ¶ added in v0.28.1
WithService sets the service name for bypass matching.