39 lines
1.3 KiB
Go
39 lines
1.3 KiB
Go
package agentapi
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
// LineTestState mirrors the agent's GET /host/line-test (agent ≥ 0.164.0; felhom.eu R-1247): the host's weekly upload
|
|
// line test — a 10-second iperf3 upload to ep0 inside the offsite tunnel, best of three runs, as ep0's server counted
|
|
// it. Present=false: never measured (no tunnel, not yet due, or disabled). An agent before the route answers 404 (a
|
|
// *StatusError); all three mean UNKNOWN, and the controller then sets no qBittorrent limit.
|
|
type LineTestState struct {
|
|
Present bool `json:"present"`
|
|
Mbps float64 `json:"mbps,omitempty"`
|
|
MeasuredAt string `json:"measured_at,omitempty"` // RFC3339 UTC
|
|
Method string `json:"method,omitempty"`
|
|
}
|
|
|
|
// LineTest calls GET /host/line-test.
|
|
func (c *Client) LineTest(ctx context.Context) (LineTestState, error) {
|
|
var out LineTestState
|
|
body, err := c.get(ctx, "/host/line-test")
|
|
if err != nil {
|
|
return out, err
|
|
}
|
|
if err := json.Unmarshal(body, &out); err != nil {
|
|
return out, fmt.Errorf("agentapi: decode /host/line-test: %w", err)
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
// MeasuredAtTime parses MeasuredAt (zero time when absent or garbled).
|
|
func (s LineTestState) MeasuredAtTime() time.Time {
|
|
t, _ := time.Parse(time.RFC3339, s.MeasuredAt)
|
|
return t
|
|
}
|