netstate

package
v0.2.7 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0 modules, 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 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

View Source
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

View Source
var ErrDown = errors.New(Marker)

ErrDown matches a DownError with errors.Is.

Functions

This section is empty.

Types

type DownError

type DownError struct {
	Host  string
	Until time.Time // when it's tried again
}

DownError is a call that wasn't made because its site didn't answer lately.

func (*DownError) Error

func (e *DownError) Error() string

func (*DownError) Is

func (e *DownError) Is(target error) bool

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 New

func New() *Tracker

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) Status

func (t *Tracker) Status() Status

Status says which sites are down.

func (*Tracker) Wrap

Wrap returns a RoundTripper that sends calls on with rt unless their site is down.

Jump to

Keyboard shortcuts

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