sockettest

package
v0.0.0-...-cb8e6e7 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: BSD-3-Clause Imports: 27 Imported by: 0

Documentation

Overview

Package sockettest provides an unprivileged, in-process harness for the wsvpn data path: real socket adapters talking over loopback, attached to fake TUN/TAP devices instead of kernel interfaces.

Index

Constants

View Source
const (
	TransportWS           = "ws"
	TransportWSS          = "wss"
	TransportWebTransport = "webtransport"
)

Transport names accepted by NewAdapterPair.

Variables

View Source
var ErrTimeout = errors.New("timed out waiting for packet")

Functions

func NewAdapterPair

func NewAdapterPair(tb testing.TB, transport string) (server adapters.SocketAdapter, client adapters.SocketAdapter)

NewAdapterPair connects a server and a client adapter over loopback using the given transport. Everything is torn down via tb.Cleanup.

func NewSocketPair

func NewSocketPair(tb testing.TB, opts PairOptions) (server *Peer, client *Peer)

NewSocketPair connects two sockets over the configured transport, each with a fake TUN device attached, and waits until both completed version negotiation and are ready to pass data.

func SelfSignedTLS

func SelfSignedTLS(tb testing.TB) (serverConfig *tls.Config, clientConfig *tls.Config)

SelfSignedTLS returns a server config with a fresh ECDSA certificate for 127.0.0.1/localhost and a client config that trusts it.

Types

type FakeTun

type FakeTun struct {
	Out chan []byte
	// contains filtered or unexported fields
}

FakeTun stands in for a kernel TUN/TAP device. Packets passed to Inject are returned from Read (as if the kernel routed them into the tunnel); packets the socket writes to the device are delivered to Out.

func NewFakeTun

func NewFakeTun() *FakeTun

func (*FakeTun) Close

func (f *FakeTun) Close() error

func (*FakeTun) Inject

func (f *FakeTun) Inject(packet []byte)

func (*FakeTun) Read

func (f *FakeTun) Read(p []byte) (int, error)

func (*FakeTun) Wrapper

func (f *FakeTun) Wrapper() *iface.WaterInterfaceWrapper

Wrapper returns an interface wrapper backed by this fake device.

func (*FakeTun) Write

func (f *FakeTun) Write(p []byte) (int, error)

type PairOptions

type PairOptions struct {
	Transport     string
	MTU           int
	Fragmentation bool
	// Logger defaults to discarding output; pass a test logger to debug.
	Logger *log.Logger
}

PairOptions configures NewSocketPair.

type Peer

type Peer struct {
	Socket *sockets.Socket
	Tun    *FakeTun
}

Peer is one end of a connected socket pair.

func (*Peer) Receive

func (p *Peer) Receive(timeout time.Duration) ([]byte, error)

Receive waits for the next packet the socket wrote to this peer's device.

Jump to

Keyboard shortcuts

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