Documentation
¶
Overview ¶
Package netstate keeps Matinee quick when the internet is down. Every call the server makes to a site outside goes through Tracker's RoundTripper, which remembers the sites that didn't answer and fails further calls to them at once, instead of each one waiting out its timeout, until it's time to try again. Pages, scans and playback never wait on a site that's known to be down, and the server's health page can say "No internet connection" instead of listing every failed lookup.
Index ¶
Constants ¶
const Marker = "waiting for the connection to come back"
Marker is in the text of every error for a call that wasn't made because its site is down, so logs and the health page can tell them apart.
Variables ¶
var ErrDown = errors.New(Marker)
ErrDown matches a DownError with errors.Is.
Functions ¶
This section is empty.
Types ¶
type Site ¶
type Site struct {
Host string `json:"host"`
Since int64 `json:"since"` // milliseconds
Retry int64 `json:"retry"` // when it's tried again, milliseconds
Error string `json:"error,omitempty"`
// Home means it's on the home network, such as Radarr or Home
// Assistant, rather than on the internet.
Home bool `json:"home,omitempty"`
}
Site is a site that's down.
type Status ¶
type Status struct {
// Offline means sites on the internet stopped answering and none has
// answered since.
Offline bool `json:"offline"`
Since int64 `json:"since,omitempty"` // milliseconds, while offline
Down []Site `json:"down"`
}
Status is how the server's connections are doing.
type Tracker ¶
type Tracker struct {
// Back runs, in its own goroutine, when the internet answers again
// after being down, so work that waited can catch up.
Back func()
// FirstWait is how long a site that stopped answering is left alone
// before it's tried again; the wait doubles each time, up to MaxWait.
// Zero is 30 seconds, and five minutes.
FirstWait, MaxWait time.Duration
// contains filtered or unexported fields
}
Tracker remembers which sites are down.
func (*Tracker) Run ¶
func (t *Tracker) Run(ctx context.Context, next http.RoundTripper)
Run checks, while the internet is down, whether it's back: once a down site's wait is over and nothing else has tried it, it's asked for its front page through next (wrapped like every other call), so Back runs within a minute or so of the connection returning, even when nothing else needed the internet meanwhile.
func (*Tracker) Wrap ¶
func (t *Tracker) Wrap(rt http.RoundTripper) http.RoundTripper
Wrap returns a RoundTripper that sends calls on with rt unless their site is down.