vsockconn

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package vsockconn implements a WireGuard bind supporting TCP and VSOCK transport protocols.

Index

Constants

View Source
const (

	// AnyCID can be used to check if the context ID of a VSOCK address is
	// equivalent to VMADDR_CID_ANY.
	AnyCID = math.MaxUint32

	// AnyCID can be used to check if the port of a VSOCK address is equivalent
	// to VMADDR_PORT_ANY.
	AnyPort = math.MaxUint32
)

Variables

View Source
var (
	ErrInvalid       = errors.New("invalid address")
	ErrPacketTooLong = errors.New("packet is too long (>64kb)")
	ErrBadCRC        = errors.New("bad packet checksum")
)

Functions

func NewBind

func NewBind(logger *device.Logger, opts ...Option) conn.Bind

func ParseVsockAddress

func ParseVsockAddress(s string) (uint32, uint32, error)

ParseVsockAddress returns the context ID and port of a VSOCK string address in the format

`\(hypervisor(0)|local(1)|host(\([2-9]|[1-9][0-9]+\))\):[0-9]*`

Example:

vsockconn.ParseVsockAddress("host(2):12201")

will return context ID 2 and port 12201.

Types

type Option

type Option func(bind *VSOCKBind)

func WithNetwork

func WithNetwork(network string) Option

WithNetwork returns an Option to define thee network to be used while creating listening sockets and connecting to peers. It can be 'vsock' or 'tcp'. The 'tcp' option doesn't provide a much robust implementation of a WireGuard transport; it should be used only for testing purposes on architectures lacking VSOCK. Defaults to 'vsock'.

func WithReconnectIntervalFactor

func WithReconnectIntervalFactor(factor float64) Option

WithReconnectInterval returns an Option defining the multiplying factor for each increment step while reconnecting. Defaults to 2.

func WithReconnectIntervalJitter

func WithReconnectIntervalJitter(b bool) Option

WithReconnectInterval returns an Option defining the jitter used at reconnecting. Jitter eases contention by randomizing backoff steps. Defaults to true.

func WithReconnectIntervalMax

func WithReconnectIntervalMax(t time.Duration) Option

WithReconnectIntervalMax returns an Option that defines the maximum interval to attempt reconnecting. Defaults to 30s.

func WithReconnectIntervalMin

func WithReconnectIntervalMin(t time.Duration) Option

WithReconnectIntervalMin returns an Option that defines the minimum interval to attempt reconnecting. Defaults to 500ms.

type VSOCKBind added in v0.2.2

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

func (*VSOCKBind) BatchSize added in v0.2.2

func (s *VSOCKBind) BatchSize() int

func (*VSOCKBind) Close added in v0.2.2

func (bind *VSOCKBind) Close() error

func (*VSOCKBind) Open added in v0.2.2

func (bind *VSOCKBind) Open(port uint16) ([]conn.ReceiveFunc, uint16, error)

func (*VSOCKBind) ParseEndpoint added in v0.2.2

func (bind *VSOCKBind) ParseEndpoint(s string) (conn.Endpoint, error)

func (*VSOCKBind) Send added in v0.2.2

func (bind *VSOCKBind) Send(bufs [][]byte, end conn.Endpoint) error

func (*VSOCKBind) SetMark added in v0.2.2

func (bind *VSOCKBind) SetMark(value uint32) error

type VSOCKEndpoint added in v0.2.2

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

func (*VSOCKEndpoint) ClearSrc added in v0.2.2

func (e *VSOCKEndpoint) ClearSrc()

func (VSOCKEndpoint) DstIP added in v0.2.2

func (e VSOCKEndpoint) DstIP() netip.Addr

func (VSOCKEndpoint) DstToBytes added in v0.2.2

func (e VSOCKEndpoint) DstToBytes() []byte

func (VSOCKEndpoint) DstToString added in v0.2.2

func (e VSOCKEndpoint) DstToString() string

func (VSOCKEndpoint) SrcIP added in v0.2.2

func (e VSOCKEndpoint) SrcIP() netip.Addr

func (VSOCKEndpoint) SrcToString added in v0.2.2

func (e VSOCKEndpoint) SrcToString() string

Jump to

Keyboard shortcuts

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