transport

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2026 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Overview

Package transport provides the direct and agent network dialers.

Package transport builds the NetTransport a plugin uses to reach its target. Connectivity is orthogonal to protocol: "direct" dials out from the gateway, "agent" dials through a reverse tunnel registered by an in-target agent.

Index

Constants

View Source
const (
	AgentModeTCP         = "tcp"
	AgentModeUnix        = "unix"
	AgentModeHTTP        = "http_proxy"
	AgentModeHostMonitor = "host_monitor"
)

Agent proxy mode wire values, mirroring plugin.AgentMode. They live here so the standalone agent binary depends only on this package, not internal/plugin.

Variables

View Source
var ErrAgentUnavailable = errors.New("transport: agent tunnel unavailable")

ErrAgentUnavailable is returned when an agent-transport connection has no live tunnel registered (the agent has not connected, or has gone offline).

Functions

func Build

Build returns the NetTransport for a connection.

func ReadStreamTarget

func ReadStreamTarget(r io.Reader) (network, addr string, err error)

ReadStreamTarget reads a target preamble written by WriteStreamTarget.

func ServeGatewayTunnel

func ServeGatewayTunnel(c *websocket.Conn, connectionID string, reg *Registry, forward bool) error

ServeGatewayTunnel runs the gateway side of an agent tunnel over an already authenticated WebSocket. The gateway is the yamux *client* (it opens a stream per upstream dial); the in-target agent is the yamux *server* (it accepts each stream and proxies it to the declared target). The connection's dialer is registered for the lifetime of the tunnel and removed when it closes.

It blocks until the tunnel is torn down.

func WriteStreamTarget

func WriteStreamTarget(w io.Writer, network, addr string) error

WriteStreamTarget prefixes a forward-mode stream with the address the agent should dial: a 2-byte length then "network\x00addr".

Types

type AgentConnectResponse

type AgentConnectResponse struct {
	OK    bool             `json:"ok"`
	Error string           `json:"error,omitempty"`
	Proxy AgentProxyTarget `json:"proxy,omitzero"`
}

AgentConnectResponse is the gateway's reply to AgentHello. On OK the tunnel switches to multiplexed streaming; otherwise the agent disconnects.

type AgentHello

type AgentHello struct {
	Token   string `json:"token"`
	Forward bool   `json:"forward,omitempty"`
}

AgentHello is the first message an agent sends on the connect WebSocket, presenting its enrollment token (never in the URL or query). Forward advertises that the agent understands a per-stream target preamble (see WriteStreamTarget).

type AgentProxyTarget

type AgentProxyTarget struct {
	Mode      string `json:"mode"`
	Address   string `json:"address"`
	TokenFile string `json:"tokenFile,omitempty"`
	CAFile    string `json:"caFile,omitempty"`
	// Forward: each L4 stream begins with a target preamble the agent dials
	// instead of Address. Set only when the plugin opted in and the agent supports it.
	Forward bool `json:"forward,omitempty"`
}

AgentProxyTarget tells the agent what local endpoint to expose back. The L7 (http_proxy) fields are generic credential-injection knobs: a token file to turn into a bearer header and a CA file to verify the upstream — no protocol vocabulary, so the agent stays plugin-agnostic.

type DialFunc

type DialFunc func(ctx context.Context, network, addr string) (net.Conn, error)

DialFunc is a context-aware L4 dialer.

type Direct

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

Direct dials the target straight from the gateway.

func NewDirect

func NewDirect() *Direct

NewDirect returns a direct transport with a sane dial timeout.

func NewDirectForConnection

func NewDirectForConnection(conn models.Connection) *Direct

func (*Direct) DialContext

func (d *Direct) DialContext(ctx context.Context, network, addr string) (net.Conn, error)

DialContext dials the requested address directly.

func (*Direct) HTTP

func (d *Direct) HTTP() (string, http.RoundTripper, bool)

HTTP reports ok=false for direct transport.

type Registry

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

Registry is the concurrent in-memory tunnel registry.

func NewRegistry

func NewRegistry() *Registry

NewRegistry returns an empty tunnel registry.

func (*Registry) Dialer

func (r *Registry) Dialer(connectionID string) (DialFunc, bool)

Dialer returns the registered dialer for a connection, if any.

func (*Registry) Register

func (r *Registry) Register(connectionID string, dial DialFunc) (release func())

Register binds an agent dialer and returns a release func for this registration.

func (*Registry) Remove

func (r *Registry) Remove(connectionID string)

Remove drops a connection's tunnel unconditionally (e.g. on revocation).

type TunnelRegistry

type TunnelRegistry interface {
	Dialer(connectionID string) (DialFunc, bool)
}

TunnelRegistry resolves a live agent dialer for a connection.

Jump to

Keyboard shortcuts

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