holepunch

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2026 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ExitNode

type ExitNode struct {
	Endpoint  string `json:"endpoint"`
	RelayPort uint16 `json:"relayPort"`
	PublicKey string `json:"publicKey"`
	SiteIds   []int  `json:"siteIds,omitempty"`
}

ExitNode represents a WireGuard exit node for hole punching

type HolepunchStatus

type HolepunchStatus struct {
	Endpoint  string
	Connected bool
	RTT       time.Duration
}

HolepunchStatus represents the status of a holepunch connection

type HolepunchStatusCallback

type HolepunchStatusCallback func(status HolepunchStatus)

HolepunchStatusCallback is called when holepunch status changes

type HolepunchTester

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

HolepunchTester monitors holepunch connectivity using magic packets

func NewHolepunchTester

func NewHolepunchTester(sharedBind *bind.SharedBind) *HolepunchTester

NewHolepunchTester creates a new holepunch tester using the given SharedBind

func (*HolepunchTester) ClearCache added in v1.9.0

func (t *HolepunchTester) ClearCache()

ClearCache clears all cached addresses

func (*HolepunchTester) InvalidateCache added in v1.9.0

func (t *HolepunchTester) InvalidateCache(endpoint string)

InvalidateCache removes a specific endpoint from the address cache

func (*HolepunchTester) SetCallback

func (t *HolepunchTester) SetCallback(callback HolepunchStatusCallback)

SetCallback sets the callback for connection status changes

func (*HolepunchTester) Start

func (t *HolepunchTester) Start() error

Start begins listening for magic packet responses

func (*HolepunchTester) Stop

func (t *HolepunchTester) Stop()

Stop stops the tester

func (*HolepunchTester) TestEndpoint

func (t *HolepunchTester) TestEndpoint(endpoint string, timeout time.Duration) TestResult

TestEndpoint sends a magic test packet to the endpoint and waits for a response. This uses the SharedBind so packets come from the same source port as WireGuard.

type Manager

type Manager struct {
	ID string
	// contains filtered or unexported fields
}

Manager handles UDP hole punching operations

func NewManager

func NewManager(sharedBind *bind.SharedBind, ID string, clientType string, publicKey string) *Manager

NewManager creates a new hole punch manager

func (*Manager) AddExitNode

func (m *Manager) AddExitNode(exitNode ExitNode) bool

AddExitNode adds a new exit node to the rotation if it doesn't already exist

func (*Manager) GetExitNodes

func (m *Manager) GetExitNodes() []ExitNode

GetExitNodes returns a copy of the current exit nodes

func (*Manager) GetServerHolepunchInterval added in v1.9.0

func (m *Manager) GetServerHolepunchInterval() (min, max time.Duration)

GetInterval returns the current min and max intervals

func (*Manager) IsRunning

func (m *Manager) IsRunning() bool

IsRunning returns whether hole punching is currently active

func (*Manager) RemoveExitNode

func (m *Manager) RemoveExitNode(endpoint string) bool

RemoveExitNode removes an exit node from the rotation

func (*Manager) RemoveExitNodesByPeer

func (m *Manager) RemoveExitNodesByPeer(peerID int) int

RemoveExitNodesByPeer removes the peer ID from the SiteIds list in each exit node. If the SiteIds list becomes empty after removal, the exit node is removed entirely. Returns the number of exit nodes removed.

func (*Manager) ResetServerHolepunchInterval added in v1.9.0

func (m *Manager) ResetServerHolepunchInterval()

ResetServerHolepunchInterval resets the hole punch interval back to the default values. This restores normal operation after low power mode or other custom settings.

func (*Manager) SetServerHolepunchInterval added in v1.9.0

func (m *Manager) SetServerHolepunchInterval(min, max time.Duration)

SetServerHolepunchInterval sets custom min and max intervals for hole punching. This is useful for low power mode where longer intervals are desired.

func (*Manager) SetToken

func (m *Manager) SetToken(token string)

SetToken updates the authentication token used for hole punching

func (*Manager) Start

func (m *Manager) Start() error

Start starts hole punching with the current set of exit nodes

func (*Manager) StartMultipleExitNodes

func (m *Manager) StartMultipleExitNodes(exitNodes []ExitNode) error

StartMultipleExitNodes starts hole punching to multiple exit nodes

func (*Manager) Stop

func (m *Manager) Stop()

Stop stops any ongoing hole punch operations

func (*Manager) TriggerHolePunch

func (m *Manager) TriggerHolePunch() error

TriggerHolePunch sends an immediate hole punch packet to all configured exit nodes This is useful for triggering hole punching on demand without waiting for the interval

type TestConnectionOptions

type TestConnectionOptions struct {
	// Timeout is how long to wait for a response (default: 5 seconds)
	Timeout time.Duration
	// Retries is the number of times to retry on failure (default: 0)
	Retries int
}

TestConnectionOptions configures the connection test

func DefaultTestOptions

func DefaultTestOptions() TestConnectionOptions

DefaultTestOptions returns the default test options

type TestResult

type TestResult struct {
	// Success indicates whether the test was successful
	Success bool
	// RTT is the round-trip time of the test packet
	RTT time.Duration
	// Endpoint is the endpoint that was tested
	Endpoint string
	// Error contains any error that occurred during the test
	Error error
}

TestResult represents the result of a connection test

func TestConnectionWithBind

func TestConnectionWithBind(sharedBind *bind.SharedBind, endpoint string, opts *TestConnectionOptions) TestResult

TestConnectionWithBind sends a magic test packet using an existing SharedBind. This is useful when you want to test the connection through the same socket that WireGuard is using, which tests the actual hole-punched path.

Jump to

Keyboard shortcuts

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