-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial capver packet tracking version (#2391)
* initial capver packet tracking version Signed-off-by: Kristoffer Dalby <[email protected]> * Log the minimum version as client version, not only capver Signed-off-by: Kristoffer Dalby <[email protected]> * remove old versions Signed-off-by: Kristoffer Dalby <[email protected]> * use capver for integration tests Signed-off-by: Kristoffer Dalby <[email protected]> * changelog Signed-off-by: Kristoffer Dalby <[email protected]> * patch through m and n key Signed-off-by: Kristoffer Dalby <[email protected]> --------- Signed-off-by: Kristoffer Dalby <[email protected]>
- Loading branch information
Showing
8 changed files
with
397 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package capver | ||
|
||
import ( | ||
"sort" | ||
"strings" | ||
|
||
xmaps "golang.org/x/exp/maps" | ||
"tailscale.com/tailcfg" | ||
"tailscale.com/util/set" | ||
) | ||
|
||
func tailscaleVersSorted() []string { | ||
vers := xmaps.Keys(tailscaleToCapVer) | ||
sort.Strings(vers) | ||
return vers | ||
} | ||
|
||
func capVersSorted() []tailcfg.CapabilityVersion { | ||
capVers := xmaps.Keys(capVerToTailscaleVer) | ||
sort.Slice(capVers, func(i, j int) bool { | ||
return capVers[i] < capVers[j] | ||
}) | ||
return capVers | ||
} | ||
|
||
// TailscaleVersion returns the Tailscale version for the given CapabilityVersion. | ||
func TailscaleVersion(ver tailcfg.CapabilityVersion) string { | ||
return capVerToTailscaleVer[ver] | ||
} | ||
|
||
// CapabilityVersion returns the CapabilityVersion for the given Tailscale version. | ||
func CapabilityVersion(ver string) tailcfg.CapabilityVersion { | ||
if !strings.HasPrefix(ver, "v") { | ||
ver = "v" + ver | ||
} | ||
return tailscaleToCapVer[ver] | ||
} | ||
|
||
// TailscaleLatest returns the n latest Tailscale versions. | ||
func TailscaleLatest(n int) []string { | ||
if n <= 0 { | ||
return nil | ||
} | ||
|
||
tsSorted := tailscaleVersSorted() | ||
|
||
if n > len(tsSorted) { | ||
return tsSorted | ||
} | ||
|
||
return tsSorted[len(tsSorted)-n:] | ||
} | ||
|
||
// TailscaleLatestMajorMinor returns the n latest Tailscale versions (e.g. 1.80). | ||
func TailscaleLatestMajorMinor(n int, stripV bool) []string { | ||
if n <= 0 { | ||
return nil | ||
} | ||
|
||
majors := set.Set[string]{} | ||
for _, vers := range tailscaleVersSorted() { | ||
if stripV { | ||
vers = strings.TrimPrefix(vers, "v") | ||
} | ||
v := strings.Split(vers, ".") | ||
majors.Add(v[0] + "." + v[1]) | ||
} | ||
|
||
majorSl := majors.Slice() | ||
sort.Strings(majorSl) | ||
|
||
if n > len(majorSl) { | ||
return majorSl | ||
} | ||
|
||
return majorSl[len(majorSl)-n:] | ||
} | ||
|
||
// CapVerLatest returns the n latest CapabilityVersions. | ||
func CapVerLatest(n int) []tailcfg.CapabilityVersion { | ||
if n <= 0 { | ||
return nil | ||
} | ||
|
||
s := capVersSorted() | ||
|
||
if n > len(s) { | ||
return s | ||
} | ||
|
||
return s[len(s)-n:] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package capver | ||
|
||
//Generated DO NOT EDIT | ||
|
||
import "tailscale.com/tailcfg" | ||
|
||
var tailscaleToCapVer = map[string]tailcfg.CapabilityVersion{ | ||
"v1.44.3": 63, | ||
"v1.56.1": 82, | ||
"v1.58.0": 85, | ||
"v1.58.1": 85, | ||
"v1.58.2": 85, | ||
"v1.60.0": 87, | ||
"v1.60.1": 87, | ||
"v1.62.0": 88, | ||
"v1.62.1": 88, | ||
"v1.64.0": 90, | ||
"v1.64.1": 90, | ||
"v1.64.2": 90, | ||
"v1.66.0": 95, | ||
"v1.66.1": 95, | ||
"v1.66.2": 95, | ||
"v1.66.3": 95, | ||
"v1.66.4": 95, | ||
"v1.68.0": 97, | ||
"v1.68.1": 97, | ||
"v1.68.2": 97, | ||
"v1.70.0": 102, | ||
"v1.72.0": 104, | ||
"v1.72.1": 104, | ||
"v1.74.0": 106, | ||
"v1.74.1": 106, | ||
"v1.76.0": 106, | ||
"v1.76.1": 106, | ||
"v1.76.6": 106, | ||
"v1.78.0": 109, | ||
"v1.78.1": 109, | ||
} | ||
|
||
|
||
var capVerToTailscaleVer = map[tailcfg.CapabilityVersion]string{ | ||
63: "v1.44.3", | ||
82: "v1.56.1", | ||
85: "v1.58.0", | ||
87: "v1.60.0", | ||
88: "v1.62.0", | ||
90: "v1.64.0", | ||
95: "v1.66.0", | ||
97: "v1.68.0", | ||
102: "v1.70.0", | ||
104: "v1.72.0", | ||
106: "v1.74.0", | ||
109: "v1.78.0", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package capver | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
"tailscale.com/tailcfg" | ||
) | ||
|
||
func TestTailscaleLatestMajorMinor(t *testing.T) { | ||
tests := []struct { | ||
n int | ||
stripV bool | ||
expected []string | ||
}{ | ||
{3, false, []string{"v1.74", "v1.76", "v1.78"}}, | ||
{2, true, []string{"1.76", "1.78"}}, | ||
{0, false, nil}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run("", func(t *testing.T) { | ||
output := TailscaleLatestMajorMinor(test.n, test.stripV) | ||
if diff := cmp.Diff(output, test.expected); diff != "" { | ||
t.Errorf("TailscaleLatestMajorMinor(%d, %v) mismatch (-want +got):\n%s", test.n, test.stripV, diff) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestCapVerMinimumTailscaleVersion(t *testing.T) { | ||
tests := []struct { | ||
input tailcfg.CapabilityVersion | ||
expected string | ||
}{ | ||
{85, "v1.58.0"}, | ||
{90, "v1.64.0"}, | ||
{95, "v1.66.0"}, | ||
{106, "v1.74.0"}, | ||
{109, "v1.78.0"}, | ||
{9001, ""}, // Test case for a version higher than any in the map | ||
{60, ""}, // Test case for a version lower than any in the map | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run("", func(t *testing.T) { | ||
output := TailscaleVersion(test.input) | ||
if output != test.expected { | ||
t.Errorf("CapVerFromTailscaleVersion(%d) = %s; want %s", test.input, output, test.expected) | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.