network

package
v0.1.0 Latest Latest
Warning

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

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

Documentation

Overview

Package network keeps the shared network services admins set up once in Panelarr: challenge solvers and proxies, which network profiles use. Nothing uses them until an admin assigns a profile.

Index

Constants

View Source
const (
	SolverFlareSolverr = "flaresolverr"
	SolverByparr       = "byparr"
)

Solver types.

View Source
const (
	KindGlobal   = "global"
	KindPlugin   = "plugin"
	KindPackage  = "package"
	KindSource   = "source"
	KindMeta     = "meta"
	KindProvider = "provider"
)

Owner kinds of custom profiles (and assignment target kinds).

View Source
const (
	UAPluginDefault = "default"
	UAFixed         = "fixed"
	UARandomDesktop = "random_desktop"
	UAFromSolver    = "from_solver"
)

User agent modes.

View Source
const UnsetHash = "unset"

UnsetHash is the hash of "no profile": the plugin's own settings.

Variables

View Source
var (
	ErrNotFound  = errors.New("network: not found")
	ErrIDTaken   = errors.New("network: the ID is taken")
	ErrInvalidID = errors.New("network: IDs are lowercase letters, digits, '-' and '_', up to 40")
	ErrInUse     = errors.New("network: in use by a network profile")
)

Errors.

View Source
var ErrNotShared = errors.New("network: a custom profile can only be assigned to its owner")

ErrNotShared is a custom profile assigned elsewhere than to its owner.

Functions

func Hash

func Hash(m proto.Message) string

Hash identifies a profile as pushed (secrets included, so a changed password is pushed again); nil is UnsetHash.

Types

type Assignment

type Assignment struct {
	Kind, TargetID string
	// ProfileID empty means the plugin's own settings ("plugin default").
	ProfileID string
	UpdatedAt time.Time
}

Assignment puts a profile, or the plugin's own settings, at one level: global, a plugin, a package ("plugin:package"), a source, all of meta or one metadata provider. Without an assignment a level inherits.

func (Assignment) PluginDefault

func (a Assignment) PluginDefault() bool

PluginDefault reports whether the assignment opts out to the plugin's own settings.

type Effective

type Effective struct {
	Level string
	// ProfileID empty means the plugin's own settings.
	ProfileID string
}

Effective is the profile in force for a source or a provider, and the level it comes from ("source", "package", "plugin", "global" for sources; "provider", "meta", "global" for providers; "none" when nothing is assigned).

type InvalidError

type InvalidError struct{ Field, Reason string }

InvalidError is a field with a bad value.

func (*InvalidError) Error

func (e *InvalidError) Error() string

type MetaPusher

type MetaPusher interface {
	Assignments(ctx context.Context) ([]*metav1.Assignment, error)
	PushProfile(ctx context.Context, provider string, p *metadatav1.NetworkProfile) error
}

MetaPusher is the part of the meta service pushes use.

type Owner

type Owner struct{ Kind, ID string }

Owner is who a custom profile belongs to.

type Profile

type Profile struct {
	ID, Name          string
	ProxyID, SolverID string
	RateLimit         *RateLimit
	Concurrency       int
	UserAgentMode     string
	UserAgent         string
	DoHURL            string
	Headers           map[string]string
	SharedCookieJar   string
	Timeouts          Timeouts
	// Owner is set on custom profiles.
	Owner                *Owner
	CreatedAt, UpdatedAt time.Time
}

Profile is a network profile: a proxy, a solver and how requests are made. Unset parts mean the plugin's own defaults.

type Proxy

type Proxy struct {
	ID, Name, URL, Username string
	HasPassword             bool
	// Owner is set on custom proxies.
	Owner                *Owner
	CreatedAt, UpdatedAt time.Time
}

Proxy is an HTTP, HTTPS or SOCKS5 proxy, e.g. a VPN container's. Its password is kept encrypted and never shown.

type ProxyInput

type ProxyInput struct {
	ID, Name, URL, Username, Password string
	// Owner makes a custom proxy (on creation only).
	Owner *Owner
}

ProxyInput is a proxy as given: Password is plain.

type ProxyPatch

type ProxyPatch struct {
	Name, URL, Username, Password *string
}

ProxyPatch changes some of a proxy's fields. An empty Password keeps the stored one; an empty Username removes the credentials.

type Push

type Push = db.NetworkPush

Push is what was last pushed to a source or provider.

type RateLimit

type RateLimit struct {
	Requests int
	Period   time.Duration
	Burst    int
	// Scope is "source" (one budget per source) or "host" (per target host).
	Scope string
}

RateLimit is a profile's request rate.

type Resolver

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

Resolver resolves effective profiles from one read of the assignments.

func (*Resolver) Assigned

func (r *Resolver) Assigned(kind, id string) (Assignment, bool)

Assigned is the assignment at exactly this level, if any.

func (*Resolver) Provider

func (r *Resolver) Provider(id string) Effective

Provider is a metadata provider's effective profile: provider, then all of meta, then global.

func (*Resolver) Source

func (r *Resolver) Source(sourceID, pluginID, packageID string) Effective

Source is a source's effective profile: source, then its package, then its plugin, then global; the most specific assignment wins.

type Service

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

Service manages solvers and proxies.

func New

func New(st *store.Store, box *secret.Box, log *slog.Logger) *Service

New returns the service.

func (*Service) Assign

func (s *Service) Assign(ctx context.Context, kind, id, profileID string) (Assignment, error)

Assign puts a profile (empty: the plugin's own settings) at a level.

func (*Service) Assignments

func (s *Service) Assignments(ctx context.Context) ([]Assignment, error)

Assignments lists every assignment.

func (*Service) CreateProfile

func (s *Service) CreateProfile(ctx context.Context, p Profile) (Profile, error)

CreateProfile adds a shared profile, or a custom one when p.Owner is set.

func (*Service) CreateProxy

func (s *Service) CreateProxy(ctx context.Context, in ProxyInput) (Proxy, error)

CreateProxy adds a proxy.

func (*Service) CreateSolver

func (s *Service) CreateSolver(ctx context.Context, in Solver) (Solver, error)

CreateSolver adds a solver.

func (*Service) DeleteProfile

func (s *Service) DeleteProfile(ctx context.Context, id string) error

DeleteProfile removes a profile nothing is assigned.

func (*Service) DeleteProxy

func (s *Service) DeleteProxy(ctx context.Context, id string) error

DeleteProxy removes a proxy no profile uses.

func (*Service) DeleteSolver

func (s *Service) DeleteSolver(ctx context.Context, id string) error

DeleteSolver removes a solver no profile uses.

func (*Service) MetaProfile

func (s *Service) MetaProfile(ctx context.Context, id string) (*metadatav1.NetworkProfile, error)

MetaProfile builds a profile as metadata plugins receive it, solver inline (meta has no separate solver service) and the proxy's password.

func (*Service) Profile

func (s *Service) Profile(ctx context.Context, id string) (Profile, error)

Profile returns one profile.

func (*Service) Profiles

func (s *Service) Profiles(ctx context.Context, owner *Owner, withCustom bool) ([]Profile, error)

Profiles lists shared profiles, and custom ones when withCustom; owner narrows the list to one owner's custom profiles.

func (*Service) Proxies

func (s *Service) Proxies(ctx context.Context, owner *Owner, withCustom bool) ([]Proxy, error)

Proxies lists shared proxies, and custom ones when withCustom; owner narrows the list to one owner's custom proxies.

func (*Service) Proxy

func (s *Service) Proxy(ctx context.Context, id string) (Proxy, error)

Proxy returns one proxy.

func (*Service) PushMeta

func (s *Service) PushMeta(ctx context.Context, m MetaPusher, force bool) (pushed, failed int, err error)

PushMeta pushes each metadata provider's profile in force when it changed, failed before, or meta doesn't have what it should (all of them with force). Without a metadata service it does nothing.

func (*Service) Pushes

func (s *Service) Pushes(ctx context.Context, kind string) (map[string]Push, error)

Pushes maps a kind's targets to what was last pushed.

func (*Service) RecordPush

func (s *Service) RecordPush(ctx context.Context, kind, target, plugin, hash string, pushErr error) error

RecordPush keeps the outcome of a push: the hash when it worked, the error (and no hash, so it's tried again) when not.

func (*Service) ReplaceProfile

func (s *Service) ReplaceProfile(ctx context.Context, id string, p Profile) (Profile, error)

ReplaceProfile replaces a profile's settings (not its ID or owner).

func (*Service) Resolver

func (s *Service) Resolver(ctx context.Context) (*Resolver, error)

Resolver reads the assignments for resolving.

func (*Service) SetChanged

func (s *Service) SetChanged(fn func(ctx context.Context))

SetChanged sets what runs after a profile or an assignment changed (the push to plugins and meta).

func (*Service) Solver

func (s *Service) Solver(ctx context.Context, id string) (Solver, error)

Solver returns one solver.

func (*Service) Solvers

func (s *Service) Solvers(ctx context.Context, owner *Owner, withCustom bool) ([]Solver, error)

Solvers lists shared solvers, and custom ones when withCustom; owner narrows the list to one owner's custom solvers.

func (*Service) SourceProfile

func (s *Service) SourceProfile(ctx context.Context, id string, withSolver bool) (*sourcev1.NetworkProfile, error)

SourceProfile builds a profile as source plugins receive it, with the proxy's password and the solver inline. withSolver leaves the solver out for plugins that don't take one.

func (*Service) TestProxy

func (s *Service) TestProxy(ctx context.Context, in ProxyInput, target string) (TestResult, error)

TestProxy checks a proxy: with target, a request through it; without, that it accepts connections. in may be unsaved; a saved proxy's stored password is used when in.Password is empty and in.ID names it.

func (*Service) TestSolver

func (s *Service) TestSolver(ctx context.Context, in Solver) (TestResult, error)

TestSolver checks a solver answers. It may be unsaved.

func (*Service) Touch

func (s *Service) Touch(ctx context.Context)

Touch runs what follows a change (a push), e.g. after meta was connected.

func (*Service) Unassign

func (s *Service) Unassign(ctx context.Context, kind, id string) error

Unassign removes the assignment at a level, which then inherits.

func (*Service) UpdateProxy

func (s *Service) UpdateProxy(ctx context.Context, id string, p ProxyPatch) (Proxy, error)

UpdateProxy changes a proxy.

func (*Service) UpdateSolver

func (s *Service) UpdateSolver(ctx context.Context, id string, p SolverPatch) (Solver, error)

UpdateSolver changes a solver.

type Solver

type Solver struct {
	ID, Name, Type, URL    string
	SessionTTL, MaxTimeout time.Duration
	AsResponseFallback     bool
	// Owner is set on custom solvers.
	Owner                *Owner
	CreatedAt, UpdatedAt time.Time
}

Solver is a challenge solver (FlareSolverr-compatible endpoint).

type SolverPatch

type SolverPatch struct {
	Name, Type, URL        *string
	SessionTTL, MaxTimeout *time.Duration
	AsResponseFallback     *bool
}

SolverPatch changes some of a solver's fields.

type TestResult

type TestResult struct {
	OK      bool
	Message string
	// Version is the solver's, when it says.
	Version string
	Latency time.Duration
}

TestResult is how a solver or proxy test went.

type Timeouts

type Timeouts struct{ Connect, Read, Call time.Duration }

Timeouts bound a plugin's requests; zero means the plugin's default.

Jump to

Keyboard shortcuts

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