tunnel

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultServerListenAddr        = "0.0.0.0:18080"
	DefaultTunnelControlListenAddr = "127.0.0.1:19091"
	DefaultDialTimeout             = "10s"
	DefaultOpenTimeout             = "10s"
	DefaultReconnectMin            = "1s"
	DefaultReconnectMax            = "30s"
)
View Source
const (
	MessageHello  = "hello"
	MessageAccept = "accept"
	MessageOpen   = "open"
	MessageData   = "data"
	MessageUDP    = "udp"
	MessageClose  = "close"
	MessagePing   = "ping"
	MessagePong   = "pong"
	MessageError  = "error"
)
View Source
const ProtocolVersion = 1

Variables

This section is empty.

Functions

func NewControlHandler added in v0.3.0

func NewControlHandler(server *Server, opts ControlHandlerOptions) http.Handler

Types

type AllowConfig

type AllowConfig struct {
	Protocols   []string `json:"protocols,omitempty" yaml:"protocols,omitempty"`
	RemotePorts []int    `json:"remote_ports,omitempty" yaml:"remote_ports,omitempty"`
	MaxTunnels  int      `json:"max_tunnels,omitempty" yaml:"max_tunnels,omitempty"`
}

type Client

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

func NewClient

func NewClient(cfg ClientConfig, logger *slog.Logger) *Client

func (*Client) Run

func (client *Client) Run(ctx context.Context) error

type ClientConfig

type ClientConfig struct {
	Version      int                `json:"version" yaml:"version"`
	Log          config.LogConfig   `json:"log,omitempty" yaml:"log,omitempty"`
	TunnelClient TunnelClientConfig `json:"tunnel_client" yaml:"tunnel_client"`
}

func LoadClientConfig

func LoadClientConfig(path string) (ClientConfig, error)

type ClientSnapshot

type ClientSnapshot struct {
	ClientID      string `json:"client_id"`
	SessionID     string `json:"session_id"`
	RemoteAddr    string `json:"remote_addr,omitempty"`
	ConnectedTime int64  `json:"connected_time"`
	TunnelCount   int    `json:"tunnel_count"`
}

type ConfigCheckItem

type ConfigCheckItem struct {
	Level   string `json:"level"`
	Field   string `json:"field,omitempty"`
	Message string `json:"message"`
}

type ConfigCheckResult

type ConfigCheckResult struct {
	OK           bool              `json:"ok"`
	ErrorCount   int               `json:"error_count"`
	WarningCount int               `json:"warning_count"`
	Items        []ConfigCheckItem `json:"items"`
}

type ControlHandlerOptions added in v0.3.0

type ControlHandlerOptions struct {
	ConfigPath string
	Auth       *controlapi.Authenticator
	Logger     *slog.Logger
}

type Message

type Message struct {
	Type      string       `json:"type"`
	Version   int          `json:"version,omitempty"`
	ClientID  string       `json:"client_id,omitempty"`
	Token     string       `json:"token,omitempty"`
	SessionID string       `json:"session_id,omitempty"`
	TunnelID  string       `json:"tunnel_id,omitempty"`
	ConnID    string       `json:"conn_id,omitempty"`
	Tunnels   []TunnelSpec `json:"tunnels,omitempty"`
	OK        bool         `json:"ok,omitempty"`
	Error     string       `json:"error,omitempty"`
	Time      int64        `json:"time,omitempty"`
}

type ReloadResult

type ReloadResult struct {
	OK                  bool              `json:"ok"`
	ClientCount         int               `json:"client_count"`
	DisconnectedClients []string          `json:"disconnected_clients,omitempty"`
	Check               ConfigCheckResult `json:"check"`
}

type Server

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

func NewServer

func NewServer(cfg ServerConfig, logger *slog.Logger) *Server

func (*Server) Clients

func (server *Server) Clients() []ClientSnapshot

func (*Server) Collector

func (server *Server) Collector() *engine.Collector

func (*Server) Config

func (server *Server) Config() ServerConfig

func (*Server) PrecheckConfig

func (server *Server) PrecheckConfig(next ServerConfig) ConfigCheckResult

func (*Server) ReloadConfig

func (server *Server) ReloadConfig(next ServerConfig) (ReloadResult, error)

func (*Server) Run

func (server *Server) Run(ctx context.Context) error

func (*Server) RunningClients

func (server *Server) RunningClients() int

func (*Server) RunningTunnels

func (server *Server) RunningTunnels() int

func (*Server) Stats

func (server *Server) Stats() []engine.TrafficSnapshot

func (*Server) Tunnels

func (server *Server) Tunnels() []TunnelSnapshot

type ServerClientACL

type ServerClientACL struct {
	ClientID string      `json:"client_id" yaml:"client_id"`
	Token    string      `json:"token" yaml:"token"`
	Allow    AllowConfig `json:"allow,omitempty" yaml:"allow,omitempty"`
}

type ServerConfig

type ServerConfig struct {
	Version           int                `json:"version" yaml:"version"`
	ControlListenAddr string             `json:"control_listen_addr,omitempty" yaml:"control_listen_addr,omitempty"`
	Log               config.LogConfig   `json:"log,omitempty" yaml:"log,omitempty"`
	Auth              config.AuthConfig  `json:"auth,omitempty" yaml:"auth,omitempty"`
	TunnelServer      TunnelServerConfig `json:"tunnel_server" yaml:"tunnel_server"`
}

func LoadServerConfig

func LoadServerConfig(path string) (ServerConfig, error)

type TLSConfig

type TLSConfig struct {
	Enabled            bool   `json:"enabled" yaml:"enabled"`
	CertFile           string `json:"cert_file,omitempty" yaml:"cert_file,omitempty"`
	KeyFile            string `json:"key_file,omitempty" yaml:"key_file,omitempty"`
	ServerName         string `json:"server_name,omitempty" yaml:"server_name,omitempty"`
	InsecureSkipVerify bool   `json:"insecure_skip_verify,omitempty" yaml:"insecure_skip_verify,omitempty"`
}

type TunnelClientConfig

type TunnelClientConfig struct {
	Enabled      bool         `json:"enabled" yaml:"enabled"`
	ServerAddr   string       `json:"server_addr" yaml:"server_addr"`
	TLS          TLSConfig    `json:"tls,omitempty" yaml:"tls,omitempty"`
	ClientID     string       `json:"client_id" yaml:"client_id"`
	Token        string       `json:"token" yaml:"token"`
	DialTimeout  string       `json:"dial_timeout,omitempty" yaml:"dial_timeout,omitempty"`
	ReconnectMin string       `json:"reconnect_min,omitempty" yaml:"reconnect_min,omitempty"`
	ReconnectMax string       `json:"reconnect_max,omitempty" yaml:"reconnect_max,omitempty"`
	Tunnels      []TunnelSpec `json:"tunnels" yaml:"tunnels"`
}

type TunnelServerConfig

type TunnelServerConfig struct {
	Enabled     bool              `json:"enabled" yaml:"enabled"`
	ListenAddr  string            `json:"listen_addr" yaml:"listen_addr"`
	TLS         TLSConfig         `json:"tls,omitempty" yaml:"tls,omitempty"`
	OpenTimeout string            `json:"open_timeout,omitempty" yaml:"open_timeout,omitempty"`
	Clients     []ServerClientACL `json:"clients" yaml:"clients"`
}

type TunnelSnapshot

type TunnelSnapshot struct {
	ClientID         string `json:"client_id"`
	TunnelID         string `json:"tunnel_id"`
	Protocol         string `json:"protocol"`
	RemoteListenAddr string `json:"remote_listen_addr"`
	RemoteListenPort int    `json:"remote_listen_port"`
	LocalAddr        string `json:"local_addr"`
	LocalPort        int    `json:"local_port"`
	ActiveConns      int64  `json:"active_conns"`
	MaxConn          int    `json:"max_conn,omitempty"`
	Remark           string `json:"remark,omitempty"`
}

type TunnelSpec

type TunnelSpec struct {
	TunnelID         string `json:"tunnel_id" yaml:"tunnel_id"`
	Protocol         string `json:"protocol" yaml:"protocol"`
	RemoteListenAddr string `json:"remote_listen_addr" yaml:"remote_listen_addr"`
	RemoteListenPort int    `json:"remote_listen_port" yaml:"remote_listen_port"`
	LocalAddr        string `json:"local_addr" yaml:"local_addr"`
	LocalPort        int    `json:"local_port" yaml:"local_port"`
	MaxConn          int    `json:"max_conn,omitempty" yaml:"max_conn,omitempty"`
	SpeedLimit       int64  `json:"speed_limit,omitempty" yaml:"speed_limit,omitempty"`
	Remark           string `json:"remark,omitempty" yaml:"remark,omitempty"`
}

Jump to

Keyboard shortcuts

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