Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MaintainTunnel ¶
func MaintainTunnel(ctx context.Context, cfg MaintainTunnelConfig)
MaintainTunnel continuously connects to the MASQUE server, then starts two forwarding goroutines: one forwarding from the device to the IP connection (and handling any ICMP reply), and the other forwarding from the IP connection to the device. If an error occurs in either loop, the connection is closed and a reconnect is attempted.
Parameters:
- ctx: context.Context - The context for the connection.
- cfg: MaintainTunnelConfig - Tunnel maintenance runtime configuration.
func RunHook ¶
RunHook executes the given path as a subprocess in a fire-and-forget manner.
The path is exec'd directly with no arguments and no shell, so the caller controls exactly what runs. The parent process's environment is inherited, with extraEnv layered on top (later entries win). stdout and stderr are captured and relayed to the standard logger, one line at a time, prefixed with the hook event (taken from extraEnv["USQUE_EVENT"] when present).
If path is empty, RunHook is a no-op. The function returns immediately; the subprocess and its log relays run in background goroutines.
Parameters:
- path: string - Absolute or $PATH-resolvable executable to run.
- extraEnv: map[string]string - Additional environment variables to expose.
Types ¶
type MaintainTunnelConfig ¶
type MaintainTunnelConfig struct {
TLSConfig *tls.Config
KeepalivePeriod time.Duration
InitialPacketSize uint16
Endpoint net.Addr
Device TunnelDevice
MTU int
ReconnectDelay time.Duration
AlwaysReconnect bool
UseHTTP2 bool
// OnConnect is a path to an executable run after every successful tunnel
// connect. It is exec'd directly (no shell, no args) and runs fire-and-forget.
OnConnect string
// OnDisconnect is a path to an executable run after every tunnel loss.
// It is exec'd directly (no shell, no args) and runs fire-and-forget.
OnDisconnect string
// HookEnv is a set of USQUE_* environment variables layered on top of the
// parent process env for OnConnect / OnDisconnect invocations. USQUE_EVENT
// and USQUE_ENDPOINT are set by MaintainTunnel itself.
HookEnv map[string]string
}
MaintainTunnelConfig contains runtime settings for tunnel maintenance.
type NetBuffer ¶
type NetBuffer struct {
// contains filtered or unexported fields
}
NetBuffer is a pool of byte slices with a fixed capacity. Helps to reduce memory allocations and improve performance. It uses a sync.Pool to manage the byte slices. The capacity of the byte slices is set when the pool is created.
func NewNetBuffer ¶
NewNetBuffer creates a new NetBuffer with the specified capacity. The capacity must be greater than 0.
type NetstackAdapter ¶
type NetstackAdapter struct {
// contains filtered or unexported fields
}
NetstackAdapter wraps a tun.Device (e.g. from netstack) to satisfy TunnelDevice.
func (*NetstackAdapter) ReadPacket ¶
func (n *NetstackAdapter) ReadPacket(buf []byte) (int, error)
func (*NetstackAdapter) WritePacket ¶
func (n *NetstackAdapter) WritePacket(pkt []byte) error
type TunnelDevice ¶
type TunnelDevice interface {
// ReadPacket reads a packet from the device (using the given mtu) and returns its contents.
ReadPacket(buf []byte) (int, error)
// WritePacket writes a packet to the device.
WritePacket(pkt []byte) error
}
TunnelDevice abstracts a TUN device so that we can use the same tunnel-maintenance code regardless of the underlying implementation.
func NewNetstackAdapter ¶
func NewNetstackAdapter(dev tun.Device) TunnelDevice
NewNetstackAdapter creates a new NetstackAdapter.