types/ptr: deprecate ptr.To, use Go 1.26 new
Updates #18682 Change-Id: I62f6aa0de2a15ef8c1435032c6aa74a181c25f8f Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
committed by
Brad Fitzpatrick
parent
8cfbaa717d
commit
2a64c03c95
@@ -51,7 +51,6 @@ import (
|
||||
"tailscale.com/types/logger"
|
||||
"tailscale.com/types/netmap"
|
||||
"tailscale.com/types/persist"
|
||||
"tailscale.com/types/ptr"
|
||||
"tailscale.com/types/tkatype"
|
||||
"tailscale.com/util/clientmetric"
|
||||
"tailscale.com/util/eventbus"
|
||||
@@ -383,7 +382,7 @@ func (c *Direct) SetHostinfo(hi *tailcfg.Hostinfo) bool {
|
||||
if hi == nil {
|
||||
panic("nil Hostinfo")
|
||||
}
|
||||
hi = ptr.To(*hi)
|
||||
hi = new(*hi)
|
||||
hi.NetInfo = nil
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
|
||||
@@ -28,7 +28,6 @@ import (
|
||||
"tailscale.com/types/key"
|
||||
"tailscale.com/types/logger"
|
||||
"tailscale.com/types/netmap"
|
||||
"tailscale.com/types/ptr"
|
||||
"tailscale.com/types/views"
|
||||
"tailscale.com/util/clientmetric"
|
||||
"tailscale.com/util/mak"
|
||||
@@ -504,7 +503,7 @@ func (ms *mapSession) updatePeersStateFromResponse(resp *tailcfg.MapResponse) (s
|
||||
if vp, ok := ms.peers[nodeID]; ok {
|
||||
mut := vp.AsStruct()
|
||||
if seen {
|
||||
mut.LastSeen = ptr.To(clock.Now())
|
||||
mut.LastSeen = new(clock.Now())
|
||||
} else {
|
||||
mut.LastSeen = nil
|
||||
}
|
||||
@@ -516,7 +515,7 @@ func (ms *mapSession) updatePeersStateFromResponse(resp *tailcfg.MapResponse) (s
|
||||
for nodeID, online := range resp.OnlineChange {
|
||||
if vp, ok := ms.peers[nodeID]; ok {
|
||||
mut := vp.AsStruct()
|
||||
mut.Online = ptr.To(online)
|
||||
mut.Online = new(online)
|
||||
ms.peers[nodeID] = mut.View()
|
||||
stats.changed++
|
||||
}
|
||||
@@ -550,11 +549,11 @@ func (ms *mapSession) updatePeersStateFromResponse(resp *tailcfg.MapResponse) (s
|
||||
patchDiscoKey.Add(1)
|
||||
}
|
||||
if v := pc.Online; v != nil {
|
||||
mut.Online = ptr.To(*v)
|
||||
mut.Online = new(*v)
|
||||
patchOnline.Add(1)
|
||||
}
|
||||
if v := pc.LastSeen; v != nil {
|
||||
mut.LastSeen = ptr.To(*v)
|
||||
mut.LastSeen = new(*v)
|
||||
patchLastSeen.Add(1)
|
||||
}
|
||||
if v := pc.KeyExpiry; v != nil {
|
||||
@@ -688,11 +687,11 @@ func peerChangeDiff(was tailcfg.NodeView, n *tailcfg.Node) (_ *tailcfg.PeerChang
|
||||
}
|
||||
case "Key":
|
||||
if was.Key() != n.Key {
|
||||
pc().Key = ptr.To(n.Key)
|
||||
pc().Key = new(n.Key)
|
||||
}
|
||||
case "KeyExpiry":
|
||||
if !was.KeyExpiry().Equal(n.KeyExpiry) {
|
||||
pc().KeyExpiry = ptr.To(n.KeyExpiry)
|
||||
pc().KeyExpiry = new(n.KeyExpiry)
|
||||
}
|
||||
case "KeySignature":
|
||||
if !was.KeySignature().Equal(n.KeySignature) {
|
||||
@@ -704,7 +703,7 @@ func peerChangeDiff(was tailcfg.NodeView, n *tailcfg.Node) (_ *tailcfg.PeerChang
|
||||
}
|
||||
case "DiscoKey":
|
||||
if was.DiscoKey() != n.DiscoKey {
|
||||
pc().DiscoKey = ptr.To(n.DiscoKey)
|
||||
pc().DiscoKey = new(n.DiscoKey)
|
||||
}
|
||||
case "Addresses":
|
||||
if !views.SliceEqual(was.Addresses(), views.SliceOf(n.Addresses)) {
|
||||
@@ -773,11 +772,11 @@ func peerChangeDiff(was tailcfg.NodeView, n *tailcfg.Node) (_ *tailcfg.PeerChang
|
||||
}
|
||||
case "Online":
|
||||
if wasOnline, ok := was.Online().GetOk(); ok && n.Online != nil && *n.Online != wasOnline {
|
||||
pc().Online = ptr.To(*n.Online)
|
||||
pc().Online = new(*n.Online)
|
||||
}
|
||||
case "LastSeen":
|
||||
if wasSeen, ok := was.LastSeen().GetOk(); ok && n.LastSeen != nil && !wasSeen.Equal(*n.LastSeen) {
|
||||
pc().LastSeen = ptr.To(*n.LastSeen)
|
||||
pc().LastSeen = new(*n.LastSeen)
|
||||
}
|
||||
case "MachineAuthorized":
|
||||
if was.MachineAuthorized() != n.MachineAuthorized {
|
||||
|
||||
@@ -30,7 +30,6 @@ import (
|
||||
"tailscale.com/types/logger"
|
||||
"tailscale.com/types/netmap"
|
||||
"tailscale.com/types/persist"
|
||||
"tailscale.com/types/ptr"
|
||||
"tailscale.com/util/eventbus/eventbustest"
|
||||
"tailscale.com/util/mak"
|
||||
"tailscale.com/util/must"
|
||||
@@ -250,7 +249,7 @@ func TestUpdatePeersStateFromResponse(t *testing.T) {
|
||||
mapRes: &tailcfg.MapResponse{
|
||||
PeersChangedPatch: []*tailcfg.PeerChange{{
|
||||
NodeID: 1,
|
||||
Key: ptr.To(key.NodePublicFromRaw32(mem.B(append(make([]byte, 31), 'A')))),
|
||||
Key: new(key.NodePublicFromRaw32(mem.B(append(make([]byte, 31), 'A')))),
|
||||
}},
|
||||
}, want: peers(&tailcfg.Node{
|
||||
ID: 1,
|
||||
@@ -281,7 +280,7 @@ func TestUpdatePeersStateFromResponse(t *testing.T) {
|
||||
mapRes: &tailcfg.MapResponse{
|
||||
PeersChangedPatch: []*tailcfg.PeerChange{{
|
||||
NodeID: 1,
|
||||
DiscoKey: ptr.To(key.DiscoPublicFromRaw32(mem.B(append(make([]byte, 31), 'A')))),
|
||||
DiscoKey: new(key.DiscoPublicFromRaw32(mem.B(append(make([]byte, 31), 'A')))),
|
||||
}},
|
||||
},
|
||||
want: peers(&tailcfg.Node{
|
||||
@@ -297,13 +296,13 @@ func TestUpdatePeersStateFromResponse(t *testing.T) {
|
||||
mapRes: &tailcfg.MapResponse{
|
||||
PeersChangedPatch: []*tailcfg.PeerChange{{
|
||||
NodeID: 1,
|
||||
Online: ptr.To(true),
|
||||
Online: new(true),
|
||||
}},
|
||||
},
|
||||
want: peers(&tailcfg.Node{
|
||||
ID: 1,
|
||||
Name: "foo",
|
||||
Online: ptr.To(true),
|
||||
Online: new(true),
|
||||
}),
|
||||
wantStats: updateStats{changed: 1},
|
||||
},
|
||||
@@ -313,13 +312,13 @@ func TestUpdatePeersStateFromResponse(t *testing.T) {
|
||||
mapRes: &tailcfg.MapResponse{
|
||||
PeersChangedPatch: []*tailcfg.PeerChange{{
|
||||
NodeID: 1,
|
||||
LastSeen: ptr.To(time.Unix(123, 0).UTC()),
|
||||
LastSeen: new(time.Unix(123, 0).UTC()),
|
||||
}},
|
||||
},
|
||||
want: peers(&tailcfg.Node{
|
||||
ID: 1,
|
||||
Name: "foo",
|
||||
LastSeen: ptr.To(time.Unix(123, 0).UTC()),
|
||||
LastSeen: new(time.Unix(123, 0).UTC()),
|
||||
}),
|
||||
wantStats: updateStats{changed: 1},
|
||||
},
|
||||
@@ -329,7 +328,7 @@ func TestUpdatePeersStateFromResponse(t *testing.T) {
|
||||
mapRes: &tailcfg.MapResponse{
|
||||
PeersChangedPatch: []*tailcfg.PeerChange{{
|
||||
NodeID: 1,
|
||||
KeyExpiry: ptr.To(time.Unix(123, 0).UTC()),
|
||||
KeyExpiry: new(time.Unix(123, 0).UTC()),
|
||||
}},
|
||||
},
|
||||
want: peers(&tailcfg.Node{
|
||||
@@ -770,21 +769,21 @@ func TestPeerChangeDiff(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "patch-lastseen",
|
||||
a: &tailcfg.Node{ID: 1, LastSeen: ptr.To(time.Unix(1, 0))},
|
||||
b: &tailcfg.Node{ID: 1, LastSeen: ptr.To(time.Unix(2, 0))},
|
||||
want: &tailcfg.PeerChange{NodeID: 1, LastSeen: ptr.To(time.Unix(2, 0))},
|
||||
a: &tailcfg.Node{ID: 1, LastSeen: new(time.Unix(1, 0))},
|
||||
b: &tailcfg.Node{ID: 1, LastSeen: new(time.Unix(2, 0))},
|
||||
want: &tailcfg.PeerChange{NodeID: 1, LastSeen: new(time.Unix(2, 0))},
|
||||
},
|
||||
{
|
||||
name: "patch-online-to-true",
|
||||
a: &tailcfg.Node{ID: 1, Online: ptr.To(false)},
|
||||
b: &tailcfg.Node{ID: 1, Online: ptr.To(true)},
|
||||
want: &tailcfg.PeerChange{NodeID: 1, Online: ptr.To(true)},
|
||||
a: &tailcfg.Node{ID: 1, Online: new(false)},
|
||||
b: &tailcfg.Node{ID: 1, Online: new(true)},
|
||||
want: &tailcfg.PeerChange{NodeID: 1, Online: new(true)},
|
||||
},
|
||||
{
|
||||
name: "patch-online-to-false",
|
||||
a: &tailcfg.Node{ID: 1, Online: ptr.To(true)},
|
||||
b: &tailcfg.Node{ID: 1, Online: ptr.To(false)},
|
||||
want: &tailcfg.PeerChange{NodeID: 1, Online: ptr.To(false)},
|
||||
a: &tailcfg.Node{ID: 1, Online: new(true)},
|
||||
b: &tailcfg.Node{ID: 1, Online: new(false)},
|
||||
want: &tailcfg.PeerChange{NodeID: 1, Online: new(false)},
|
||||
},
|
||||
{
|
||||
name: "mix-patchable-and-not",
|
||||
@@ -818,14 +817,14 @@ func TestPeerChangeDiff(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "miss-change-masq-v4",
|
||||
a: &tailcfg.Node{ID: 1, SelfNodeV4MasqAddrForThisPeer: ptr.To(netip.MustParseAddr("100.64.0.1"))},
|
||||
b: &tailcfg.Node{ID: 1, SelfNodeV4MasqAddrForThisPeer: ptr.To(netip.MustParseAddr("100.64.0.2"))},
|
||||
a: &tailcfg.Node{ID: 1, SelfNodeV4MasqAddrForThisPeer: new(netip.MustParseAddr("100.64.0.1"))},
|
||||
b: &tailcfg.Node{ID: 1, SelfNodeV4MasqAddrForThisPeer: new(netip.MustParseAddr("100.64.0.2"))},
|
||||
want: nil,
|
||||
},
|
||||
{
|
||||
name: "miss-change-masq-v6",
|
||||
a: &tailcfg.Node{ID: 1, SelfNodeV6MasqAddrForThisPeer: ptr.To(netip.MustParseAddr("2001::3456"))},
|
||||
b: &tailcfg.Node{ID: 1, SelfNodeV6MasqAddrForThisPeer: ptr.To(netip.MustParseAddr("2001::3006"))},
|
||||
a: &tailcfg.Node{ID: 1, SelfNodeV6MasqAddrForThisPeer: new(netip.MustParseAddr("2001::3456"))},
|
||||
b: &tailcfg.Node{ID: 1, SelfNodeV6MasqAddrForThisPeer: new(netip.MustParseAddr("2001::3006"))},
|
||||
want: nil,
|
||||
},
|
||||
{
|
||||
@@ -1079,7 +1078,7 @@ func TestUpgradeNode(t *testing.T) {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
var got *tailcfg.Node
|
||||
if tt.in != nil {
|
||||
got = ptr.To(*tt.in) // shallow clone
|
||||
got = new(*tt.in) // shallow clone
|
||||
}
|
||||
upgradeNode(got)
|
||||
if diff := cmp.Diff(tt.want, got); diff != "" {
|
||||
@@ -1122,7 +1121,7 @@ func BenchmarkMapSessionDelta(b *testing.B) {
|
||||
{Proto: "peerapi-dns-proxy", Port: 1},
|
||||
},
|
||||
}).View(),
|
||||
LastSeen: ptr.To(time.Unix(int64(i), 0)),
|
||||
LastSeen: new(time.Unix(int64(i), 0)),
|
||||
})
|
||||
}
|
||||
ms.HandleNonKeepAliveMapResponse(ctx, res)
|
||||
|
||||
Reference in New Issue
Block a user