Help us shape the future of Go! Take the 2026 Go Developer Survey

adapter

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: GPL-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIClient

type APIClient interface {
	FetchNodeConfig(ctx context.Context) (*NodeConfig, error)
	FetchUsers(ctx context.Context) ([]User, error)
	FetchDetectRules(ctx context.Context) ([]DetectRule, error)
	Heartbeat(ctx context.Context, onlineUsers int) error
	ReportTraffic(ctx context.Context, items []UserTraffic) error
	ReportOnline(ctx context.Context, items []UserOnline) error
	ReportDetectLogs(ctx context.Context, items []DetectLog) error
}

APIClient talks to the panel. The Fetch methods return (nil, nil) when the resource is unchanged since the last successful fetch.

type AnyTLSConfig

type AnyTLSConfig struct {
	PaddingScheme []string
}

type DetectLog

type DetectLog struct {
	UserID int
	RuleID int
}

type DetectRule

type DetectRule struct {
	ID     int
	Type   DetectRuleType
	Regexp *regexp.Regexp
}

type DetectRuleType

type DetectRuleType int

DetectRuleType selects what a detect rule's regex is matched against.

const (
	// DetectRuleTypePlain matches the destination host, the sniffed domain
	// and the first payload of the connection as text.
	DetectRuleTypePlain DetectRuleType = 1
	// DetectRuleTypeHex matches the hex encoding of the first payload.
	DetectRuleTypeHex DetectRuleType = 2
)

type Hysteria2Config

type Hysteria2Config struct {
	ObfsType     string
	ObfsPassword string
}

type NodeConfig

type NodeConfig struct {
	Type       NodeType
	ListenPort uint16
	// SpeedLimit is the node-wide per-user limit in bytes per second, 0 for none.
	SpeedLimit uint64

	// TLS is nil for protocols or node settings without TLS.
	TLS *boxOption.InboundTLSOptions
	// Transport is nil for plain TCP.
	Transport *boxOption.V2RayTransportOptions

	Shadowsocks ShadowsocksConfig
	TUIC        TUICConfig
	Hysteria2   Hysteria2Config
	AnyTLS      AnyTLSConfig
}

NodeConfig is everything a node server needs to listen, decoded from the panel's node info and merged with the local server options. Two configs that compare equal with reflect.DeepEqual produce the same listener, so the server only restarts when this changes.

type NodeServer

type NodeServer interface {
	Start() error
	Close() error
	UpdateUsers(users []User) error
}

NodeServer is one protocol listener. Users are swapped in place so that a user list change never drops the listener or other users' sessions.

type NodeType

type NodeType int

NodeType is the panel's node `sort`.

const (
	NodeTypeShadowsocks2022 NodeType = 1
	NodeTypeTUIC            NodeType = 2
	NodeTypeSnell           NodeType = 3
	NodeTypeHysteria2       NodeType = 4
	NodeTypeAnyTLS          NodeType = 5
	NodeTypeNaive           NodeType = 6
	NodeTypeVMess           NodeType = 11
	NodeTypeTrojan          NodeType = 14
)

func (NodeType) String

func (t NodeType) String() string

type Router

type Router interface {
	boxAdapter.ConnectionRouterEx
}

Router receives every proxied connection from a node server. The context must carry the panel user ID, set with auth.ContextWithUser[int].

type ShadowsocksConfig

type ShadowsocksConfig struct {
	Method    string
	ServerKey string
}

type TUICConfig

type TUICConfig struct {
	CongestionControl string
}

type User

type User struct {
	ID       int
	UUID     string
	Password string
	// SpeedLimit is in bytes per second, 0 for none.
	SpeedLimit uint64
}

User is a panel account allowed on this node. Which credential a protocol reads depends on the node type: VMess and Trojan authenticate with UUID, TUIC with UUID and Password, everything else with Password.

type UserOnline

type UserOnline struct {
	UserID int
	IP     string
}

type UserTraffic

type UserTraffic struct {
	UserID   int
	Upload   int64
	Download int64
}

Jump to

Keyboard shortcuts

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