Documentation
¶
Overview ¶
Package settings holds piecemeal's runtime settings: the ones that can be changed through the API while it runs.
Values come from three places, highest priority first:
- Environment variables. A setting set this way is pinned: the API reports it as read-only and refuses to change it.
- The settings table in the store, written when the API changes a value.
- The defaults below.
Each setting's environment variable is PIECEMEAL_ followed by its JSON name in upper snake case: downloadLimit is PIECEMEAL_DOWNLOAD_LIMIT.
Index ¶
- Constants
- Variables
- func EnvName(jsonName string) string
- func Names() []string
- func ParseClock(s string) (int, error)
- func RedactPatch(patch []byte) string
- type Manager
- func (m *Manager) AddValidator(fn func(Settings) error)
- func (m *Manager) Get() Settings
- func (m *Manager) Locked() map[string]string
- func (m *Manager) Set(ctx context.Context, values map[string]any) (Settings, error)
- func (m *Manager) Subscribe(fn func(old, cur Settings))
- func (m *Manager) Update(ctx context.Context, patch json.RawMessage) (Settings, error)
- type Settings
- type ValidationError
Constants ¶
const DefaultSmartEpisodeFilters = `s(\d+)e(\d+)
(\d+)x(\d+)
(\d{4}[.\-]\d{1,2}[.\-]\d{1,2})
(\d{1,2}[.\-]\d{1,2}[.\-]\d{4})`
DefaultSmartEpisodeFilters recognise SxxEyy, NxNN and dates.
Variables ¶
var ErrLocked = errors.New("set by an environment variable")
ErrLocked is returned when a change touches a setting pinned by an environment variable.
Functions ¶
func EnvName ¶
EnvName is the environment variable for a setting's JSON name. An acronym is one word: proxyRSS is PIECEMEAL_PROXY_RSS and bannedIPs PIECEMEAL_BANNED_IPS.
func ParseClock ¶ added in v0.4.0
ParseClock parses HH:MM into minutes after midnight.
func RedactPatch ¶ added in v1.2.0
RedactPatch returns a settings patch for logs and the audit trail, with the values of write-only settings replaced.
Types ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager holds the current settings and persists changes.
func Load ¶
func Load(ctx context.Context, st *store.Store, defaults Settings, environ []string) (*Manager, error)
Load reads stored settings over the defaults and applies environment overrides from environ (os.Environ's format).
func (*Manager) AddValidator ¶
AddValidator adds a check that changes must pass, for constraints from outside this package such as the allowed save roots.
func (*Manager) Locked ¶
Locked returns the JSON names of settings pinned by environment variables, mapped to the variable.
type Settings ¶
type Settings struct {
// Downloads
DefaultSavePath string `json:"defaultSavePath" doc:"Where torrents are saved when neither the request nor its category names a path."`
AddStopped bool `json:"addStopped" doc:"Add new torrents stopped."`
// Incomplete folder
IncompletePathEnabled bool `` /* 167-byte string literal not displayed */
IncompletePath string `json:"incompletePath" doc:"Where incomplete torrents are kept while incompletePathEnabled is on."`
// Automatic torrent management
AutoManagement bool `` /* 162-byte string literal not displayed */
RelocateOnCategoryChange bool `` /* 193-byte string literal not displayed */
RelocateOnDefaultPathChange bool `` /* 210-byte string literal not displayed */
RelocateOnCategoryPathChange bool `` /* 200-byte string literal not displayed */
// Speed
DownloadLimit int64 `json:"downloadLimit" minimum:"0" doc:"Global download limit in bytes per second, 0 for unlimited."`
UploadLimit int64 `json:"uploadLimit" minimum:"0" doc:"Global upload limit in bytes per second, 0 for unlimited."`
AltDownloadLimit int64 `json:"altDownloadLimit" minimum:"0" doc:"Alternative download limit, used while altSpeedEnabled is on."`
AltUploadLimit int64 `json:"altUploadLimit" minimum:"0" doc:"Alternative upload limit, used while altSpeedEnabled is on."`
AltSpeedEnabled bool `json:"altSpeedEnabled" doc:"Use the alternative limits."`
// Connection
PeerPort int `` /* 137-byte string literal not displayed */
MaxConnectionsPerTorrent int `json:"maxConnectionsPerTorrent" minimum:"1" doc:"Established peer connections per torrent."`
MaxHalfOpenConnections int `json:"maxHalfOpenConnections" minimum:"1" doc:"Outgoing connection attempts in progress, across all torrents."`
UTP bool `json:"utp" doc:"Use uTP as well as TCP for peer connections."`
// BitTorrent
DHT bool `json:"dht" doc:"Use the DHT to find peers."`
PEX bool `json:"pex" doc:"Exchange peers with other peers."`
Encryption string `json:"encryption" enum:"prefer,require,disable" doc:"Peer connection encryption: prefer, require or disable."`
// Proxy
ProxyType string `` /* 142-byte string literal not displayed */
ProxyHost string `json:"proxyHost" doc:"The proxy server's hostname or IP address."`
ProxyPort int `json:"proxyPort" minimum:"0" maximum:"65535" doc:"The proxy server's port."`
ProxyUsername string `json:"proxyUsername" maxLength:"255" doc:"The username for the proxy, empty for none."`
ProxyPassword string `` /* 212-byte string literal not displayed */
ProxyBitTorrent bool `` /* 173-byte string literal not displayed */
ProxyPeerConnections bool `` /* 173-byte string literal not displayed */
ProxyHostnameLookup bool `` /* 172-byte string literal not displayed */
ProxyRSS bool `json:"proxyRSS" doc:"Fetch RSS feeds through the proxy."`
ProxyTorrentFiles bool `` /* 190-byte string literal not displayed */
// Seeding goals. A torrent's own goals override these, then its
// category's.
RatioLimit float64 `json:"ratioLimit" doc:"Stop seeding at this upload ratio, -1 for unlimited."`
SeedingTimeLimit int64 `json:"seedingTimeLimit" doc:"Stop seeding after this many minutes, -1 for unlimited."`
InactiveSeedingTimeLimit int64 `json:"inactiveSeedingTimeLimit" doc:"Stop seeding after this many minutes without upload, -1 for unlimited."`
SeedGoalAction string `json:"seedGoalAction" enum:"stop,remove,removeWithData" doc:"What to do once a torrent reaches its seeding goals."`
SeedGoalMode string `` /* 140-byte string literal not displayed */
// Queueing
QueueingEnabled bool `json:"queueingEnabled" doc:"Run only a limited number of torrents at a time; the rest wait in the queue."`
MaxActiveDownloads int `json:"maxActiveDownloads" minimum:"-1" doc:"Torrents downloading at once, -1 for unlimited."`
MaxActiveUploads int `json:"maxActiveUploads" minimum:"-1" doc:"Torrents seeding at once, -1 for unlimited."`
MaxActiveTorrents int `json:"maxActiveTorrents" minimum:"-1" doc:"Torrents running at once, -1 for unlimited."`
DontCountSlowTorrents bool `json:"dontCountSlowTorrents" doc:"Slow torrents don't count toward the limits."`
SlowDownloadRate int64 `json:"slowDownloadRate" minimum:"0" doc:"A torrent below this download rate, in bytes per second, is slow."`
SlowUploadRate int64 `json:"slowUploadRate" minimum:"0" doc:"A torrent below this upload rate, in bytes per second, is slow."`
SlowTorrentTime int64 `json:"slowTorrentTime" minimum:"0" doc:"Seconds a torrent must stay below the slow rates to count as slow."`
// Checking
MaxActiveCheckingTorrents int `` /* 126-byte string literal not displayed */
// IP filter
IPFilterEnabled bool `json:"ipFilterEnabled" doc:"Refuse peers in the ranges of the IP filter file."`
IPFilterPath string `json:"ipFilterPath" doc:"An IP filter file: eMule .dat, PeerGuardian .p2p, or one IP address or CIDR range per line."`
BannedIPs string `json:"bannedIPs" doc:"Peers to refuse: IP addresses or CIDR ranges, one per line."`
// Alternative speed schedule
AltSpeedSchedule bool `json:"altSpeedSchedule" doc:"Turn the alternative limits on and off on a schedule."`
AltSpeedScheduleFrom string `` /* 128-byte string literal not displayed */
AltSpeedScheduleTo string `` /* 149-byte string literal not displayed */
AltSpeedScheduleDays string `` /* 177-byte string literal not displayed */
// RSS
RSSEnabled bool `json:"rssEnabled" doc:"Fetch RSS feeds on their schedule."`
RSSRefreshInterval int `json:"rssRefreshInterval" minimum:"1" doc:"Minutes between fetches of a feed without its own interval."`
RSSFetchDelay int `json:"rssFetchDelay" minimum:"0" doc:"Seconds between requests to the same host."`
RSSMaxArticles int `json:"rssMaxArticles" minimum:"0" doc:"Articles kept per feed; older ones are dropped."`
RSSAutoDownload bool `json:"rssAutoDownload" doc:"Add torrents from new articles that RSS rules match."`
RSSDownloadRepacks bool `json:"rssDownloadRepacks" doc:"With the smart episode filter, also take a REPACK or PROPER of an episode already downloaded."`
RSSSmartEpisodeFilters string `` /* 187-byte string literal not displayed */
}
Settings are the runtime settings. Rates are in bytes per second, where 0 means unlimited. Seed goals use -1 for unlimited.
func Defaults ¶
Defaults returns the built-in defaults. defaultSavePath is the configured download directory.
func (Settings) InAltSpeedWindow ¶ added in v0.4.0
InAltSpeedWindow reports whether the alternative speed schedule is on at now, in now's location.
func (Settings) ProxyServer ¶ added in v1.2.0
ProxyServer returns the proxy server, or nil when proxyType is none.
type ValidationError ¶
type ValidationError struct{ Err error }
ValidationError wraps errors in the requested values.
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string
func (*ValidationError) Unwrap ¶
func (e *ValidationError) Unwrap() error