diff --git a/control/tsp/map_test.go b/control/tsp/map_test.go index ddfde3971..089b83050 100644 --- a/control/tsp/map_test.go +++ b/control/tsp/map_test.go @@ -11,6 +11,7 @@ import ( "fmt" "io" "net/http/httptest" + "slices" "strings" "testing" "time" @@ -259,7 +260,7 @@ func TestSendMapUpdateAgainstTestControl(t *testing.T) { // B should now observe A's new DiscoKey in a subsequent MapResponse. for { resp := nextNonKeepalive() - for _, p := range resp.Peers { + for _, p := range slices.Concat(resp.Peers, resp.PeersChanged) { if p.Key != nodeKeyA.Public() { continue } @@ -267,6 +268,11 @@ func TestSendMapUpdateAgainstTestControl(t *testing.T) { return // success } } + for _, p := range resp.PeersChangedPatch { + if p.NodeID == initialA.ID && p.DiscoKey != nil && *p.DiscoKey == wantDisco { + return // success via a field-level update + } + } } } diff --git a/flake.nix b/flake.nix index 57f74eeb4..cabece505 100644 --- a/flake.nix +++ b/flake.nix @@ -173,4 +173,4 @@ }); }; } -# nix-direnv cache busting line: sha256-Kysr52akpXixZ7/zoWaHjqUHQPLCLyHevb4JH+ZJwTw= \ No newline at end of file +# nix-direnv cache busting line: sha256-d8bEjbu413IgbGdDnglZvsoXHjKVrgtA6hWchpYe/Xc= \ No newline at end of file diff --git a/flakehashes.json b/flakehashes.json index 862531ba5..24c9aa728 100644 --- a/flakehashes.json +++ b/flakehashes.json @@ -4,7 +4,7 @@ "sri": "sha256-qxNiwlI/KJpwx7VZQU9C5puJGMUtN5vBXm3ApNYIolI=" }, "vendor": { - "goModSum": "sha256-+mk46yWJIBkUoh9P7rD+OZcS9e2yhbk2eIWgwnNX4Z8=", - "sri": "sha256-Kysr52akpXixZ7/zoWaHjqUHQPLCLyHevb4JH+ZJwTw=" + "goModSum": "sha256-pe7G/m6tu+29a71VnGEIVRS5dP8N8a3gSQjdG1WHjj4=", + "sri": "sha256-d8bEjbu413IgbGdDnglZvsoXHjKVrgtA6hWchpYe/Xc=" } } diff --git a/go.mod b/go.mod index 9bd94a793..15d62d249 100644 --- a/go.mod +++ b/go.mod @@ -24,6 +24,7 @@ require ( github.com/bradfitz/go-tool-cache v0.0.0-20260919185303-c660171c910c github.com/bradfitz/monogok v0.0.0-20260630033929-b1eef977b41f github.com/bradfitz/qemu-guest-kragent v0.0.0-20240513123539-55a43ea02a03 + github.com/bradfitz/reco v0.0.0-20260929154613-b883fbd17e3f github.com/bramvdbogaerde/go-scp v1.6.1 github.com/chromedp/cdproto v0.0.0-20260714215040-dc233986426f github.com/chromedp/chromedp v0.16.0 diff --git a/go.sum b/go.sum index 84ec3e316..e8e182c00 100644 --- a/go.sum +++ b/go.sum @@ -207,6 +207,8 @@ github.com/bradfitz/monogok v0.0.0-20260630033929-b1eef977b41f h1:voy0korWbg2e1g github.com/bradfitz/monogok v0.0.0-20260630033929-b1eef977b41f/go.mod h1:TG1HbU9fRVDnNgXncVkKz9GdvjIvqquXjH6QZSEVmY4= github.com/bradfitz/qemu-guest-kragent v0.0.0-20240513123539-55a43ea02a03 h1:V1gD/xbQZtimHXZ0y19oMgTVBIXQyazG/mG9JIflrIY= github.com/bradfitz/qemu-guest-kragent v0.0.0-20240513123539-55a43ea02a03/go.mod h1:DFLM0H5mh/gbb8viqnMwZzZ8TU4o3bbXOa5tyknrOQY= +github.com/bradfitz/reco v0.0.0-20260929154613-b883fbd17e3f h1:jdXGSp5Ge5/kzikuxGOw9+6HSStUjkNBJZjGNtpItek= +github.com/bradfitz/reco v0.0.0-20260929154613-b883fbd17e3f/go.mod h1:oiCPXxBoDKSkb/RGEZwAZk8y/fwDlQ1vYlBbNRxPysw= github.com/bramvdbogaerde/go-scp v1.6.1 h1:HE63uMkmMEB62JwqdRrVqRTBi7H/L/rkTp8TPC7uffY= github.com/bramvdbogaerde/go-scp v1.6.1/go.mod h1:Lqx75BOgAvQoeBbPuPN/MfU3jf5tlfZVmUqpPbSZkZc= github.com/breml/bidichk v0.3.3 h1:WSM67ztRusf1sMoqH6/c4OBCUlRVTKq+CbSeo0R17sE= diff --git a/shell.nix b/shell.nix index 813677f06..11d2a9ffd 100644 --- a/shell.nix +++ b/shell.nix @@ -16,4 +16,4 @@ ) { src = ./.; }).shellNix -# nix-direnv cache busting line: sha256-Kysr52akpXixZ7/zoWaHjqUHQPLCLyHevb4JH+ZJwTw= +# nix-direnv cache busting line: sha256-d8bEjbu413IgbGdDnglZvsoXHjKVrgtA6hWchpYe/Xc= diff --git a/tstest/integration/testcontrol/capability_default_test.go b/tstest/integration/testcontrol/capability_default_test.go new file mode 100644 index 000000000..9cd16bbb3 --- /dev/null +++ b/tstest/integration/testcontrol/capability_default_test.go @@ -0,0 +1,9 @@ +// Copyright (c) Tailscale Inc & contributors +// SPDX-License-Identifier: BSD-3-Clause + +//go:build !experiment.reco + +package testcontrol_test + +// The original test server also implements legacy map protocol versions. +const minTestControlCapabilityVersion = 0 diff --git a/tstest/integration/testcontrol/capability_reco_test.go b/tstest/integration/testcontrol/capability_reco_test.go new file mode 100644 index 000000000..ec6f3f8d9 --- /dev/null +++ b/tstest/integration/testcontrol/capability_reco_test.go @@ -0,0 +1,10 @@ +// Copyright (c) Tailscale Inc & contributors +// SPDX-License-Identifier: BSD-3-Clause + +//go:build experiment.reco + +package testcontrol_test + +import "github.com/bradfitz/reco/recotestcontrol" + +const minTestControlCapabilityVersion = recotestcontrol.MinCapabilityVersion diff --git a/tstest/integration/testcontrol/doc.go b/tstest/integration/testcontrol/doc.go new file mode 100644 index 000000000..4e3f45d32 --- /dev/null +++ b/tstest/integration/testcontrol/doc.go @@ -0,0 +1,5 @@ +// Copyright (c) Tailscale Inc & contributors +// SPDX-License-Identifier: BSD-3-Clause + +// Package testcontrol contains a minimal control plane server for testing purposes. +package testcontrol diff --git a/tstest/integration/testcontrol/reco-experiment.go b/tstest/integration/testcontrol/reco-experiment.go new file mode 100644 index 000000000..472759471 --- /dev/null +++ b/tstest/integration/testcontrol/reco-experiment.go @@ -0,0 +1,18 @@ +// Copyright (c) Tailscale Inc & contributors +// SPDX-License-Identifier: BSD-3-Clause + +//go:build experiment.reco + +package testcontrol + +import "github.com/bradfitz/reco/recotestcontrol" + +// Re-export the test server API so callers can select either implementation +// using only a build tag. The reco implementation supports capability 109+. +type Server = recotestcontrol.Server +type AuthPath = recotestcontrol.AuthPath +type MasqueradePair = recotestcontrol.MasqueradePair +type AltMapStreamFunc = recotestcontrol.AltMapStreamFunc +type MapStreamWriter = recotestcontrol.MapStreamWriter + +var RejectRequestForPath = recotestcontrol.RejectRequestForPath diff --git a/tstest/integration/testcontrol/reco.md b/tstest/integration/testcontrol/reco.md new file mode 100644 index 000000000..d360be90b --- /dev/null +++ b/tstest/integration/testcontrol/reco.md @@ -0,0 +1,22 @@ +# Experimental reco implementation + +By default, this package uses the original in-memory test control server. +The `experiment.reco` build tag substitutes +[`github.com/bradfitz/reco/recotestcontrol`](https://pkg.go.dev/github.com/bradfitz/reco/recotestcontrol) +using type aliases, without changing callers. + +Reco is an experimental research prototype, not a production control server or +a stable API. Its test server requires capability version 109 or later. The +protocol tests check both legacy behavior in the default server and rejection +of obsolete versions with the experiment enabled. + +For example, from the module root: + +```sh +GOWORK=off GOFLAGS=-tags=experiment.reco go test \ + ./tstest/integration/testcontrol ./control/tsp ./control/controlclient \ + ./tsnet ./tstest/integration +``` + +Use `GOFLAGS` so integration tests' child Go builds receive the tag too. +Omit it to exercise the default implementation. diff --git a/tstest/integration/testcontrol/testcontrol.go b/tstest/integration/testcontrol/testcontrol.go index f63bc817e..024607a17 100644 --- a/tstest/integration/testcontrol/testcontrol.go +++ b/tstest/integration/testcontrol/testcontrol.go @@ -1,7 +1,8 @@ // Copyright (c) Tailscale Inc & contributors // SPDX-License-Identifier: BSD-3-Clause -// Package testcontrol contains a minimal control plane server for testing purposes. +//go:build !experiment.reco + package testcontrol import ( diff --git a/tstest/integration/testcontrol/testcontrol_test.go b/tstest/integration/testcontrol/testcontrol_test.go index d3008cdb7..b60f4210b 100644 --- a/tstest/integration/testcontrol/testcontrol_test.go +++ b/tstest/integration/testcontrol/testcontrol_test.go @@ -34,13 +34,18 @@ import ( // // For older (cap<68) clients, the streaming MapRequest is still a write and // writes do happen, so DiscoKey=zero in the request does clobber. +// Implementations with a newer protocol floor must reject older versions +// without mutating the node instead. func TestStreamingMapReqReadOnlyByVersion(t *testing.T) { tests := []struct { version tailcfg.CapabilityVersion wantClobber bool }{ - {67, true}, // pre-cap-68: streaming is a write, DiscoKey=zero clobbers. - {68, false}, // cap>=68: streaming is read-only, DiscoKey unchanged. + {67, true}, // pre-cap-68: streaming is a write, DiscoKey=zero clobbers. + {68, false}, // cap>=68: streaming is read-only, DiscoKey unchanged. + {108, false}, // just below the reco implementation's version floor. + {109, false}, // the reco implementation's oldest supported version. + {tailcfg.CurrentCapabilityVersion, false}, } for _, tt := range tests { @@ -115,15 +120,24 @@ func TestStreamingMapReqReadOnlyByVersion(t *testing.T) { t.Fatalf("nc.Do: %v", err) } res.Body.Close() // tears down the streaming session server-side + wantStatus := http.StatusOK + wantClobber := tt.wantClobber + if tt.version < minTestControlCapabilityVersion { + wantStatus = http.StatusBadRequest + wantClobber = false + } + if res.StatusCode != wantStatus { + t.Fatalf("map response status = %d, want %d", res.StatusCode, wantStatus) + } got := ctrl.Node(nodeKey.Public()) if got == nil { t.Fatal("node disappeared") } switch { - case tt.wantClobber && !got.DiscoKey.IsZero(): + case wantClobber && !got.DiscoKey.IsZero(): t.Errorf("v%d: expected DiscoKey clobbered to zero, got %v", tt.version, got.DiscoKey) - case !tt.wantClobber && got.DiscoKey != wantDisco: + case !wantClobber && got.DiscoKey != wantDisco: t.Errorf("v%d: DiscoKey changed from %v to %v; should have been left alone", tt.version, wantDisco, got.DiscoKey) }