Documentation
¶
Overview ¶
Package engine runs Xray-core in-process from a generated config.
Index ¶
- func CloseConnections() int
- func ForgetHysteria()
- func Load(config []byte) (*core.Config, error)
- func RefuseIPv6(inst *core.Instance) int
- func SetAssetDir(dir string) error
- func SetLink(l Link)
- func Start(config []byte, setup ...func(*core.Instance) error) (*core.Instance, error)
- func Stop(inst *core.Instance) error
- func Track(c any)
- type Link
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CloseConnections ¶
func CloseConnections() int
CloseConnections closes every connection the cores have open to the network and returns how many were open. Closing one that is closed already does nothing.
func ForgetHysteria ¶
func ForgetHysteria()
ForgetHysteria drops the cached Hysteria clients, so that the next core dials its servers with its own settings: noise before QUIC in the smart mode only. Call it with no core running, after CloseConnections has closed the old clients' sockets.
func RefuseIPv6 ¶
RefuseIPv6 makes the TUN inbounds of inst refuse IPv6 at once: a TCP connection gets a reset, a UDP packet "port unreachable". Xray's own stack takes every connection before routing it, so an IPv6 one looked open and was then closed by the routing rule that blocks IPv6. A browser that resolves names itself, over DNS-over-HTTPS, gets IPv6 addresses for sites like YouTube and kept failing on them instead of falling back to IPv4. It returns how many stacks it changed.
func SetAssetDir ¶
SetAssetDir points Xray at the directory with geosite.dat and geoip.dat.
func SetLink ¶
func SetLink(l Link)
SetLink tunes the TCP connections dialled from now on for the network.
func Start ¶
Start builds the config and starts Xray. Close the instance to stop it. setup hooks run on the created instance before it starts, to add what a JSON config cannot describe, such as the transport picker.
func Stop ¶
Stop closes the instance and the network stacks of its TUN inbounds.
Xray's TUN inbound has no Close: closing the instance leaves its gVisor stack running and still reading the TUN descriptor. On Android the app then closes that descriptor and opens a new TUN for the next start, which usually gets the same number, so the stale stack takes packets from the new tunnel and connections stall. Every reconnect (a mode switch, a new network) added one more such stack.
On Windows the stack's Wintun device stays open too: its session holds the adapter, and the next start failed with "initialization has already been completed". There the device is closed with the stack, which also removes the adapter; on Android the app closes its TUN descriptor itself.
Types ¶
type Link ¶
type Link struct {
// Mobile is the LTE mode: TCP keepalives every 10 s after 30 s of
// silence hold the operator's NAT open, and a connection whose data goes
// unacknowledged for 30 s, lost in a handover, is dropped and redialled
// instead of hanging.
Mobile bool
// MSS, when set, caps the TCP segments so that a path narrower than
// 1500 bytes never has to split them (netauto.MSS).
MSS int
}
Link describes the network the phone is on now. The panel's own socket options always win.