tunnel

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConnectionState

type ConnectionState int

ConnectionState represents the state of the SSH tunnel. It's returned to an optional function provided to SetConnState.

const (
	// StateStopped represents a stopped tunnel. A call to Start will make the state to transition to StateStarting.
	StateStopped ConnectionState = iota

	// StateStarting represents a tunnel initializing and preparing to listen for connections.
	// A successful initialization will make the state to transition to StateStarted, otherwise it will transition to StateStopped.
	StateStarting

	// StateStarted represents a tunnel ready to accept connections.
	// A call to stop or an error will make the state to transition to StateStopped.
	StateStarted
)

type Endpoint

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

func NewTCPEndpoint

func NewTCPEndpoint(host string, port int) *Endpoint

func NewUnixEndpoint

func NewUnixEndpoint(socket string) *Endpoint

func (*Endpoint) String

func (e *Endpoint) String() string

func (*Endpoint) Type

func (e *Endpoint) Type() string

type SshTunnel

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

func New

func New(tsnetConn *tsnet.Server, localPort int, server string, serverPort, remotePort int) *SshTunnel

New creates a new SSH tunnel to the specified server redirecting a port on local localhost to a port on remote localhost. The states of the tunnel can be received through a callback function with SetConnState. The states of the tunneled connections can be received through a callback function with SetTunneledConnState.

func NewUnix

func NewUnix(tsnetConn *tsnet.Server, localUnixSocket, server string, serverPort int, remoteUnixSocket string) *SshTunnel

NewUnix does the same as New but using unix sockets.

func (*SshTunnel) SetConnState

func (tun *SshTunnel) SetConnState(connStateFun func(*SshTunnel, ConnectionState))

SetConnState specifies an optional callback function that is called when a SSH tunnel changes state. See the ConnState type and associated constants for details.

func (*SshTunnel) SetTunneledConnState

func (tun *SshTunnel) SetTunneledConnState(tunneledConnStateFun func(*SshTunnel, *TunneledConnectionState))

SetTunneledConnState specifies an optional callback function that is called when the underlying tunneled connections change state.

func (*SshTunnel) Start

func (tun *SshTunnel) Start(ctx context.Context) error

Start starts the SSH tunnel. It can be stopped by calling `Stop` or cancelling its context. This call will block until the tunnel is stopped either calling those methods or by an error.

func (*SshTunnel) Stop

func (tun *SshTunnel) Stop()

Stop closes all connections and makes Start exit gracefuly.

type TunneledConnectionState

type TunneledConnectionState struct {
	// From is the address initating the connection.
	From string
	// Info holds a message with info on the state of the connection (useful for debug purposes).
	Info string
	// Error holds an error on the connection or nil if the connection is successful.
	Error error
	// Ready indicates if the connection is established.
	Ready bool
	// Closed indicates if the coonnection is closed.
	Closed bool
}

TunneledConnectionState represents the state of the final connections made through the tunnel.

func (*TunneledConnectionState) String

func (s *TunneledConnectionState) String() string

Jump to

Keyboard shortcuts

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