defs

package
v1.0.11 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2024 License: LGPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OptionHelp            = "help"
	OptionIPv4            = "ipv4"
	OptionIPv4Alt         = "4"
	OptionIPv6            = "ipv6"
	OptionIPv6Alt         = "6"
	OptionNoDownload      = "no-download"
	OptionNoUpload        = "no-upload"
	OptionNoICMP          = "no-icmp"
	OptionConcurrent      = "concurrent"
	OptionBytes           = "bytes"
	OptionMebiBytes       = "mebibytes"
	OptionDistance        = "distance"
	OptionShare           = "share"
	OptionSimple          = "simple"
	OptionCSV             = "csv"
	OptionCSVDelimiter    = "csv-delimiter"
	OptionCSVHeader       = "csv-header"
	OptionJSON            = "json"
	OptionList            = "list"
	OptionServer          = "server"
	OptionExclude         = "exclude"
	OptionServerJSON      = "server-json"
	OptionSource          = "source"
	OptionInterface       = "interface"
	OptionTimeout         = "timeout"
	OptionChunks          = "chunks"
	OptionUploadSize      = "upload-size"
	OptionDuration        = "duration"
	OptionSecure          = "secure"
	OptionCACert          = "ca-cert"
	OptionSkipCertVerify  = "skip-cert-verify"
	OptionNoPreAllocate   = "no-pre-allocate"
	OptionVersion         = "version"
	OptionLocalJSON       = "local-json"
	OptionDebug           = "debug"
	OptionTelemetryJSON   = "telemetry-json"
	OptionTelemetryLevel  = "telemetry-level"
	OptionTelemetryServer = "telemetry-server"
	OptionTelemetryPath   = "telemetry-path"
	OptionTelemetryShare  = "telemetry-share"
	OptionTelemetryExtra  = "telemetry-extra"
)
View Source
const (
	TelemetryLevelDisabled = "disabled"
	TelemetryLevelBasic    = "basic"
	TelemetryLevelFull     = "full"
	TelemetryLevelDebug    = "debug"
)

Variables

View Source
var (
	// values to be filled in by build script
	BuildDate   string
	ProgName    string
	ProgVersion string
	UserAgent   = ProgName + "/" + ProgVersion
)

Functions

This section is empty.

Types

type BytesCounter

type BytesCounter struct {
	// contains filtered or unexported fields
}

BytesCounter implements io.Reader and io.Writer interface, for counting bytes being read/written in HTTP requests

func NewCounter

func NewCounter() *BytesCounter

func (*BytesCounter) AvgBytes

func (c *BytesCounter) AvgBytes() float64

AvgBytes returns the average bytes/second

func (*BytesCounter) AvgHumanize

func (c *BytesCounter) AvgHumanize() string

AvgHumanize returns the average bytes/kilobytes/megabytes/gigabytes (or bytes/kibibytes/mebibytes/gibibytes) per second

func (*BytesCounter) AvgMbps

func (c *BytesCounter) AvgMbps() float64

AvgMbps returns the average mbits/second

func (*BytesCounter) CurrentSpeed

func (c *BytesCounter) CurrentSpeed() float64

CurrentSpeed returns the current bytes/second

func (*BytesCounter) GenerateBlob

func (c *BytesCounter) GenerateBlob()

GenerateBlob generates a random byte array of `uploadSize` in the `payload` field, and sets the `reader` field to read from it

func (*BytesCounter) Read

func (c *BytesCounter) Read(p []byte) (int, error)

Read implements io.Reader

func (*BytesCounter) SetMebi

func (c *BytesCounter) SetMebi(mebi bool)

SetBase sets the base for dividing bytes into megabyte or mebibyte

func (*BytesCounter) SetUploadSize

func (c *BytesCounter) SetUploadSize(uploadSize int)

SetUploadSize sets the size of payload being uploaded

func (*BytesCounter) Start

func (c *BytesCounter) Start()

Start will set the `start` field to current time

func (*BytesCounter) Total

func (c *BytesCounter) Total() uint64

Total returns the total bytes read/written

func (*BytesCounter) Write

func (c *BytesCounter) Write(p []byte) (int, error)

Write implements io.Writer

type GetIPResult

type GetIPResult struct {
	ProcessedString string         `json:"processedString"`
	RawISPInfo      IPInfoResponse `json:"rawIspInfo"`
}

GetIPResults represents the returned JSON from backend server's getIP.php endpoint

type IPInfoResponse

type IPInfoResponse struct {
	IP           string `json:"ip"`
	Hostname     string `json:"hostname"`
	City         string `json:"city"`
	Region       string `json:"region"`
	Country      string `json:"country"`
	Location     string `json:"loc"`
	Organization string `json:"org"`
	Postal       string `json:"postal"`
	Timezone     string `json:"timezone"`
	Readme       string `json:"readme,omitempty"`
}

IPInfoResponse represents the returned JSON from IPInfo.io's API

type NoFormatter

type NoFormatter struct{}

NoFormatter is the formatter for logrus

func (*NoFormatter) Format

func (f *NoFormatter) Format(entry *log.Entry) ([]byte, error)

Format prints the log message without timestamp/log level etc.

type SeekWrapper

type SeekWrapper struct {
	io.Reader
}

SeekWrapper is a wrapper around io.Reader to give it a noop io.Seeker interface

func (*SeekWrapper) Seek

func (r *SeekWrapper) Seek(offset int64, whence int) (int64, error)

Seek implements the io.Seeker interface

type Server

type Server struct {
	ID          int    `json:"id"`
	Name        string `json:"name"`
	Server      string `json:"server"`
	DownloadURL string `json:"dlURL"`
	UploadURL   string `json:"ulURL"`
	PingURL     string `json:"pingURL"`
	GetIPURL    string `json:"getIpURL"`
	SponsorName string `json:"sponsorName"`
	SponsorURL  string `json:"sponsorURL"`

	NoICMP bool         `json:"-"`
	TLog   TelemetryLog `json:"-"`
}

Server represents a speed test server

func (*Server) Download

func (s *Server) Download(silent bool, useBytes, useMebi bool, requests int, chunks int, duration time.Duration) (float64, uint64, error)

Download performs the actual download test

func (*Server) GetIPInfo

func (s *Server) GetIPInfo(distanceUnit string) (*GetIPResult, error)

GetIPInfo accesses the backend's getIP.php endpoint and get current client's IP information

func (*Server) GetURL

func (s *Server) GetURL() (*url.URL, error)

GetURL parses the server's URL into a url.URL

func (*Server) ICMPPingAndJitter

func (s *Server) ICMPPingAndJitter(count int, srcIp, network string) (float64, float64, error)

ICMPPingAndJitter pings the server via ICMP echos and calculate the average ping and jitter

func (*Server) IsUp

func (s *Server) IsUp() bool

IsUp checks the speed test backend is up by accessing the ping URL

func (*Server) PingAndJitter

func (s *Server) PingAndJitter(count int) (float64, float64, error)

PingAndJitter pings the server via accessing ping URL and calculate the average ping and jitter

func (*Server) Sponsor

func (s *Server) Sponsor() string

Sponsor returns the sponsor's info

func (*Server) Upload

func (s *Server) Upload(noPrealloc, silent, useBytes, useMebi bool, requests int, uploadSize int, duration time.Duration) (float64, uint64, error)

Upload performs the actual upload test

type TelemetryExtra

type TelemetryExtra struct {
	ServerName string `json:"server"`
	Extra      string `json:"extra,omitempty"`
}

TelemetryExtra represents the `extra` field in the telemetry data

type TelemetryLog

type TelemetryLog struct {
	// contains filtered or unexported fields
}

TelemetryLog is the logger for `log` field in telemetry data

func (*TelemetryLog) Logf

func (t *TelemetryLog) Logf(format string, a ...interface{})

Logf logs when log level is higher than or equal to "full"

func (*TelemetryLog) SetLevel

func (t *TelemetryLog) SetLevel(level int)

SetLevel sets the log level

func (*TelemetryLog) String

func (t *TelemetryLog) String() string

String returns the concatenated string of field `content`

func (*TelemetryLog) Verbosef

func (t *TelemetryLog) Verbosef(format string, a ...interface{})

Verbosef logs when log level is higher than or equal to "debug"

func (*TelemetryLog) Warnf

func (t *TelemetryLog) Warnf(format string, a ...interface{})

Warnf logs when log level is higher than or equal to "full", with a WARN prefix

type TelemetryServer

type TelemetryServer struct {
	Level  string `json:"telemetryLevel"`
	Server string `json:"server"`
	Path   string `json:"path"`
	Share  string `json:"shareURL"`
}

TelemetryServer represents the telemetry server configuration

func (*TelemetryServer) Basic

func (t *TelemetryServer) Basic() bool

Basic checks if the telemetry level is "basic"

func (*TelemetryServer) Debug

func (t *TelemetryServer) Debug() bool

Debug checks if the telemetry level is "debug"

func (*TelemetryServer) Disabled

func (t *TelemetryServer) Disabled() bool

Disabled checks if the telemetry level is "disabled"

func (*TelemetryServer) Full

func (t *TelemetryServer) Full() bool

Full checks if the telemetry level is "full"

func (*TelemetryServer) GetLevel

func (t *TelemetryServer) GetLevel() int

GetLevel translates the level string to corresponding integer value

func (*TelemetryServer) GetPath

func (t *TelemetryServer) GetPath() (*url.URL, error)

GetPath parses and returns the telemetry path

func (*TelemetryServer) GetShare

func (t *TelemetryServer) GetShare() (*url.URL, error)

GetShare parses and returns the telemetry share path

Jump to

Keyboard shortcuts

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