tailcfg, all: use []netip.AddrPort instead of []string for Endpoints

It's JSON wire compatible.

Updates #cleanup

Change-Id: Ifa5c17768fec35b305b06d75eb5f0611c8a135a6
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick 2023-09-30 21:05:02 -07:00 committed by Brad Fitzpatrick
parent 5f5c9142cc
commit 425cf9aa9d
14 changed files with 98 additions and 103 deletions

View File

@ -845,8 +845,10 @@ func (c *Direct) sendMapRequest(ctx context.Context, isStreaming bool, nu Netmap
hi := c.hostInfoLocked()
backendLogID := hi.BackendLogID
var epStrs []string
var eps []netip.AddrPort
var epTypes []tailcfg.EndpointType
for _, ep := range c.endpoints {
eps = append(eps, ep.Addr)
epStrs = append(epStrs, ep.Addr.String())
epTypes = append(epTypes, ep.Type)
}
@ -881,7 +883,7 @@ func (c *Direct) sendMapRequest(ctx context.Context, isStreaming bool, nu Netmap
KeepAlive: true,
NodeKey: persist.PublicNodeKey(),
DiscoKey: c.discoPubKey,
Endpoints: epStrs,
Endpoints: eps,
EndpointTypes: epTypes,
Stream: isStreaming,
Hostinfo: hi,

View File

@ -29,6 +29,14 @@ import (
"tailscale.com/util/must"
)
func eps(s ...string) []netip.AddrPort {
var eps []netip.AddrPort
for _, ep := range s {
eps = append(eps, netip.MustParseAddrPort(ep))
}
return eps
}
func TestUpdatePeersStateFromResponse(t *testing.T) {
var curTime time.Time
@ -49,7 +57,7 @@ func TestUpdatePeersStateFromResponse(t *testing.T) {
}
withEP := func(ep string) func(*tailcfg.Node) {
return func(n *tailcfg.Node) {
n.Endpoints = []string{ep}
n.Endpoints = []netip.AddrPort{netip.MustParseAddrPort(ep)}
}
}
n := func(id tailcfg.NodeID, name string, mod ...func(*tailcfg.Node)) *tailcfg.Node {
@ -197,7 +205,7 @@ func TestUpdatePeersStateFromResponse(t *testing.T) {
mapRes: &tailcfg.MapResponse{
PeersChangedPatch: []*tailcfg.PeerChange{{
NodeID: 1,
Endpoints: []string{"1.2.3.4:56"},
Endpoints: eps("1.2.3.4:56"),
}},
},
want: peers(n(1, "foo", withEP("1.2.3.4:56"))),
@ -209,7 +217,7 @@ func TestUpdatePeersStateFromResponse(t *testing.T) {
mapRes: &tailcfg.MapResponse{
PeersChangedPatch: []*tailcfg.PeerChange{{
NodeID: 1,
Endpoints: []string{"1.2.3.4:56"},
Endpoints: eps("1.2.3.4:56"),
}},
},
want: peers(n(1, "foo", withDERP("127.3.3.40:3"), withEP("1.2.3.4:56"))),
@ -222,7 +230,7 @@ func TestUpdatePeersStateFromResponse(t *testing.T) {
PeersChangedPatch: []*tailcfg.PeerChange{{
NodeID: 1,
DERPRegion: 2,
Endpoints: []string{"1.2.3.4:56"},
Endpoints: eps("1.2.3.4:56"),
}},
},
want: peers(n(1, "foo", withDERP("127.3.3.40:2"), withEP("1.2.3.4:56"))),
@ -667,9 +675,9 @@ func TestPeerChangeDiff(t *testing.T) {
},
{
name: "patch-endpoints",
a: &tailcfg.Node{ID: 1, Endpoints: []string{"10.0.0.1:1"}},
b: &tailcfg.Node{ID: 1, Endpoints: []string{"10.0.0.2:2"}},
want: &tailcfg.PeerChange{NodeID: 1, Endpoints: []string{"10.0.0.2:2"}},
a: &tailcfg.Node{ID: 1, Endpoints: eps("10.0.0.1:1")},
b: &tailcfg.Node{ID: 1, Endpoints: eps("10.0.0.2:2")},
want: &tailcfg.PeerChange{NodeID: 1, Endpoints: eps("10.0.0.2:2")},
},
{
name: "patch-cap",
@ -809,13 +817,13 @@ func TestPatchifyPeersChanged(t *testing.T) {
},
mr1: &tailcfg.MapResponse{
PeersChanged: []*tailcfg.Node{
{ID: 1, Endpoints: []string{"10.0.0.1:1111"}, Hostinfo: hi},
{ID: 1, Endpoints: eps("10.0.0.1:1111"), Hostinfo: hi},
},
},
want: &tailcfg.MapResponse{
PeersChanged: nil,
PeersChangedPatch: []*tailcfg.PeerChange{
{NodeID: 1, Endpoints: []string{"10.0.0.1:1111"}},
{NodeID: 1, Endpoints: eps("10.0.0.1:1111")},
},
},
},
@ -891,7 +899,10 @@ func TestPatchifyPeersChanged(t *testing.T) {
mr1 := new(tailcfg.MapResponse)
must.Do(json.Unmarshal(must.Get(json.Marshal(tt.mr1)), mr1))
ms.patchifyPeersChanged(mr1)
if diff := cmp.Diff(tt.want, mr1); diff != "" {
opts := []cmp.Option{
cmp.Comparer(func(a, b netip.AddrPort) bool { return a == b }),
}
if diff := cmp.Diff(tt.want, mr1, opts...); diff != "" {
t.Errorf("wrong result (-want +got):\n%s", diff)
}
})
@ -917,7 +928,7 @@ func BenchmarkMapSessionDelta(b *testing.B) {
DERP: "127.3.3.40:10",
Addresses: []netip.Prefix{netip.MustParsePrefix("100.100.2.3/32"), netip.MustParsePrefix("fd7a:115c:a1e0::123/128")},
AllowedIPs: []netip.Prefix{netip.MustParsePrefix("100.100.2.3/32"), netip.MustParsePrefix("fd7a:115c:a1e0::123/128")},
Endpoints: []string{"192.168.1.2:345", "192.168.1.3:678"},
Endpoints: eps("192.168.1.2:345", "192.168.1.3:678"),
Hostinfo: (&tailcfg.Hostinfo{
OS: "fooOS",
Hostname: "MyHostname",

View File

@ -269,9 +269,9 @@ type Node struct {
KeySignature tkatype.MarshaledSignature `json:",omitempty"`
Machine key.MachinePublic
DiscoKey key.DiscoPublic
Addresses []netip.Prefix // IP addresses of this Node directly
AllowedIPs []netip.Prefix // range of IP addresses to route to this node
Endpoints []string `json:",omitempty"` // IP+port (public via STUN, and local LANs)
Addresses []netip.Prefix // IP addresses of this Node directly
AllowedIPs []netip.Prefix // range of IP addresses to route to this node
Endpoints []netip.AddrPort `json:",omitempty"` // IP+port (public via STUN, and local LANs)
// DERP is this node's home DERP region ID integer, but shoved into an
// IP:port string for legacy reasons. The IP address is always "127.3.3.40"
@ -1211,7 +1211,7 @@ type MapRequest struct {
// Endpoints are the client's magicsock UDP ip:port endpoints (IPv4 or IPv6).
// These can be ignored if Stream is true and Version >= 68.
Endpoints []string
Endpoints []netip.AddrPort `json:",omitempty"`
// EndpointTypes are the types of the corresponding endpoints in Endpoints.
EndpointTypes []EndpointType `json:",omitempty"`
@ -2516,7 +2516,7 @@ type PeerChange struct {
// Endpoints, if non-empty, means that NodeID's UDP Endpoints
// have changed to these.
Endpoints []string `json:",omitempty"`
Endpoints []netip.AddrPort `json:",omitempty"`
// Key, if non-nil, means that the NodeID's wireguard public key changed.
Key *key.NodePublic `json:",omitempty"`

View File

@ -97,7 +97,7 @@ var _NodeCloneNeedsRegeneration = Node(struct {
DiscoKey key.DiscoPublic
Addresses []netip.Prefix
AllowedIPs []netip.Prefix
Endpoints []string
Endpoints []netip.AddrPort
DERP string
Hostinfo HostinfoView
Created time.Time

View File

@ -466,13 +466,13 @@ func TestNodeEqual(t *testing.T) {
true,
},
{
&Node{Endpoints: []string{}},
&Node{Endpoints: []netip.AddrPort{}},
&Node{Endpoints: nil},
false,
},
{
&Node{Endpoints: []string{}},
&Node{Endpoints: []string{}},
&Node{Endpoints: []netip.AddrPort{}},
&Node{Endpoints: []netip.AddrPort{}},
true,
},
{
@ -677,7 +677,7 @@ func TestCloneNode(t *testing.T) {
{"zero_fields", &Node{
Addresses: make([]netip.Prefix, 0),
AllowedIPs: make([]netip.Prefix, 0),
Endpoints: make([]string, 0),
Endpoints: make([]netip.AddrPort, 0),
}},
}
for _, tt := range tests {

View File

@ -142,7 +142,7 @@ func (v NodeView) Machine() key.MachinePublic { return v.ж.Machin
func (v NodeView) DiscoKey() key.DiscoPublic { return v.ж.DiscoKey }
func (v NodeView) Addresses() views.Slice[netip.Prefix] { return views.SliceOf(v.ж.Addresses) }
func (v NodeView) AllowedIPs() views.Slice[netip.Prefix] { return views.SliceOf(v.ж.AllowedIPs) }
func (v NodeView) Endpoints() views.Slice[string] { return views.SliceOf(v.ж.Endpoints) }
func (v NodeView) Endpoints() views.Slice[netip.AddrPort] { return views.SliceOf(v.ж.Endpoints) }
func (v NodeView) DERP() string { return v.ж.DERP }
func (v NodeView) Hostinfo() HostinfoView { return v.ж.Hostinfo }
func (v NodeView) Created() time.Time { return v.ж.Created }
@ -214,7 +214,7 @@ var _NodeViewNeedsRegeneration = Node(struct {
DiscoKey key.DiscoPublic
Addresses []netip.Prefix
AllowedIPs []netip.Prefix
Endpoints []string
Endpoints []netip.AddrPort
DERP string
Hostinfo HostinfoView
Created time.Time

View File

@ -1035,7 +1035,7 @@ func (s *Server) encode(mkey key.MachinePublic, compress bool, v any) (b []byte,
//
// Two types of IPv6 endpoints are considered invalid: link-local
// addresses, and anything with a zone.
func filterInvalidIPv6Endpoints(eps []string) []string {
func filterInvalidIPv6Endpoints(eps []netip.AddrPort) []netip.AddrPort {
clean := eps[:0]
for _, ep := range eps {
if keepClientEndpoint(ep) {
@ -1045,13 +1045,7 @@ func filterInvalidIPv6Endpoints(eps []string) []string {
return clean
}
func keepClientEndpoint(ep string) bool {
ipp, err := netip.ParseAddrPort(ep)
if err != nil {
// Shouldn't have made it this far if we unmarshalled
// the incoming JSON response.
return false
}
func keepClientEndpoint(ipp netip.AddrPort) bool {
ip := ipp.Addr()
if ip.Zone() != "" {
return false

View File

@ -267,7 +267,7 @@ func printPeerConcise(buf *strings.Builder, p tailcfg.NodeView) {
ep := make([]string, p.Endpoints().Len())
for i := range ep {
e := p.Endpoints().At(i)
e := p.Endpoints().At(i).String()
// Align vertically on the ':' between IP and port
colon := strings.IndexByte(e, ':')
spaces := 0

View File

@ -42,6 +42,14 @@ func nodeViews(v []*tailcfg.Node) []tailcfg.NodeView {
return nv
}
func eps(s ...string) []netip.AddrPort {
var eps []netip.AddrPort
for _, ep := range s {
eps = append(eps, netip.MustParseAddrPort(ep))
}
return eps
}
func TestNetworkMapConcise(t *testing.T) {
for _, tt := range []struct {
name string
@ -56,12 +64,12 @@ func TestNetworkMapConcise(t *testing.T) {
{
Key: testNodeKey(2),
DERP: "127.3.3.40:2",
Endpoints: []string{"192.168.0.100:12", "192.168.0.100:12354"},
Endpoints: eps("192.168.0.100:12", "192.168.0.100:12354"),
},
{
Key: testNodeKey(3),
DERP: "127.3.3.40:4",
Endpoints: []string{"10.2.0.100:12", "10.1.0.100:12345"},
Endpoints: eps("10.2.0.100:12", "10.1.0.100:12345"),
},
}),
},
@ -95,7 +103,7 @@ func TestConciseDiffFrom(t *testing.T) {
{
Key: testNodeKey(2),
DERP: "127.3.3.40:2",
Endpoints: []string{"192.168.0.100:12", "192.168.0.100:12354"},
Endpoints: eps("192.168.0.100:12", "192.168.0.100:12354"),
},
}),
},
@ -105,7 +113,7 @@ func TestConciseDiffFrom(t *testing.T) {
{
Key: testNodeKey(2),
DERP: "127.3.3.40:2",
Endpoints: []string{"192.168.0.100:12", "192.168.0.100:12354"},
Endpoints: eps("192.168.0.100:12", "192.168.0.100:12354"),
},
}),
},
@ -119,7 +127,7 @@ func TestConciseDiffFrom(t *testing.T) {
{
Key: testNodeKey(2),
DERP: "127.3.3.40:2",
Endpoints: []string{"192.168.0.100:12", "192.168.0.100:12354"},
Endpoints: eps("192.168.0.100:12", "192.168.0.100:12354"),
},
}),
},
@ -129,7 +137,7 @@ func TestConciseDiffFrom(t *testing.T) {
{
Key: testNodeKey(2),
DERP: "127.3.3.40:2",
Endpoints: []string{"192.168.0.100:12", "192.168.0.100:12354"},
Endpoints: eps("192.168.0.100:12", "192.168.0.100:12354"),
},
}),
},
@ -144,7 +152,7 @@ func TestConciseDiffFrom(t *testing.T) {
ID: 2,
Key: testNodeKey(2),
DERP: "127.3.3.40:2",
Endpoints: []string{"192.168.0.100:12", "192.168.0.100:12354"},
Endpoints: eps("192.168.0.100:12", "192.168.0.100:12354"),
},
}),
},
@ -155,19 +163,19 @@ func TestConciseDiffFrom(t *testing.T) {
ID: 1,
Key: testNodeKey(1),
DERP: "127.3.3.40:1",
Endpoints: []string{"192.168.0.100:12", "192.168.0.100:12354"},
Endpoints: eps("192.168.0.100:12", "192.168.0.100:12354"),
},
{
ID: 2,
Key: testNodeKey(2),
DERP: "127.3.3.40:2",
Endpoints: []string{"192.168.0.100:12", "192.168.0.100:12354"},
Endpoints: eps("192.168.0.100:12", "192.168.0.100:12354"),
},
{
ID: 3,
Key: testNodeKey(3),
DERP: "127.3.3.40:3",
Endpoints: []string{"192.168.0.100:12", "192.168.0.100:12354"},
Endpoints: eps("192.168.0.100:12", "192.168.0.100:12354"),
},
}),
},
@ -182,19 +190,19 @@ func TestConciseDiffFrom(t *testing.T) {
ID: 1,
Key: testNodeKey(1),
DERP: "127.3.3.40:1",
Endpoints: []string{"192.168.0.100:12", "192.168.0.100:12354"},
Endpoints: eps("192.168.0.100:12", "192.168.0.100:12354"),
},
{
ID: 2,
Key: testNodeKey(2),
DERP: "127.3.3.40:2",
Endpoints: []string{"192.168.0.100:12", "192.168.0.100:12354"},
Endpoints: eps("192.168.0.100:12", "192.168.0.100:12354"),
},
{
ID: 3,
Key: testNodeKey(3),
DERP: "127.3.3.40:3",
Endpoints: []string{"192.168.0.100:12", "192.168.0.100:12354"},
Endpoints: eps("192.168.0.100:12", "192.168.0.100:12354"),
},
}),
},
@ -205,7 +213,7 @@ func TestConciseDiffFrom(t *testing.T) {
ID: 2,
Key: testNodeKey(2),
DERP: "127.3.3.40:2",
Endpoints: []string{"192.168.0.100:12", "192.168.0.100:12354"},
Endpoints: eps("192.168.0.100:12", "192.168.0.100:12354"),
},
}),
},
@ -220,7 +228,7 @@ func TestConciseDiffFrom(t *testing.T) {
ID: 2,
Key: testNodeKey(2),
DERP: "127.3.3.40:2",
Endpoints: []string{"192.168.0.100:12", "1.1.1.1:1"},
Endpoints: eps("192.168.0.100:12", "1.1.1.1:1"),
},
}),
},
@ -231,7 +239,7 @@ func TestConciseDiffFrom(t *testing.T) {
ID: 2,
Key: testNodeKey(2),
DERP: "127.3.3.40:2",
Endpoints: []string{"192.168.0.100:12", "1.1.1.1:2"},
Endpoints: eps("192.168.0.100:12", "1.1.1.1:2"),
},
}),
},
@ -246,7 +254,7 @@ func TestConciseDiffFrom(t *testing.T) {
ID: 2,
Key: testNodeKey(2),
DERP: "127.3.3.40:2",
Endpoints: []string{"192.168.0.100:41641", "1.1.1.1:41641"},
Endpoints: eps("192.168.0.100:41641", "1.1.1.1:41641"),
DiscoKey: testDiscoKey("f00f00f00f"),
AllowedIPs: []netip.Prefix{netip.PrefixFrom(netaddr.IPv4(100, 102, 103, 104), 32)},
},
@ -259,7 +267,7 @@ func TestConciseDiffFrom(t *testing.T) {
ID: 2,
Key: testNodeKey(2),
DERP: "127.3.3.40:2",
Endpoints: []string{"192.168.0.100:41641", "1.1.1.1:41641"},
Endpoints: eps("192.168.0.100:41641", "1.1.1.1:41641"),
DiscoKey: testDiscoKey("ba4ba4ba4b"),
AllowedIPs: []netip.Prefix{netip.PrefixFrom(netaddr.IPv4(100, 102, 103, 104), 32)},
},

View File

@ -45,11 +45,7 @@ type NodeMutationEndpoints struct {
}
func (m NodeMutationEndpoints) Apply(n *tailcfg.Node) {
eps := make([]string, len(m.Endpoints))
for i, ep := range m.Endpoints {
eps[i] = ep.String()
}
n.Endpoints = eps
n.Endpoints = slices.Clone(m.Endpoints)
}
// NodeMutationOnline is a NodeMutation that says a node is now online or
@ -105,15 +101,7 @@ func NodeMutationsFromPatch(p *tailcfg.PeerChange) (_ []NodeMutation, ok bool) {
case "DERPRegion":
ret = append(ret, NodeMutationDERPHome{mutatingNodeID(p.NodeID), p.DERPRegion})
case "Endpoints":
eps := make([]netip.AddrPort, len(p.Endpoints))
for i, epStr := range p.Endpoints {
var err error
eps[i], err = netip.ParseAddrPort(epStr)
if err != nil {
return nil, false
}
}
ret = append(ret, NodeMutationEndpoints{mutatingNodeID(p.NodeID), eps})
ret = append(ret, NodeMutationEndpoints{mutatingNodeID(p.NodeID), slices.Clone(p.Endpoints)})
case "Online":
ret = append(ret, NodeMutationOnline{mutatingNodeID(p.NodeID), *p.Online})
case "LastSeen":

View File

@ -91,10 +91,10 @@ func TestMutationsFromMapResponse(t *testing.T) {
name: "patch-ep",
mr: fromChanges(&tailcfg.PeerChange{
NodeID: 1,
Endpoints: []string{"1.2.3.4:567"},
Endpoints: eps("1.2.3.4:567"),
}, &tailcfg.PeerChange{
NodeID: 2,
Endpoints: []string{"8.9.10.11:1234"},
Endpoints: eps("8.9.10.11:1234"),
}),
want: muts(
NodeMutationEndpoints{1, []netip.AddrPort{netip.MustParseAddrPort("1.2.3.4:567")}},

View File

@ -26,6 +26,13 @@ import (
"tailscale.com/wgengine/wgcfg"
)
func epFromTyped(eps []tailcfg.Endpoint) (ret []netip.AddrPort) {
for _, ep := range eps {
ret = append(ret, ep.Addr)
}
return
}
func setupWGTest(b *testing.B, logf logger.Logf, traf *TrafficGen, a1, a2 netip.Prefix) {
l1 := logger.WithPrefix(logf, "e1: ")
k1 := key.NewNode()
@ -96,17 +103,12 @@ func setupWGTest(b *testing.B, logf logger.Logf, traf *TrafficGen, a1, a2 netip.
}
logf("e1 status: %v", *st)
var eps []string
for _, ep := range st.LocalAddrs {
eps = append(eps, ep.Addr.String())
}
n := &tailcfg.Node{
ID: tailcfg.NodeID(0),
Name: "n1",
Addresses: []netip.Prefix{a1},
AllowedIPs: []netip.Prefix{a1},
Endpoints: eps,
Endpoints: epFromTyped(st.LocalAddrs),
}
e2.SetNetworkMap(&netmap.NetworkMap{
NodeKey: k2.Public(),
@ -133,17 +135,12 @@ func setupWGTest(b *testing.B, logf logger.Logf, traf *TrafficGen, a1, a2 netip.
}
logf("e2 status: %v", *st)
var eps []string
for _, ep := range st.LocalAddrs {
eps = append(eps, ep.Addr.String())
}
n := &tailcfg.Node{
ID: tailcfg.NodeID(0),
Name: "n2",
Addresses: []netip.Prefix{a2},
AllowedIPs: []netip.Prefix{a2},
Endpoints: eps,
Endpoints: epFromTyped(st.LocalAddrs),
}
e1.SetNetworkMap(&netmap.NetworkMap{
NodeKey: k1.Public(),

View File

@ -29,7 +29,6 @@ import (
"tailscale.com/tstime/mono"
"tailscale.com/types/key"
"tailscale.com/types/logger"
"tailscale.com/types/views"
"tailscale.com/util/mak"
"tailscale.com/util/ringbuffer"
)
@ -812,19 +811,7 @@ func (de *endpoint) updateFromNode(n tailcfg.NodeView, heartbeatDisabled bool) {
de.derpAddr = newDerp
}
de.setEndpointsLocked(addrPortsFromStringsView{n.Endpoints()})
}
// addrPortsFromStringsView converts a view of AddrPort strings
// to a view-like thing of netip.AddrPort.
// TODO(bradfitz): change the type of tailcfg.Node.Endpoint.
type addrPortsFromStringsView struct {
views.Slice[string]
}
func (a addrPortsFromStringsView) At(i int) netip.AddrPort {
ap, _ := netip.ParseAddrPort(a.Slice.At(i))
return ap // or the zero value on error
de.setEndpointsLocked(n.Endpoints())
}
func (de *endpoint) setEndpointsLocked(eps interface {

View File

@ -290,7 +290,7 @@ func meshStacks(logf logger.Logf, mutateNetmap func(idx int, nm *netmap.NetworkM
DiscoKey: peer.conn.DiscoPublicKey(),
Addresses: addrs,
AllowedIPs: addrs,
Endpoints: epStrings(eps[i]),
Endpoints: epFromTyped(eps[i]),
DERP: "127.3.3.40:1",
}
nm.Peers = append(nm.Peers, peer.View())
@ -1265,7 +1265,7 @@ func addTestEndpoint(tb testing.TB, conn *Conn, sendConn net.PacketConn) (key.No
ID: 1,
Key: nodeKey,
DiscoKey: discoKey,
Endpoints: []string{sendConn.LocalAddr().String()},
Endpoints: eps(sendConn.LocalAddr().String()),
},
}),
})
@ -1470,7 +1470,7 @@ func TestSetNetworkMapChangingNodeKey(t *testing.T) {
ID: 1,
Key: nodeKey1,
DiscoKey: discoKey,
Endpoints: []string{"192.168.1.2:345"},
Endpoints: eps("192.168.1.2:345"),
},
}),
})
@ -1486,7 +1486,7 @@ func TestSetNetworkMapChangingNodeKey(t *testing.T) {
ID: 2,
Key: nodeKey2,
DiscoKey: discoKey,
Endpoints: []string{"192.168.1.2:345"},
Endpoints: eps("192.168.1.2:345"),
},
}),
})
@ -1752,13 +1752,21 @@ func TestBetterAddr(t *testing.T) {
}
func epStrings(eps []tailcfg.Endpoint) (ret []string) {
func epFromTyped(eps []tailcfg.Endpoint) (ret []netip.AddrPort) {
for _, ep := range eps {
ret = append(ret, ep.Addr.String())
ret = append(ret, ep.Addr)
}
return
}
func eps(s ...string) []netip.AddrPort {
var eps []netip.AddrPort
for _, ep := range s {
eps = append(eps, netip.MustParseAddrPort(ep))
}
return eps
}
func TestStressSetNetworkMap(t *testing.T) {
t.Parallel()
@ -1778,7 +1786,7 @@ func TestStressSetNetworkMap(t *testing.T) {
ID: tailcfg.NodeID(i) + 1,
DiscoKey: randDiscoKey(),
Key: randNodeKey(),
Endpoints: []string{fmt.Sprintf("192.168.1.2:%d", i)},
Endpoints: eps(fmt.Sprintf("192.168.1.2:%d", i)),
}
}
@ -2276,7 +2284,7 @@ func TestIsWireGuardOnlyPeer(t *testing.T) {
{
ID: 1,
Key: wgkey.Public(),
Endpoints: []string{wgEp.String()},
Endpoints: []netip.AddrPort{wgEp},
IsWireGuardOnly: true,
Addresses: []netip.Prefix{wgaip},
AllowedIPs: []netip.Prefix{wgaip},
@ -2337,7 +2345,7 @@ func TestIsWireGuardOnlyPeerWithMasquerade(t *testing.T) {
{
ID: 1,
Key: wgkey.Public(),
Endpoints: []string{wgEp.String()},
Endpoints: []netip.AddrPort{wgEp},
IsWireGuardOnly: true,
Addresses: []netip.Prefix{wgaip},
AllowedIPs: []netip.Prefix{wgaip},
@ -2465,7 +2473,7 @@ func TestIsWireGuardOnlyPickEndpointByPing(t *testing.T) {
Peers: nodeViews([]*tailcfg.Node{
{
Key: wgkey.Public(),
Endpoints: []string{wgEp.String(), wgEp2.String(), wgEpV6.String()},
Endpoints: []netip.AddrPort{wgEp, wgEp2, wgEpV6},
IsWireGuardOnly: true,
Addresses: []netip.Prefix{wgaip},
AllowedIPs: []netip.Prefix{wgaip},