Documentation
¶
Index ¶
- Constants
- type AppCallback
- type Controller
- func (c *Controller) IsRunning() bool
- func (c *Controller) SetNameservers(csv string)
- func (c *Controller) Start(CdUID string, ProvisionID string, CustomHostname string, HomeDir string, ...)
- func (c *Controller) StartWithOptions(o *StartOptions)
- func (c *Controller) Stop(restart bool, pin int64) int
- type StartOptions
Constants ¶
const LogLevelNotice = -1
LogLevelNotice is the StartOptions.LogLevel that writes only notice, warn, and error lines.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AppCallback ¶
type AppCallback interface {
Hostname() string
LanIp() string
MacAddress() string
// Exit gets a failure line of the run. ctrld calls it on the thread that
// called Start or on a Go thread, always before the run ends. The run
// does not end until Exit returns. So Exit must return without waiting
// for the run to end: it must not call Stop, wait for Start to return,
// or wait for a thread that can be in Stop. Otherwise Stop waits its
// full 15 seconds and returns while the run is still active.
//
// If Exit gives the line to another thread, it must also give the run
// that the line belongs to, because the next run can start before that
// thread reads the line.
Exit(error string)
}
AppCallback provides access to app instance.
type Controller ¶
type Controller struct {
AppCallback AppCallback
Config cli.AppConfig
// contains filtered or unexported fields
}
Controller holds global state. Start, Stop and IsRunning are safe for concurrent use. AppCallback and Config must not be accessed concurrently.
func NewController ¶
func NewController(appCallback AppCallback) *Controller
NewController provides reference to global state to be managed by android vpn service and iOS network extension.
func (*Controller) IsRunning ¶
func (c *Controller) IsRunning() bool
IsRunning remains true until the run has finished releasing its resources.
func (*Controller) SetNameservers ¶ added in v1.5.11
func (c *Controller) SetNameservers(csv string)
SetNameservers replaces the OS resolvers with the comma-separated list csv. Call it when the network of the device changes. It is safe to call from any thread, also during a run. A csv with no IP address keeps the current OS resolvers. The next StartWithOptions replaces the list with StartOptions.Nameservers.
func (*Controller) Start ¶
func (c *Controller) Start(CdUID string, ProvisionID string, CustomHostname string, HomeDir string, UpstreamProto string, logLevel int, logPath string)
Start configures utility with config.toml from provided directory. This function blocks until the run exits, including teardown after Stop. A call made while a run is active or stopping returns immediately. Check port availability prior to calling it. In Control D mode the listener address is fixed. When another process holds it, Exit gets a stage=listener line with the code LISTENER_CONFIGURED_ADDR_UNAVAILABLE. With a config.toml or ctrld.toml in HomeDir that ctrld cannot read or parse, Exit gets a stage=service line with the code UNCLASSIFIED. The message in provision_result.json in HomeDir names the file error. The start fails before the log files open, and each later start fails the same way until the app replaces or deletes the file. With no config file in HomeDir, the start writes a default ctrld.toml there, with one listener, and goes on. If it cannot write that file, or if the listener config is one that ctrld cannot use (no listener, or a key that is not a number), Exit gets a stage=service line with the code UNCLASSIFIED. If ctrld can write to HomeDir, the message in provision_result.json there names the reason.
func (*Controller) StartWithOptions ¶ added in v1.5.11
func (c *Controller) StartWithOptions(o *StartOptions)
StartWithOptions is Start with the configuration in o. It blocks and ignores a call during a run, as Start does. A nil o is NewStartOptions(). It provisions by resolver UID only: StartOptions has no provision token.
func (*Controller) Stop ¶
func (c *Controller) Stop(restart bool, pin int64) int
Stop requests shutdown after validating pin, unless restart bypasses the check. A zero result means the stop request was accepted, not that teardown finished. After cancellation it waits up to 15 seconds. Callers must check IsRunning after Stop: while it remains true, teardown still owns the session and Start will be rejected. PIN failure codes are returned unchanged.
type StartOptions ¶ added in v1.5.11
type StartOptions struct {
CdUID string
CustomHostname string
// HomeDir is the folder of ctrld. It must exist, and ctrld must be able
// to write to it. ctrld reads config.toml, then ctrld.toml, there, and
// writes ctrld.toml when it finds neither.
HomeDir string
UpstreamProto string
// LogLevel is the level of the ctrld log, the same value as the -v flag of
// the CLI. It applies as follows when LogPath is empty:
//
// - LogLevelNotice (-1): ctrld.log in HomeDir gets notice, warn, and
// error lines.
// - 0: ctrld.log gets debug lines.
// - 1: ctrld.log gets info lines. Each DNS query writes its query name.
// - 2: ctrld.log gets debug lines.
//
// When LogPath is set, a LogLevel of 0 or less writes debug lines to it.
// With LogLevelNotice, a log_level in the custom configuration of the
// resolver can change the level.
//
// Thus LogLevelNotice with an empty LogPath keeps query names out of
// ctrld.log. ctrld also removes the resolver UID, the provision token,
// and the paths of URLs from each line that it writes to its log files
// and to the console.
LogLevel int
LogPath string
// Dev makes ctrld use the dev API, like the --dev flag of the CLI.
Dev bool
// MemoryLimitMiB, if more than 0, sets the Go memory limit of the process
// before the run starts. 0 keeps the current limit.
MemoryLimitMiB int
// Nameservers is a comma-separated list of the OS resolvers of the device.
// On iOS, ctrld cannot read them, so the app supplies them. ctrld uses them
// for the "os" upstream and for the exclude rules. SetNameservers changes
// them during the run. Each start replaces the list that an earlier
// SetNameservers set, so pass the current list here at every start.
Nameservers string
}
StartOptions configures StartWithOptions. gomobile exports only fields of basic types.
func NewStartOptions ¶ added in v1.5.11
func NewStartOptions() *StartOptions
NewStartOptions returns options with LogLevel set to LogLevelNotice.