Documentation
¶
Overview ¶
Package controller serves the RESTful "external controller" API of Clash and mihomo, so web panels such as zashboard, metacubexd and yacd can watch and steer sudoku. The routes, JSON shapes and status codes follow mihomo; see https://wiki.metacubex.one/api/.
Index ¶
Constants ¶
const ( TypeDirect = "Direct" TypeReject = "Reject" TypeSelector = "Selector" TypeLoadBalance = "LoadBalance" TypeSudoku = "Sudoku" )
Proxy types, as mihomo names them.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Client ¶
type Client interface {
Mode() string // "rule", "global" or "direct"
SetMode(mode string) error
MixedPort() int
// Proxies lists every outbound and group, groups first in the order panels should show them.
Proxies() []Proxy
// Select makes the selector group use the named member.
Select(group, name string) error
// DialContext connects to addr through the named outbound or group, as traffic would.
DialContext(ctx context.Context, proxy, addr string) (net.Conn, error)
Rules() []Rule
RuleProviders() []RuleProvider
// UpdateRuleProvider starts reloading a provider; false means there is none by that name.
UpdateRuleProvider(name string) bool
}
Client is what the API needs from a running client.
type DelayHistory ¶
type Flow ¶
type Flow struct {
// contains filtered or unexported fields
}
Flow is one tracked connection. Upload counts bytes toward the destination.
type Metadata ¶
type Metadata struct {
Network string `json:"network"`
Type string `json:"type"`
SourceIP string `json:"sourceIP"`
DestinationIP string `json:"destinationIP"`
SourceGeoIP []string `json:"sourceGeoIP"`
DestinationGeoIP []string `json:"destinationGeoIP"`
SourceIPASN string `json:"sourceIPASN"`
DestinationIPASN string `json:"destinationIPASN"`
SourcePort string `json:"sourcePort"`
DestinationPort string `json:"destinationPort"`
InboundIP string `json:"inboundIP"`
InboundPort string `json:"inboundPort"`
InboundName string `json:"inboundName"`
InboundUser string `json:"inboundUser"`
Host string `json:"host"`
DNSMode string `json:"dnsMode"`
UID uint32 `json:"uid"`
Process string `json:"process"`
ProcessPath string `json:"processPath"`
SpecialProxy string `json:"specialProxy"`
SpecialRules string `json:"specialRules"`
RemoteDestination string `json:"remoteDestination"`
DSCP uint8 `json:"dscp"`
SniffHost string `json:"sniffHost"`
}
Metadata describes a connection with the field names mihomo uses. Fields sudoku has no notion of stay empty but present, since panels read them unconditionally.
type Options ¶
type Options struct {
Addr string // host:port to listen on
Secret string // bearer token; empty leaves the API open
Client Client
Tracker *Tracker
Users func() []users.Stat
}
Options selects what the API exposes. A client sets Client and Tracker; a server sets Users.
type Route ¶
Route is how a connection left: Chains runs from the outbound actually used up through the groups that chose it, e.g. ["node", "Balance", "PROXY"] or ["DIRECT"]. Rule and RulePayload name the rule that matched, empty when the mode alone decided.
type Tracker ¶
type Tracker struct {
// contains filtered or unexported fields
}
Tracker lists the connections a client is relaying and counts their bytes. A nil *Tracker tracks nothing, so callers need no checks when the API is off.
func NewTracker ¶
func NewTracker() *Tracker
func (*Tracker) Open ¶
Open starts tracking a connection that closer ends. The caller counts its bytes and must call Done once it is over.