control

package
v0.35.2 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: GPL-3.0 Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package control holds the messages of the protocol's control streams. Their JSON field names and the frames around them are frozen for released peers: fields are only ever ignored or added, never renamed.

Index

Constants

View Source
const (
	P2PCodeRefused     = "refused"     // unknown, disabled or misconfigured task, P2P off on the server
	P2PCodeUnsupported = "unsupported" // the peer is too old
	P2PCodeOffline     = "offline"     // the provider is not connected
	P2PCodeBusy        = "busy"        // the server's session limits refused the session
)

P2P reply codes. An empty code accepts the request.

View Source
const P2PTransportMode = "quic"

P2PTransportMode is the upper-layer transport both sides of a P2P session offer.

Variables

View Source
var ErrEmptyInfo = errors.New("empty info payload")

ErrEmptyInfo is a message holding JSON null.

View Source
var ErrP2PMessageSize = errors.New("p2p message length out of range")

ErrP2PMessageSize is a message whose length prefix is out of range.

Functions

func Encode

func Encode(v any, flag string) ([]byte, error)

Encode returns v as one message: flag, which may be empty, and a frame holding its JSON.

func FileKey

func FileKey(key, mode, serverIP string, port int, localPath, stripPre string, readOnly bool, accounts string) string

FileKey names a client's file server: the same on both sides of a file task.

func Read

func Read(r io.Reader, v any) error

Read reads a message into v, a pointer to a pointer. It decodes leniently: a field of the wrong type is left out rather than failing the message, for peers that sent other types over the versions.

func ReadP2P

func ReadP2P(r io.Reader, v any) error

ReadP2P reads one message written by WriteP2P into v.

func ReadStatus

func ReadStatus(r io.Reader) (ok bool, err error)

ReadStatus reads what WriteStatus wrote.

func Write

func Write(w io.Writer, v any, flag string) error

Write writes v as one message in one write.

func WriteP2P

func WriteP2P(w io.Writer, v any) error

WriteP2P sends v as one length-prefixed JSON message.

func WriteStatus

func WriteStatus(w io.Writer, ok bool) error

WriteStatus reports whether an entry was added.

Types

type Client

type Client struct {
	NowConn         int32
	Status          bool
	IsConnect       bool
	NoStore         bool
	NoDisplay       bool
	ConfigConnAllow bool
	Cnf             *Config
	Id              int
	VerifyKey       string
	Mode            string
	Addr            string
	LocalAddr       string
	Remark          string
	RateLimit       int
	Flow            *Flow
	ExportFlow      int64
	InletFlow       int64
	Rate            *Rate
	MaxConn         int
	WebUserName     string
	WebPassword     string
	WebTotpSecret   string
	MaxTunnelNum    int
	Version         string
	SourceLists
	CreateTime        string
	LastOnlineTime    string
	ConnectionHistory json.RawMessage `json:",omitempty"`
	RegisterKey       string
	RegisterMaxHours  int
}

Client describes a client sent with FlagNewConf.

type Config

type Config struct {
	U        string
	P        string
	Compress bool
	Crypt    bool
}

Config is the client's connection settings.

type Flow

type Flow struct {
	ExportFlow int64
	InletFlow  int64
	FlowLimit  int64
	TimeLimit  time.Time
}

Flow is a traffic account.

type Health

type Health struct {
	HealthCheckTimeout  int
	HealthMaxFail       int
	HealthCheckInterval int
	HttpHealthUrl       string
	HealthCheckType     string
	HealthCheckTarget   string
}

Health is what a released client sends of a health check it configured itself; the server ignores it.

type Host

type Host struct {
	RateLimits
	Id               int
	Host             string
	HeaderChange     string
	RespHeaderChange string
	HostChange       string
	Location         string
	PathRewrite      string
	Remark           string
	Scheme           string
	RedirectURL      string
	HttpsJustProxy   bool
	TlsOffload       bool
	AutoSSL          bool
	CertType         string
	CertHash         string
	CertFile         string
	KeyFile          string
	NoStore          bool
	IsClose          bool
	AutoHttps        bool
	AutoCORS         bool
	CompatMode       bool
	Flow             *Flow
	MaxConn          int
	NowConn          int32
	Client           *Client
	TargetIsHttps    bool
	Target           *Target
	UserAuth         *MultiAccount
	MultiAccount     *MultiAccount
	SourceLists
}

Host describes a domain entry sent with FlagNewHost.

type Link struct {
	ConnType   string
	Host       string
	Crypt      bool
	Compress   bool
	LocalProxy bool
	RemoteAddr string
	Option     LinkOptions
}

Link asks a client for a connection to a target.

type LinkOptions

type LinkOptions struct {
	Timeout time.Duration
	NeedAck bool
}

LinkOptions are the options a Link carries.

type MultiAccount

type MultiAccount struct {
	Content    string
	AccountMap map[string]string
}

MultiAccount holds the accounts of an entry.

type P2PInvite

type P2PInvite struct {
	SessionID string `json:"session_id"` // the invitation id
	Token     string `json:"token"`      // one-time join token
	// Policy is what the visitor may reach over the direct path, a JSON
	// proxy.SecretPolicy: the provider applies it to every link arriving
	// on that path, as nps does to relayed ones.
	Policy json.RawMessage `json:"policy"`
	// Grant is the visitor's grant the session serves: a P2PRevoke naming
	// it ends the session's direct path.
	Grant   string `json:"grant"`
	Tunnel  int    `json:"tunnel,omitempty"`  // the secret task, for logs
	Route   string `json:"route,omitempty"`   // the secret task's route, for logs
	Visitor int    `json:"visitor,omitempty"` // the visitor's client id, for logs
}

P2PInvite asks the provider on its signal connection to join a session.

type P2PJoin

type P2PJoin struct {
	SessionID string `json:"session_id"`
	Token     string `json:"token"`
	ServerIP  string `json:"server_ip,omitempty"` // as in P2PRequest
	Decline   string `json:"decline,omitempty"`   // the provider refuses the session, and why
}

P2PJoin answers an invitation.

type P2PRefusedError

type P2PRefusedError struct {
	Code    string
	Message string
}

P2PRefusedError is a P2PReply that did not accept the request.

func (*P2PRefusedError) Error

func (e *P2PRefusedError) Error() string

type P2PReply

type P2PReply struct {
	Code      string `json:"code,omitempty"`
	Message   string `json:"message,omitempty"`
	SessionID string `json:"session_id,omitempty"`
	Tunnel    int    `json:"tunnel,omitempty"` // to the visitor: the secret task, for logs
	Peer      int    `json:"peer,omitempty"`   // to the visitor: the provider's client id, for logs
}

P2PReply answers a P2PRequest or a P2PJoin.

func (P2PReply) Err

func (r P2PReply) Err() error

Err returns the reply as an error: nil when it accepts, a *P2PRefusedError otherwise.

type P2PRequest

type P2PRequest struct {
	Grant      string `json:"grant"`                // the visitor's grant of the task (SecretGranted)
	Background bool   `json:"background,omitempty"` // the visitor relays meanwhile; nobody waits for the session
	ServerIP   string `json:"server_ip,omitempty"`  // the server address the client's connection reached, when known
}

P2PRequest opens a session as the visitor.

type P2PRevoke

type P2PRevoke struct {
	Grant string `json:"grant"`
}

P2PRevoke tells the provider on its signal connection that a grant ended: the direct paths serving it close.

type Rate

type Rate struct {
	NowRate int64 `json:"NowRate"`
	Limit   int64 `json:"Limit"`
}

Rate is a rate limiter's state, in bytes per second.

type RateLimits

type RateLimits struct {
	UploadLimit   int
	DownloadLimit int
}

RateLimits are an entry's limits.

type SecretAttach

type SecretAttach struct {
	Index string `json:"index"`
	Proof []byte `json:"proof"`
}

SecretAttach asks for a grant: Index names the task (crypt.SecretIndex of its password) and Proof shows the password (crypt.SecretProof over the challenge's nonce and the visitor's node).

type SecretChallenge

type SecretChallenge struct {
	Nonce []byte `json:"nonce"`
}

SecretChallenge is the bridge's nonce of one attach.

type SecretGranted

type SecretGranted struct {
	Code    string `json:"code,omitempty"` // a P2PCode* refusal
	Message string `json:"message,omitempty"`
	Grant   string `json:"grant,omitempty"`
	Tunnel  int    `json:"tunnel,omitempty"` // the secret task, for logs
	Peer    int    `json:"peer,omitempty"`   // the provider's client id, for logs
	// NameDest: the visitor may name destinations (within the task's
	// destination list); otherwise it reaches the task's targets only.
	NameDest bool `json:"name_dest,omitempty"`
	// AllowLocal: a visitor naming a destination may have nps reach it.
	AllowLocal bool `json:"allow_local,omitempty"`
	// Direct: a direct path can serve the task's links; false when nps
	// reaches the task's target itself.
	Direct bool `json:"direct,omitempty"`
}

SecretGranted answers a SecretAttach. An empty Code grants: Grant names the grant for the links and the P2P requests of this visitor, and the flags summarize the task's policy for the visitor.

type SecretOpen

type SecretOpen struct {
	Grant string `json:"grant"`
}

SecretOpen starts a relayed link under a grant; the link follows.

type SourceLists

type SourceLists struct {
	IpListPriority int
	BlackIpList    []string
	WhiteIpList    []string
	RegisteredOnly bool
}

SourceLists are access lists of visitor addresses.

type Target

type Target struct {
	TargetStr     string
	LocalProxy    bool
	ProxyProtocol int
}

Target is where an entry forwards to.

type Task

type Task struct {
	RateLimits
	MaxConn      int
	Id           int
	Port         int
	ServerIp     string
	Mode         string
	Status       bool
	RunStatus    bool
	Client       *Client
	Ports        string
	Flow         *Flow
	NowConn      int32
	Password     string
	Remark       string
	TargetAddr   string
	TargetType   string
	DestAclMode  int
	DestAclRules string
	SourceLists
	NoStore      bool
	IsHttp       bool
	HttpProxy    bool
	Socks5Proxy  bool
	LocalPath    string
	StripPre     string
	ReadOnly     bool
	Target       *Target
	UserAuth     *MultiAccount
	MultiAccount *MultiAccount
	Health
}

Task describes a task sent with FlagNewTask.

Jump to

Keyboard shortcuts

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