engine

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// DefaultConnections is the number of parallel streams used to saturate the link.
	DefaultConnections = 5
	// DefaultDuration is how long each transfer phase (download / upload) runs.
	DefaultDuration = 10 * time.Second
)

Variables

This section is empty.

Functions

func BytesPerSecToMbps

func BytesPerSecToMbps(bps float64) float64

BytesPerSecToMbps converts a raw byte/sec rate into megabits per second.

func Run

func Run(ctx context.Context, p *Progress, connections int, duration time.Duration)

Run executes the full test: discover targets, download, upload, latency. It streams Phase transitions on p.Phases, Samples on p.Samples, and a final Result on p.Result. Always emits a Result (best-effort partials on cancel).

func RunMonitor added in v1.3.1

func RunMonitor(ctx context.Context, p *Progress, sampleInterval time.Duration)

RunMonitor is the real Bandwidth Monitor engine for macOS. It generates no traffic: it reads OS interface byte counters via `netstat -ib -n` and derives the actual download / upload throughput of the whole machine from deltas between samples. It runs until ctx is cancelled.

Scope: every non-loopback interface reported by netstat is summed (en0, en1, utun* for VPNs, etc.), matching the spirit of Linux and Windows implementations.

Types

type Phase

type Phase int

Phase enumerates the test lifecycle.

const (
	PhaseInit Phase = iota
	PhaseFinding
	PhaseConnected
	PhaseDownload
	PhaseUpload
	PhaseLatency
	PhaseDone
)

func (Phase) String

func (p Phase) String() string

type Progress

type Progress struct {
	URLs       []string   // discovered target URLs (set once)
	ServerName string     // human-readable server/region label (set once)
	Phases     chan Phase // phase transitions
	Samples    chan Sample
	Result     chan Result
	Err        error
}

Progress is the live channel payload the UI consumes.

type Result

type Result struct {
	DownloadMbps float64
	UploadMbps   float64
	PingMs       float64
	DownloadPeak float64
	UploadPeak   float64
	Client       string // human-readable location/ISP if known
}

Result is the final measurement summary.

type Sample

type Sample struct {
	Phase Phase   // which phase produced this sample
	Bytes uint64  // bytes transferred so far in the current phase
	Rate  float64 // instantaneous rate in bytes/sec
	At    time.Time
}

Sample is one instantaneous speed measurement broadcast to the UI each tick.

Jump to

Keyboard shortcuts

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