forward

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: AGPL-3.0 Imports: 12 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 runs port forwards over SSH: local (ssh -L), remote (ssh -R) and dynamic (ssh -D, a local HTTP/SOCKS proxy whose targets are dialed, and their names resolved, on the server). A forward rides a session without a shell, so it shares the host's pooled connection with the host's terminals and reconnects with the session's backoff.

Index

Constants

This section is empty.

Variables

View Source
var ErrPortInUse = errors.New("forward: port already in use")

ErrPortInUse is a local port another program listens on.

Functions

This section is empty.

Types

type Forward

type Forward struct {

	// Conns are the connections relayed now.
	Conns *netproxy.Registry
	// contains filtered or unexported fields
}

Forward is one running rule. It is safe for concurrent use.

func New

func New(r Rule, cfg session.Config, opts session.Options) *Forward

New returns a forward of r that connects as cfg says; Start runs it. opts.NoShell is set, and reconnecting is endless.

func (*Forward) Rule

func (f *Forward) Rule() Rule

Rule is the forward's rule.

func (*Forward) Session

func (f *Forward) Session() *session.Session

Session is the session the forward rides, for prompts and Reconnect.

func (*Forward) SetOnChange

func (f *Forward) SetOnChange(fn func())

SetOnChange sets fn to be called, from any goroutine, when the status or the connections change.

func (*Forward) Start

func (f *Forward) Start() error

Start listens (Local, Dynamic) and connects. A local port in use is returned at once, as ErrPortInUse, and the forward is in Error.

func (*Forward) Status

func (f *Forward) Status() Status

Status is the forward's status.

func (*Forward) Stop

func (f *Forward) Stop()

Stop ends the forward and every connection it relays. It does not wait on the network: the local port is free when it returns.

type Kind

type Kind int

Kind is the kind of forward.

const (
	Local Kind = iota
	Remote
	Dynamic
)

type RemoteRefusedError

type RemoteRefusedError struct {
	Addr string
	Err  error
}

RemoteRefusedError is a server that would not listen for a remote forward.

func (*RemoteRefusedError) Error

func (e *RemoteRefusedError) Error() string

func (*RemoteRefusedError) Unwrap

func (e *RemoteRefusedError) Unwrap() error

type Rule

type Rule struct {
	Kind Kind
	// Listen is host:port: on this computer for Local and Dynamic, on the
	// server for Remote.
	Listen string
	// Target is host:port: seen from the server for Local, from this
	// computer for Remote; unused for Dynamic.
	Target string
	// Protocol limits a dynamic forward's proxy; netproxy.Auto takes all.
	Protocol netproxy.Protocol
	// User and Password, when User is set, are asked of a dynamic
	// forward's HTTP and SOCKS5 clients.
	User, Password string
}

Rule is what a forward does.

type State

type State int

State is a forward's state.

const (
	Stopped State = iota
	Connecting
	Running
	Reconnecting
	Error
)

func (State) String

func (s State) String() string

type Status

type Status struct {
	State State
	Err   error
	Conns int
	// Session is the underlying session's status (the hop being
	// dialed, the reconnect attempt).
	Session session.Status
}

Status is a forward's state for the UI: why it is in Error, and how many connections it relays.

Jump to

Keyboard shortcuts

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