Documentation
¶
Overview ¶
Package mobile is the core API the Android app calls through gomobile bind. It keeps the same state as tigersb-core and runs Xray on the TUN that the app's VpnService opens.
gomobile exports only simple types, so structured results are JSON strings.
Index ¶
- func About() string
- func AddKey(key string) (string, error)
- func AddKeyAside(key string) (string, error)
- func Current() (string, error)
- func Delete(id string) (string, error)
- func Freezing() string
- func Healthy() bool
- func Init(dir, version string)
- func Journal() string
- func Note(event string)
- func Online() bool
- func OtherPanel(key string) bool
- func PathKnown() bool
- func PickMTU(transport string, linkMTU int) int
- func Profiles() (string, error)
- func Protocol() string
- func Refresh() (string, error)
- func RefreshProfile(id string) (string, error)
- func ResetConnections() int
- func Running() bool
- func Select(id string) (string, error)
- func SetDevice(hwid, osName, osVersion, model string)
- func SetNetwork(transport string)
- func SetProtocolsOff(names string) error
- func SetStateKey(key []byte) error
- func SetUserApps(apps string) error
- func Start(fd int, mode string, mtu int) error
- func StartTUN(name, mode string, mtu int) error
- func Stats() (string, error)
- func Stop() error
- func SwitchNetwork(transport string) int
- func TakeRestart() bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func About ¶
func About() string
About returns, as JSON, the versions the app's about screen shows: the app itself, the Xray core and Go.
func AddKey ¶
AddKey adds a key (tigersb://, https:// or a share link) as a new profile, or updates the profile with the same key, downloads the profile and the lists it needs, makes it the active one and returns its info as JSON.
func AddKeyAside ¶
AddKeyAside adds a key as AddKey does but leaves the active profile as it is, unless there was none: for a key from another panel that came by a link (OtherPanel). The user switches to it on purpose (Select).
func Delete ¶
Delete removes the profile id. When it was the active one, the next profile becomes active; the VPN must be off then. It returns the active profile's info as JSON, or "" when no profile is left, and then the lists go too.
func Freezing ¶
func Freezing() string
Freezing is the watchdog's last look before it restarts the core. When the checks fail on connections that have been open a while but pass on fresh ones, the network freezes connections after some data, as DPI does, and a restart would only break every connection the apps have. Freezing returns what to tell the user then, and "" when the server does not answer on fresh connections either, so that a restart may help. It closes the connections the core has open and takes up to 5 seconds.
func Healthy ¶
func Healthy() bool
Healthy checks the channel through the server in use like the app's ping: t.me and YouTube through a server abroad, two requests each over one connection, within 5 seconds. False when the VPN is not running or nothing answers.
func Init ¶
func Init(dir, version string)
Init sets the app's private directory and version. Call it once before anything else.
func Journal ¶
func Journal() string
Journal returns the journal as text to send: the last events, the last warnings of Xray and the last crash, if any.
func Online ¶
func Online() bool
Online reports whether the phone's network reaches the internet by itself, outside the VPN (the app's own connections bypass it). When it does not, restarting the VPN fixes nothing and the app only waits. It takes up to 3 seconds.
func OtherPanel ¶
OtherPanel reports whether key is a tigersb:// key signed by a panel none of the saved profiles comes from. Such a key that came by a link may be a trap: someone else's server that would see the user's traffic. Without saved profiles there is nothing to compare with, and it reports false.
func PathKnown ¶
func PathKnown() bool
PathKnown reports whether the last PickMTU measured the path. An unmeasured one, as on mobile networks that drop pings, only guesses a safe MTU, which is no reason to rebuild a working tunnel.
func PickMTU ¶
PickMTU chooses the TUN MTU for the network the phone uses now: transport is "wifi", "cellular", "ethernet" or "", linkMTU is what the system reports for that network (0 if unknown). It measures how large a packet reaches the server without being split (netauto.PathMTU), which takes up to a few seconds, so call it off the main thread, before Start or SwitchNetwork: the connections dialled from then on are tuned for this network (the LTE mode on mobile data, segments sized to the path).
func Profiles ¶
Profiles returns the info of every profile, in the order they were added, as a JSON array; the active one has "active": true.
func Protocol ¶
func Protocol() string
Protocol names the protocol of the server in use, such as "Xray · gRPC", in the smart mode with what it adds ("Xray · gRPC · обход DPI", "Hysteria 2 · шумы"), or "" when the VPN is not running.
func Refresh ¶
Refresh downloads the active profile and the lists again. On failure the old profile stays usable.
func RefreshProfile ¶
RefreshProfile downloads the profile id and the lists again and returns its info as JSON. On failure the old profile stays usable. A running VPN takes the new profile when it reconnects.
func ResetConnections ¶
func ResetConnections() int
ResetConnections closes the running VPN's connections to the network and has the transports checked again, for a channel that comes back after an outage on the same network or that DPI started to cut: the apps' connections stuck on the dead ones reconnect at once, and the smart mode tunes its DPI preset again. It returns how many connections were closed.
func Select ¶
Select makes the profile id the active one and returns its info as JSON. A running VPN takes it when it reconnects.
func SetDevice ¶
func SetDevice(hwid, osName, osVersion, model string)
SetDevice tells subscription servers which device asks. Panels with a device limit (Remnawave HWID and similar) count devices by hwid.
func SetNetwork ¶
func SetNetwork(transport string)
SetNetwork tells the core what network the phone is on now: "wifi", "cellular", "ethernet" or "". Call it before Start: the smart mode remembers the DPI preset that worked on each kind of network.
func SetProtocolsOff ¶
SetProtocolsOff saves the protocols the user turned off, a JSON array of names as the profile info lists them under "protocols": ones that work poorly on the user's networks. They stay off for every profile that has them. A running VPN applies them when it reconnects.
func SetStateKey ¶
SetStateKey sets the 32-byte key that encrypts the saved subscriptions (see subscription.StateKey) and encrypts the ones saved without it. Call it right after Init.
func SetUserApps ¶
SetUserApps saves the apps the user leaves out of the VPN, a JSON array of Android package names, or of program names ("game.exe") on Windows. A running VPN applies them when it reconnects.
func Start ¶
Start runs the VPN on the TUN file descriptor fd in mode "auto", "main" or "all". mtu is the MTU the app gave the TUN (see PickMTU).
func StartTUN ¶
StartTUN runs the VPN as Start does, on a TUN the core creates itself by the name: on Windows a Wintun adapter, which the caller then gives its addresses, routes and DNS server.
func Stats ¶
Stats returns what the app shows about the running VPN as JSON: {"up", "down": bytes through the servers since the start, "ping": ms to the server in use or -1, "uptime": seconds since the start}. The ping takes up to 5 seconds, so call it off the main thread.
func SwitchNetwork ¶
SwitchNetwork moves the running VPN to the network the phone switched to: transport is its kind, as for SetNetwork. Call PickMTU for that network first. The old network's connections are closed, the transports are checked again, and the smart mode takes the DPI preset that worked last on this kind of network and tunes it again. It returns how many connections were closed.
func TakeRestart ¶
func TakeRestart() bool
TakeRestart reports, once, that the routing lists the VPN started without have been downloaded, so the app should reconnect to use them.
Types ¶
This section is empty.