speedtestdotnet

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2021 License: MIT Imports: 19 Imported by: 2

Documentation

Index

Constants

View Source
const DefaultLatencySamples = 4

Variables

This section is empty.

Functions

func SortServersByDistance

func SortServersByDistance(servers []Server, org geo.Coordinates) map[ServerID]geo.Kilometers

func StableSortServersByAverageLatency

func StableSortServersByAverageLatency(
	servers []Server,
	ctx context.Context,
	client *Client,
	samples int,
) (map[ServerID]time.Duration, error)

Probes each and every server and stable sorts them based on their average latencies.

Returns the average latencies in a map keyed by each server's ID and an error if all probes were unsuccessful. An error for a particular server gets treated as if the latency was higher than any successful probe.

Types

type Client

type Client http.Client

func (*Client) Config

func (c *Client) Config(ctx context.Context) (Config, error)

func (*Client) LoadAllServers

func (c *Client) LoadAllServers(ctx context.Context) ([]Server, error)

type Config

type Config struct {
	Coordinates        geo.Coordinates
	IP                 string  `xml:"ip,attr"`
	ISP                string  `xml:"isp,attr"`
	ISPRating          float32 `xml:"isprating,attr"`
	ISPDownloadAverage uint    `xml:"ispdlavg,attr"`
	ISPUploadAverage   uint    `xml:"ispulavg,attr"`
	Rating             float32 `xml:"rating,attr"`
}

type Server

type Server struct {
	ID          ServerID `xml:"id,attr"`
	Name        string   `xml:"name,attr"`
	Coordinates geo.Coordinates
	URL         string `xml:"url,attr"`
	URL2        string `xml:"url2,attr"`
	Country     string `xml:"country,attr"`
	CC          string `xml:"cc,attr"`
	Sponsor     string `xml:"sponsor,attr"`
	Host        string `xml:"host,attr"`
}

func (Server) AverageLatency

func (s Server) AverageLatency(
	ctx context.Context,
	client *Client,
	samples int,
) (time.Duration, error)

Takes samples of a server's latency and returns the average.

Serialized and fails fast. It is assumed that if there is an error doing a single latency probe to a server, that server is not a good candidate for a speed test.

func (Server) Latency

func (s Server) Latency(
	ctx context.Context,
	client *Client,
) (time.Duration, error)

func (Server) ProbeDownloadSpeed

func (s Server) ProbeDownloadSpeed(
	ctx context.Context,
	client *Client,
	stream chan<- units.BytesPerSecond,
) (units.BytesPerSecond, error)

Will probe download speed until enough samples are taken or ctx expires.

func (Server) ProbeUploadSpeed

func (s Server) ProbeUploadSpeed(
	ctx context.Context,
	client *Client,
	stream chan<- units.BytesPerSecond,
) (units.BytesPerSecond, error)

Will probe upload speed until enough samples are taken or ctx expires.

func (*Server) RelativeURL

func (s *Server) RelativeURL(local string) (string, error)

func (Server) String

func (s Server) String() string

type ServerID

type ServerID uint64

Jump to

Keyboard shortcuts

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