various: use NodePublic.AsNodeKey() instead of tailcfg.NodeKeyFromNodePublic()

Updates #3206

Signed-off-by: David Anderson <danderson@tailscale.com>
pull/3227/head
David Anderson 3 years ago
parent ff16e58d23
commit 418adae379

@ -357,8 +357,8 @@ func (c *Direct) doLogin(ctx context.Context, opt loginOpt) (mustRegen bool, new
now := time.Now().Round(time.Second)
request := tailcfg.RegisterRequest{
Version: 1,
OldNodeKey: tailcfg.NodeKeyFromNodePublic(oldNodeKey),
NodeKey: tailcfg.NodeKeyFromNodePublic(tryingNewKey.Public()),
OldNodeKey: oldNodeKey.AsNodeKey(),
NodeKey: tryingNewKey.Public().AsNodeKey(),
Hostinfo: hostinfo,
Followup: opt.URL,
Timestamp: &now,
@ -595,7 +595,7 @@ func (c *Direct) sendMapRequest(ctx context.Context, maxPolls int, cb func(*netm
request := &tailcfg.MapRequest{
Version: tailcfg.CurrentMapRequestVersion,
KeepAlive: c.keepAlive,
NodeKey: tailcfg.NodeKeyFromNodePublic(persist.PrivateNodeKey.Public()),
NodeKey: persist.PrivateNodeKey.Public().AsNodeKey(),
DiscoKey: c.discoPubKey,
Endpoints: epStrs,
EndpointTypes: epTypes,

@ -110,7 +110,7 @@ func (ms *mapSession) netmapForResponse(resp *tailcfg.MapResponse) *netmap.Netwo
}
nm := &netmap.NetworkMap{
NodeKey: tailcfg.NodeKeyFromNodePublic(ms.privateNodeKey.Public()),
NodeKey: ms.privateNodeKey.Public().AsNodeKey(),
PrivateKey: ms.privateNodeKey,
MachineKey: ms.machinePubKey,
Peers: resp.Peers,

@ -2692,7 +2692,7 @@ func (b *LocalBackend) TestOnlyPublicKeys() (machineKey key.MachinePublic, nodeK
mk := machinePrivKey.Public()
nk := prefs.Persist.PrivateNodeKey.Public()
return mk, tailcfg.NodeKeyFromNodePublic(nk)
return mk, nk.AsNodeKey()
}
func (b *LocalBackend) WaitingFiles() ([]apitype.WaitingFile, error) {
@ -2782,7 +2782,7 @@ func (b *LocalBackend) SetDNS(ctx context.Context, name, value string) error {
b.mu.Lock()
cc := b.cc
if prefs := b.prefs; prefs != nil {
req.NodeKey = tailcfg.NodeKeyFromNodePublic(prefs.Persist.PrivateNodeKey.Public())
req.NodeKey = prefs.Persist.PrivateNodeKey.Public().AsNodeKey()
}
b.mu.Unlock()
if cc == nil {

@ -90,7 +90,7 @@ func TestLocalLogLines(t *testing.T) {
TxBytes: 10,
RxBytes: 10,
LastHandshake: time.Now(),
NodeKey: tailcfg.NodeKeyFromNodePublic(key.NewNode().Public()),
NodeKey: key.NewNode().Public().AsNodeKey(),
}},
})
lb.mu.Unlock()
@ -105,7 +105,7 @@ func TestLocalLogLines(t *testing.T) {
TxBytes: 11,
RxBytes: 12,
LastHandshake: time.Now(),
NodeKey: tailcfg.NodeKeyFromNodePublic(key.NewNode().Public()),
NodeKey: key.NewNode().Public().AsNodeKey(),
}},
})
lb.mu.Unlock()

@ -274,7 +274,7 @@ func (s *Server) AddFakeNode() {
if s.nodes == nil {
s.nodes = make(map[tailcfg.NodeKey]*tailcfg.Node)
}
nk := tailcfg.NodeKeyFromNodePublic(key.NewNode().Public())
nk := key.NewNode().Public().AsNodeKey()
mk := key.NewMachine().Public()
dk := tailcfg.DiscoKeyFromDiscoPublic(key.NewDisco().Public())
id := int64(binary.LittleEndian.Uint64(nk[:]))

@ -105,7 +105,7 @@ func setupWGTest(b *testing.B, logf logger.Logf, traf *TrafficGen, a1, a2 netadd
Endpoints: eps,
}
e2.SetNetworkMap(&netmap.NetworkMap{
NodeKey: tailcfg.NodeKeyFromNodePublic(k2.Public()),
NodeKey: k2.Public().AsNodeKey(),
PrivateKey: k2,
Peers: []*tailcfg.Node{&n},
})
@ -142,7 +142,7 @@ func setupWGTest(b *testing.B, logf logger.Logf, traf *TrafficGen, a1, a2 netadd
Endpoints: eps,
}
e1.SetNetworkMap(&netmap.NetworkMap{
NodeKey: tailcfg.NodeKeyFromNodePublic(k1.Public()),
NodeKey: k1.Public().AsNodeKey(),
PrivateKey: k1,
Peers: []*tailcfg.Node{&n},
})

@ -1710,13 +1710,13 @@ func (c *Conn) processDERPReadResult(dm derpReadResult, b []byte) (n int, ep *en
}
ipp := netaddr.IPPortFrom(derpMagicIPAddr, uint16(regionID))
if c.handleDiscoMessage(b[:n], ipp, tailcfg.NodeKeyFromNodePublic(dm.src)) {
if c.handleDiscoMessage(b[:n], ipp, dm.src.AsNodeKey()) {
return 0, nil
}
var ok bool
c.mu.Lock()
ep, ok = c.peerMap.endpointForNodeKey(tailcfg.NodeKeyFromNodePublic(dm.src))
ep, ok = c.peerMap.endpointForNodeKey(dm.src.AsNodeKey())
c.mu.Unlock()
if !ok {
// We don't know anything about this node key, nothing to
@ -2132,7 +2132,7 @@ func (c *Conn) SetPrivateKey(privateKey key.NodePrivate) error {
if newKey.IsZero() {
c.publicKeyAtomic.Store(tailcfg.NodeKey{})
} else {
c.publicKeyAtomic.Store(tailcfg.NodeKeyFromNodePublic(newKey.Public()))
c.publicKeyAtomic.Store(newKey.Public().AsNodeKey())
}
if oldKey.IsZero() {
@ -2818,7 +2818,7 @@ func (c *Conn) ParseEndpoint(nodeKeyStr string) (conn.Endpoint, error) {
if err != nil {
return nil, fmt.Errorf("magicsock: ParseEndpoint: parse failed on %q: %w", nodeKeyStr, err)
}
pk := tailcfg.NodeKeyFromNodePublic(k)
pk := k.AsNodeKey()
c.mu.Lock()
defer c.mu.Unlock()

@ -247,7 +247,7 @@ func meshStacks(logf logger.Logf, mutateNetmap func(idx int, nm *netmap.NetworkM
me := ms[myIdx]
nm := &netmap.NetworkMap{
PrivateKey: me.privateKey,
NodeKey: tailcfg.NodeKeyFromNodePublic(me.privateKey.Public()),
NodeKey: me.privateKey.Public().AsNodeKey(),
Addresses: []netaddr.IPPrefix{netaddr.IPPrefixFrom(netaddr.IPv4(1, 0, 0, byte(myIdx+1)), 32)},
}
for i, peer := range ms {
@ -258,7 +258,7 @@ func meshStacks(logf logger.Logf, mutateNetmap func(idx int, nm *netmap.NetworkM
peer := &tailcfg.Node{
ID: tailcfg.NodeID(i + 1),
Name: fmt.Sprintf("node%d", i+1),
Key: tailcfg.NodeKeyFromNodePublic(peer.privateKey.Public()),
Key: peer.privateKey.Public().AsNodeKey(),
DiscoKey: tailcfg.DiscoKeyFromDiscoPublic(peer.conn.DiscoPublicKey()),
Addresses: addrs,
AllowedIPs: addrs,
@ -1136,7 +1136,7 @@ func TestDiscoMessage(t *testing.T) {
peer1Pub := c.DiscoPublicKey()
peer1Priv := c.discoPrivate
n := &tailcfg.Node{
Key: tailcfg.NodeKeyFromNodePublic(key.NewNode().Public()),
Key: key.NewNode().Public().AsNodeKey(),
DiscoKey: tailcfg.DiscoKeyFromDiscoPublic(peer1Pub),
}
c.peerMap.upsertEndpoint(&endpoint{
@ -1229,7 +1229,7 @@ func addTestEndpoint(tb testing.TB, conn *Conn, sendConn net.PacketConn) (tailcf
// codepath.
discoKey := key.DiscoPublicFromRaw32(mem.B([]byte{31: 1}))
nodeKey := key.NodePublicFromRaw32(mem.B([]byte{0: 'N', 1: 'K', 31: 0}))
tnk := tailcfg.NodeKeyFromNodePublic(nodeKey)
tnk := nodeKey.AsNodeKey()
conn.SetNetworkMap(&netmap.NetworkMap{
Peers: []*tailcfg.Node{
{

@ -648,7 +648,7 @@ func (e *userspaceEngine) maybeReconfigWireguardLocked(discoChanged map[tailcfg.
for i := range full.Peers {
p := &full.Peers[i]
nk := p.PublicKey
tnk := tailcfg.NodeKeyFromNodePublic(nk)
tnk := nk.AsNodeKey()
if !isTrimmablePeer(p, len(full.Peers)) {
min.Peers = append(min.Peers, *p)
if discoChanged[tnk] {
@ -687,7 +687,7 @@ func (e *userspaceEngine) maybeReconfigWireguardLocked(discoChanged map[tailcfg.
minner.Peers = nil
numRemove := 0
for _, p := range min.Peers {
if discoChanged[tailcfg.NodeKeyFromNodePublic(p.PublicKey)] {
if discoChanged[p.PublicKey.AsNodeKey()] {
numRemove++
continue
}
@ -807,7 +807,7 @@ func (e *userspaceEngine) Reconfig(cfg *wgcfg.Config, routerCfg *router.Config,
e.mu.Lock()
e.peerSequence = e.peerSequence[:0]
for _, p := range cfg.Peers {
e.peerSequence = append(e.peerSequence, tailcfg.NodeKeyFromNodePublic(p.PublicKey))
e.peerSequence = append(e.peerSequence, p.PublicKey.AsNodeKey())
peerSet[p.PublicKey] = struct{}{}
}
e.mu.Unlock()
@ -845,7 +845,7 @@ func (e *userspaceEngine) Reconfig(cfg *wgcfg.Config, routerCfg *router.Config,
prevEP := make(map[tailcfg.NodeKey]key.DiscoPublic)
for i := range e.lastCfgFull.Peers {
if p := &e.lastCfgFull.Peers[i]; !p.DiscoKey.IsZero() {
prevEP[tailcfg.NodeKeyFromNodePublic(p.PublicKey)] = p.DiscoKey
prevEP[p.PublicKey.AsNodeKey()] = p.DiscoKey
}
}
for i := range cfg.Peers {
@ -853,7 +853,7 @@ func (e *userspaceEngine) Reconfig(cfg *wgcfg.Config, routerCfg *router.Config,
if p.DiscoKey.IsZero() {
continue
}
pub := tailcfg.NodeKeyFromNodePublic(p.PublicKey)
pub := p.PublicKey.AsNodeKey()
if old, ok := prevEP[pub]; ok && old != p.DiscoKey {
discoChanged[pub] = true
e.logf("wgengine: Reconfig: %s changed from %q to %q", pub.ShortString(), old, p.DiscoKey)
@ -1014,7 +1014,7 @@ func (e *userspaceEngine) getStatus() (*Status, error) {
if !p.NodeKey.IsZero() {
pp[p.NodeKey] = p
}
p = ipnstate.PeerStatusLite{NodeKey: tailcfg.NodeKeyFromNodePublic(pk)}
p = ipnstate.PeerStatusLite{NodeKey: pk.AsNodeKey()}
case "rx_bytes":
n, err = mem.ParseInt(v, 10, 64)
p.RxBytes = n
@ -1464,7 +1464,7 @@ func (e *userspaceEngine) peerForIP(ip netaddr.IP) (n *tailcfg.Node, isSelf bool
}
if best.IsZero() || cidr.Bits() > best.Bits() {
best = cidr
bestKey = tailcfg.NodeKeyFromNodePublic(p.PublicKey)
bestKey = p.PublicKey.AsNodeKey()
}
}
}

@ -45,7 +45,7 @@ func TestNoteReceiveActivity(t *testing.T) {
}
ra := e.recvActivityAt
nk := tailcfg.NodeKeyFromNodePublic(key.NewNode().Public())
nk := key.NewNode().Public().AsNodeKey()
// Activity on an untracked key should do nothing.
e.noteRecvActivity(nk)
@ -217,7 +217,7 @@ func nkFromHex(hex string) tailcfg.NodeKey {
if err != nil {
panic(fmt.Sprintf("%q is not hex: %v", hex, err))
}
return tailcfg.NodeKeyFromNodePublic(k)
return k.AsNodeKey()
}
// an experiment to see if genLocalAddrFunc was worth it. As of Go

Loading…
Cancel
Save