vsockconn

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2024 License: MIT Imports: 17 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)")
)

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.

Jump to

Keyboard shortcuts

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