api

package
v0.2.0-dev.1 Latest Latest
Warning

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

Go to latest
Published: May 10, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrConnectionClosed    = errors.New("connection closed")
	ErrCtrlInvalidResponse = errors.New("invalid response on control channel")
	ErrInvalidMessageType  = errors.New("invalid message type")
	ErrInvalidPort         = errors.New("invalid port")
	ErrInvalidStreamType   = errors.New("invalid stream type")
	ErrInvalidStreamID     = errors.New("invalid stream id")
	ErrSessionTimeout      = errors.New("timeout getting session")
	ErrListenerStopped     = errors.New("listener stopped")
	ErrInvalidConnection   = errors.New("invalid connection")
)

Functions

This section is empty.

Types

type AddPortRequestMessage

type AddPortRequestMessage struct {
	Type          string `json:"type"`
	ID            string `json:"id"`
	RequestedPort int    `json:"port"`
}

type AddPortResponseMessage

type AddPortResponseMessage struct {
	Type         string `json:"tcp"`
	ID           string `json:"id"`
	AssignedPort int    `json:"port"`
	Address      string `json:"address"`
}

type Client

type Client interface {
	Connect(ctx context.Context) error
	AddTCPPort(id string, requestedPort int) (net.Listener, error)
}

type ControlStream

type ControlStream interface {
	Stream
	AddMessageHandler(messageType MessageType, handler MessageHandler)
}

type Dialer

type Dialer interface {
	DialContext(ctx context.Context, network, address string) (net.Conn, error)
}

type Message

type Message struct {
	ID   string      `json:"id"`
	Type MessageType `json:"type"`
	Data []byte      `json:"data"`
}

func CreateMessage

func CreateMessage(messageType MessageType, message interface{}) (Message, []byte, error)

func CreateMessageWithID

func CreateMessageWithID(id string, messageType MessageType, message interface{}) (Message, []byte, error)

func SendMessage

func SendMessage(writeTo io.Writer, messageType MessageType, message interface{}) (Message, []byte, error)

func (Message) Decode

func (m Message) Decode(v any) error

type MessageHandler

type MessageHandler func(msg []byte) error

type MessageType

type MessageType string
const (
	OpenTCPStreamMessageType     MessageType = "openTCPStream"
	OpenControlStreamMessageType MessageType = "openControlStream"
	AddPortMessageType           MessageType = "addPort"
	AddPortResponseMessageType   MessageType = "addPortResponse"
	PongMessageType              MessageType = "pong"
	PingMessageType              MessageType = "ping"
	RequestConnectionMessageType MessageType = "requestConnection"
	StreamOpenedMessageType      MessageType = "streamOpened"

	ErrCtrlStreamAlreadyExistsMessageType MessageType = "errCtrlStreamAlreadyExists"
	ErrInvalidStreamTypeMessageType       MessageType = "errInvalidStreamType"
	ErrInvalidStreamIDMessageType         MessageType = "errInvalidStreamID"
)

type OpenTCPStreamMessage

type OpenTCPStreamMessage struct {
	ID string `json:"id"`
}

type PortProvider

type PortProvider interface {
	GetFreePort() int
	GetPort(port int) bool
	ReleasePort(int)
}

type RequestConnectionMessage

type RequestConnectionMessage struct {
	PortID        string `json:"portID"`
	Identifier    string `json:"identifier"`
	RemoteAddress string `json:"remoteAddress"`
	LocalAddress  string `json:"localAddress"`
}

type Server

type Server interface {
	Start(ctx context.Context) error
}

type Session

type Session interface {
	Close() error
	Handle() error
	GetControlStream() io.ReadWriter
	OpenTCPStream(id string) (net.Conn, error)
}

type Stream

type Stream interface {
	io.ReadWriteCloser
	Handle() error
}

Jump to

Keyboard shortcuts

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