relay

package
v0.9.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 30, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package relay holds low-level primitives for proxying streams to a WireGuard interface. The package can later be abstracted to support other proxying mechanisms.

Index

Constants

View Source
const DefaultUDPBuffer = 1024 * 1024 * 4

DefaultUDPBuffer is the default buffer size to use for UDP relays.

Variables

This section is empty.

Functions

This section is empty.

Types

type LocalUDP

type LocalUDP struct {
	net.Conn
	// contains filtered or unexported fields
}

LocalUDP is a local UDP relay.

func (*LocalUDP) Close

func (r *LocalUDP) Close() error

Close closes the relay.

func (*LocalUDP) Closed

func (r *LocalUDP) Closed() <-chan struct{}

Closed returns a channel that is closed when the relay is closed.

func (*LocalUDP) LocalAddr

func (r *LocalUDP) LocalAddr() netip.AddrPort

LocalAddr returns the local address of the relay.

func (*LocalUDP) Relay

func (r *LocalUDP) Relay(ctx context.Context, from io.ReadWriteCloser) error

Relay copies data from the given stream to and from the UDP connection. The stream will be closed when the relay is closed.

type Relay

type Relay interface {
	// Relay proxies data to and from the given stream.
	Relay(ctx context.Context, from io.ReadWriteCloser) error
	// LocalAddr returns the local address of the relay.
	LocalAddr() netip.AddrPort
	// Closed returns a channel that is closed when the relay is closed.
	Closed() <-chan struct{}
	// Close closes the relay.
	Close() error
}

Relay is a generic interface for proxying read-write streams between each other.

func NewLocalUDP

func NewLocalUDP(opts UDPOptions) (Relay, error)

NewLocalUDP creates a new UDP relay listening on the given port and proxying traffic to the listener on the given target port.

type UDPOptions

type UDPOptions struct {
	// TargetPort is the port to proxy traffic to.
	TargetPort uint16
	// BufferSize is the size of the buffer to use for copying data.
	// If 0, DefaultUDPBuffer will be used.
	BufferSize int
}

UDPOptions are generic options for a UDP relay.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL