Documentation
¶
Overview ¶
Package speedtest measures how fast a node reaches the internet, for the panel's "network capacity" suggestion (agent.proto "BANDWIDTH TEST"). It is an estimate from a few short tests against a public server that needs no account: three runs back to back, each with parallel downloads for a few seconds and then parallel uploads, the best run per direction wins; a hard cap on the bytes moved and a deadline on every phase. In the counted window of every run the node's main network interface is read too, so the traffic of the people already using the node counts as part of the capacity instead of being lost from it. It asks nothing of the host and keeps nothing.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrUnreachable = errors.New("no speed test server answered")
ErrUnreachable means no endpoint gave a usable answer (blocked, down, or the node has no route out).
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
Endpoints []Endpoint
// Client overrides the HTTP client (tests). Nil = a client without proxy or HTTP/2: every stream is its own TCP connection.
Client *http.Client
// Runs of download + upload one after another (at least 1), Pause between them.
Runs int
Pause time.Duration
// DownStreams and UpStreams run in parallel.
DownStreams, UpStreams int
// DownFor and UpFor are the lengths of the two phases of a run; in-flight uploads may finish up to upGrace later.
DownFor, UpFor time.Duration
// Warm is the start of the download that does not count: TCP slow start. A run cut short (the cap) counts as a whole.
Warm time.Duration
// DownCap and UpCap are hard limits on the bytes moved in a phase of one run. Runs times both is the cap of a click.
DownCap, UpCap int64
// Overall ends everything, whatever the endpoints do. A run is not started when what is left would not fit it.
Overall time.Duration
// Counters is the host's interface counters; nil = the test alone is measured.
Counters Counters
// contains filtered or unexported fields
}
Config is the whole test. Default() is the production one; tests shrink it and point it at a local server.
func Default ¶
Default is the production test: three runs of 6 streams down for 5 s (the first second is not counted) and 4 up for 2 s, a second apart, at most 400 MB down and 100 MB up per run (1.5 GB in all), 45 s in all. Cloudflare answers any size up to 50 MB per request (50 MB a request keeps the number of requests low: it rate-limits an address with 429) and takes uploads; the two fallbacks are plain files for a node that cannot reach it. counters may be nil.
type Counters ¶
Counters reads the byte counters of the node's main network interface: its name (a changed name between two reads means the route moved and the pair is useless), bytes received and bytes sent since boot. ok = false when it cannot.
type Endpoint ¶
type Endpoint struct {
// Name is what the result says, e.g. "speed.cloudflare.com".
Name string
// DownURL answers a GET with a body to read; the stream reads it to the end and asks again until the time is up.
DownURL string
// UpURL takes a POST with a body of any size up to a few MB; "" = this server has no upload, the result says 0.
UpURL string
}
Endpoint is one public test server.
type Result ¶
type Result struct {
// Mbps are megabits per second (10^6 bit/s), the unit of node.bandwidth_mbps. Each is the better of what the test alone
// moved and what the interface carried in the same window, so people's traffic is part of it. UpMbps is 0 when it
// could not be measured.
DownMbps, UpMbps float64
// PeopleDownMbps and PeopleUpMbps are what the interface carried beyond the test in the best run of that direction
// (traffic of people using the node), 0 when it was not more than the test's own headers, or there are no counters.
PeopleDownMbps, PeopleUpMbps float64
Server string
DownStreams int
// Runs that gave a result.
Runs int
DownBytes int64 // all runs together
UpBytes int64
Seconds float64
}
Result is what the panel gets: the best run per direction.
func Run ¶
Run measures Runs times with the first endpoint that works for the first run, and keeps the best run per direction. A failed upload does not fail a run (its up stays 0); a download that moved no byte moves the first run on to the next endpoint; a later run that fails, or does not fit in what is left of Overall, is skipped. It fails only when no run worked.