relay

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2025 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MessageTypeHello             = "hello"
	MessageTypeAuth              = "auth"
	MessageTypeAuthResponse      = "auth_response"
	MessageTypeTunnelInfo        = "tunnel_info"
	MessageTypeTunnelResponse    = "tunnel_response"
	MessageTypeHeartbeat         = "heartbeat"
	MessageTypeHeartbeatResponse = "heartbeat_response"
	MessageTypeError             = "error"

	MaxMessageSize      = 1024 * 1024 // 1MB
	ConnectTimeout      = 10 * time.Second
	ReadWriteTimeout    = 30 * time.Second
	HeartbeatInterval   = 30 * time.Second
	HeartbeatTimeout    = 5 * time.Second
	MaxMissedHeartbeats = 3
)

Message types

Variables

This section is empty.

Functions

func HealthCheckHandler

func HealthCheckHandler(w http.ResponseWriter, r *http.Request)

HealthCheckHandler обрабатывает запросы к /health

func NewTLSConfig

func NewTLSConfig(certFile, keyFile, caFile string) (*tls.Config, error)

NewTLSConfig creates a new TLS configuration

func RecordConnection

func RecordConnection(duration float64)

RecordConnection records a new connection

func RecordError

func RecordError(code string)

RecordError records an error

func RecordHeartbeat

func RecordHeartbeat(latency float64)

RecordHeartbeat records a heartbeat

func RecordMissedHeartbeat

func RecordMissedHeartbeat()

RecordMissedHeartbeat records a missed heartbeat

func SetActiveTunnels

func SetActiveTunnels(count int)

SetActiveTunnels sets the number of active tunnels

func UpdateHealthStatus

func UpdateHealthStatus(status string)

UpdateHealthStatus обновляет статус здоровья

Types

type Client

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

Client represents a CloudBridge Relay client

func NewClient

func NewClient(useTLS bool, tlsConfig *tls.Config) *Client

NewClient creates a new CloudBridge Relay client

func NewClientFromConfig

func NewClientFromConfig(cfg *config.Config) (*Client, error)

NewClientFromConfig creates a new client from config

func NewClientV1

func NewClientV1(useTLS bool, tlsConfig *tls.Config) *Client

NewClientV1 creates a new CloudBridge Relay client for v1.0.0 (backward compatibility)

func (*Client) Close

func (c *Client) Close() error

Close closes the connection to the relay server

func (*Client) Connect

func (c *Client) Connect(host string, port int) error

Connect establishes a connection to the relay server

func (*Client) CreateTunnel

func (c *Client) CreateTunnel(localPort int, remoteHost string, remotePort int) (string, error)

CreateTunnel creates a new tunnel

func (*Client) GetFeatures

func (c *Client) GetFeatures() []string

GetFeatures returns the supported features

func (*Client) GetTenantID

func (c *Client) GetTenantID() string

GetTenantID returns the current tenant ID

func (*Client) GetVersion

func (c *Client) GetVersion() string

GetVersion returns the protocol version

func (*Client) Handshake

func (c *Client) Handshake(token string) error

Handshake: ждет hello, отправляет auth, ждет auth_response

func (*Client) IsConnected

func (c *Client) IsConnected() bool

IsConnected returns true if the client is connected

func (*Client) ReadMessage

func (c *Client) ReadMessage() (map[string]interface{}, error)

ReadMessage читает строку, парсит JSON, ограничивает размер

func (*Client) SendMessage

func (c *Client) SendMessage(msg interface{}) error

SendMessage отправляет JSON-сообщение с \n

func (*Client) SetTenantID

func (c *Client) SetTenantID(tenantID string)

SetTenantID sets the tenant ID for multi-tenancy support

type Config

type Config struct {
	UseTLS         bool
	TLSCertFile    string
	TLSKeyFile     string
	TLSCAFile      string
	ServerHost     string
	ServerPort     int
	JWTToken       string
	LocalPort      int
	ReconnectDelay int
	MaxRetries     int
}

Config represents the client configuration

func (*Config) Validate

func (c *Config) Validate() error

Validate validates the configuration

type HealthStatus

type HealthStatus struct {
	Status           string    `json:"status"`
	Version          string    `json:"version"`
	Uptime           string    `json:"uptime"`
	ConnectionsTotal float64   `json:"connections_total"`
	ActiveTunnels    float64   `json:"active_tunnels"`
	ErrorsTotal      float64   `json:"errors_total"`
	MissedHeartbeats float64   `json:"missed_heartbeats"`
	LastUpdate       time.Time `json:"last_update"`
}

HealthStatus представляет текущее состояние сервера

func GetHealthStatus

func GetHealthStatus() HealthStatus

GetHealthStatus возвращает текущий статус здоровья

type Tunnel

type Tunnel struct {
	ID         string
	LocalPort  int
	RemoteHost string
	RemotePort int
	Protocol   string
	Options    map[string]interface{}
	// contains filtered or unexported fields
}

Tunnel represents a managed tunnel connection

Jump to

Keyboard shortcuts

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