loopback

package
v0.83.2 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: BSD-3-Clause Imports: 18 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PacketHeaders

type PacketHeaders struct {
	// contains filtered or unexported fields
}

PacketHeaders holds pre-created headers and buffers for efficient packet sending

func NewPacketHeaders

func NewPacketHeaders(localWGListenPort int, endpoint *net.UDPAddr) (*PacketHeaders, error)

type Proxy

type Proxy struct {
	// contains filtered or unexported fields
}

Proxy forwards packets between relayed connections and a local kernel WireGuard instance. Every relayed peer gets its own loopback address as its WireGuard endpoint, so a single socket serves all of them: the destination address of an incoming packet identifies the peer.

func NewProxy

func NewProxy(wgPort int, mtu uint16) *Proxy

NewProxy creates a proxy for the WireGuard instance listening on wgPort.

func (*Proxy) AddRelayedConn

func (p *Proxy) AddRelayedConn(relayedConn net.Conn) (*net.UDPAddr, netip.Addr, error)

AddRelayedConn assigns an endpoint address to the relayed connection and returns the address WireGuard should send to, along with the key the connection is stored under.

func (*Proxy) Free

func (p *Proxy) Free() error

Free releases the proxy resources. The relayed connections are left open.

func (*Proxy) Listen

func (p *Proxy) Listen() error

Listen opens the shared socket and starts forwarding WireGuard packets to the relayed connections.

type ProxyWrapper

type ProxyWrapper struct {
	// contains filtered or unexported fields
}

ProxyWrapper help to keep the remoteConn instance for net.Conn.Close function call

func NewProxyWrapper

func NewProxyWrapper(proxy *Proxy) *ProxyWrapper

func (*ProxyWrapper) AddRelayedConn

func (p *ProxyWrapper) AddRelayedConn(ctx context.Context, _ *net.UDPAddr, remoteConn net.Conn) error

func (*ProxyWrapper) CloseConn

func (p *ProxyWrapper) CloseConn() error

CloseConn close the remoteConn and automatically remove the conn instance from the map

func (*ProxyWrapper) EndpointAddr

func (p *ProxyWrapper) EndpointAddr() *net.UDPAddr

func (*ProxyWrapper) InjectPacket

func (p *ProxyWrapper) InjectPacket(b []byte) error

InjectPacket writes b to the remote peer over the underlying transport.

func (*ProxyWrapper) Pause

func (p *ProxyWrapper) Pause()

func (*ProxyWrapper) RedirectAs

func (p *ProxyWrapper) RedirectAs(endpoint *net.UDPAddr)

func (*ProxyWrapper) SetDisconnectListener

func (p *ProxyWrapper) SetDisconnectListener(disconnected func())

func (*ProxyWrapper) Work

func (p *ProxyWrapper) Work()

Jump to

Keyboard shortcuts

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