mobile

package
v0.0.0-...-44d3390 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: GPL-3.0 Imports: 36 Imported by: 0

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

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

func AddKey(key string) (string, error)

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

func AddKeyAside(key string) (string, error)

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 Current

func Current() (string, error)

Current returns the active profile's info as JSON, or "" when no key has been added.

func Delete

func Delete(id string) (string, error)

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 Note

func Note(event string)

Note adds a line to the journal: what the VPN did and why.

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

func OtherPanel(key string) bool

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

func PickMTU(transport string, linkMTU int) int

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

func Profiles() (string, error)

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

func Refresh() (string, error)

Refresh downloads the active profile and the lists again. On failure the old profile stays usable.

func RefreshProfile

func RefreshProfile(id string) (string, error)

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 Running

func Running() bool

Running reports whether the VPN is running.

func Select

func Select(id string) (string, error)

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

func SetProtocolsOff(names string) error

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

func SetStateKey(key []byte) error

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

func SetUserApps(apps string) error

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

func Start(fd int, mode string, mtu int) error

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

func StartTUN(name, mode string, mtu int) error

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

func Stats() (string, error)

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 Stop

func Stop() error

Stop stops the VPN. The app closes the TUN descriptor afterwards.

func SwitchNetwork

func SwitchNetwork(transport string) int

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.

Jump to

Keyboard shortcuts

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