port

package
v0.0.0-...-955c50f Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: Apache-2.0 Imports: 33 Imported by: 1

Documentation

Overview

Package port implements session manager's port plugin

Package port implements session manager's port plugin

Package port implements session manager's port plugin.

Index

Constants

This section is empty.

Variables

View Source
var DialCall = func(context context.T, network string, host string, portNumber string, addressList []string) (string, net.Conn, error) {
	if host == "" {
		destinationAddress := net.JoinHostPort("localhost", portNumber)
		conn, err := net.Dial(network, destinationAddress)
		return destinationAddress, conn, err
	}
	context.Log().Debugf("Using remote host: %s", host)
	var firstErr error // The error from the first address is most relevant.
	for _, addr := range addressList {
		destinationAddress := net.JoinHostPort(addr, portNumber)
		conn, err := net.Dial(network, destinationAddress)
		if err == nil {
			return destinationAddress, conn, err
		}
		if firstErr == nil {
			firstErr = err
		}
	}
	if firstErr == nil {
		firstErr = errors.New("missing address")
	}
	return "", nil, firstErr
}

DialCall connects to a list of addresses in sequence, returning either the first successful connection, or the first error

View Source
var GetSession = func(context context.T, portParameters PortParameters, addresses []string, cancelled chan struct{}, clientVersion string, sessionId string) (session IPortSession, err error) {

	if portParameters.Type == mgsConfig.LocalPortForwarding &&
		versionutil.Compare(clientVersion, muxSupportedClientVersion, true) >= 0 {

		if session, err = NewMuxPortSession(context, clientVersion, cancelled, portParameters.Host, portParameters.PortNumber, addresses, sessionId); err == nil {
			return session, nil
		}
	} else {
		if session, err = NewBasicPortSession(context, cancelled, portParameters.Host, portParameters.PortNumber, addresses, portParameters.Type); err == nil {
			return session, nil
		}
	}
	return nil, err
}

GetSession initializes session based on the type of the port session mux for port forwarding session and if client supports multiplexing; basic otherwise

Functions

func NewPlugin

func NewPlugin(context context.T) (sessionplugin.ISessionPlugin, error)

NewPlugin NewPortPlugin returns a new instance of the Port Plugin.

Types

type BasicPortSession

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

BasicPortSession is the type for the port session. It supports only one connection to the destination server.

func (*BasicPortSession) HandleStreamMessage

func (p *BasicPortSession) HandleStreamMessage(streamDataMessage mgsContracts.AgentMessage) error

HandleStreamMessage passes payload byte stream to opened connection

func (*BasicPortSession) InitializeSession

func (p *BasicPortSession) InitializeSession() (err error)

InitializeSession dials a connection to port

func (*BasicPortSession) IsConnectionAvailable

func (p *BasicPortSession) IsConnectionAvailable() bool

IsConnectionAvailable returns a boolean value indicating the availability of connection to destination

func (*BasicPortSession) Stop

func (p *BasicPortSession) Stop()

Stop closes the TCP Connection to port

func (*BasicPortSession) WritePump

func (p *BasicPortSession) WritePump(dataChannel datachannel.IDataChannel) (errorCode int)

WritePump reads from the instance's port and writes to datachannel

type IPortSession

type IPortSession interface {
	InitializeSession() (err error)
	HandleStreamMessage(streamDataMessage mgsContracts.AgentMessage) (err error)
	WritePump(channel datachannel.IDataChannel) (errorCode int)
	IsConnectionAvailable() (isAvailable bool)
	Stop()
}

IPortSession interface represents functions that need to be implemented by all port sessions

func NewBasicPortSession

func NewBasicPortSession(context context.T, cancelled chan struct{}, host string, portNumber string, addressList []string, portType string) (IPortSession, error)

NewBasicPortSession returns a new instance of the BasicPortSession.

func NewMuxPortSession

func NewMuxPortSession(context agentContext.T, clientVersion string, cancelled chan struct{}, host string, portNumber string, addressList []string, sessionId string) (IPortSession, error)

NewMuxPortSession returns a new instance of the MuxPortSession.

type MgsConn

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

MgsConn contains local server and corresponding server side connection to smux server

type MuxPortSession

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

MuxPortSession is the type for the multiplexer port session. supports making multiple connections to the destination server.

func (*MuxPortSession) HandleStreamMessage

func (p *MuxPortSession) HandleStreamMessage(streamDataMessage mgsContracts.AgentMessage) error

HandleStreamMessage passes payload byte stream to smux server

func (*MuxPortSession) InitializeSession

func (p *MuxPortSession) InitializeSession() (err error)

InitializeSession initializes MuxPortSession

func (*MuxPortSession) IsConnectionAvailable

func (p *MuxPortSession) IsConnectionAvailable() bool

IsConnectionAvailable returns a boolean value indicating the availability of connection to destination

func (*MuxPortSession) Stop

func (p *MuxPortSession) Stop()

Stop closes all opened connections on instance

func (*MuxPortSession) WritePump

func (p *MuxPortSession) WritePump(dataChannel datachannel.IDataChannel) (errorCode int)

WritePump handles communication between <smux server, datachannel> and <smux server, destination server>

type MuxServer

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

MuxServer contains smux server session and corresponding network connection

type PortParameters

type PortParameters struct {
	Host       string `json:"host" yaml:"host"`
	PortNumber string `json:"portNumber" yaml:"portNumber"`
	Type       string `json:"type"`
}

PortParameters contains inputs required to execute port plugin.

type PortPlugin

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

PortPlugin is the type for the port plugin.

func (*PortPlugin) Execute

func (p *PortPlugin) Execute(
	config agentContracts.Configuration,
	cancelFlag task.CancelFlag,
	output iohandler.IOHandler,
	dataChannel datachannel.IDataChannel)

Execute establishes a connection to a specified port from the parameters It reads incoming messages from the data channel and writes to the port It reads from the port and writes to the data channel

func (*PortPlugin) GetPluginParameters

func (p *PortPlugin) GetPluginParameters(parameters interface{}) interface{}

GetPluginParameters Returns parameters required for CLI to start session

func (*PortPlugin) InputStreamMessageHandler

func (p *PortPlugin) InputStreamMessageHandler(log log.T, streamDataMessage mgsContracts.AgentMessage) error

InputStreamMessageHandler passes payload byte stream to port

func (*PortPlugin) RequireHandshake

func (p *PortPlugin) RequireHandshake() bool

RequireHandshake Port plugin requires handshake to establish session

Directories

Path Synopsis
Code generated by mockery v1.0.0.
Code generated by mockery v1.0.0.

Jump to

Keyboard shortcuts

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