speedtestclient

package
v0.0.0-...-d937dcb Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2023 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// SessionTime speedtest 会话最长时间
	SessionTime    = 1 * time.Minute
	PingTimeout    = 10 * time.Second
	HiTimeout      = 1 * time.Minute
	UpDownloadSize = 128 * converter.PB
)
View Source
const (
	SpeedtestHost = "www.speedtest.net"
)

Variables

View Source
var (
	ErrHiResponse     = errors.New("unexpected HI response")
	ErrPingResponse   = errors.New("unexpected PING response")
	ErrNotSocks5Proxy = errors.New("not socks5 proxy")
)

Functions

func IsTimeout

func IsTimeout(err error) bool

Types

type HIRes

type HIRes struct {
	Message string
	Latency time.Duration
}

HIRes HI 结果

type LocalInfo

type LocalInfo struct {
	IP        string
	Lat       float64
	Lon       float64
	ISP       string
	ISPID     int
	Carrier   string
	CarrierID int
	LatestVer string
	// contains filtered or unexported fields
}

func (*LocalInfo) PrintTo

func (li *LocalInfo) PrintTo(w io.Writer)

type PingCallback

type PingCallback func(seq int, latency time.Duration)

type PingRes

type PingRes struct {
	Latencies []time.Duration
	Average   time.Duration
	Min       time.Duration
	Max       time.Duration
	Median    time.Duration
}

PingRes PING 结果

func NewPingRes

func NewPingRes(latencies []time.Duration) *PingRes

type SpeedtestClient

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

func NewSpeedtestClient

func NewSpeedtestClient() *SpeedtestClient

func (*SpeedtestClient) GetAllServerList

func (sc *SpeedtestClient) GetAllServerList() (servList SpeedtestServerList, err error)

func (*SpeedtestClient) GetLocalInfoAndServerList

func (sc *SpeedtestClient) GetLocalInfoAndServerList() (li *LocalInfo, servList SpeedtestServerList, err error)

func (*SpeedtestClient) SetProxy

func (sc *SpeedtestClient) SetProxy(proxyAddr string)

SetProxy 设置代理

func (*SpeedtestClient) WithHost

func (sc *SpeedtestClient) WithHost(host string) *SpeedtestClientWithHost

type SpeedtestClientWithHost

type SpeedtestClientWithHost struct {
	SpeedtestClient
	Host string
	// contains filtered or unexported fields
}

func (*SpeedtestClientWithHost) Download

func (sch *SpeedtestClientWithHost) Download(opt *UpDownloadOption, callback UpDownloadCallback) (res *UpDownloadRes, err error)

func (*SpeedtestClientWithHost) HI

func (sch *SpeedtestClientWithHost) HI() (res *HIRes, err error)

func (*SpeedtestClientWithHost) Ping

func (sch *SpeedtestClientWithHost) Ping(times int, sleep time.Duration, callback PingCallback) (res *PingRes, err error)

func (*SpeedtestClientWithHost) SetLocalAddr

func (sch *SpeedtestClientWithHost) SetLocalAddr(localAddr *net.TCPAddr)

func (*SpeedtestClientWithHost) SetSocks5Proxy

func (sch *SpeedtestClientWithHost) SetSocks5Proxy(proxyAddr string) (err error)

func (*SpeedtestClientWithHost) Upload

func (sch *SpeedtestClientWithHost) Upload(opt *UpDownloadOption, callback UpDownloadCallback) (res *UpDownloadRes, err error)

type SpeedtestServer

type SpeedtestServer struct {
	ID      int
	Name    string
	Sponsor string
	Lat     float64
	Lon     float64
	Host    string
	// contains filtered or unexported fields
}

func (*SpeedtestServer) String

func (server *SpeedtestServer) String() string

type SpeedtestServerList

type SpeedtestServerList []*SpeedtestServer

func (SpeedtestServerList) FindByID

func (servList SpeedtestServerList) FindByID(id int) (server *SpeedtestServer)

func (SpeedtestServerList) PrintTo

func (servList SpeedtestServerList) PrintTo(w io.Writer)

type Statistic

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

Statistic 统计

func (*Statistic) AddTransferSize

func (s *Statistic) AddTransferSize(size int64) int64

func (*Statistic) AppendSpeedPerSecond

func (s *Statistic) AppendSpeedPerSecond(speed int64)

func (*Statistic) Elapsed

func (s *Statistic) Elapsed() (elapsed time.Duration)

func (*Statistic) ElapsedAndLeft

func (s *Statistic) ElapsedAndLeft() (elapsed, left time.Duration)

func (*Statistic) SpeedPerSecond

func (s *Statistic) SpeedPerSecond() int64

func (*Statistic) StartTimer

func (s *Statistic) StartTimer()

func (*Statistic) TotalSize

func (s *Statistic) TotalSize() int64

func (*Statistic) TransferSize

func (s *Statistic) TransferSize() int64

type TimeDurationSlice

type TimeDurationSlice []time.Duration

func (TimeDurationSlice) Len

func (p TimeDurationSlice) Len() int

func (TimeDurationSlice) Less

func (p TimeDurationSlice) Less(i, j int) bool

func (TimeDurationSlice) Swap

func (p TimeDurationSlice) Swap(i, j int)

type UpDownloadCallback

type UpDownloadCallback func(statistic *Statistic)

UpDownloadCallback 上传或下载的回调

type UpDownloadOption

type UpDownloadOption struct {
	Timeout          time.Duration
	Parallel         int
	CallbackInterval time.Duration // 回调函数调用的时间间隔
}

type UpDownloadRes

type UpDownloadRes struct {
	TimeElapsed       time.Duration
	SpeedsPerSecond   []int64
	MaxSpeedPerSecond int64
	MinSpeedPerSecond int64
	AverageSpeed      int64
	MedianSpeed       int64
}

UpDownloadRes 下载或上传的结果

func NewUpDownloadRes

func NewUpDownloadRes(timeElapsed time.Duration, statistic *Statistic) *UpDownloadRes

Jump to

Keyboard shortcuts

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