Compare commits
1
Commits
next
..
71774015db
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
71774015db |
+10
-25
@@ -1,28 +1,19 @@
|
||||
# .dockerignore does NOT use .gitignore semantics. Docker matches with
|
||||
# moby/patternmatcher: filepath.Match plus `**`, so `*` does not cross
|
||||
# `/` and an unprefixed pattern is anchored at the context root. Every
|
||||
# depth-independent pattern therefore needs `**/`, or `config/.env` and
|
||||
# `certs/server.key` still ship while this file reads as solved. Only
|
||||
# genuinely root-anchored entries go unprefixed. Never transplant these
|
||||
# into .gitignore, where `**/` is wrong.
|
||||
# depth-independent pattern therefore needs `**/`; only genuinely
|
||||
# root-anchored entries go unprefixed. Never transplant these into
|
||||
# .gitignore, where `**/` is wrong.
|
||||
#
|
||||
# Matching is case-sensitive, so secrets use character ranges rather
|
||||
# than an ALL-CAPS twin, which would still miss `Server.Key`.
|
||||
#
|
||||
# Extend with this repo's own host-built artifacts, written anchored:
|
||||
# `/myapp`, never `**/myapp`, which also matches `cmd/myapp/` and
|
||||
# deletes the package directory from the context.
|
||||
|
||||
# .git is sent without its config. Without a VERSION build argument the
|
||||
# stage that compiles runs `git describe --tags --always` on .git, which
|
||||
# does not need .git/config; that file can hold a credential, such as a
|
||||
# password in a remote URL or the token the CI checkout step stores there.
|
||||
.git/config
|
||||
# Excluding .git means `git describe` cannot run in any build stage and
|
||||
# fails quietly there; rtnetmon embeds no version, so this is safe.
|
||||
.git
|
||||
|
||||
# Agent scratch: one full checkout of the repo per in-flight agent.
|
||||
# Anchored because it occurs once where agents run at the repo root.
|
||||
# KNOWN GAP: a repo running agents in subdirectories still ships
|
||||
# `services/api/.claude/` and must add its own anchored entry.
|
||||
# Anchored because agents run at the repo root here.
|
||||
.claude
|
||||
|
||||
# This repo's own host-built artifacts, root-anchored so `bin/` is not
|
||||
@@ -31,15 +22,12 @@
|
||||
/rtnetmon
|
||||
main.go.old
|
||||
|
||||
# Environment files. `*.env` covers bare `.env` and the `prod.env`
|
||||
# convention. Re-include a committed template with a negation if the
|
||||
# build needs one: `!docs/example.env`.
|
||||
# Environment files.
|
||||
**/*.[eE][nN][vV]
|
||||
**/.[eE][nN][vV].*
|
||||
**/.[eE][nN][vV][rR][cC]
|
||||
|
||||
# Private keys and the bundles carrying them. Public certificates
|
||||
# (*.crt, *.cer) are deliberately absent: they are legitimate inputs.
|
||||
# Private keys and the bundles carrying them.
|
||||
**/*.[pP][eE][mM]
|
||||
**/*.[kK][eE][yY]
|
||||
**/*.[pP]12
|
||||
@@ -49,14 +37,11 @@ main.go.old
|
||||
**/[iI][dD]_[eE][cC][dD][sS][aA]
|
||||
**/[iI][dD]_[eE][dD]25519
|
||||
|
||||
# Dependencies: restored inside the image, never copied in.
|
||||
**/node_modules
|
||||
|
||||
# OS metadata.
|
||||
**/.DS_Store
|
||||
**/Thumbs.db
|
||||
|
||||
# Editor state: never a build input, and it churns COPY.
|
||||
# Editor state.
|
||||
**/*.swp
|
||||
**/*.swo
|
||||
**/*~
|
||||
|
||||
+1
-15
@@ -34,18 +34,4 @@ WORKDIR /src
|
||||
COPY go.mod go.sum ./
|
||||
RUN go mod download
|
||||
COPY . .
|
||||
# The version stamped into the binary: the VERSION build argument when one
|
||||
# is given, otherwise `git describe --tags --always` of the .git the build
|
||||
# context carries: the tag on a tagged commit, tag-N-gHASH on a commit after
|
||||
# one, the short commit when no tag is reachable. git ships in this base
|
||||
# image. A context that carries .git and still yields no version fails the
|
||||
# build. With neither, as from a source tarball, the binary reports dev.
|
||||
ARG VERSION
|
||||
RUN version="${VERSION:-$(git describe --tags --always)}"; \
|
||||
if [ -e .git ] && { [ -z "$version" ] || [ "$version" = dev ] || \
|
||||
[ "$version" = unknown ]; }; then \
|
||||
echo "no version could be derived although the build context carries .git" >&2; \
|
||||
exit 1; \
|
||||
fi; \
|
||||
CGO_ENABLED=0 go build -trimpath -ldflags="-X main.Version=${version:-dev}" \
|
||||
-o /rtnetmon ./cmd/rtnetmon/
|
||||
RUN CGO_ENABLED=0 go build -trimpath -o /rtnetmon ./cmd/rtnetmon/
|
||||
|
||||
@@ -5,8 +5,6 @@
|
||||
# below are thin shims that call them.
|
||||
.DEFAULT_GOAL := check
|
||||
|
||||
VERSION ?= $(shell git describe --tags --always)
|
||||
|
||||
bootstrap:
|
||||
@script/bootstrap
|
||||
|
||||
@@ -38,14 +36,13 @@ hooks:
|
||||
@script/install-precommit
|
||||
|
||||
build:
|
||||
CGO_ENABLED=0 go build -trimpath -ldflags "-X main.Version=$(VERSION)" \
|
||||
-o bin/rtnetmon ./cmd/rtnetmon
|
||||
CGO_ENABLED=0 go build -trimpath -o bin/rtnetmon ./cmd/rtnetmon
|
||||
|
||||
run: build
|
||||
./bin/rtnetmon
|
||||
|
||||
dev:
|
||||
go run -ldflags "-X main.Version=$(VERSION)" ./cmd/rtnetmon
|
||||
go run ./cmd/rtnetmon
|
||||
|
||||
deps:
|
||||
go mod download
|
||||
|
||||
@@ -46,47 +46,27 @@ single pane.
|
||||
setup, unchanged. When neither exists, the single default-route interface is
|
||||
monitored instead.
|
||||
|
||||
**macOS.** The physical internet interface is found from the default route. The
|
||||
VPN pane appears only while a VPN is connected, meaning its `utun` tunnel
|
||||
carries the IPv4 default route: in `netstat -rn -f inet` that is a `default` row
|
||||
on the tunnel, or both a `0/1` and a `128.0/1` row on it, which some VPN clients
|
||||
install instead of replacing the default. That tunnel is then monitored as the
|
||||
primary pane alongside the physical interface. A tunnel that is up without the
|
||||
default route is ignored, whatever its address: Tailscale without an exit node,
|
||||
or a tunnel a disconnected client left behind. A default route scoped to the
|
||||
tunnel alone (flag `I`) does not count either. With no VPN connected, only the
|
||||
physical interface is monitored. Interface names are detected on macOS; the
|
||||
**macOS.** The physical internet interface is found from the default route. When
|
||||
a VPN client is running (Mullvad and similar clients create a `utun` tunnel that
|
||||
carries a default route or holds a routable address), that tunnel is monitored
|
||||
as the primary pane alongside the physical interface. With no VPN running, only
|
||||
the physical interface is monitored. Interface names are detected on macOS; the
|
||||
`--ifaceA`/`--ifaceB` flags are not used there, but `--labelA`/`--labelB` still
|
||||
set the pane labels.
|
||||
|
||||
### Supported matrix
|
||||
|
||||
| OS | Interfaces monitored |
|
||||
| ----- | --------------------------------------------------------------------- |
|
||||
| Linux | `gu0` + `backhaul0` when both exist (two panes) |
|
||||
| Linux | the single default-route interface otherwise (one pane) |
|
||||
| macOS | connected VPN tunnel + physical default-route interface (two panes) |
|
||||
| macOS | the physical default-route interface with no VPN connected (one pane) |
|
||||
| OS | Interfaces monitored |
|
||||
| ----- | ----------------------------------------------------------- |
|
||||
| Linux | `gu0` + `backhaul0` when both exist (two panes) |
|
||||
| Linux | the single default-route interface otherwise (one pane) |
|
||||
| macOS | VPN tunnel + physical default-route interface (two panes) |
|
||||
| macOS | the physical default-route interface with no VPN (one pane) |
|
||||
|
||||
Anything outside this matrix — on Linux, only one of the named pair present, or
|
||||
no/multiple default routes when neither is present; on macOS, no default route
|
||||
or more than one physical default route — exits with a clear error.
|
||||
|
||||
## Starlink status
|
||||
|
||||
When the non-VPN physical gateway is a Starlink dish, two extra lines appear
|
||||
under that pane: dish state, uptime, obstruction and alert count on the first,
|
||||
and pop-ping latency and drop rate with downlink/uplink throughput on the
|
||||
second. They turn red when the dish is not connected or an alert is active.
|
||||
|
||||
Detection is a TCP connect to the dish's fixed local endpoint,
|
||||
`192.168.100.1:9200`, made over the physical interface (the same binding the
|
||||
latency probes use). The dish sits behind the Starlink router, so this is not a
|
||||
gateway-address check. rtnetmon probes once a minute until a dish answers and
|
||||
then reads its status every few seconds; when no dish answers, nothing is drawn
|
||||
and no status is fetched. The status comes from the dish's local `get_status`
|
||||
gRPC call.
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
@@ -127,10 +107,6 @@ rtnetmon/
|
||||
│ │ ├── netdetect.go # selection logic and route parsers (pure)
|
||||
│ │ ├── routes_linux.go # Linux default-route query (build-tagged)
|
||||
│ │ └── routes_darwin.go # macOS default-route query (build-tagged)
|
||||
│ ├── starlink/ # Starlink dish detection and status
|
||||
│ │ ├── starlink.go # Status, Client interface, pure Render
|
||||
│ │ ├── client.go # real gRPC client (get_status)
|
||||
│ │ └── pb/ # generated bindings for the get_status RPC
|
||||
│ └── monitor/ # core monitoring functionality
|
||||
│ ├── monitor.go # monitor types, probes, logging
|
||||
│ ├── loops.go # monitoring loops (reachability, loss, TCP)
|
||||
|
||||
@@ -5,37 +5,38 @@ One issue per unit of work, one branch and one PR per issue:
|
||||
- ensure a tracked issue exists with a definition of done
|
||||
- branch from `next` (never from `main`)
|
||||
- do the work; open a PR based on `next` (never on `main`)
|
||||
- pass an independent review, then `clawbot` squash-merges it into `next`
|
||||
- pass an independent review, then the change is squash-merged into `next`
|
||||
- push; nothing stays local-only
|
||||
|
||||
`next` is the branch for the next milestone and must stay green and mergeable to
|
||||
`main` without notice. Only `sneak` merges `next` into `main`. No commits land
|
||||
directly on `main` or `next`, only merges via PRs. A deploy is a squash commit
|
||||
from `main` onto `prod`; `prod` never follows `main` automatically.
|
||||
`next` is the branch for the next milestone and must stay green and
|
||||
mergeable to `main` without notice. Only `sneak` merges `next` into
|
||||
`main`, and for now only `sneak` merges into `next`. No commits land
|
||||
directly on `main` or `next` — only merges via PRs.
|
||||
|
||||
Other issue branches do not touch this file; it changes only in its own PR to
|
||||
`next`, because every branch editing `TODO.md` conflicts with every other.
|
||||
Issue branches do NOT touch this file — it is maintained on `next`.
|
||||
Every branch editing `TODO.md` conflicts with every other.
|
||||
|
||||
# Status
|
||||
|
||||
On `next`:
|
||||
The repository has been brought up to current repo standards: `script/`
|
||||
Scripts to Rule Them All entrypoints with the `Makefile` reduced to thin
|
||||
shims, a `Dockerfile` whose `lint` and `test` phases gate the build, a
|
||||
`.gitea/workflows/` CI workflow running `script/cibuild`, the vendored
|
||||
`.golangci.yml`, `REPO_POLICIES.md`, `.editorconfig`, `.dockerignore`, a
|
||||
`LICENSE` file, and a comprehensive `.gitignore`.
|
||||
|
||||
- Repo standards (https://git.eeqj.de/sneak/rtnetmon/issues/1): the `script/`
|
||||
entrypoints, the vendored `.golangci.yml`, and `REPO_POLICIES.md`.
|
||||
- Interface detection on Linux and macOS
|
||||
(https://git.eeqj.de/sneak/rtnetmon/issues/2).
|
||||
- The fix for macOS VPN detection (https://git.eeqj.de/sneak/rtnetmon/issues/8).
|
||||
- Starlink status lines (https://git.eeqj.de/sneak/rtnetmon/issues/3).
|
||||
- A version stamp: built with `make build` or a plain `docker build .`, the
|
||||
binary logs its git tag or short commit at startup
|
||||
(https://git.eeqj.de/sneak/rtnetmon/issues/10).
|
||||
- CI that runs `script/cibuild` on every push to a branch
|
||||
(https://git.eeqj.de/sneak/rtnetmon/issues/12).
|
||||
Lint is clean under the standard `default: all` configuration, with the
|
||||
findings fixed rather than suppressed. The only annotations are
|
||||
justified `//nolint:gosec` on the `ping`/`curl` subprocess calls (G204)
|
||||
and on opening the operator-chosen log file (G304): fixed argv with no
|
||||
shell, so these are false positives, annotated as the reference repos do.
|
||||
|
||||
# Next Step
|
||||
|
||||
- `sneak` merges the milestone PR, https://git.eeqj.de/sneak/rtnetmon/pulls/6,
|
||||
carrying `next` into `main`.
|
||||
- A first run on a real Mac of what is on `next` now. The fix for
|
||||
https://git.eeqj.de/sneak/rtnetmon/issues/8 has not run on a Mac yet;
|
||||
`sneak`'s first run on his Mac is its test.
|
||||
Feature work, each on its own branch and PR from `next`:
|
||||
|
||||
- https://git.eeqj.de/sneak/rtnetmon/issues/2 — macOS support:
|
||||
VPN-aware interface detection and a single-interface UI when only one
|
||||
interface exists.
|
||||
- https://git.eeqj.de/sneak/rtnetmon/issues/3 — show Starlink status
|
||||
lines when Starlink is the non-VPN gateway.
|
||||
|
||||
@@ -8,12 +8,8 @@ import (
|
||||
"git.eeqj.de/sneak/rtnetmon/internal/cli"
|
||||
)
|
||||
|
||||
// Version is the git tag or short commit, set at link time with -X by the
|
||||
// Makefile and the Dockerfile. Builds that do not set it report dev.
|
||||
var Version = "dev" //nolint:gochecknoglobals // set at link time with -X
|
||||
|
||||
func main() {
|
||||
err := cli.Execute(Version)
|
||||
err := cli.Execute()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -7,8 +7,6 @@ require (
|
||||
github.com/spf13/cobra v1.8.0
|
||||
github.com/spf13/viper v1.18.2
|
||||
golang.org/x/sys v0.29.0
|
||||
google.golang.org/grpc v1.67.1
|
||||
google.golang.org/protobuf v1.36.6
|
||||
)
|
||||
|
||||
require (
|
||||
@@ -32,10 +30,8 @@ require (
|
||||
go.uber.org/atomic v1.9.0 // indirect
|
||||
go.uber.org/multierr v1.9.0 // indirect
|
||||
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
|
||||
golang.org/x/net v0.28.0 // indirect
|
||||
golang.org/x/term v0.28.0 // indirect
|
||||
golang.org/x/text v0.21.0 // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 // indirect
|
||||
gopkg.in/ini.v1 v1.67.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
|
||||
@@ -91,8 +91,6 @@ golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
|
||||
golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk=
|
||||
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
|
||||
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
|
||||
golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE=
|
||||
golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
@@ -139,12 +137,6 @@ golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
|
||||
golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58=
|
||||
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 h1:e7S5W7MGGLaSu8j3YjdezkZ+m1/Nm0uRVRMEMGk26Xs=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142/go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU=
|
||||
google.golang.org/grpc v1.67.1 h1:zWnc1Vrcno+lHZCOofnIMvycFcc0QRGIzm9dhnDX68E=
|
||||
google.golang.org/grpc v1.67.1/go.mod h1:1gLDyUQU7CTLJI90u3nXZ9ekeghjeM7pTDZlqFNg2AA=
|
||||
google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY=
|
||||
google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
|
||||
@@ -3,4 +3,4 @@ package cli
|
||||
import "github.com/spf13/cobra"
|
||||
|
||||
// NewRootCmd exposes newRootCmd for external tests.
|
||||
func NewRootCmd() *cobra.Command { return newRootCmd("dev") }
|
||||
func NewRootCmd() *cobra.Command { return newRootCmd() }
|
||||
|
||||
+8
-14
@@ -51,9 +51,8 @@ func defaultTCPHosts() []string {
|
||||
}
|
||||
}
|
||||
|
||||
// newRootCmd builds the cobra root command with its flags bound. version is
|
||||
// logged at startup.
|
||||
func newRootCmd(version string) *cobra.Command {
|
||||
// newRootCmd builds the cobra root command with its flags bound.
|
||||
func newRootCmd() *cobra.Command {
|
||||
cfg := &config{}
|
||||
cmd := &cobra.Command{
|
||||
Use: "rtnetmon",
|
||||
@@ -61,7 +60,7 @@ func newRootCmd(version string) *cobra.Command {
|
||||
Long: `rtnetmon is a dual-interface network monitoring dashboard that provides
|
||||
real-time visibility into network health, packet loss, and latency.`,
|
||||
RunE: func(cmd *cobra.Command, _ []string) error {
|
||||
return runMonitor(cmd, cfg, version)
|
||||
return runMonitor(cmd, cfg)
|
||||
},
|
||||
}
|
||||
registerFlags(cmd, cfg)
|
||||
@@ -89,8 +88,8 @@ func registerFlags(cmd *cobra.Command, cfg *config) {
|
||||
|
||||
// runMonitor detects the interfaces to monitor, then constructs and runs the
|
||||
// monitor from cfg.
|
||||
func runMonitor(cmd *cobra.Command, cfg *config, version string) error {
|
||||
monitor.Logf(cfg.LogFile, "Starting rtnetmon %s", version)
|
||||
func runMonitor(cmd *cobra.Command, cfg *config) error {
|
||||
monitor.Logf(cfg.LogFile, "Starting rtnetmon")
|
||||
|
||||
specs, err := detectInterfaces(cmd, cfg)
|
||||
if err != nil {
|
||||
@@ -99,11 +98,6 @@ func runMonitor(cmd *cobra.Command, cfg *config, version string) error {
|
||||
|
||||
mon := monitor.NewMonitor(specs, cfg.LogFile)
|
||||
|
||||
// The non-VPN physical gateway is the last pane: pane B when there are
|
||||
// two, the only pane when there is one. That is where a Starlink dish,
|
||||
// if present upstream, is detected and its status shown.
|
||||
mon.EnableStarlink(specs[len(specs)-1].Name)
|
||||
|
||||
for _, host := range cfg.Hosts {
|
||||
mon.AddReachabilityHost(host)
|
||||
}
|
||||
@@ -170,7 +164,7 @@ func detectInterfaces(
|
||||
return specs, nil
|
||||
}
|
||||
|
||||
// Execute builds the root command and runs it. version is logged at startup.
|
||||
func Execute(version string) error {
|
||||
return newRootCmd(version).Execute()
|
||||
// Execute builds the root command and runs it.
|
||||
func Execute() error {
|
||||
return newRootCmd().Execute()
|
||||
}
|
||||
|
||||
@@ -1,52 +1,7 @@
|
||||
package monitor
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.eeqj.de/sneak/rtnetmon/internal/starlink"
|
||||
)
|
||||
|
||||
// Test-only accessors exposing unexported state for white-box assertions.
|
||||
|
||||
// SetStarlinkClient injects a Starlink client for iface, bypassing the real
|
||||
// gRPC dialer so the loop can be driven with a fake.
|
||||
func (m *Monitor) SetStarlinkClient(iface string, c starlink.Client) {
|
||||
for _, st := range m.interfaces {
|
||||
if st.Name == iface {
|
||||
m.slPane = st
|
||||
m.slState = &starlinkState{}
|
||||
m.slClient = c
|
||||
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// StarlinkEnabled reports whether a Starlink client is configured.
|
||||
func (m *Monitor) StarlinkEnabled() bool { return m.slClient != nil }
|
||||
|
||||
// StarlinkPaneName returns the name of the pane the Starlink lines attach
|
||||
// to, or "" if none.
|
||||
func (m *Monitor) StarlinkPaneName() string {
|
||||
if m.slPane == nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
return m.slPane.Name
|
||||
}
|
||||
|
||||
// StarlinkProbeStep runs one detection step.
|
||||
func (m *Monitor) StarlinkProbeStep(ctx context.Context) { m.starlinkProbe(ctx) }
|
||||
|
||||
// StarlinkRefreshStep runs one status-refresh step.
|
||||
func (m *Monitor) StarlinkRefreshStep(ctx context.Context) { m.starlinkRefresh(ctx) }
|
||||
|
||||
// StarlinkSnapshot returns the current Starlink display state: detected,
|
||||
// have-status, and the latest status.
|
||||
func (m *Monitor) StarlinkSnapshot() (bool, bool, starlink.Status) {
|
||||
return m.slState.snapshot()
|
||||
}
|
||||
|
||||
// ReachabilityHosts returns the configured reachability hosts.
|
||||
func (m *Monitor) ReachabilityHosts() []string { return m.reachabilityHosts }
|
||||
|
||||
|
||||
@@ -19,8 +19,6 @@ import (
|
||||
"time"
|
||||
|
||||
tcell "github.com/gdamore/tcell/v2"
|
||||
|
||||
"git.eeqj.de/sneak/rtnetmon/internal/starlink"
|
||||
)
|
||||
|
||||
// Meter glyphs used to render the ASCII loss meter.
|
||||
@@ -92,12 +90,6 @@ type Monitor struct {
|
||||
// Interfaces to monitor (one or two)
|
||||
interfaces []*InterfaceStatus
|
||||
|
||||
// Starlink status for the physical (non-VPN gateway) pane. All three
|
||||
// are nil unless EnableStarlink was called for a monitored interface.
|
||||
slClient starlink.Client
|
||||
slState *starlinkState
|
||||
slPane *InterfaceStatus
|
||||
|
||||
// Logging
|
||||
logFile string
|
||||
|
||||
@@ -216,8 +208,6 @@ func (m *Monitor) Run(ctx context.Context) error {
|
||||
go m.tcpLoop(ctx, st, tcpHosts)
|
||||
}
|
||||
|
||||
go m.starlinkLoop(ctx)
|
||||
|
||||
m.logf("Starting UI loop")
|
||||
m.uiLoop(ctx)
|
||||
m.logf("UI loop exited, monitor ending")
|
||||
|
||||
@@ -1,166 +0,0 @@
|
||||
package monitor
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
tcell "github.com/gdamore/tcell/v2"
|
||||
|
||||
"git.eeqj.de/sneak/rtnetmon/internal/starlink"
|
||||
)
|
||||
|
||||
// Starlink probe and status cadence: detect once a minute until a dish
|
||||
// answers, then refresh the status every few seconds.
|
||||
const (
|
||||
starlinkProbePeriod = time.Minute
|
||||
starlinkStatusPeriod = 5 * time.Second
|
||||
)
|
||||
|
||||
// starlinkState holds the latest dish status for the physical pane. Nothing
|
||||
// is drawn until a dish first answers, so an absent dish adds no lines.
|
||||
type starlinkState struct {
|
||||
mu sync.RWMutex
|
||||
detected bool
|
||||
haveStatus bool
|
||||
status starlink.Status
|
||||
}
|
||||
|
||||
// snapshot returns whether a dish was detected, whether a status has been
|
||||
// read, and the latest status, all under the read lock.
|
||||
func (s *starlinkState) snapshot() (bool, bool, starlink.Status) {
|
||||
s.mu.RLock()
|
||||
defer s.mu.RUnlock()
|
||||
|
||||
return s.detected, s.haveStatus, s.status
|
||||
}
|
||||
|
||||
// EnableStarlink turns on Starlink detection for the named interface, which
|
||||
// must be the non-VPN physical gateway pane. It is a no-op if no monitored
|
||||
// interface has that name.
|
||||
func (m *Monitor) EnableStarlink(iface string) {
|
||||
for _, st := range m.interfaces {
|
||||
if st.Name == iface {
|
||||
m.slPane = st
|
||||
m.slState = &starlinkState{}
|
||||
m.slClient = starlink.NewClient(m.starlinkDialer(iface))
|
||||
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// starlinkDialer returns a dialer that binds to iface exactly as the TCP
|
||||
// latency probes do, so the dish is reached over the physical interface.
|
||||
func (m *Monitor) starlinkDialer(iface string) starlink.DialFunc {
|
||||
return func(ctx context.Context, addr string) (net.Conn, error) {
|
||||
la, err := localAddr(iface)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
d := net.Dialer{LocalAddr: la, Control: bindControl(iface)}
|
||||
|
||||
return d.DialContext(ctx, "tcp", addr)
|
||||
}
|
||||
}
|
||||
|
||||
// starlinkLoop probes for a dish and refreshes its status until the context
|
||||
// is cancelled. It does nothing when Starlink was not enabled.
|
||||
func (m *Monitor) starlinkLoop(ctx context.Context) {
|
||||
if m.slClient == nil {
|
||||
return
|
||||
}
|
||||
|
||||
m.logf("Starting Starlink monitoring for %s", m.slPane.Name)
|
||||
m.starlinkProbe(ctx)
|
||||
|
||||
probe := time.NewTicker(starlinkProbePeriod)
|
||||
status := time.NewTicker(starlinkStatusPeriod)
|
||||
|
||||
defer probe.Stop()
|
||||
defer status.Stop()
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
m.logf("Stopping Starlink monitoring for %s", m.slPane.Name)
|
||||
|
||||
return
|
||||
case <-probe.C:
|
||||
m.starlinkProbe(ctx)
|
||||
case <-status.C:
|
||||
m.starlinkRefresh(ctx)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// starlinkProbe detects the dish; once detected it stays detected, and a
|
||||
// first status is fetched immediately.
|
||||
func (m *Monitor) starlinkProbe(ctx context.Context) {
|
||||
if detected, _, _ := m.slState.snapshot(); detected {
|
||||
return
|
||||
}
|
||||
|
||||
if !m.slClient.Probe(ctx) {
|
||||
return
|
||||
}
|
||||
|
||||
m.slState.mu.Lock()
|
||||
m.slState.detected = true
|
||||
m.slState.mu.Unlock()
|
||||
|
||||
m.notifyUI()
|
||||
m.starlinkRefresh(ctx)
|
||||
}
|
||||
|
||||
// starlinkRefresh fetches status only once a dish has been detected, so an
|
||||
// absent dish produces no status traffic.
|
||||
func (m *Monitor) starlinkRefresh(ctx context.Context) {
|
||||
if detected, _, _ := m.slState.snapshot(); !detected {
|
||||
return
|
||||
}
|
||||
|
||||
st, err := m.slClient.Status(ctx)
|
||||
if err != nil {
|
||||
m.logf("Starlink status error: %v", err)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
m.slState.mu.Lock()
|
||||
m.slState.status = st
|
||||
m.slState.haveStatus = true
|
||||
m.slState.mu.Unlock()
|
||||
|
||||
m.notifyUI()
|
||||
}
|
||||
|
||||
// drawStarlink draws the two dish status lines under the physical pane. It
|
||||
// draws nothing until a dish has answered.
|
||||
func (m *Monitor) drawStarlink(scr tcell.Screen, y int) int {
|
||||
detected, haveStatus, st := m.slState.snapshot()
|
||||
if !detected {
|
||||
return y
|
||||
}
|
||||
|
||||
if !haveStatus {
|
||||
Put(scr, colLeft, y, "Starlink: detected, status unavailable", styleBrightRed())
|
||||
|
||||
return y + lineStep
|
||||
}
|
||||
|
||||
line1, line2, alert := starlink.Render(st)
|
||||
|
||||
style := tcell.StyleDefault
|
||||
if alert {
|
||||
style = styleBrightRed()
|
||||
}
|
||||
|
||||
Put(scr, colLeft, y, line1, style)
|
||||
y += lineStep
|
||||
Put(scr, colLeft, y, line2, style)
|
||||
|
||||
return y + lineStep
|
||||
}
|
||||
@@ -1,141 +0,0 @@
|
||||
package monitor_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.eeqj.de/sneak/rtnetmon/internal/monitor"
|
||||
"git.eeqj.de/sneak/rtnetmon/internal/starlink"
|
||||
)
|
||||
|
||||
// fakeDish is a Starlink client for tests: no dish, no network. It records
|
||||
// how often each method is called and returns programmed results.
|
||||
type fakeDish struct {
|
||||
mu sync.Mutex
|
||||
probeOK bool
|
||||
status starlink.Status
|
||||
statusErr error
|
||||
probeCalls int
|
||||
statusCalls int
|
||||
}
|
||||
|
||||
func (f *fakeDish) Probe(_ context.Context) bool {
|
||||
f.mu.Lock()
|
||||
defer f.mu.Unlock()
|
||||
|
||||
f.probeCalls++
|
||||
|
||||
return f.probeOK
|
||||
}
|
||||
|
||||
func (f *fakeDish) Status(_ context.Context) (starlink.Status, error) {
|
||||
f.mu.Lock()
|
||||
defer f.mu.Unlock()
|
||||
|
||||
f.statusCalls++
|
||||
|
||||
return f.status, f.statusErr
|
||||
}
|
||||
|
||||
func (f *fakeDish) counts() (int, int) {
|
||||
f.mu.Lock()
|
||||
defer f.mu.Unlock()
|
||||
|
||||
return f.probeCalls, f.statusCalls
|
||||
}
|
||||
|
||||
func newTwoPaneMonitor() *monitor.Monitor {
|
||||
return monitor.NewMonitor([]monitor.IfaceSpec{
|
||||
{Name: ifaceTest0, Label: "A"},
|
||||
{Name: ifaceTest1, Label: "B"},
|
||||
}, "")
|
||||
}
|
||||
|
||||
func TestEnableStarlinkSelectsPane(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
mon := newTwoPaneMonitor()
|
||||
mon.EnableStarlink(ifaceTest1)
|
||||
|
||||
if !mon.StarlinkEnabled() {
|
||||
t.Fatal("StarlinkEnabled = false, want true")
|
||||
}
|
||||
|
||||
if got := mon.StarlinkPaneName(); got != ifaceTest1 {
|
||||
t.Errorf("StarlinkPaneName = %q, want %q", got, ifaceTest1)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEnableStarlinkUnknownInterface(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
mon := newTwoPaneMonitor()
|
||||
mon.EnableStarlink("does-not-exist")
|
||||
|
||||
if mon.StarlinkEnabled() {
|
||||
t.Error("StarlinkEnabled = true for an unknown interface, want false")
|
||||
}
|
||||
}
|
||||
|
||||
// TestStarlinkNoDishNoStatus verifies that when no dish answers, no status
|
||||
// is ever fetched and nothing is marked detected.
|
||||
func TestStarlinkNoDishNoStatus(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
mon := newTwoPaneMonitor()
|
||||
fake := &fakeDish{probeOK: false}
|
||||
mon.SetStarlinkClient(ifaceTest1, fake)
|
||||
|
||||
ctx := context.Background()
|
||||
mon.StarlinkProbeStep(ctx)
|
||||
mon.StarlinkRefreshStep(ctx)
|
||||
|
||||
detected, haveStatus, _ := mon.StarlinkSnapshot()
|
||||
if detected || haveStatus {
|
||||
t.Errorf("detected=%v haveStatus=%v, want both false", detected, haveStatus)
|
||||
}
|
||||
|
||||
if _, status := fake.counts(); status != 0 {
|
||||
t.Errorf("status calls = %d, want 0 (no probing noise)", status)
|
||||
}
|
||||
}
|
||||
|
||||
// TestStarlinkDetectedFetchesStatus verifies that once a dish answers,
|
||||
// detection triggers a status fetch and later refreshes fetch again.
|
||||
func TestStarlinkDetectedFetchesStatus(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
mon := newTwoPaneMonitor()
|
||||
want := starlink.Status{
|
||||
State: "CONNECTED",
|
||||
Uptime: 2 * time.Hour,
|
||||
DownlinkMbps: 100,
|
||||
}
|
||||
fake := &fakeDish{probeOK: true, status: want}
|
||||
mon.SetStarlinkClient(ifaceTest1, fake)
|
||||
|
||||
ctx := context.Background()
|
||||
mon.StarlinkProbeStep(ctx)
|
||||
|
||||
detected, haveStatus, got := mon.StarlinkSnapshot()
|
||||
if !detected || !haveStatus {
|
||||
t.Fatalf("detected=%v haveStatus=%v, want both true", detected, haveStatus)
|
||||
}
|
||||
|
||||
if got != want {
|
||||
t.Errorf("status = %+v, want %+v", got, want)
|
||||
}
|
||||
|
||||
mon.StarlinkRefreshStep(ctx)
|
||||
|
||||
probe, status := fake.counts()
|
||||
if probe != 1 {
|
||||
t.Errorf("probe calls = %d, want 1", probe)
|
||||
}
|
||||
|
||||
if status != 2 {
|
||||
t.Errorf("status calls = %d, want 2", status)
|
||||
}
|
||||
}
|
||||
@@ -107,11 +107,6 @@ func (m *Monitor) DrawInterface(scr tcell.Screen, y, w int, st *InterfaceStatus)
|
||||
y = m.drawTCPTable(scr, y, st, tcpHosts)
|
||||
y = drawICMPStats(scr, y, st)
|
||||
|
||||
// The Starlink lines belong to the physical (non-VPN gateway) pane only.
|
||||
if st == m.slPane {
|
||||
y = m.drawStarlink(scr, y)
|
||||
}
|
||||
|
||||
return y
|
||||
}
|
||||
|
||||
|
||||
@@ -41,14 +41,11 @@ type Interface struct {
|
||||
IPv4 []string
|
||||
}
|
||||
|
||||
// Route is one routing-table entry reduced to what detection needs. Scoped
|
||||
// marks a macOS interface-scoped route (flag I), which only traffic bound to
|
||||
// that interface uses.
|
||||
// Route is one routing-table entry reduced to what detection needs.
|
||||
type Route struct {
|
||||
Iface string
|
||||
Gateway string
|
||||
Default bool
|
||||
Scoped bool
|
||||
}
|
||||
|
||||
// Pane names one interface to display, with its label.
|
||||
@@ -136,7 +133,7 @@ func selectLinux(ifaces []Interface, routes []Route, f Flags) ([]Pane, error) {
|
||||
}
|
||||
|
||||
// selectDarwin monitors the physical default-route interface, plus a VPN
|
||||
// tunnel as the primary pane while one is connected.
|
||||
// tunnel as the primary pane when one is running.
|
||||
func selectDarwin(ifaces []Interface, routes []Route, f Flags) ([]Pane, error) {
|
||||
vpn := findVPN(ifaces, routes)
|
||||
|
||||
@@ -155,16 +152,15 @@ func selectDarwin(ifaces []Interface, routes []Route, f Flags) ([]Pane, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
// findVPN returns the name of the connected VPN tunnel, or "" if there is
|
||||
// none. A tunnel is the VPN only while it carries the default route; one that
|
||||
// is merely up, even with a routable address (Tailscale without an exit node,
|
||||
// or a tunnel a disconnected client left behind), is not. A default route
|
||||
// scoped to the tunnel does not count: only traffic bound there uses it.
|
||||
// findVPN returns the name of a VPN tunnel interface, or "" if none is
|
||||
// running. A tunnel counts as a running VPN when it carries a default route,
|
||||
// or when it is up with a routable (non-link-local) IPv4 address. Idle system
|
||||
// tunnels have only a link-local IPv6 address and are skipped.
|
||||
func findVPN(ifaces []Interface, routes []Route) string {
|
||||
routeIfaces := map[string]bool{}
|
||||
|
||||
for _, r := range routes {
|
||||
if r.Default && !r.Scoped {
|
||||
if r.Default {
|
||||
routeIfaces[r.Iface] = true
|
||||
}
|
||||
}
|
||||
@@ -180,6 +176,10 @@ func findVPN(ifaces []Interface, routes []Route) string {
|
||||
if routeIfaces[ifi.Name] {
|
||||
return ifi.Name
|
||||
}
|
||||
|
||||
if ifi.Up && hasRoutableIPv4(ifi) {
|
||||
return ifi.Name
|
||||
}
|
||||
}
|
||||
|
||||
return ""
|
||||
@@ -219,8 +219,6 @@ func onlyPhysicalDefaultRoute(routes []Route, vpn string) (string, error) {
|
||||
|
||||
// defaultRouteIfaces returns the sorted, unique interface names that carry a
|
||||
// default route, excluding the named VPN interface and any other tunnel.
|
||||
// Scoped routes count: while a VPN holds the default route, the physical
|
||||
// interface keeps only a default route scoped to itself.
|
||||
func defaultRouteIfaces(routes []Route, vpn string) []string {
|
||||
seen := map[string]bool{}
|
||||
|
||||
@@ -257,6 +255,21 @@ func isTunnel(name string) bool {
|
||||
return strings.HasPrefix(name, "utun")
|
||||
}
|
||||
|
||||
// hasRoutableIPv4 reports whether the interface has an IPv4 address that is
|
||||
// neither loopback nor link-local.
|
||||
func hasRoutableIPv4(ifi Interface) bool {
|
||||
for _, s := range ifi.IPv4 {
|
||||
ip := net.ParseIP(s)
|
||||
if ip == nil || ip.IsLoopback() || ip.IsLinkLocalUnicast() {
|
||||
continue
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// singleLabel is the label for a lone pane: the explicit --labelA if given,
|
||||
// otherwise a plain description.
|
||||
func singleLabel(f Flags) string {
|
||||
@@ -327,47 +340,23 @@ func parseProcNetRoute(out string) []Route {
|
||||
return routes
|
||||
}
|
||||
|
||||
// parseNetstat reads `netstat -rn -f inet` output (macOS); the Netif column
|
||||
// (field 4) names the interface. A row whose destination is "default" is a
|
||||
// default route, scoped when its flags include I. A "0/1" row and a "128.0/1"
|
||||
// row on one interface together also make a default route there: VPN clients
|
||||
// that leave the physical default in place send all traffic through them.
|
||||
// parseNetstat reads `netstat -rn -f inet` output (macOS). Rows whose
|
||||
// destination is "default" are default routes; the Netif column (field 4)
|
||||
// names the interface.
|
||||
func parseNetstat(out string) []Route {
|
||||
const columns = 4 // Destination, Gateway, Flags, Netif; Expire is optional
|
||||
|
||||
var routes []Route
|
||||
|
||||
var lowHalf []string // interfaces with a 0/1 row
|
||||
|
||||
highHalf := map[string]bool{} // interfaces with a 128.0/1 row
|
||||
|
||||
for _, line := range strings.Split(out, "\n") {
|
||||
fields := strings.Fields(line)
|
||||
if len(fields) < columns {
|
||||
if len(fields) < 4 || fields[0] != "default" {
|
||||
continue
|
||||
}
|
||||
|
||||
dest, gateway, flags, iface := fields[0], fields[1], fields[2], fields[3]
|
||||
|
||||
switch dest {
|
||||
case "default":
|
||||
routes = append(routes, Route{
|
||||
Iface: iface,
|
||||
Gateway: gateway,
|
||||
Default: true,
|
||||
Scoped: strings.Contains(flags, "I"),
|
||||
})
|
||||
case "0/1":
|
||||
lowHalf = append(lowHalf, iface)
|
||||
case "128.0/1":
|
||||
highHalf[iface] = true
|
||||
}
|
||||
}
|
||||
|
||||
for _, iface := range lowHalf {
|
||||
if highHalf[iface] {
|
||||
routes = append(routes, Route{Iface: iface, Default: true})
|
||||
}
|
||||
routes = append(routes, Route{
|
||||
Iface: fields[3],
|
||||
Gateway: fields[1],
|
||||
Default: true,
|
||||
})
|
||||
}
|
||||
|
||||
return routes
|
||||
|
||||
@@ -17,96 +17,13 @@ const (
|
||||
ifaceEth0 = "eth0"
|
||||
ifaceWlan0 = "wlan0"
|
||||
ifaceEn0 = "en0"
|
||||
ifaceUtun0 = "utun0"
|
||||
ifaceUtun3 = "utun3"
|
||||
ifaceUtun4 = "utun4"
|
||||
|
||||
labelGu = "gu LAN - VPN outbound"
|
||||
labelCox = "Cox cable direct"
|
||||
labelDefault = "default route"
|
||||
labelVPN = "VPN"
|
||||
|
||||
addrEn0 = "192.168.1.20"
|
||||
addrVPN = "10.64.0.2"
|
||||
addrTailscale = "100.101.102.103"
|
||||
)
|
||||
|
||||
// netstatHeader starts `netstat -rn -f inet` output on macOS. Each output
|
||||
// below adds the rows of one routing state: en0 is the physical interface,
|
||||
// utun3 is Tailscale's tunnel and utun4 a VPN client's.
|
||||
const netstatHeader = `Routing tables
|
||||
|
||||
Internet:
|
||||
Destination Gateway Flags Netif Expire`
|
||||
|
||||
const (
|
||||
netstatNoTunnel = netstatHeader + `
|
||||
default 192.168.1.1 UGScg en0
|
||||
127 127.0.0.1 UCS lo0
|
||||
127.0.0.1 127.0.0.1 UH lo0
|
||||
192.168.1 link#6 UCS en0 !
|
||||
192.168.1.1 a4:2b:b0:12:34:56 UHLWIir en0 1187
|
||||
`
|
||||
|
||||
// Tailscale on without an exit node: routes for its own range only.
|
||||
netstatTailscaleIdle = netstatHeader + `
|
||||
default 192.168.1.1 UGScg en0
|
||||
100.64/10 link#22 UCS utun3
|
||||
100.100.100.100/32 link#22 UCS utun3
|
||||
100.101.102.103/32 link#22 UCS utun3
|
||||
127.0.0.1 127.0.0.1 UH lo0
|
||||
`
|
||||
|
||||
// A tunnel a disconnected client left behind, still holding its address.
|
||||
netstatTunnelLeftBehind = netstatHeader + `
|
||||
default 192.168.1.1 UGScg en0
|
||||
10.64.0.2 10.64.0.2 UH utun4
|
||||
127.0.0.1 127.0.0.1 UH lo0
|
||||
`
|
||||
|
||||
// A tunnel whose only default route is scoped to it.
|
||||
netstatTunnelScopedDefault = netstatHeader + `
|
||||
default 192.168.1.1 UGScg en0
|
||||
default link#22 UCSIg utun3
|
||||
100.64/10 link#22 UCS utun3
|
||||
127.0.0.1 127.0.0.1 UH lo0
|
||||
`
|
||||
|
||||
// A tunnel with the lower half of the address space but not the upper.
|
||||
netstatVPNOneHalf = netstatHeader + `
|
||||
0/1 utun4 USc utun4
|
||||
default 192.168.1.1 UGScg en0
|
||||
127.0.0.1 127.0.0.1 UH lo0
|
||||
`
|
||||
|
||||
// A VPN holding the default route; the physical default is now scoped.
|
||||
netstatVPNDefault = netstatHeader + `
|
||||
default link#15 UCSg utun4
|
||||
default 192.168.1.1 UGScIg en0
|
||||
10.64.0.2 10.64.0.2 UH utun4
|
||||
127.0.0.1 127.0.0.1 UH lo0
|
||||
`
|
||||
|
||||
// A VPN on both halves, leaving the physical default in place.
|
||||
netstatVPNHalves = netstatHeader + `
|
||||
0/1 utun4 USc utun4
|
||||
default 192.168.1.1 UGScg en0
|
||||
default 192.168.1.1 UGScIg en0
|
||||
10.64.0.2 10.64.0.2 UH utun4
|
||||
127.0.0.1 127.0.0.1 UH lo0
|
||||
128.0/1 utun4 USc utun4
|
||||
`
|
||||
|
||||
// Idle Tailscale next to a VPN on both halves.
|
||||
netstatTailscaleAndVPN = netstatHeader + `
|
||||
0/1 utun4 USc utun4
|
||||
default 192.168.1.1 UGScg en0
|
||||
10.64.0.2 10.64.0.2 UH utun4
|
||||
100.64/10 link#22 UCS utun3
|
||||
100.101.102.103/32 link#22 UCS utun3
|
||||
127.0.0.1 127.0.0.1 UH lo0
|
||||
128.0/1 utun4 USc utun4
|
||||
`
|
||||
addrEn0 = "192.168.1.20"
|
||||
)
|
||||
|
||||
// linuxFlags describes the Linux bridge interfaces rtnetmon was built for.
|
||||
@@ -117,17 +34,6 @@ func linuxFlags() netdetect.Flags {
|
||||
}
|
||||
}
|
||||
|
||||
// macIfaces returns the interfaces every Mac in these tests has (en0,
|
||||
// loopback, and an idle system tunnel with no IPv4 address) plus the given
|
||||
// tunnels.
|
||||
func macIfaces(tunnels ...netdetect.Interface) []netdetect.Interface {
|
||||
return append([]netdetect.Interface{
|
||||
{Name: ifaceEn0, Up: true, IPv4: []string{addrEn0}},
|
||||
{Name: "lo0", Up: true, IPv4: []string{"127.0.0.1"}},
|
||||
{Name: ifaceUtun0, Up: true},
|
||||
}, tunnels...)
|
||||
}
|
||||
|
||||
// selectCase is one Select scenario with fake interfaces and routes.
|
||||
type selectCase struct {
|
||||
name string
|
||||
@@ -260,8 +166,8 @@ func TestSelectDarwinPanes(t *testing.T) {
|
||||
goos: osDarwin,
|
||||
ifaces: []netdetect.Interface{
|
||||
{Name: ifaceEn0, Up: true, IPv4: []string{addrEn0}},
|
||||
{Name: ifaceUtun4, Up: true, IPv4: []string{addrVPN}},
|
||||
{Name: ifaceUtun0, Up: true, IPv4: nil},
|
||||
{Name: ifaceUtun4, Up: true, IPv4: []string{"10.64.0.2"}},
|
||||
{Name: "utun0", Up: true, IPv4: nil},
|
||||
},
|
||||
routes: []netdetect.Route{
|
||||
{Iface: ifaceUtun4, Default: true},
|
||||
@@ -269,7 +175,21 @@ func TestSelectDarwinPanes(t *testing.T) {
|
||||
},
|
||||
flags: linuxFlags(),
|
||||
want: []netdetect.Pane{
|
||||
{Name: ifaceUtun4, Label: labelVPN},
|
||||
{Name: ifaceUtun4, Label: "VPN"},
|
||||
{Name: ifaceEn0, Label: labelDefault},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "vpn detected by routable address without its own route",
|
||||
goos: osDarwin,
|
||||
ifaces: []netdetect.Interface{
|
||||
{Name: ifaceEn0, Up: true, IPv4: []string{addrEn0}},
|
||||
{Name: "utun6", Up: true, IPv4: []string{"10.2.0.2"}},
|
||||
},
|
||||
routes: []netdetect.Route{{Iface: ifaceEn0, Default: true}},
|
||||
flags: linuxFlags(),
|
||||
want: []netdetect.Pane{
|
||||
{Name: "utun6", Label: "VPN"},
|
||||
{Name: ifaceEn0, Label: labelDefault},
|
||||
},
|
||||
},
|
||||
@@ -278,7 +198,7 @@ func TestSelectDarwinPanes(t *testing.T) {
|
||||
goos: osDarwin,
|
||||
ifaces: []netdetect.Interface{
|
||||
{Name: ifaceEn0, Up: true, IPv4: []string{addrEn0}},
|
||||
{Name: ifaceUtun4, Up: true, IPv4: []string{addrVPN}},
|
||||
{Name: ifaceUtun4, Up: true, IPv4: []string{"10.64.0.2"}},
|
||||
},
|
||||
routes: []netdetect.Route{
|
||||
{Iface: ifaceUtun4, Default: true},
|
||||
@@ -305,24 +225,13 @@ func TestSelectDarwinSingleAndErrors(t *testing.T) {
|
||||
goos: osDarwin,
|
||||
ifaces: []netdetect.Interface{
|
||||
{Name: ifaceEn0, Up: true, IPv4: []string{addrEn0}},
|
||||
{Name: ifaceUtun0, Up: true, IPv4: nil},
|
||||
{Name: "utun0", Up: true, IPv4: nil},
|
||||
{Name: "utun1", Up: true, IPv4: []string{"169.254.1.1"}},
|
||||
},
|
||||
routes: []netdetect.Route{{Iface: ifaceEn0, Default: true}},
|
||||
flags: linuxFlags(),
|
||||
want: []netdetect.Pane{{Name: ifaceEn0, Label: labelDefault}},
|
||||
},
|
||||
{
|
||||
name: "tunnel with a routable address but no default route",
|
||||
goos: osDarwin,
|
||||
ifaces: []netdetect.Interface{
|
||||
{Name: ifaceEn0, Up: true, IPv4: []string{addrEn0}},
|
||||
{Name: "utun6", Up: true, IPv4: []string{"10.2.0.2"}},
|
||||
},
|
||||
routes: []netdetect.Route{{Iface: ifaceEn0, Default: true}},
|
||||
flags: linuxFlags(),
|
||||
want: []netdetect.Pane{{Name: ifaceEn0, Label: labelDefault}},
|
||||
},
|
||||
{
|
||||
name: "no default route",
|
||||
goos: osDarwin,
|
||||
@@ -355,81 +264,6 @@ func TestSelectDarwinSingleAndErrors(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
// TestSelectDarwinFromNetstat runs macOS routing tables through the netstat
|
||||
// parser into Select: only a tunnel carrying the default route is the VPN.
|
||||
func TestSelectDarwinFromNetstat(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tailscale := netdetect.Interface{
|
||||
Name: ifaceUtun3, Up: true, IPv4: []string{addrTailscale},
|
||||
}
|
||||
vpn := netdetect.Interface{Name: ifaceUtun4, Up: true, IPv4: []string{addrVPN}}
|
||||
physicalOnly := []netdetect.Pane{{Name: ifaceEn0, Label: labelDefault}}
|
||||
vpnAndPhysical := []netdetect.Pane{
|
||||
{Name: ifaceUtun4, Label: labelVPN},
|
||||
{Name: ifaceEn0, Label: labelDefault},
|
||||
}
|
||||
|
||||
runSelectCases(t, []selectCase{
|
||||
{
|
||||
name: "no tunnel",
|
||||
goos: osDarwin,
|
||||
ifaces: macIfaces(),
|
||||
routes: netdetect.ParseNetstat(netstatNoTunnel),
|
||||
want: physicalOnly,
|
||||
},
|
||||
{
|
||||
name: "tailscale without an exit node",
|
||||
goos: osDarwin,
|
||||
ifaces: macIfaces(tailscale),
|
||||
routes: netdetect.ParseNetstat(netstatTailscaleIdle),
|
||||
want: physicalOnly,
|
||||
},
|
||||
{
|
||||
name: "tunnel left behind by a disconnected client",
|
||||
goos: osDarwin,
|
||||
ifaces: macIfaces(vpn),
|
||||
routes: netdetect.ParseNetstat(netstatTunnelLeftBehind),
|
||||
want: physicalOnly,
|
||||
},
|
||||
{
|
||||
name: "tunnel with only a scoped default route",
|
||||
goos: osDarwin,
|
||||
ifaces: macIfaces(tailscale),
|
||||
routes: netdetect.ParseNetstat(netstatTunnelScopedDefault),
|
||||
want: physicalOnly,
|
||||
},
|
||||
{
|
||||
name: "tunnel with only one half of the address space",
|
||||
goos: osDarwin,
|
||||
ifaces: macIfaces(vpn),
|
||||
routes: netdetect.ParseNetstat(netstatVPNOneHalf),
|
||||
want: physicalOnly,
|
||||
},
|
||||
{
|
||||
name: "vpn on the default route",
|
||||
goos: osDarwin,
|
||||
ifaces: macIfaces(vpn),
|
||||
routes: netdetect.ParseNetstat(netstatVPNDefault),
|
||||
want: vpnAndPhysical,
|
||||
},
|
||||
{
|
||||
name: "vpn on both halves",
|
||||
goos: osDarwin,
|
||||
ifaces: macIfaces(vpn),
|
||||
routes: netdetect.ParseNetstat(netstatVPNHalves),
|
||||
want: vpnAndPhysical,
|
||||
},
|
||||
{
|
||||
name: "idle tailscale next to a connected vpn",
|
||||
goos: osDarwin,
|
||||
ifaces: macIfaces(tailscale, vpn),
|
||||
routes: netdetect.ParseNetstat(netstatTailscaleAndVPN),
|
||||
want: vpnAndPhysical,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestParseIPRoute(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
||||
@@ -1,129 +0,0 @@
|
||||
package starlink
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
|
||||
pb "git.eeqj.de/sneak/rtnetmon/internal/starlink/pb"
|
||||
)
|
||||
|
||||
// errNoDishStatus is returned when the dish answers but the response
|
||||
// carries no dish status.
|
||||
var errNoDishStatus = errors.New("no dish status in response")
|
||||
|
||||
// Per-call deadlines so a silent dish never wedges the monitor loop.
|
||||
const (
|
||||
probeTimeout = 2 * time.Second
|
||||
statusTimeout = 3 * time.Second
|
||||
)
|
||||
|
||||
// DialFunc opens a TCP connection to addr bound to a chosen interface. The
|
||||
// monitor supplies one that binds the same way its TCP latency probes do,
|
||||
// so the dish is reached over the physical (non-VPN) interface rather than
|
||||
// a VPN tunnel that may hold the default route.
|
||||
type DialFunc func(ctx context.Context, addr string) (net.Conn, error)
|
||||
|
||||
// GRPCClient is the real Client: it reaches a dish at Address over whatever
|
||||
// interface dial binds to.
|
||||
type GRPCClient struct {
|
||||
dial DialFunc
|
||||
}
|
||||
|
||||
// NewClient returns a client that talks to a dish at Address, dialing with
|
||||
// dial so the connection leaves the intended interface.
|
||||
func NewClient(dial DialFunc) *GRPCClient {
|
||||
return &GRPCClient{dial: dial}
|
||||
}
|
||||
|
||||
// Probe connects to the dish's endpoint and closes it. A successful TCP
|
||||
// connect over the bound interface is the detection signal.
|
||||
func (c *GRPCClient) Probe(ctx context.Context) bool {
|
||||
ctx, cancel := context.WithTimeout(ctx, probeTimeout)
|
||||
defer cancel()
|
||||
|
||||
conn, err := c.dial(ctx, Address)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
_ = conn.Close()
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// Status calls the dish's get_status RPC and reduces the response to the
|
||||
// fields rtnetmon shows.
|
||||
func (c *GRPCClient) Status(ctx context.Context) (Status, error) {
|
||||
ctx, cancel := context.WithTimeout(ctx, statusTimeout)
|
||||
defer cancel()
|
||||
|
||||
// passthrough:/// hands Address straight to our dialer, with no name
|
||||
// resolution, so the connection is made over the bound interface.
|
||||
conn, err := grpc.NewClient("passthrough:///"+Address,
|
||||
grpc.WithTransportCredentials(insecure.NewCredentials()),
|
||||
grpc.WithContextDialer(func(ctx context.Context, addr string) (net.Conn, error) {
|
||||
return c.dial(ctx, addr)
|
||||
}),
|
||||
)
|
||||
if err != nil {
|
||||
return Status{}, fmt.Errorf("starlink dial: %w", err)
|
||||
}
|
||||
defer func() { _ = conn.Close() }()
|
||||
|
||||
resp, err := pb.NewDeviceClient(conn).Handle(ctx, &pb.Request{
|
||||
Request: &pb.Request_GetStatus{GetStatus: &pb.GetStatusRequest{}},
|
||||
})
|
||||
if err != nil {
|
||||
return Status{}, fmt.Errorf("starlink get_status: %w", err)
|
||||
}
|
||||
|
||||
dish := resp.GetDishGetStatus()
|
||||
if dish == nil {
|
||||
return Status{}, errNoDishStatus
|
||||
}
|
||||
|
||||
return statusFromDish(dish), nil
|
||||
}
|
||||
|
||||
// statusFromDish reduces the dish's status message to a Status. The
|
||||
// generated getters are nil-safe, so absent sub-messages read as zero.
|
||||
func statusFromDish(d *pb.DishGetStatusResponse) Status {
|
||||
obstruction := float64(d.GetObstructionStats().GetFractionObstructed())
|
||||
//nolint:gosec // G115: dish uptime in seconds never approaches int64 max
|
||||
uptime := time.Duration(d.GetDeviceState().GetUptimeS()) * time.Second
|
||||
|
||||
return Status{
|
||||
State: d.GetState().String(),
|
||||
Uptime: uptime,
|
||||
ObstructionPct: obstruction * percentScale,
|
||||
Alerts: countAlerts(d.GetAlerts()),
|
||||
PopPingMs: float64(d.GetPopPingLatencyMs()),
|
||||
PopPingDropPct: float64(d.GetPopPingDropRate()) * percentScale,
|
||||
DownlinkMbps: float64(d.GetDownlinkThroughputBps()) / bitsPerMegabit,
|
||||
UplinkMbps: float64(d.GetUplinkThroughputBps()) / bitsPerMegabit,
|
||||
}
|
||||
}
|
||||
|
||||
// countAlerts counts the active dish alert flags.
|
||||
func countAlerts(a *pb.DishAlerts) int {
|
||||
n := 0
|
||||
|
||||
for _, on := range []bool{
|
||||
a.GetMotorsStuck(),
|
||||
a.GetThermalShutdown(),
|
||||
a.GetThermalThrottle(),
|
||||
a.GetUnexpectedLocation(),
|
||||
} {
|
||||
if on {
|
||||
n++
|
||||
}
|
||||
}
|
||||
|
||||
return n
|
||||
}
|
||||
@@ -1,629 +0,0 @@
|
||||
// A minimal slice of the Starlink dish's local gRPC API: just the one
|
||||
// unary RPC (SpaceX.API.Device.Device/Handle) and the get_status request
|
||||
// and dish status response, reduced to the handful of fields rtnetmon
|
||||
// shows. The proto package name and field numbers must match the dish
|
||||
// exactly for the wire format to line up; every other field the dish sends
|
||||
// is ignored as an unknown field.
|
||||
//
|
||||
// Field numbers, message names and the DishState enum are transcribed from
|
||||
// the community-maintained pre-generated bindings at
|
||||
// github.com/starlink-community/starlink-grpc-go, commit
|
||||
// 2e89f3d7e3092adecbcc04e9e003e61ed5f7c6a3 (get_status = 1004,
|
||||
// dish_get_status = 2004). They are not verified against a live dish here.
|
||||
//
|
||||
// Regenerate with:
|
||||
// protoc --go_out=. --go_opt=paths=source_relative \
|
||||
// --go-grpc_out=. --go-grpc_opt=paths=source_relative \
|
||||
// internal/starlink/pb/starlink.proto
|
||||
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.36.6
|
||||
// protoc v7.36.2
|
||||
// source: internal/starlink/pb/starlink.proto
|
||||
|
||||
package starlinkpb
|
||||
|
||||
import (
|
||||
reflect "reflect"
|
||||
sync "sync"
|
||||
unsafe "unsafe"
|
||||
|
||||
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
|
||||
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
|
||||
)
|
||||
|
||||
const (
|
||||
// Verify that this generated code is sufficiently up-to-date.
|
||||
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
|
||||
// Verify that runtime/protoimpl is sufficiently up-to-date.
|
||||
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
|
||||
)
|
||||
|
||||
type DishState int32
|
||||
|
||||
const (
|
||||
DishState_UNKNOWN DishState = 0
|
||||
DishState_CONNECTED DishState = 1
|
||||
DishState_SEARCHING DishState = 2
|
||||
DishState_BOOTING DishState = 3
|
||||
)
|
||||
|
||||
// Enum value maps for DishState.
|
||||
var (
|
||||
DishState_name = map[int32]string{
|
||||
0: "UNKNOWN",
|
||||
1: "CONNECTED",
|
||||
2: "SEARCHING",
|
||||
3: "BOOTING",
|
||||
}
|
||||
DishState_value = map[string]int32{
|
||||
"UNKNOWN": 0,
|
||||
"CONNECTED": 1,
|
||||
"SEARCHING": 2,
|
||||
"BOOTING": 3,
|
||||
}
|
||||
)
|
||||
|
||||
func (x DishState) Enum() *DishState {
|
||||
p := new(DishState)
|
||||
*p = x
|
||||
return p
|
||||
}
|
||||
|
||||
func (x DishState) String() string {
|
||||
return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x))
|
||||
}
|
||||
|
||||
func (DishState) Descriptor() protoreflect.EnumDescriptor {
|
||||
return file_internal_starlink_pb_starlink_proto_enumTypes[0].Descriptor()
|
||||
}
|
||||
|
||||
func (DishState) Type() protoreflect.EnumType {
|
||||
return &file_internal_starlink_pb_starlink_proto_enumTypes[0]
|
||||
}
|
||||
|
||||
func (x DishState) Number() protoreflect.EnumNumber {
|
||||
return protoreflect.EnumNumber(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use DishState.Descriptor instead.
|
||||
func (DishState) EnumDescriptor() ([]byte, []int) {
|
||||
return file_internal_starlink_pb_starlink_proto_rawDescGZIP(), []int{0}
|
||||
}
|
||||
|
||||
type Request struct {
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
// Types that are valid to be assigned to Request:
|
||||
//
|
||||
// *Request_GetStatus
|
||||
Request isRequest_Request `protobuf_oneof:"request"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
func (x *Request) Reset() {
|
||||
*x = Request{}
|
||||
mi := &file_internal_starlink_pb_starlink_proto_msgTypes[0]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
|
||||
func (x *Request) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*Request) ProtoMessage() {}
|
||||
|
||||
func (x *Request) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_internal_starlink_pb_starlink_proto_msgTypes[0]
|
||||
if x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use Request.ProtoReflect.Descriptor instead.
|
||||
func (*Request) Descriptor() ([]byte, []int) {
|
||||
return file_internal_starlink_pb_starlink_proto_rawDescGZIP(), []int{0}
|
||||
}
|
||||
|
||||
func (x *Request) GetRequest() isRequest_Request {
|
||||
if x != nil {
|
||||
return x.Request
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *Request) GetGetStatus() *GetStatusRequest {
|
||||
if x != nil {
|
||||
if x, ok := x.Request.(*Request_GetStatus); ok {
|
||||
return x.GetStatus
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type isRequest_Request interface {
|
||||
isRequest_Request()
|
||||
}
|
||||
|
||||
type Request_GetStatus struct {
|
||||
GetStatus *GetStatusRequest `protobuf:"bytes,1004,opt,name=get_status,json=getStatus,proto3,oneof"`
|
||||
}
|
||||
|
||||
func (*Request_GetStatus) isRequest_Request() {}
|
||||
|
||||
type GetStatusRequest struct {
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
func (x *GetStatusRequest) Reset() {
|
||||
*x = GetStatusRequest{}
|
||||
mi := &file_internal_starlink_pb_starlink_proto_msgTypes[1]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
|
||||
func (x *GetStatusRequest) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*GetStatusRequest) ProtoMessage() {}
|
||||
|
||||
func (x *GetStatusRequest) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_internal_starlink_pb_starlink_proto_msgTypes[1]
|
||||
if x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use GetStatusRequest.ProtoReflect.Descriptor instead.
|
||||
func (*GetStatusRequest) Descriptor() ([]byte, []int) {
|
||||
return file_internal_starlink_pb_starlink_proto_rawDescGZIP(), []int{1}
|
||||
}
|
||||
|
||||
type Response struct {
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
// Types that are valid to be assigned to Response:
|
||||
//
|
||||
// *Response_DishGetStatus
|
||||
Response isResponse_Response `protobuf_oneof:"response"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
func (x *Response) Reset() {
|
||||
*x = Response{}
|
||||
mi := &file_internal_starlink_pb_starlink_proto_msgTypes[2]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
|
||||
func (x *Response) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*Response) ProtoMessage() {}
|
||||
|
||||
func (x *Response) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_internal_starlink_pb_starlink_proto_msgTypes[2]
|
||||
if x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use Response.ProtoReflect.Descriptor instead.
|
||||
func (*Response) Descriptor() ([]byte, []int) {
|
||||
return file_internal_starlink_pb_starlink_proto_rawDescGZIP(), []int{2}
|
||||
}
|
||||
|
||||
func (x *Response) GetResponse() isResponse_Response {
|
||||
if x != nil {
|
||||
return x.Response
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *Response) GetDishGetStatus() *DishGetStatusResponse {
|
||||
if x != nil {
|
||||
if x, ok := x.Response.(*Response_DishGetStatus); ok {
|
||||
return x.DishGetStatus
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type isResponse_Response interface {
|
||||
isResponse_Response()
|
||||
}
|
||||
|
||||
type Response_DishGetStatus struct {
|
||||
DishGetStatus *DishGetStatusResponse `protobuf:"bytes,2004,opt,name=dish_get_status,json=dishGetStatus,proto3,oneof"`
|
||||
}
|
||||
|
||||
func (*Response_DishGetStatus) isResponse_Response() {}
|
||||
|
||||
type DishGetStatusResponse struct {
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
DeviceState *DeviceState `protobuf:"bytes,2,opt,name=device_state,json=deviceState,proto3" json:"device_state,omitempty"`
|
||||
ObstructionStats *DishObstructionStats `protobuf:"bytes,1004,opt,name=obstruction_stats,json=obstructionStats,proto3" json:"obstruction_stats,omitempty"`
|
||||
Alerts *DishAlerts `protobuf:"bytes,1005,opt,name=alerts,proto3" json:"alerts,omitempty"`
|
||||
State DishState `protobuf:"varint,1006,opt,name=state,proto3,enum=SpaceX.API.Device.DishState" json:"state,omitempty"`
|
||||
PopPingDropRate float32 `protobuf:"fixed32,1003,opt,name=pop_ping_drop_rate,json=popPingDropRate,proto3" json:"pop_ping_drop_rate,omitempty"`
|
||||
DownlinkThroughputBps float32 `protobuf:"fixed32,1007,opt,name=downlink_throughput_bps,json=downlinkThroughputBps,proto3" json:"downlink_throughput_bps,omitempty"`
|
||||
UplinkThroughputBps float32 `protobuf:"fixed32,1008,opt,name=uplink_throughput_bps,json=uplinkThroughputBps,proto3" json:"uplink_throughput_bps,omitempty"`
|
||||
PopPingLatencyMs float32 `protobuf:"fixed32,1009,opt,name=pop_ping_latency_ms,json=popPingLatencyMs,proto3" json:"pop_ping_latency_ms,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
func (x *DishGetStatusResponse) Reset() {
|
||||
*x = DishGetStatusResponse{}
|
||||
mi := &file_internal_starlink_pb_starlink_proto_msgTypes[3]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
|
||||
func (x *DishGetStatusResponse) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*DishGetStatusResponse) ProtoMessage() {}
|
||||
|
||||
func (x *DishGetStatusResponse) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_internal_starlink_pb_starlink_proto_msgTypes[3]
|
||||
if x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use DishGetStatusResponse.ProtoReflect.Descriptor instead.
|
||||
func (*DishGetStatusResponse) Descriptor() ([]byte, []int) {
|
||||
return file_internal_starlink_pb_starlink_proto_rawDescGZIP(), []int{3}
|
||||
}
|
||||
|
||||
func (x *DishGetStatusResponse) GetDeviceState() *DeviceState {
|
||||
if x != nil {
|
||||
return x.DeviceState
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *DishGetStatusResponse) GetObstructionStats() *DishObstructionStats {
|
||||
if x != nil {
|
||||
return x.ObstructionStats
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *DishGetStatusResponse) GetAlerts() *DishAlerts {
|
||||
if x != nil {
|
||||
return x.Alerts
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *DishGetStatusResponse) GetState() DishState {
|
||||
if x != nil {
|
||||
return x.State
|
||||
}
|
||||
return DishState_UNKNOWN
|
||||
}
|
||||
|
||||
func (x *DishGetStatusResponse) GetPopPingDropRate() float32 {
|
||||
if x != nil {
|
||||
return x.PopPingDropRate
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *DishGetStatusResponse) GetDownlinkThroughputBps() float32 {
|
||||
if x != nil {
|
||||
return x.DownlinkThroughputBps
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *DishGetStatusResponse) GetUplinkThroughputBps() float32 {
|
||||
if x != nil {
|
||||
return x.UplinkThroughputBps
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *DishGetStatusResponse) GetPopPingLatencyMs() float32 {
|
||||
if x != nil {
|
||||
return x.PopPingLatencyMs
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
type DeviceState struct {
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
UptimeS uint64 `protobuf:"varint,1,opt,name=uptime_s,json=uptimeS,proto3" json:"uptime_s,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
func (x *DeviceState) Reset() {
|
||||
*x = DeviceState{}
|
||||
mi := &file_internal_starlink_pb_starlink_proto_msgTypes[4]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
|
||||
func (x *DeviceState) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*DeviceState) ProtoMessage() {}
|
||||
|
||||
func (x *DeviceState) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_internal_starlink_pb_starlink_proto_msgTypes[4]
|
||||
if x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use DeviceState.ProtoReflect.Descriptor instead.
|
||||
func (*DeviceState) Descriptor() ([]byte, []int) {
|
||||
return file_internal_starlink_pb_starlink_proto_rawDescGZIP(), []int{4}
|
||||
}
|
||||
|
||||
func (x *DeviceState) GetUptimeS() uint64 {
|
||||
if x != nil {
|
||||
return x.UptimeS
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
type DishObstructionStats struct {
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
FractionObstructed float32 `protobuf:"fixed32,1,opt,name=fraction_obstructed,json=fractionObstructed,proto3" json:"fraction_obstructed,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
func (x *DishObstructionStats) Reset() {
|
||||
*x = DishObstructionStats{}
|
||||
mi := &file_internal_starlink_pb_starlink_proto_msgTypes[5]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
|
||||
func (x *DishObstructionStats) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*DishObstructionStats) ProtoMessage() {}
|
||||
|
||||
func (x *DishObstructionStats) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_internal_starlink_pb_starlink_proto_msgTypes[5]
|
||||
if x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use DishObstructionStats.ProtoReflect.Descriptor instead.
|
||||
func (*DishObstructionStats) Descriptor() ([]byte, []int) {
|
||||
return file_internal_starlink_pb_starlink_proto_rawDescGZIP(), []int{5}
|
||||
}
|
||||
|
||||
func (x *DishObstructionStats) GetFractionObstructed() float32 {
|
||||
if x != nil {
|
||||
return x.FractionObstructed
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
type DishAlerts struct {
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
MotorsStuck bool `protobuf:"varint,1,opt,name=motors_stuck,json=motorsStuck,proto3" json:"motors_stuck,omitempty"`
|
||||
ThermalShutdown bool `protobuf:"varint,2,opt,name=thermal_shutdown,json=thermalShutdown,proto3" json:"thermal_shutdown,omitempty"`
|
||||
ThermalThrottle bool `protobuf:"varint,3,opt,name=thermal_throttle,json=thermalThrottle,proto3" json:"thermal_throttle,omitempty"`
|
||||
UnexpectedLocation bool `protobuf:"varint,4,opt,name=unexpected_location,json=unexpectedLocation,proto3" json:"unexpected_location,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
func (x *DishAlerts) Reset() {
|
||||
*x = DishAlerts{}
|
||||
mi := &file_internal_starlink_pb_starlink_proto_msgTypes[6]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
|
||||
func (x *DishAlerts) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*DishAlerts) ProtoMessage() {}
|
||||
|
||||
func (x *DishAlerts) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_internal_starlink_pb_starlink_proto_msgTypes[6]
|
||||
if x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use DishAlerts.ProtoReflect.Descriptor instead.
|
||||
func (*DishAlerts) Descriptor() ([]byte, []int) {
|
||||
return file_internal_starlink_pb_starlink_proto_rawDescGZIP(), []int{6}
|
||||
}
|
||||
|
||||
func (x *DishAlerts) GetMotorsStuck() bool {
|
||||
if x != nil {
|
||||
return x.MotorsStuck
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (x *DishAlerts) GetThermalShutdown() bool {
|
||||
if x != nil {
|
||||
return x.ThermalShutdown
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (x *DishAlerts) GetThermalThrottle() bool {
|
||||
if x != nil {
|
||||
return x.ThermalThrottle
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (x *DishAlerts) GetUnexpectedLocation() bool {
|
||||
if x != nil {
|
||||
return x.UnexpectedLocation
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
var File_internal_starlink_pb_starlink_proto protoreflect.FileDescriptor
|
||||
|
||||
const file_internal_starlink_pb_starlink_proto_rawDesc = "" +
|
||||
"\n" +
|
||||
"#internal/starlink/pb/starlink.proto\x12\x11SpaceX.API.Device\"[\n" +
|
||||
"\aRequest\x12E\n" +
|
||||
"\n" +
|
||||
"get_status\x18\xec\a \x01(\v2#.SpaceX.API.Device.GetStatusRequestH\x00R\tgetStatusB\t\n" +
|
||||
"\arequest\"\x12\n" +
|
||||
"\x10GetStatusRequest\"k\n" +
|
||||
"\bResponse\x12S\n" +
|
||||
"\x0fdish_get_status\x18\xd4\x0f \x01(\v2(.SpaceX.API.Device.DishGetStatusResponseH\x00R\rdishGetStatusB\n" +
|
||||
"\n" +
|
||||
"\bresponse\"\xea\x03\n" +
|
||||
"\x15DishGetStatusResponse\x12A\n" +
|
||||
"\fdevice_state\x18\x02 \x01(\v2\x1e.SpaceX.API.Device.DeviceStateR\vdeviceState\x12U\n" +
|
||||
"\x11obstruction_stats\x18\xec\a \x01(\v2'.SpaceX.API.Device.DishObstructionStatsR\x10obstructionStats\x126\n" +
|
||||
"\x06alerts\x18\xed\a \x01(\v2\x1d.SpaceX.API.Device.DishAlertsR\x06alerts\x123\n" +
|
||||
"\x05state\x18\xee\a \x01(\x0e2\x1c.SpaceX.API.Device.DishStateR\x05state\x12,\n" +
|
||||
"\x12pop_ping_drop_rate\x18\xeb\a \x01(\x02R\x0fpopPingDropRate\x127\n" +
|
||||
"\x17downlink_throughput_bps\x18\xef\a \x01(\x02R\x15downlinkThroughputBps\x123\n" +
|
||||
"\x15uplink_throughput_bps\x18\xf0\a \x01(\x02R\x13uplinkThroughputBps\x12.\n" +
|
||||
"\x13pop_ping_latency_ms\x18\xf1\a \x01(\x02R\x10popPingLatencyMs\"(\n" +
|
||||
"\vDeviceState\x12\x19\n" +
|
||||
"\buptime_s\x18\x01 \x01(\x04R\auptimeS\"G\n" +
|
||||
"\x14DishObstructionStats\x12/\n" +
|
||||
"\x13fraction_obstructed\x18\x01 \x01(\x02R\x12fractionObstructed\"\xb6\x01\n" +
|
||||
"\n" +
|
||||
"DishAlerts\x12!\n" +
|
||||
"\fmotors_stuck\x18\x01 \x01(\bR\vmotorsStuck\x12)\n" +
|
||||
"\x10thermal_shutdown\x18\x02 \x01(\bR\x0fthermalShutdown\x12)\n" +
|
||||
"\x10thermal_throttle\x18\x03 \x01(\bR\x0fthermalThrottle\x12/\n" +
|
||||
"\x13unexpected_location\x18\x04 \x01(\bR\x12unexpectedLocation*C\n" +
|
||||
"\tDishState\x12\v\n" +
|
||||
"\aUNKNOWN\x10\x00\x12\r\n" +
|
||||
"\tCONNECTED\x10\x01\x12\r\n" +
|
||||
"\tSEARCHING\x10\x02\x12\v\n" +
|
||||
"\aBOOTING\x10\x032K\n" +
|
||||
"\x06Device\x12A\n" +
|
||||
"\x06Handle\x12\x1a.SpaceX.API.Device.Request\x1a\x1b.SpaceX.API.Device.ResponseB<Z:git.eeqj.de/sneak/rtnetmon/internal/starlink/pb;starlinkpbb\x06proto3"
|
||||
|
||||
var (
|
||||
file_internal_starlink_pb_starlink_proto_rawDescOnce sync.Once
|
||||
file_internal_starlink_pb_starlink_proto_rawDescData []byte
|
||||
)
|
||||
|
||||
func file_internal_starlink_pb_starlink_proto_rawDescGZIP() []byte {
|
||||
file_internal_starlink_pb_starlink_proto_rawDescOnce.Do(func() {
|
||||
file_internal_starlink_pb_starlink_proto_rawDescData = protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_internal_starlink_pb_starlink_proto_rawDesc), len(file_internal_starlink_pb_starlink_proto_rawDesc)))
|
||||
})
|
||||
return file_internal_starlink_pb_starlink_proto_rawDescData
|
||||
}
|
||||
|
||||
var file_internal_starlink_pb_starlink_proto_enumTypes = make([]protoimpl.EnumInfo, 1)
|
||||
var file_internal_starlink_pb_starlink_proto_msgTypes = make([]protoimpl.MessageInfo, 7)
|
||||
var file_internal_starlink_pb_starlink_proto_goTypes = []any{
|
||||
(DishState)(0), // 0: SpaceX.API.Device.DishState
|
||||
(*Request)(nil), // 1: SpaceX.API.Device.Request
|
||||
(*GetStatusRequest)(nil), // 2: SpaceX.API.Device.GetStatusRequest
|
||||
(*Response)(nil), // 3: SpaceX.API.Device.Response
|
||||
(*DishGetStatusResponse)(nil), // 4: SpaceX.API.Device.DishGetStatusResponse
|
||||
(*DeviceState)(nil), // 5: SpaceX.API.Device.DeviceState
|
||||
(*DishObstructionStats)(nil), // 6: SpaceX.API.Device.DishObstructionStats
|
||||
(*DishAlerts)(nil), // 7: SpaceX.API.Device.DishAlerts
|
||||
}
|
||||
var file_internal_starlink_pb_starlink_proto_depIdxs = []int32{
|
||||
2, // 0: SpaceX.API.Device.Request.get_status:type_name -> SpaceX.API.Device.GetStatusRequest
|
||||
4, // 1: SpaceX.API.Device.Response.dish_get_status:type_name -> SpaceX.API.Device.DishGetStatusResponse
|
||||
5, // 2: SpaceX.API.Device.DishGetStatusResponse.device_state:type_name -> SpaceX.API.Device.DeviceState
|
||||
6, // 3: SpaceX.API.Device.DishGetStatusResponse.obstruction_stats:type_name -> SpaceX.API.Device.DishObstructionStats
|
||||
7, // 4: SpaceX.API.Device.DishGetStatusResponse.alerts:type_name -> SpaceX.API.Device.DishAlerts
|
||||
0, // 5: SpaceX.API.Device.DishGetStatusResponse.state:type_name -> SpaceX.API.Device.DishState
|
||||
1, // 6: SpaceX.API.Device.Device.Handle:input_type -> SpaceX.API.Device.Request
|
||||
3, // 7: SpaceX.API.Device.Device.Handle:output_type -> SpaceX.API.Device.Response
|
||||
7, // [7:8] is the sub-list for method output_type
|
||||
6, // [6:7] is the sub-list for method input_type
|
||||
6, // [6:6] is the sub-list for extension type_name
|
||||
6, // [6:6] is the sub-list for extension extendee
|
||||
0, // [0:6] is the sub-list for field type_name
|
||||
}
|
||||
|
||||
func init() { file_internal_starlink_pb_starlink_proto_init() }
|
||||
func file_internal_starlink_pb_starlink_proto_init() {
|
||||
if File_internal_starlink_pb_starlink_proto != nil {
|
||||
return
|
||||
}
|
||||
file_internal_starlink_pb_starlink_proto_msgTypes[0].OneofWrappers = []any{
|
||||
(*Request_GetStatus)(nil),
|
||||
}
|
||||
file_internal_starlink_pb_starlink_proto_msgTypes[2].OneofWrappers = []any{
|
||||
(*Response_DishGetStatus)(nil),
|
||||
}
|
||||
type x struct{}
|
||||
out := protoimpl.TypeBuilder{
|
||||
File: protoimpl.DescBuilder{
|
||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||
RawDescriptor: unsafe.Slice(unsafe.StringData(file_internal_starlink_pb_starlink_proto_rawDesc), len(file_internal_starlink_pb_starlink_proto_rawDesc)),
|
||||
NumEnums: 1,
|
||||
NumMessages: 7,
|
||||
NumExtensions: 0,
|
||||
NumServices: 1,
|
||||
},
|
||||
GoTypes: file_internal_starlink_pb_starlink_proto_goTypes,
|
||||
DependencyIndexes: file_internal_starlink_pb_starlink_proto_depIdxs,
|
||||
EnumInfos: file_internal_starlink_pb_starlink_proto_enumTypes,
|
||||
MessageInfos: file_internal_starlink_pb_starlink_proto_msgTypes,
|
||||
}.Build()
|
||||
File_internal_starlink_pb_starlink_proto = out.File
|
||||
file_internal_starlink_pb_starlink_proto_goTypes = nil
|
||||
file_internal_starlink_pb_starlink_proto_depIdxs = nil
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
// A minimal slice of the Starlink dish's local gRPC API: just the one
|
||||
// unary RPC (SpaceX.API.Device.Device/Handle) and the get_status request
|
||||
// and dish status response, reduced to the handful of fields rtnetmon
|
||||
// shows. The proto package name and field numbers must match the dish
|
||||
// exactly for the wire format to line up; every other field the dish sends
|
||||
// is ignored as an unknown field.
|
||||
//
|
||||
// Field numbers, message names and the DishState enum are transcribed from
|
||||
// the community-maintained pre-generated bindings at
|
||||
// github.com/starlink-community/starlink-grpc-go, commit
|
||||
// 2e89f3d7e3092adecbcc04e9e003e61ed5f7c6a3 (get_status = 1004,
|
||||
// dish_get_status = 2004). They are not verified against a live dish here.
|
||||
//
|
||||
// Regenerate with:
|
||||
// protoc --go_out=. --go_opt=paths=source_relative \
|
||||
// --go-grpc_out=. --go-grpc_opt=paths=source_relative \
|
||||
// internal/starlink/pb/starlink.proto
|
||||
|
||||
syntax = "proto3";
|
||||
|
||||
package SpaceX.API.Device;
|
||||
|
||||
option go_package = "git.eeqj.de/sneak/rtnetmon/internal/starlink/pb;starlinkpb";
|
||||
|
||||
service Device {
|
||||
rpc Handle(Request) returns (Response);
|
||||
}
|
||||
|
||||
message Request {
|
||||
oneof request {
|
||||
GetStatusRequest get_status = 1004;
|
||||
}
|
||||
}
|
||||
|
||||
message GetStatusRequest {}
|
||||
|
||||
message Response {
|
||||
oneof response {
|
||||
DishGetStatusResponse dish_get_status = 2004;
|
||||
}
|
||||
}
|
||||
|
||||
message DishGetStatusResponse {
|
||||
DeviceState device_state = 2;
|
||||
DishObstructionStats obstruction_stats = 1004;
|
||||
DishAlerts alerts = 1005;
|
||||
DishState state = 1006;
|
||||
float pop_ping_drop_rate = 1003;
|
||||
float downlink_throughput_bps = 1007;
|
||||
float uplink_throughput_bps = 1008;
|
||||
float pop_ping_latency_ms = 1009;
|
||||
}
|
||||
|
||||
message DeviceState {
|
||||
uint64 uptime_s = 1;
|
||||
}
|
||||
|
||||
message DishObstructionStats {
|
||||
float fraction_obstructed = 1;
|
||||
}
|
||||
|
||||
message DishAlerts {
|
||||
bool motors_stuck = 1;
|
||||
bool thermal_shutdown = 2;
|
||||
bool thermal_throttle = 3;
|
||||
bool unexpected_location = 4;
|
||||
}
|
||||
|
||||
enum DishState {
|
||||
UNKNOWN = 0;
|
||||
CONNECTED = 1;
|
||||
SEARCHING = 2;
|
||||
BOOTING = 3;
|
||||
}
|
||||
@@ -1,140 +0,0 @@
|
||||
// A minimal slice of the Starlink dish's local gRPC API: just the one
|
||||
// unary RPC (SpaceX.API.Device.Device/Handle) and the get_status request
|
||||
// and dish status response, reduced to the handful of fields rtnetmon
|
||||
// shows. The proto package name and field numbers must match the dish
|
||||
// exactly for the wire format to line up; every other field the dish sends
|
||||
// is ignored as an unknown field.
|
||||
//
|
||||
// Field numbers, message names and the DishState enum are transcribed from
|
||||
// the community-maintained pre-generated bindings at
|
||||
// github.com/starlink-community/starlink-grpc-go, commit
|
||||
// 2e89f3d7e3092adecbcc04e9e003e61ed5f7c6a3 (get_status = 1004,
|
||||
// dish_get_status = 2004). They are not verified against a live dish here.
|
||||
//
|
||||
// Regenerate with:
|
||||
// protoc --go_out=. --go_opt=paths=source_relative \
|
||||
// --go-grpc_out=. --go-grpc_opt=paths=source_relative \
|
||||
// internal/starlink/pb/starlink.proto
|
||||
|
||||
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
||||
// versions:
|
||||
// - protoc-gen-go-grpc v1.5.1
|
||||
// - protoc v7.36.2
|
||||
// source: internal/starlink/pb/starlink.proto
|
||||
|
||||
package starlinkpb
|
||||
|
||||
import (
|
||||
context "context"
|
||||
|
||||
grpc "google.golang.org/grpc"
|
||||
codes "google.golang.org/grpc/codes"
|
||||
status "google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
// This is a compile-time assertion to ensure that this generated file
|
||||
// is compatible with the grpc package it is being compiled against.
|
||||
// Requires gRPC-Go v1.64.0 or later.
|
||||
const _ = grpc.SupportPackageIsVersion9
|
||||
|
||||
const (
|
||||
Device_Handle_FullMethodName = "/SpaceX.API.Device.Device/Handle"
|
||||
)
|
||||
|
||||
// DeviceClient is the client API for Device service.
|
||||
//
|
||||
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
|
||||
type DeviceClient interface {
|
||||
Handle(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error)
|
||||
}
|
||||
|
||||
type deviceClient struct {
|
||||
cc grpc.ClientConnInterface
|
||||
}
|
||||
|
||||
func NewDeviceClient(cc grpc.ClientConnInterface) DeviceClient {
|
||||
return &deviceClient{cc}
|
||||
}
|
||||
|
||||
func (c *deviceClient) Handle(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(Response)
|
||||
err := c.cc.Invoke(ctx, Device_Handle_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// DeviceServer is the server API for Device service.
|
||||
// All implementations must embed UnimplementedDeviceServer
|
||||
// for forward compatibility.
|
||||
type DeviceServer interface {
|
||||
Handle(context.Context, *Request) (*Response, error)
|
||||
mustEmbedUnimplementedDeviceServer()
|
||||
}
|
||||
|
||||
// UnimplementedDeviceServer must be embedded to have
|
||||
// forward compatible implementations.
|
||||
//
|
||||
// NOTE: this should be embedded by value instead of pointer to avoid a nil
|
||||
// pointer dereference when methods are called.
|
||||
type UnimplementedDeviceServer struct{}
|
||||
|
||||
func (UnimplementedDeviceServer) Handle(context.Context, *Request) (*Response, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method Handle not implemented")
|
||||
}
|
||||
func (UnimplementedDeviceServer) mustEmbedUnimplementedDeviceServer() {}
|
||||
func (UnimplementedDeviceServer) testEmbeddedByValue() {}
|
||||
|
||||
// UnsafeDeviceServer may be embedded to opt out of forward compatibility for this service.
|
||||
// Use of this interface is not recommended, as added methods to DeviceServer will
|
||||
// result in compilation errors.
|
||||
type UnsafeDeviceServer interface {
|
||||
mustEmbedUnimplementedDeviceServer()
|
||||
}
|
||||
|
||||
func RegisterDeviceServer(s grpc.ServiceRegistrar, srv DeviceServer) {
|
||||
// If the following call pancis, it indicates UnimplementedDeviceServer was
|
||||
// embedded by pointer and is nil. This will cause panics if an
|
||||
// unimplemented method is ever invoked, so we test this at initialization
|
||||
// time to prevent it from happening at runtime later due to I/O.
|
||||
if t, ok := srv.(interface{ testEmbeddedByValue() }); ok {
|
||||
t.testEmbeddedByValue()
|
||||
}
|
||||
s.RegisterService(&Device_ServiceDesc, srv)
|
||||
}
|
||||
|
||||
func _Device_Handle_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(Request)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(DeviceServer).Handle(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: Device_Handle_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(DeviceServer).Handle(ctx, req.(*Request))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
// Device_ServiceDesc is the grpc.ServiceDesc for Device service.
|
||||
// It's only intended for direct use with grpc.RegisterService,
|
||||
// and not to be introspected or modified (even as a copy)
|
||||
var Device_ServiceDesc = grpc.ServiceDesc{
|
||||
ServiceName: "SpaceX.API.Device.Device",
|
||||
HandlerType: (*DeviceServer)(nil),
|
||||
Methods: []grpc.MethodDesc{
|
||||
{
|
||||
MethodName: "Handle",
|
||||
Handler: _Device_Handle_Handler,
|
||||
},
|
||||
},
|
||||
Streams: []grpc.StreamDesc{},
|
||||
Metadata: "internal/starlink/pb/starlink.proto",
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
// Package starlink detects a Starlink dish on the local network and reads a
|
||||
// short status summary from the dish's local gRPC endpoint. Detection and
|
||||
// the status fetch sit behind the Client interface, so the monitor is
|
||||
// tested with a fake and needs no dish and no network. Render turns a
|
||||
// Status into the two lines the UI draws and is a pure function.
|
||||
package starlink
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Address is the dish's fixed local gRPC endpoint. Every dish answers here
|
||||
// from behind the Starlink router, whatever the LAN's own addressing is, so
|
||||
// this is not the default gateway (that is the router).
|
||||
const Address = "192.168.100.1:9200"
|
||||
|
||||
// StateConnected is the dish state string that means the link is up; any
|
||||
// other state is treated as an alert condition by Render.
|
||||
const StateConnected = "CONNECTED"
|
||||
|
||||
// Units used when reducing the dish's raw values to display values.
|
||||
const (
|
||||
percentScale = 100.0
|
||||
bitsPerMegabit = 1_000_000.0
|
||||
hoursPerDay = 24
|
||||
minutesPerHour = 60
|
||||
)
|
||||
|
||||
// Status is the subset of the dish's get_status response that rtnetmon
|
||||
// shows. Throughput is megabits per second; obstruction and drop are
|
||||
// percentages on a 0..100 scale.
|
||||
type Status struct {
|
||||
State string
|
||||
Uptime time.Duration
|
||||
ObstructionPct float64
|
||||
Alerts int
|
||||
PopPingMs float64
|
||||
PopPingDropPct float64
|
||||
DownlinkMbps float64
|
||||
UplinkMbps float64
|
||||
}
|
||||
|
||||
// Client probes for a dish and reads its status. The real implementation
|
||||
// speaks gRPC to Address over one bound interface; tests use a fake.
|
||||
type Client interface {
|
||||
// Probe reports whether a dish answers on Address over the bound
|
||||
// interface. It is cheap: a TCP connect, no gRPC call.
|
||||
Probe(ctx context.Context) bool
|
||||
// Status fetches the dish's current status.
|
||||
Status(ctx context.Context) (Status, error)
|
||||
}
|
||||
|
||||
// Render formats a Status as the two status lines drawn under the physical
|
||||
// pane, and reports whether they warrant an alert (red) color: the dish is
|
||||
// not connected, or an alert is active.
|
||||
func Render(s Status) (string, string, bool) {
|
||||
line1 := fmt.Sprintf(
|
||||
"Starlink: %s uptime %s obstruction %.1f%% alerts %d",
|
||||
s.State, formatUptime(s.Uptime), s.ObstructionPct, s.Alerts)
|
||||
line2 := fmt.Sprintf(
|
||||
" pop ping %.0fms / drop %.1f%% down %.1fMbps / up %.1fMbps",
|
||||
s.PopPingMs, s.PopPingDropPct, s.DownlinkMbps, s.UplinkMbps)
|
||||
alert := s.State != StateConnected || s.Alerts > 0
|
||||
|
||||
return line1, line2, alert
|
||||
}
|
||||
|
||||
// formatUptime renders a duration as whole days, hours and minutes.
|
||||
func formatUptime(d time.Duration) string {
|
||||
if d < 0 {
|
||||
d = 0
|
||||
}
|
||||
|
||||
days := int64(d / (hoursPerDay * time.Hour))
|
||||
hours := int64(d/time.Hour) % hoursPerDay
|
||||
mins := int64(d/time.Minute) % minutesPerHour
|
||||
|
||||
return fmt.Sprintf("%dd %dh %dm", days, hours, mins)
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
package starlink_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.eeqj.de/sneak/rtnetmon/internal/starlink"
|
||||
)
|
||||
|
||||
func TestRender(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
connected := starlink.Status{
|
||||
State: "CONNECTED",
|
||||
Uptime: 3*24*time.Hour + 4*time.Hour + 12*time.Minute,
|
||||
ObstructionPct: 0.1,
|
||||
Alerts: 0,
|
||||
PopPingMs: 34,
|
||||
PopPingDropPct: 0.0,
|
||||
DownlinkMbps: 145.3,
|
||||
UplinkMbps: 12.1,
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
status starlink.Status
|
||||
wantLine1 string
|
||||
wantLine2 string
|
||||
wantAlert bool
|
||||
}{
|
||||
{
|
||||
name: "connected, no alert",
|
||||
status: connected,
|
||||
wantLine1: "Starlink: CONNECTED uptime 3d 4h 12m obstruction 0.1% alerts 0",
|
||||
wantLine2: " pop ping 34ms / drop 0.0% down 145.3Mbps / up 12.1Mbps",
|
||||
wantAlert: false,
|
||||
},
|
||||
{
|
||||
name: "searching is an alert",
|
||||
status: starlink.Status{
|
||||
State: "SEARCHING",
|
||||
Uptime: 0,
|
||||
},
|
||||
wantLine1: "Starlink: SEARCHING uptime 0d 0h 0m obstruction 0.0% alerts 0",
|
||||
wantLine2: " pop ping 0ms / drop 0.0% down 0.0Mbps / up 0.0Mbps",
|
||||
wantAlert: true,
|
||||
},
|
||||
{
|
||||
name: "connected but alerts active",
|
||||
status: starlink.Status{
|
||||
State: "CONNECTED",
|
||||
Uptime: 90 * time.Minute,
|
||||
Alerts: 2,
|
||||
},
|
||||
wantLine1: "Starlink: CONNECTED uptime 0d 1h 30m obstruction 0.0% alerts 2",
|
||||
wantLine2: " pop ping 0ms / drop 0.0% down 0.0Mbps / up 0.0Mbps",
|
||||
wantAlert: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
line1, line2, alert := starlink.Render(tt.status)
|
||||
if line1 != tt.wantLine1 {
|
||||
t.Errorf("line1 = %q, want %q", line1, tt.wantLine1)
|
||||
}
|
||||
|
||||
if line2 != tt.wantLine2 {
|
||||
t.Errorf("line2 = %q, want %q", line2, tt.wantLine2)
|
||||
}
|
||||
|
||||
if alert != tt.wantAlert {
|
||||
t.Errorf("alert = %v, want %v", alert, tt.wantAlert)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -31,9 +31,6 @@ detect_pkgmgr() {
|
||||
if [ "$(id -u)" != "0" ]; then
|
||||
SUDO="sudo"
|
||||
fi
|
||||
# Fresh images, the CI runner's among them, ship with empty
|
||||
# package lists. This runs once, on the first install.
|
||||
$SUDO env DEBIAN_FRONTEND=noninteractive apt-get update
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user