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
- Variables
- func Encode(v any, flag string) ([]byte, error)
- func FileKey(key, mode, serverIP string, port int, localPath, stripPre string, ...) string
- func Read(r io.Reader, v any) error
- func ReadP2P(r io.Reader, v any) error
- func ReadStatus(r io.Reader) (ok bool, err error)
- func Write(w io.Writer, v any, flag string) error
- func WriteP2P(w io.Writer, v any) error
- func WriteStatus(w io.Writer, ok bool) error
- type Client
- type Config
- type Flow
- type Health
- type Host
- type Link
- type LinkOptions
- type MultiAccount
- type P2PInvite
- type P2PJoin
- type P2PRefusedError
- type P2PReply
- type P2PRequest
- type P2PRevoke
- type Rate
- type RateLimits
- type SecretAttach
- type SecretChallenge
- type SecretGranted
- type SecretOpen
- type SourceLists
- type Target
- type Task
Constants ¶
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.
const P2PTransportMode = "quic"
P2PTransportMode is the upper-layer transport both sides of a P2P session offer.
Variables ¶
var ErrEmptyInfo = errors.New("empty info payload")
ErrEmptyInfo is a message holding JSON null.
var ErrP2PMessageSize = errors.New("p2p message length out of range")
ErrP2PMessageSize is a message whose length prefix is out of range.
Functions ¶
func Encode ¶
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 ¶
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 ReadStatus ¶
ReadStatus reads what WriteStatus wrote.
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 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 ¶
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 ¶
LinkOptions are the options a Link carries.
type MultiAccount ¶
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 ¶
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.
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 RateLimits ¶
RateLimits are an entry's limits.
type SecretAttach ¶
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 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.