launch

package
v0.35.6 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: GPL-3.0 Imports: 28 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package launch resolves what npc is told to start into one model, a list of Profile: launch links, configuration files, -L accesses and the flags and file forms of earlier versions (compat.go) all end there and run the same way.

A connection is configuration text parsed by lib/config, so that package stays the only definition of the configuration keys.

Index

Constants

This section is empty.

Variables

View Source
var (
	SourceRetry = 30 * time.Second
	SourcePause = 5 * time.Minute
)

How long a remote source that failed is left alone.

View Source
var URLAccess bool

URLAccess lets content fetched from a URL define access too (-launch_url_access). Only the local user sets it; the keys that reach local files stay refused either way.

Functions

func CheckValue

func CheckValue(input string) error

CheckValue checks the form of a -launch value without reading or fetching what it refers to.

func Pack

func Pack(ctx context.Context, path string) (string, error)

Pack returns the content of the file at path as a -launch value, gzip and base64. The value holds every secret of the file in the clear.

func Show

func Show(ctx context.Context, sources []Source, locals []Local, reveal bool) (string, error)

Show prints what sources and locals amount to in the current form, one argument per connection and access; reveal false masks vkeys and access keys.

func Supervise

func Supervise(
	ctx context.Context,
	load func(context.Context) (Plan, error),
	run func(context.Context, Profile) error,
) error

Supervise keeps each connection of the plan running, independently of the others: when one stops it is started again once its reconnect pacing (client.Reconnect) allows, by loading the plan again and starting whatever is not running. The first load must be valid; a later invalid one is logged and tried again. It returns nil when ctx ends and an error when npc cannot continue.

Types

type Access

type Access struct {
	Access     string    `json:"access"`
	Target     string    `json:"target"`
	LocalType  string    `json:"local_type"`
	LocalPort  int       `json:"local_port"`
	LocalIP    string    `json:"local_ip"`
	ConnMode   string    `json:"conn_mode"`
	LocalProxy bool      `json:"local_proxy"`
	Auth       []Account `json:"auth"`
}

Access is one local access, however it was written: a -L URL or an entry of a configuration file. It compiles to a config.LocalServer, so the access has one path from here on.

type Account

type Account struct {
	User string `json:"user"`
	Pass string `json:"pass"`
}

Account is one proxy account of a mixed, socks5 or http listener.

type CommandLine

type CommandLine struct {
	Server, VKey, Type, Proxy, LocalIP string
	Config                             []string // npc.conf paths

	Password, LocalType, ConnMode, Target string
	LocalPort                             int
	LocalProxy                            bool
}

CommandLine is the connection and access flags of earlier versions.

func (CommandLine) Sources

func (f CommandLine) Sources() ([]Source, error)

Sources converts the flags into launch sources. An access by -password replaces the other forms, as it always has.

type Composer

type Composer struct {
	// contains filtered or unexported fields
}

Composer merges the sources and the -L accesses into a Plan, remembering the last good content of each remote source.

func NewComposer

func NewComposer(sources []Source, locals []Local) *Composer

NewComposer makes a Composer.

func (*Composer) Load

func (c *Composer) Load(ctx context.Context) (Plan, error)

Load reads the sources and composes the plan. An error is invalid local input; a remote source that fails falls back to its last good content, and without one the plan goes on without it.

type Local

type Local struct {
	Access Access
	Via    string // the name of a connection; empty when there is only one
	Source string // where it was written, for messages
}

Local is one parsed -L: the access and the connection it goes over.

func ParseLocal

func ParseLocal(raw string) (Local, error)

ParseLocal reads one -L value, scheme://[user:pass@]host:port?access=..&target=.. Errors never contain the value: it holds the access key.

func ParseLocals

func ParseLocals(values []string) ([]Local, error)

ParseLocals reads the -L values in order; a value @path is a file with one value per line (blank lines and lines starting with # are skipped), which is how an installed service keeps them off its command line.

type Options

type Options struct {
	DisconnectTimeout int
	P2PTimeout        int
}

Options holds the command line defaults a payload does not set.

type Plan

type Plan struct {
	Profiles []Profile
	Retry    time.Duration
}

Plan is what should run now. Retry is positive while a remote source has nothing to offer: load again after it.

type Profile

type Profile struct {
	Name   string
	Direct bool
	// Hosting: besides its local accesses the connection runs as an
	// ordinary client, because its role says both or an access-less
	// writing shares it.
	Hosting bool

	Config *config.Config
	// Source says where the profile was written, for messages; it holds no secret.
	Source string
	// contains filtered or unexported fields
}

Profile is one runnable client. A direct profile connects with an existing client vkey; otherwise Config is sent to the server or runs local servers.

func Resolve

func Resolve(ctx context.Context, input string) ([]Profile, error)

Resolve turns one -launch value into profiles.

func (*Profile) Key

func (p *Profile) Key() string

Key identifies the connection: same vkey and the same set of addresses.

func (*Profile) Run

func (p *Profile) Run(ctx context.Context, issued string, opts Options) (string, error)

Run runs the profile until it stops or ctx ends. issued is the client key of the previous run, and the one to pass to the next is returned.

type RemoteError

type RemoteError struct {
	Revoked bool
	Err     error
}

RemoteError reports that a URL payload could not be fetched or used, so a later attempt may succeed. Revoked means the source answered 410 Gone: the configuration it served earlier must not be used any more.

func (*RemoteError) Error

func (e *RemoteError) Error() string

func (*RemoteError) Unwrap

func (e *RemoteError) Unwrap() error

type Source

type Source struct {
	Label string // for messages; holds no secret
	Load  func(context.Context) ([]Profile, error)
}

Source is one input of the launch: Load returns its profiles.

func Sources

func Sources(values []string) []Source

Sources makes a source of each -launch value.

Jump to

Keyboard shortcuts

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