forward

package
v2.6.2 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2026 License: MIT Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package forward carries TCP from a port on the control plane to a service that only listens on a target's localhost.

An agent's dev server, a database console, a noVNC desktop: all of them bind to loopback on the machine the agent runs on, which is not the machine the operator is sitting at. A path-prefix HTTP proxy breaks real applications — absolute asset paths, redirects, websockets — so this forwards the port itself, and every protocol passes through unmodified.

A forward makes a loopback-only service reachable by whoever can reach the control plane, so it is always explicit, always listed, and always temporary.

Index

Constants

This section is empty.

Variables

View Source
var ErrFull = errors.New("no free forwarding port; stop one that is no longer needed")

ErrFull means every port in the range is taken.

Functions

This section is empty.

Types

type Dial

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

Dial opens a connection to addr as the target sees it.

type Forward

type Forward struct {
	ID         int64   `json:"id"`
	Kind       string  `json:"kind"` // port | desktop
	Title      string  `json:"title"`
	TargetID   int64   `json:"target_id"`
	TargetName string  `json:"target_name"`
	SessionID  *int64  `json:"session_id"`
	Port       int     `json:"port"`        // on the target's loopback
	ListenPort int     `json:"listen_port"` // on the control plane
	CreatedAt  float64 `json:"created_at"`
	ExpiresAt  float64 `json:"expires_at"`
	Conns      int64   `json:"connections"` // a snapshot; the live count is conns
	// Detail carries what a kind needs shown beside it, e.g. a desktop's DISPLAY.
	Detail map[string]string `json:"detail,omitempty"`
	// contains filtered or unexported fields
}

Forward is one open port.

type Manager

type Manager struct {
	BindHost string
	PortLo   int
	PortHi   int
	// contains filtered or unexported fields
}

Manager owns every open forward. They live in memory: a restart closes them all, which is the right default for something that widens what is reachable.

func New

func New(bindHost string, lo, hi int) *Manager

New builds a manager listening on bindHost within [lo, hi].

func (*Manager) Close

func (m *Manager) Close(id int64) bool

Close stops one forward and reports whether it existed.

func (*Manager) CloseAll

func (m *Manager) CloseAll()

CloseAll stops everything; the server calls it on the way down.

func (*Manager) List

func (m *Manager) List() []*Forward

List is every open forward, oldest first.

func (*Manager) Open

func (m *Manager) Open(dial Dial, spec Spec) (*Forward, error)

Open starts listening and carries each connection to 127.0.0.1:spec.Port on the target. The destination is always loopback: this exists to reach what a target keeps to itself, not to make the control plane a way into its network.

func (*Manager) Reap

func (m *Manager) Reap(now float64, sessionEnded func(id int64) bool) []int64

Reap closes what has expired and whatever belongs to a session that ended. sessionEnded is asked only about forwards that name a session.

type Spec

type Spec struct {
	Kind       string
	Title      string
	TargetID   int64
	TargetName string
	SessionID  *int64
	Port       int
	TTL        time.Duration
	Detail     map[string]string
	// OnClose runs once when the forward goes away, however it goes away.
	OnClose func()
}

Spec is what to open.

Jump to

Keyboard shortcuts

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