clis

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: May 20, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ManagerTransport *managerTransport
View Source
var TunnelsClient = make(map[lang.TunnelType]FactoryFun)

TunnelsClient at all tunnel tunnel by map.

Functions

func GetTunnelClients

func GetTunnelClients() map[lang.TunnelType]FactoryFun

GetTunnelClients returns a map of tunnel types to their corresponding factory functions This function provides access to the available tunnel client implementations

func InitManagerTransport

func InitManagerTransport(transport *Transport)

InitManagerTransport This function initializes the ManagerTransport with a given transport

func NewManagerTransport

func NewManagerTransport(tr *Transport) *managerTransport

NewManagerTransport This function creates a new managerTransport object and returns it

func RegisterTunnelClient

func RegisterTunnelClient(name lang.TunnelType, factory FactoryFun)

RegisterTunnelClient registers a tunnel client factory for a specific tunnel type This function allows the system to create and manage different types of tunnel clients

Parameters:

name - the type of tunnel client to register (utils.TunnelType)
factory - the factory function that creates instances of the tunnel client (FactoryFun)

Types

type BaseClientHandler

type BaseClientHandler struct {
}

func (BaseClientHandler) Close

func (b BaseClientHandler) Close(*ClientControl)

func (BaseClientHandler) Connection

func (b BaseClientHandler) Connection(*ClientControl)

Connection successful.

func (BaseClientHandler) Error

func (BaseClientHandler) Read

func (BaseClientHandler) Reconnect

func (b BaseClientHandler) Reconnect(v *ClientControl)

Reconnect successful.

func (BaseClientHandler) Timeout

func (b BaseClientHandler) Timeout(*ClientControl)

type BaseTunnelClient

type BaseTunnelClient struct {
	TcControl *TunnelClientControl

	DoOpen func(stream *transport.SChannel) error

	DoRelease func(stream *transport.SChannel) error
	// contains filtered or unexported fields
}

BaseTunnelClient provides a base implementation of the TunnelClient interface.

func NewBaseTunnelClient

func NewBaseTunnelClient(cfg *configs.ClientTunnelConfig, isRetryOpen bool) *BaseTunnelClient

NewBaseTunnelClient creates a new BaseTunnelClient instance with the provided configuration and determines if it should be automatically opened.

Parameters:

  • cfg: A pointer to ClientTunnelConfig containing the tunnel configuration
  • isAutoOpen: A boolean flag indicating whether the tunnel should be opened automatically

Returns:

  • A pointer to the newly created BaseTunnelClient instance

func (*BaseTunnelClient) AddReadHandler

func (b *BaseTunnelClient) AddReadHandler(cmd exchange.Cmd, read exchange.BucketRead)

AddReadHandler adds a read handler for a specific command to the tunnel client Parameters:

  • cmd: The command type to handle
  • read: The read handler function that processes the command

func (*BaseTunnelClient) AsyncRegister

func (b *BaseTunnelClient) AsyncRegister(req exchange.InBound, readCallBack exchange.BucketRead) error

AsyncRegister is an asynchronous method that registers a callback handler for incoming messages and sends a registration request to the server

Parameters:

readCallBack: A callback function of type exchange.BucketRead that will be invoked
             when messages are received for this client

Returns:

error: Any error that occurred during the registration process, or nil if successful

func (*BaseTunnelClient) Close

func (b *BaseTunnelClient) Close()

func (*BaseTunnelClient) Done

func (b *BaseTunnelClient) Done() <-chan struct{}

func (*BaseTunnelClient) GetCfg

GetCfg is get cfg GetCfg retrieves the client tunnel configuration from the BaseTunnelClient This method provides read-only access to the tunnel configuration

func (*BaseTunnelClient) GetName

func (b *BaseTunnelClient) GetName() string

GetName is get name GetName is a method of BaseTunnelClient struct that returns the name of the client It takes no parameters and returns a string value

func (*BaseTunnelClient) GetRegisterReq

func (b *BaseTunnelClient) GetRegisterReq() *exchange.RegisterReqAndRsp

GetRegisterReq returns a RegisterReqAndRsp struct with configuration data from the BaseTunnelClient This method is used to prepare registration request parameters for the tunnel connection

func (*BaseTunnelClient) Open

func (b *BaseTunnelClient) Open(session *smux.Session) error

func (*BaseTunnelClient) OpenStream

func (b *BaseTunnelClient) OpenStream() error

OpenStream opens a new stream for the BaseTunnelClient It handles both automatic and manual stream opening based on the IsAutoOpen flag

func (*BaseTunnelClient) OpenWorker

func (b *BaseTunnelClient) OpenWorker(rsp *exchange.RegisterReqAndRsp, isToManager bool) (err error)

func (*BaseTunnelClient) OpenWorkerToManager

func (b *BaseTunnelClient) OpenWorkerToManager(rsp *exchange.RegisterReqAndRsp) (err error)

func (*BaseTunnelClient) OpenWorkerToSchannel

func (b *BaseTunnelClient) OpenWorkerToSchannel(rsp *exchange.RegisterReqAndRsp) (err error)

func (*BaseTunnelClient) Register

Register is a method of BaseTunnelClient that handles the registration process It sends a registration request and processes the response Returns the registration result or an error if any step fails

type CheckHandler

type CheckHandler struct {
	BaseClientHandler
	// contains filtered or unexported fields
}

func (*CheckHandler) Close

func (b *CheckHandler) Close(*ClientControl)

func (*CheckHandler) Read

func (b *CheckHandler) Read(r *exchange.Protocol, cct *ClientControl) error

func (*CheckHandler) Timeout

func (b *CheckHandler) Timeout(cct *ClientControl)

type Client

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

Client @Description: Define Client.

func NewClient

func NewClient(host string, port int) *Client

NewClient creates a new Client instance with the provided host and port. It initializes the client's context, ID, and control channels. Parameters:

  • host: The server host address.
  • port: The server port number.

Return Returns:

  • *Client: A pointer to the newly created Client instance.

func (*Client) AddHandler

func (c *Client) AddHandler(h ...ClientHandler)

func (*Client) Connection

func (c *Client) Connection(network string, option ...ClientOption) error

func (*Client) GetConn

func (c *Client) GetConn() net.Conn

func (*Client) GetHost

func (c *Client) GetHost() string

func (*Client) GetID

func (c *Client) GetID() int32

func (*Client) GetPort

func (c *Client) GetPort() int

func (*Client) IsConnection

func (c *Client) IsConnection() bool

IsConnection checks if the client connection is active and in the correct state This method is used to verify whether the client has an active connection

Parameters:

  • None

Returns:

  • bool: Returns true if connection exists and is in Active state, false otherwise

func (*Client) OpenTunnel

func (c *Client) OpenTunnel(config *configs.ClientTunnelConfig) error

func (*Client) Reconnection

func (c *Client) Reconnection() error

Reconnection is

type ClientControl

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

func (*ClientControl) Close

func (c *ClientControl) Close()

func (*ClientControl) Error

func (c *ClientControl) Error(err error)

func (*ClientControl) Write

func (c *ClientControl) Write(bytes []byte) error

type ClientHandler

type ClientHandler interface {
	Close(cct *ClientControl)
	Connection(cct *ClientControl)
	Read(buffer *exchange.Protocol, cct *ClientControl) error
	Error(err error, cct *ClientControl)
	Timeout(cct *ClientControl)
	Reconnect(cct *ClientControl)
}

type ClientOption

type ClientOption func(*cOptions)

func WithClientHandler

func WithClientHandler(handler ...ClientHandler) ClientOption

func WithClientSmux

func WithClientSmux(opt *SmuxClientOption) ClientOption

func WithKeepAlive

func WithKeepAlive(t time.Duration) ClientOption

func WithPingTime

func WithPingTime(t time.Duration) ClientOption

func WithTimeout

func WithTimeout(t time.Duration) ClientOption

type ClientScheduler

type ClientScheduler struct {
}

func (*ClientScheduler) Next

func (t *ClientScheduler) Next(t2 time.Time) time.Time

type ClientState

type ClientState int
const (
	NotAction ClientState = 0

	Closed ClientState = 1

	Active ClientState = 2

	OpenSession ClientState = 3
)

func (ClientState) String

func (i ClientState) String() string

type CmdNotify

type CmdNotify func(*exchange.Protocol) error

type FactoryFun

type FactoryFun func(config *configs.ClientTunnelConfig) TunnelClient

FactoryFun New tunnel client.

type ReconnectFunction

type ReconnectFunction func() bool

type ReconnectManager

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

func NewReconnectionManager

func NewReconnectionManager(t time.Duration) *ReconnectManager

func (*ReconnectManager) TryReconnect

func (r *ReconnectManager) TryReconnect(rf ReconnectFunction)

type SmuxClientOption

type SmuxClientOption struct {
	// enable smux client.
	Enable bool

	KeepAlive bool

	Timeout time.Duration
}

func NewSmuxClientOption

func NewSmuxClientOption() *SmuxClientOption

type Transport

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

Transport @Description:Transport manages client and request tracking.

func NewTransport

func NewTransport(config *configs.ClientConfig) *Transport

NewTransport

@Description: Init Transport.
@param ct
@return Transport

func (*Transport) Close

func (t *Transport) Close()

Close closes the transport by closing the underlying client connection. It ensures proper cleanup of resources associated with the transport.

func (*Transport) Connection

func (t *Transport) Connection(opts ...ClientOption)

Connection establishes a new connection with the server using the provided options It sets up a new client, adds a handler for checking the connection, and either adds the transport to a reconnection list or opens a tunnel based on the connection result

func (*Transport) SyncWrite

func (t *Transport) SyncWrite(message exchange.InBound, timeout time.Duration) (*exchange.Protocol, error)

type TunnelClient

type TunnelClient interface {
	// GetName returns the name of the tunnel client.
	// Returns:
	//   - string: The name of the tunnel client.
	GetName() string

	// Open Active opens a tunnel using the provided session.
	// Parameters:
	//   - session: The smux session to use.
	// Returns:
	//   - error: An error if the tunnel could not be opened.
	Open(session *smux.Session) error

	Done() <-chan struct{}

	// Close closes the tunnel.
	Close()
}

TunnelClient defines the interface for a tunnel client.

func GetTunnelClient

func GetTunnelClient(name lang.TunnelType, config *configs.ClientTunnelConfig) TunnelClient

GetTunnelClient creates and returns a tunnel client based on the provided tunnel type and configuration Parameters:

  • name: The type of tunnel to create (utils.TunnelType)
  • configs: Configuration for the tunnel client (configs.ClientTunnelConfig)

Returns:

  • TunnelClient: The created tunnel client instance, or nil if the tunnel type is not supported

type TunnelClientControl

type TunnelClientControl struct {
	Bucket *exchange.MessageBucket
	// contains filtered or unexported fields
}

func (*TunnelClientControl) Cancel

func (receiver *TunnelClientControl) Cancel()

Cancel cancels the tunnel client operation by calling the underlying cancel function. It takes a receiver of type TunnelClientControl as a pointer to modify the instance.

func (*TunnelClientControl) Context

func (receiver *TunnelClientControl) Context() context.Context

Context returns the context associated with the TunnelClientControl. This context can be used to track the lifecycle of the tunnel client and to cancel operations if needed.

Parameters:

receiver - A pointer to the TunnelClientControl instance on which the method is called

Returns:

context.Context - The context associated with the TunnelClientControl

Jump to

Keyboard shortcuts

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