sthttp

package
v0.0.0-...-29aba68 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2020 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ByDistance

type ByDistance []Server

ByDistance allows us to sort servers by distance

func (ByDistance) Len

func (server ByDistance) Len() int

func (ByDistance) Less

func (server ByDistance) Less(i, j int) bool

func (ByDistance) Swap

func (server ByDistance) Swap(i, j int)

type ByLatency

type ByLatency []Server

ByLatency allows us to sort servers by latency

func (ByLatency) Len

func (server ByLatency) Len() int

func (ByLatency) Less

func (server ByLatency) Less(i, j int) bool

func (ByLatency) Swap

func (server ByLatency) Swap(i, j int)

type Client

type Client struct {
	Config          *Config
	SpeedtestConfig *SpeedtestConfig
	HTTPConfig      *HTTPConfig
	Debug           bool
	ReportChar      string
}

Client define a Speedtest HTTP client

func NewClient

func NewClient(speedtestConfig *SpeedtestConfig, httpConfig *HTTPConfig, debug bool, reportChar string) *Client

NewClient define a new Speedtest client.

func (*Client) DownloadSpeed

func (stClient *Client) DownloadSpeed(url string) (speed float64, err error)

DownloadSpeed measures the mbps of downloading a URL

func (*Client) GetClosestServers

func (stClient *Client) GetClosestServers(servers []Server) []Server

GetClosestServers takes the full server list and sorts by distance

func (*Client) GetConfig

func (stClient *Client) GetConfig() (c Config, err error)

GetConfig downloads the master config from speedtest.net

func (*Client) GetFastestServer

func (stClient *Client) GetFastestServer(servers []Server) Server

GetFastestServer test all servers until we find numServers that respond, then find the fastest of them. Some servers show up in the master list but timeout or are "corrupt" therefore we bump their latency to something really high (1 minute) and they will drop out of this test

func (*Client) GetLatency

func (stClient *Client) GetLatency(server Server, url string) (result float64, err error)

GetLatency will test the latency (ping) the given server NUMLATENCYTESTS times and return either the lowest or average depending on what algorithm is set

func (*Client) GetLatencyURL

func (stClient *Client) GetLatencyURL(server Server) string

GetLatencyURL will return the proper url for the latency

func (*Client) GetServers

func (stClient *Client) GetServers() (servers []Server, err error)

GetServers will get the full server list

func (*Client) UploadSpeed

func (stClient *Client) UploadSpeed(url string, mimetype string, data []byte) (speed float64, err error)

UploadSpeed measures the mbps to http.Post to a URL

type Config

type Config struct {
	IP  string
	Lat float64
	Lon float64
	Isp string
}

Config struct holds our config (users current ip, lat, lon and isp)

type HTTPConfig

type HTTPConfig struct {
	HTTPTimeout time.Duration
}

HTTPConfig define settings for HTTP requests

type Server

type Server struct {
	URL      string
	Lat      float64
	Lon      float64
	Name     string
	Country  string
	CC       string
	Sponsor  string
	ID       string
	Distance float64
	Latency  float64
}

Server struct is a speedtest candidate server

type ServerSettings

type ServerSettings struct {
	XMLName          xml.Name            `xml:"settings"`
	ServersContainer TheServersContainer `xml:"servers"`
}

ServerSettings is the servers part of the setings

type SpeedtestConfig

type SpeedtestConfig struct {
	ConfigURL       string
	ServersURL      string
	AlgoType        string
	NumClosest      int
	NumLatencyTests int
	Interface       string
	Blacklist       []string
	UserAgent       string
}

SpeedtestConfig define Speedtest settings

type TheClient

type TheClient struct {
	IP  string `xml:"ip,attr"`
	Lat string `xml:"lat,attr"`
	Lon string `xml:"lon,attr"`
	Isp string `xml:"isp,attr"`
}

TheClient is our users information

type TheServersContainer

type TheServersContainer struct {
	XMLName    xml.Name    `xml:"servers"`
	XMLServers []XMLServer `xml:"server"`
}

TheServersContainer is a list of servers

type XMLConfigSettings

type XMLConfigSettings struct {
	XMLName xml.Name  `xml:"settings"`
	Client  TheClient `xml:"client"`
}

XMLConfigSettings is a container for settings

type XMLServer

type XMLServer struct {
	XMLName xml.Name `xml:"server"`
	URL     string   `xml:"url,attr"`
	Lat     string   `xml:"lat,attr"`
	Lon     string   `xml:"lon,attr"`
	Name    string   `xml:"name,attr"`
	Country string   `xml:"country,attr"`
	CC      string   `xml:"cc,attr"`
	Sponsor string   `xml:"sponsor,attr"`
	ID      string   `xml:"id,attr"`
}

XMLServer is a candidate server

Jump to

Keyboard shortcuts

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