wgengine/magicsock,all: allocate peer relay over disco instead of PeerAPI (#16603)

Updates tailscale/corp#30583
Updates tailscale/corp#30534
Updates tailscale/corp#30557

Signed-off-by: Dylan Bargatze <dylan@tailscale.com>
Signed-off-by: Jordan Whited <jordan@tailscale.com>
Co-authored-by: Dylan Bargatze <dylan@tailscale.com>
This commit is contained in:
Jordan Whited
2025-07-21 10:02:37 -07:00
committed by GitHub
parent 5d4e67fd93
commit 1677fb1905
16 changed files with 1290 additions and 743 deletions

View File

@@ -73,6 +73,44 @@ func (k DiscoPrivate) Shared(p DiscoPublic) DiscoShared {
return ret
}
// SortedPairOfDiscoPublic is a lexicographically sorted container of two
// [DiscoPublic] keys.
type SortedPairOfDiscoPublic struct {
k [2]DiscoPublic
}
// Get returns the underlying keys.
func (s SortedPairOfDiscoPublic) Get() [2]DiscoPublic {
return s.k
}
// NewSortedPairOfDiscoPublic returns a SortedPairOfDiscoPublic from a and b.
func NewSortedPairOfDiscoPublic(a, b DiscoPublic) SortedPairOfDiscoPublic {
s := SortedPairOfDiscoPublic{}
if a.Compare(b) < 0 {
s.k[0] = a
s.k[1] = b
} else {
s.k[0] = b
s.k[1] = a
}
return s
}
func (s SortedPairOfDiscoPublic) String() string {
return fmt.Sprintf("%s <=> %s", s.k[0].ShortString(), s.k[1].ShortString())
}
// Equal returns true if s and b are equal, otherwise it returns false.
func (s SortedPairOfDiscoPublic) Equal(b SortedPairOfDiscoPublic) bool {
for i := range s.k {
if s.k[i].Compare(b.k[i]) != 0 {
return false
}
}
return true
}
// DiscoPublic is the public portion of a DiscoPrivate.
type DiscoPublic struct {
k [32]byte

View File

@@ -81,3 +81,21 @@ func TestDiscoShared(t *testing.T) {
t.Error("k1.Shared(k2) != k2.Shared(k1)")
}
}
func TestSortedPairOfDiscoPublic(t *testing.T) {
pubA := DiscoPublic{}
pubA.k[0] = 0x01
pubB := DiscoPublic{}
pubB.k[0] = 0x02
sortedInput := NewSortedPairOfDiscoPublic(pubA, pubB)
unsortedInput := NewSortedPairOfDiscoPublic(pubB, pubA)
if sortedInput.Get() != unsortedInput.Get() {
t.Fatal("sortedInput.Get() != unsortedInput.Get()")
}
if unsortedInput.Get()[0] != pubA {
t.Fatal("unsortedInput.Get()[0] != pubA")
}
if unsortedInput.Get()[1] != pubB {
t.Fatal("unsortedInput.Get()[1] != pubB")
}
}