portforward

package
v0.46.2 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsPersistent added in v0.24.0

func IsPersistent(localPort uint16) bool

IsPersistent checks if a port forward is marked as persistent.

func IsPortForwarded

func IsPortForwarded(localPort uint16) bool

IsPortForwarded checks if a port is already being forwarded

func MarkPersistent added in v0.24.0

func MarkPersistent(localPort uint16)

MarkPersistent marks a port forward as persistent.

func NewThrottledWriter added in v0.31.0

func NewThrottledWriter(dest io.Writer, fwd *ForwardInfo) io.Writer

NewThrottledWriter is the exported version for use by the direct dial path.

func ResetModeForSpace added in v0.31.0

func ResetModeForSpace(space string)

ResetModeForSpace clears the relay latch on all forwards targeting the given space, called when a fresh PeerIntroduce arrives with an updated peer address. The mode only reports "direct" after a connection has actually gone through, so clearing — not stamping "direct" — keeps it truthful: the forward keeps showing relay until a direct dial succeeds, while the cleared latch makes the next connection retry direct.

func RunTCPForwarderViaAgentWithContext

func RunTCPForwarderViaAgentWithContext(ctx context.Context, proxyServerURL, listen, space string, port int, token string, skipTLSVerify bool) net.Listener

RunTCPForwarderViaAgentWithContext runs a TCP forwarder via the agent proxy server

func SetDirectDialer added in v0.31.0

func SetDirectDialer(fn DirectDialFunc)

SetDirectDialer installs the global direct-connection function. Called once at agent startup; the port forwarder checks it for every accepted connection.

func StopForward

func StopForward(localPort uint16)

StopForward stops and removes a port forward

func StopForwardIfMatch added in v0.31.0

func StopForwardIfMatch(localPort uint16, expected *ForwardInfo) bool

StopForwardIfMatch stops the port forward at localPort only if the entry currently in the map is the same instance as expected. Returns true if stopped, false otherwise.

This is used by forward cleanup goroutines to avoid deleting a replacement forward that was installed on the same local port after the goroutine's own forward was already torn down by a new forward request.

func StoreListener

func StoreListener(localPort uint16, listener net.Listener)

StoreListener stores the listener for a port forward (called after listener is created)

func UnmarkPersistent added in v0.24.0

func UnmarkPersistent(localPort uint16)

UnmarkPersistent removes the persistent mark from a port forward.

Types

type DirectDialFunc added in v0.31.0

type DirectDialFunc func(ctx context.Context, conn net.Conn, space string, remotePort uint16) error

DirectDialFunc attempts to forward a connection directly to a peer agent. Returns nil if the connection was fully handled (caller should close the local conn). Returns non-nil error if direct failed and the caller should fall back to relay.

type ForwardInfo

type ForwardInfo struct {
	LocalPort  uint16
	Space      string
	RemotePort uint16

	Cancel   context.CancelFunc
	Listener net.Listener
	// contains filtered or unexported fields
}

ForwardInfo holds information about an active port forward

func FindForwardBySpace added in v0.31.0

func FindForwardBySpace(space string) *ForwardInfo

FindForwardBySpace returns the first forward targeting the given space.

func GetForward

func GetForward(localPort uint16) (*ForwardInfo, bool)

GetForward returns info about a specific port forward

func ListForwards

func ListForwards() []*ForwardInfo

ListForwards returns all active port forwards

func StartForward

func StartForward(localPort, remotePort uint16, space string, cancel context.CancelFunc) *ForwardInfo

StartForward starts a new port forward and returns the info

func (*ForwardInfo) GetMode added in v0.31.0

func (f *ForwardInfo) GetMode() string

GetMode returns the current connection mode (thread-safe).

func (*ForwardInfo) GetThrottle added in v0.31.0

func (f *ForwardInfo) GetThrottle() (latencyMs, jitterMs, bandwidthKB, timeoutMs int, down bool)

GetThrottle returns the current throttle settings.

func (*ForwardInfo) HasThrottle added in v0.31.0

func (f *ForwardInfo) HasThrottle() bool

HasThrottle reports whether any throttle setting is active.

func (*ForwardInfo) SetMode added in v0.31.0

func (f *ForwardInfo) SetMode(mode string)

SetMode sets the connection mode (thread-safe).

func (*ForwardInfo) SetThrottle added in v0.31.0

func (f *ForwardInfo) SetThrottle(latencyMs, jitterMs, bandwidthKB, timeoutMs int, down bool)

SetThrottle applies latency, jitter, and/or bandwidth limits to an existing forward. All values are optional; pass 0 to clear any individual setting. A new limiter is created on each call.

Jump to

Keyboard shortcuts

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