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
- Variables
- func Hash(m proto.Message) string
- type Assignment
- type Effective
- type InvalidError
- type MetaPusher
- type Owner
- type Profile
- type Proxy
- type ProxyInput
- type ProxyPatch
- type Push
- type RateLimit
- type Resolver
- type Service
- func (s *Service) Assign(ctx context.Context, kind, id, profileID string) (Assignment, error)
- func (s *Service) Assignments(ctx context.Context) ([]Assignment, error)
- func (s *Service) CreateProfile(ctx context.Context, p Profile) (Profile, error)
- func (s *Service) CreateProxy(ctx context.Context, in ProxyInput) (Proxy, error)
- func (s *Service) CreateSolver(ctx context.Context, in Solver) (Solver, error)
- func (s *Service) DeleteProfile(ctx context.Context, id string) error
- func (s *Service) DeleteProxy(ctx context.Context, id string) error
- func (s *Service) DeleteSolver(ctx context.Context, id string) error
- func (s *Service) MetaProfile(ctx context.Context, id string) (*metadatav1.NetworkProfile, error)
- func (s *Service) Profile(ctx context.Context, id string) (Profile, error)
- func (s *Service) Profiles(ctx context.Context, owner *Owner, withCustom bool) ([]Profile, error)
- func (s *Service) Proxies(ctx context.Context, owner *Owner, withCustom bool) ([]Proxy, error)
- func (s *Service) Proxy(ctx context.Context, id string) (Proxy, error)
- func (s *Service) PushMeta(ctx context.Context, m MetaPusher, force bool) (pushed, failed int, err error)
- func (s *Service) Pushes(ctx context.Context, kind string) (map[string]Push, error)
- func (s *Service) RecordPush(ctx context.Context, kind, target, plugin, hash string, pushErr error) error
- func (s *Service) ReplaceProfile(ctx context.Context, id string, p Profile) (Profile, error)
- func (s *Service) Resolver(ctx context.Context) (*Resolver, error)
- func (s *Service) SetChanged(fn func(ctx context.Context))
- func (s *Service) Solver(ctx context.Context, id string) (Solver, error)
- func (s *Service) Solvers(ctx context.Context, owner *Owner, withCustom bool) ([]Solver, error)
- func (s *Service) SourceProfile(ctx context.Context, id string, withSolver bool) (*sourcev1.NetworkProfile, error)
- func (s *Service) TestProxy(ctx context.Context, in ProxyInput, target string) (TestResult, error)
- func (s *Service) TestSolver(ctx context.Context, in Solver) (TestResult, error)
- func (s *Service) Touch(ctx context.Context)
- func (s *Service) Unassign(ctx context.Context, kind, id string) error
- func (s *Service) UpdateProxy(ctx context.Context, id string, p ProxyPatch) (Proxy, error)
- func (s *Service) UpdateSolver(ctx context.Context, id string, p SolverPatch) (Solver, error)
- type Solver
- type SolverPatch
- type TestResult
- type Timeouts
Constants ¶
const ( SolverFlareSolverr = "flaresolverr" SolverByparr = "byparr" )
Solver types.
const ( KindGlobal = "global" KindPlugin = "plugin" KindPackage = "package" KindSource = "source" KindMeta = "meta" KindProvider = "provider" )
Owner kinds of custom profiles (and assignment target kinds).
const ( UAPluginDefault = "default" UAFixed = "fixed" UARandomDesktop = "random_desktop" UAFromSolver = "from_solver" )
User agent modes.
const UnsetHash = "unset"
UnsetHash is the hash of "no profile": the plugin's own settings.
Variables ¶
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.
ErrNotShared is a custom profile assigned elsewhere than to its owner.
Functions ¶
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 Profile ¶
type Profile struct {
ID, Name string
ProxyID, SolverID string
RateLimit *RateLimit
Concurrency int
UserAgentMode string
UserAgent string
DoHURL string
Headers map[string]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 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.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service manages solvers and proxies.
func (*Service) Assignments ¶
func (s *Service) Assignments(ctx context.Context) ([]Assignment, error)
Assignments lists every assignment.
func (*Service) CreateProfile ¶
CreateProfile adds a shared profile, or a custom one when p.Owner is set.
func (*Service) CreateProxy ¶
CreateProxy adds a proxy.
func (*Service) CreateSolver ¶
CreateSolver adds a solver.
func (*Service) DeleteProfile ¶
DeleteProfile removes a profile nothing is assigned.
func (*Service) DeleteProxy ¶
DeleteProxy removes a proxy no profile uses.
func (*Service) DeleteSolver ¶
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) Profiles ¶
Profiles lists shared profiles, and custom ones when withCustom; owner narrows the list to one owner's custom profiles.
func (*Service) Proxies ¶
Proxies lists shared proxies, and custom ones when withCustom; owner narrows the list to one owner's custom proxies.
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) 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 ¶
ReplaceProfile replaces a profile's settings (not its ID or owner).
func (*Service) SetChanged ¶
SetChanged sets what runs after a profile or an assignment changed (the push to plugins and meta).
func (*Service) Solvers ¶
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 ¶
TestSolver checks a solver answers. It may be unsaved.
func (*Service) UpdateProxy ¶
UpdateProxy changes a proxy.
func (*Service) UpdateSolver ¶
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.