app: show what the server reports as facts, not as inputs
The settings card offered three editable boxes and said nothing about the server itself — which addresses a test will actually use, on which ports, what it can measure. That is the part a person checks before trusting a result, and "which address did this come from" is precisely the question a report leaves open. The server now publishes it. The profile's targets carried one IPv4 and a TODO; it reports both families and both alternates, derived from the UDP listen spec rather than configured separately, so the list cannot drift from what is actually bound. No reservation means no alternate is claimed: announcing a second address as the RFC 5780 alternate when none was set aside would promise a redirect the server will not send. The app renders them read-only, in a panel visibly distinct from the fields above. An editable box that changes nothing is worse than no box, and these are facts to read rather than settings to apply. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
fe4ec23ba1
commit
c4f2a10790
@@ -260,7 +260,9 @@ func serve(cfg *config.Config) error {
|
||||
"every upload will be refused")
|
||||
}
|
||||
|
||||
ip4, ip6, ip4Alt, ip6Alt := cfg.MeasurementAddrs()
|
||||
ctl := &control.Server{
|
||||
IP4: ip4, IP6: ip6, IP4Alt: ip4Alt, IP6Alt: ip6Alt,
|
||||
Store: st, Sessions: sessions, Name: cfg.Name,
|
||||
UDPPort: mustPort(firstAddr(cfg.UDPListen)), TCPPort: mustPort(firstAddr(cfg.TCPListen)),
|
||||
StunPort: mustPort(firstAddr(cfg.StunListen)), PinB64: pin, CertChain: cert.Certificate,
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
// SPDX-FileCopyrightText: 2026 Echolot contributors
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
package config
|
||||
|
||||
import "testing"
|
||||
|
||||
// The fixture is fmr's real UDP listen spec, because the point of deriving these from the bound
|
||||
// listeners is that they cannot disagree with what the server actually answers on.
|
||||
const fmrUDP = "89.185.109.150:8442,89.185.109.151:8442," +
|
||||
"[2001:1ad0:c4fe:6767::150]:8442,[2001:1ad0:c4fe:6767::151]:8442"
|
||||
|
||||
func TestMeasurementAddrsSplitsPrimaryFromReserved(t *testing.T) {
|
||||
c := &Config{
|
||||
UDPListen: fmrUDP,
|
||||
ReservedAddrs: "89.185.109.151,2001:1ad0:c4fe:6767::151",
|
||||
}
|
||||
ip4, ip6, ip4Alt, ip6Alt := c.MeasurementAddrs()
|
||||
for _, tc := range []struct{ got, want, name string }{
|
||||
{ip4, "89.185.109.150", "ip4"},
|
||||
{ip6, "2001:1ad0:c4fe:6767::150", "ip6"},
|
||||
{ip4Alt, "89.185.109.151", "ip4_alt"},
|
||||
{ip6Alt, "2001:1ad0:c4fe:6767::151", "ip6_alt"},
|
||||
} {
|
||||
if tc.got != tc.want {
|
||||
t.Errorf("%s = %q, want %q", tc.name, tc.got, tc.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestMeasurementAddrsWithNothingReserved(t *testing.T) {
|
||||
// No reservation means no alternate: reporting a second address as the RFC 5780 alternate
|
||||
// when it was never set aside for that would tell a client to expect a redirect that the
|
||||
// server has no intention of sending.
|
||||
c := &Config{UDPListen: fmrUDP}
|
||||
ip4, ip6, ip4Alt, ip6Alt := c.MeasurementAddrs()
|
||||
if ip4 == "" || ip6 == "" {
|
||||
t.Fatalf("primaries should still be found: ip4=%q ip6=%q", ip4, ip6)
|
||||
}
|
||||
if ip4Alt != "" || ip6Alt != "" {
|
||||
t.Errorf("no address is reserved, so there is no alternate; got %q / %q", ip4Alt, ip6Alt)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMeasurementAddrsIgnoresWhatItCannotRead(t *testing.T) {
|
||||
// A wildcard bind names no address, and a hostname is not resolved here. Either would be a
|
||||
// guess presented to clients as fact.
|
||||
c := &Config{UDPListen: ":8442,probe.example.net:8442,89.185.109.150:8442"}
|
||||
ip4, ip6, _, _ := c.MeasurementAddrs()
|
||||
if ip4 != "89.185.109.150" {
|
||||
t.Errorf("ip4 = %q, want the one address that was actually spelled out", ip4)
|
||||
}
|
||||
if ip6 != "" {
|
||||
t.Errorf("ip6 = %q, want empty — none was configured", ip6)
|
||||
}
|
||||
}
|
||||
@@ -322,6 +322,44 @@ func (c *Config) Listeners() []Listener {
|
||||
}
|
||||
}
|
||||
|
||||
// MeasurementAddrs picks out the addresses this server can be measured on, by family, splitting
|
||||
// primaries from the reserved alternates.
|
||||
//
|
||||
// Derived from what is actually bound rather than configured separately: a second list of the
|
||||
// server's own addresses is a second thing to keep in step, and the copy that drifts is the one
|
||||
// clients are told about.
|
||||
func (c *Config) MeasurementAddrs() (ip4, ip6, ip4Alt, ip6Alt string) {
|
||||
reserved := map[string]bool{}
|
||||
for _, ip := range c.ReservedIPs() {
|
||||
reserved[ip.String()] = true
|
||||
}
|
||||
// The UDP data plane binds every address a client may be pointed at, which makes it the
|
||||
// honest source for this.
|
||||
for _, a := range Addrs(c.UDPListen) {
|
||||
host, _, err := net.SplitHostPort(a)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
host = strings.Trim(host, "[]")
|
||||
ip := net.ParseIP(host)
|
||||
if ip == nil {
|
||||
continue
|
||||
}
|
||||
alt := reserved[ip.String()]
|
||||
switch {
|
||||
case ip.To4() != nil && alt && ip4Alt == "":
|
||||
ip4Alt = host
|
||||
case ip.To4() != nil && !alt && ip4 == "":
|
||||
ip4 = host
|
||||
case ip.To4() == nil && alt && ip6Alt == "":
|
||||
ip6Alt = host
|
||||
case ip.To4() == nil && !alt && ip6 == "":
|
||||
ip6 = host
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Addrs splits a comma-separated listen spec into individual addresses.
|
||||
// Explicit per-address binds matter on multi-IP hosts: a wildcard bind
|
||||
// (":8443") would also claim addresses reserved for other purposes (e.g. an
|
||||
|
||||
@@ -80,6 +80,10 @@ type Server struct {
|
||||
CanaryQueries func(sessionPrefix string) any
|
||||
// CanaryZone is surfaced in the profile so the app knows what to query.
|
||||
CanaryZone string
|
||||
// The addresses this server can be measured on. The "_alt" pair is the second address
|
||||
// RFC 5780 behaviour discovery redirects to, and the one reserved from services so that
|
||||
// nothing answering there is itself a measurement.
|
||||
IP4, IP6, IP4Alt, IP6Alt string
|
||||
// ProvenGood reports the server's self-test signal (may be nil). Surfaced
|
||||
// in the profile so a client can trust — or skip — MTU tests: if the
|
||||
// server's own egress isn't full-MTU, client MTU results measure the
|
||||
@@ -614,13 +618,7 @@ func (s *Server) profile(w http.ResponseWriter, r *http.Request) {
|
||||
// modified builds and gives clients provenance for the measurement.
|
||||
"source_url": "", // TODO: stamp from build metadata
|
||||
"capabilities": s.Capabilities,
|
||||
"targets": []map[string]any{{
|
||||
"id": s.Name,
|
||||
"ip4": host, // TODO: explicit configured addresses, v6, second STUN addr
|
||||
"udp_port": s.UDPPort,
|
||||
"tcp_port": s.TCPPort,
|
||||
"stun_port": s.StunPort,
|
||||
}},
|
||||
"targets": []map[string]any{s.target(host)},
|
||||
"pins": []string{"pin-sha256:" + s.PinB64},
|
||||
"next_pins": []string{},
|
||||
"canary_zone": s.CanaryZone,
|
||||
@@ -838,6 +836,34 @@ func EnrollmentURI(publicURL, pinB64, token string) string {
|
||||
"&t=" + url.QueryEscape(token)
|
||||
}
|
||||
|
||||
// target describes where this server can be measured, so a client can say which address a result
|
||||
// came from instead of "the server".
|
||||
//
|
||||
// The alternates matter as much as the primaries: RFC 5780 behaviour discovery needs a second
|
||||
// address to redirect to, and an operator reading a report needs to know which of their addresses
|
||||
// a finding refers to. [fallback] is used only when nothing was configured explicitly, so a server
|
||||
// that has not been told its own addresses still answers with something usable.
|
||||
func (s *Server) target(fallback string) map[string]any {
|
||||
t := map[string]any{
|
||||
"id": s.Name,
|
||||
"udp_port": s.UDPPort,
|
||||
"tcp_port": s.TCPPort,
|
||||
"stun_port": s.StunPort,
|
||||
}
|
||||
ip4 := s.IP4
|
||||
if ip4 == "" {
|
||||
ip4 = fallback
|
||||
}
|
||||
for k, v := range map[string]string{
|
||||
"ip4": ip4, "ip6": s.IP6, "ip4_alt": s.IP4Alt, "ip6_alt": s.IP6Alt,
|
||||
} {
|
||||
if v != "" {
|
||||
t[k] = v
|
||||
}
|
||||
}
|
||||
return t
|
||||
}
|
||||
|
||||
// upstreamJSON renders the upstream tally with the derived figures already computed, so every
|
||||
// consumer does not have to repeat (and risk fumbling) the same arithmetic.
|
||||
func upstreamJSON(sess *session.Session) map[string]any {
|
||||
|
||||
Reference in New Issue
Block a user