various: use NodePublic.AsNodeKey() instead of tailcfg.NodeKeyFromNodePublic()
Updates #3206 Signed-off-by: David Anderson <danderson@tailscale.com>
This commit is contained in:
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)
|
now := time.Now().Round(time.Second)
|
||||||
request := tailcfg.RegisterRequest{
|
request := tailcfg.RegisterRequest{
|
||||||
Version: 1,
|
Version: 1,
|
||||||
OldNodeKey: tailcfg.NodeKeyFromNodePublic(oldNodeKey),
|
OldNodeKey: oldNodeKey.AsNodeKey(),
|
||||||
NodeKey: tailcfg.NodeKeyFromNodePublic(tryingNewKey.Public()),
|
NodeKey: tryingNewKey.Public().AsNodeKey(),
|
||||||
Hostinfo: hostinfo,
|
Hostinfo: hostinfo,
|
||||||
Followup: opt.URL,
|
Followup: opt.URL,
|
||||||
Timestamp: &now,
|
Timestamp: &now,
|
||||||
|
@ -595,7 +595,7 @@ func (c *Direct) sendMapRequest(ctx context.Context, maxPolls int, cb func(*netm
|
||||||
request := &tailcfg.MapRequest{
|
request := &tailcfg.MapRequest{
|
||||||
Version: tailcfg.CurrentMapRequestVersion,
|
Version: tailcfg.CurrentMapRequestVersion,
|
||||||
KeepAlive: c.keepAlive,
|
KeepAlive: c.keepAlive,
|
||||||
NodeKey: tailcfg.NodeKeyFromNodePublic(persist.PrivateNodeKey.Public()),
|
NodeKey: persist.PrivateNodeKey.Public().AsNodeKey(),
|
||||||
DiscoKey: c.discoPubKey,
|
DiscoKey: c.discoPubKey,
|
||||||
Endpoints: epStrs,
|
Endpoints: epStrs,
|
||||||
EndpointTypes: epTypes,
|
EndpointTypes: epTypes,
|
||||||
|
|
|
@ -110,7 +110,7 @@ func (ms *mapSession) netmapForResponse(resp *tailcfg.MapResponse) *netmap.Netwo
|
||||||
}
|
}
|
||||||
|
|
||||||
nm := &netmap.NetworkMap{
|
nm := &netmap.NetworkMap{
|
||||||
NodeKey: tailcfg.NodeKeyFromNodePublic(ms.privateNodeKey.Public()),
|
NodeKey: ms.privateNodeKey.Public().AsNodeKey(),
|
||||||
PrivateKey: ms.privateNodeKey,
|
PrivateKey: ms.privateNodeKey,
|
||||||
MachineKey: ms.machinePubKey,
|
MachineKey: ms.machinePubKey,
|
||||||
Peers: resp.Peers,
|
Peers: resp.Peers,
|
||||||
|
|
|
@ -2692,7 +2692,7 @@ func (b *LocalBackend) TestOnlyPublicKeys() (machineKey key.MachinePublic, nodeK
|
||||||
|
|
||||||
mk := machinePrivKey.Public()
|
mk := machinePrivKey.Public()
|
||||||
nk := prefs.Persist.PrivateNodeKey.Public()
|
nk := prefs.Persist.PrivateNodeKey.Public()
|
||||||
return mk, tailcfg.NodeKeyFromNodePublic(nk)
|
return mk, nk.AsNodeKey()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *LocalBackend) WaitingFiles() ([]apitype.WaitingFile, error) {
|
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()
|
b.mu.Lock()
|
||||||
cc := b.cc
|
cc := b.cc
|
||||||
if prefs := b.prefs; prefs != nil {
|
if prefs := b.prefs; prefs != nil {
|
||||||
req.NodeKey = tailcfg.NodeKeyFromNodePublic(prefs.Persist.PrivateNodeKey.Public())
|
req.NodeKey = prefs.Persist.PrivateNodeKey.Public().AsNodeKey()
|
||||||
}
|
}
|
||||||
b.mu.Unlock()
|
b.mu.Unlock()
|
||||||
if cc == nil {
|
if cc == nil {
|
||||||
|
|
|
@ -90,7 +90,7 @@ func TestLocalLogLines(t *testing.T) {
|
||||||
TxBytes: 10,
|
TxBytes: 10,
|
||||||
RxBytes: 10,
|
RxBytes: 10,
|
||||||
LastHandshake: time.Now(),
|
LastHandshake: time.Now(),
|
||||||
NodeKey: tailcfg.NodeKeyFromNodePublic(key.NewNode().Public()),
|
NodeKey: key.NewNode().Public().AsNodeKey(),
|
||||||
}},
|
}},
|
||||||
})
|
})
|
||||||
lb.mu.Unlock()
|
lb.mu.Unlock()
|
||||||
|
@ -105,7 +105,7 @@ func TestLocalLogLines(t *testing.T) {
|
||||||
TxBytes: 11,
|
TxBytes: 11,
|
||||||
RxBytes: 12,
|
RxBytes: 12,
|
||||||
LastHandshake: time.Now(),
|
LastHandshake: time.Now(),
|
||||||
NodeKey: tailcfg.NodeKeyFromNodePublic(key.NewNode().Public()),
|
NodeKey: key.NewNode().Public().AsNodeKey(),
|
||||||
}},
|
}},
|
||||||
})
|
})
|
||||||
lb.mu.Unlock()
|
lb.mu.Unlock()
|
||||||
|
|
|
@ -274,7 +274,7 @@ func (s *Server) AddFakeNode() {
|
||||||
if s.nodes == nil {
|
if s.nodes == nil {
|
||||||
s.nodes = make(map[tailcfg.NodeKey]*tailcfg.Node)
|
s.nodes = make(map[tailcfg.NodeKey]*tailcfg.Node)
|
||||||
}
|
}
|
||||||
nk := tailcfg.NodeKeyFromNodePublic(key.NewNode().Public())
|
nk := key.NewNode().Public().AsNodeKey()
|
||||||
mk := key.NewMachine().Public()
|
mk := key.NewMachine().Public()
|
||||||
dk := tailcfg.DiscoKeyFromDiscoPublic(key.NewDisco().Public())
|
dk := tailcfg.DiscoKeyFromDiscoPublic(key.NewDisco().Public())
|
||||||
id := int64(binary.LittleEndian.Uint64(nk[:]))
|
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,
|
Endpoints: eps,
|
||||||
}
|
}
|
||||||
e2.SetNetworkMap(&netmap.NetworkMap{
|
e2.SetNetworkMap(&netmap.NetworkMap{
|
||||||
NodeKey: tailcfg.NodeKeyFromNodePublic(k2.Public()),
|
NodeKey: k2.Public().AsNodeKey(),
|
||||||
PrivateKey: k2,
|
PrivateKey: k2,
|
||||||
Peers: []*tailcfg.Node{&n},
|
Peers: []*tailcfg.Node{&n},
|
||||||
})
|
})
|
||||||
|
@ -142,7 +142,7 @@ func setupWGTest(b *testing.B, logf logger.Logf, traf *TrafficGen, a1, a2 netadd
|
||||||
Endpoints: eps,
|
Endpoints: eps,
|
||||||
}
|
}
|
||||||
e1.SetNetworkMap(&netmap.NetworkMap{
|
e1.SetNetworkMap(&netmap.NetworkMap{
|
||||||
NodeKey: tailcfg.NodeKeyFromNodePublic(k1.Public()),
|
NodeKey: k1.Public().AsNodeKey(),
|
||||||
PrivateKey: k1,
|
PrivateKey: k1,
|
||||||
Peers: []*tailcfg.Node{&n},
|
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))
|
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
|
return 0, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var ok bool
|
var ok bool
|
||||||
c.mu.Lock()
|
c.mu.Lock()
|
||||||
ep, ok = c.peerMap.endpointForNodeKey(tailcfg.NodeKeyFromNodePublic(dm.src))
|
ep, ok = c.peerMap.endpointForNodeKey(dm.src.AsNodeKey())
|
||||||
c.mu.Unlock()
|
c.mu.Unlock()
|
||||||
if !ok {
|
if !ok {
|
||||||
// We don't know anything about this node key, nothing to
|
// 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() {
|
if newKey.IsZero() {
|
||||||
c.publicKeyAtomic.Store(tailcfg.NodeKey{})
|
c.publicKeyAtomic.Store(tailcfg.NodeKey{})
|
||||||
} else {
|
} else {
|
||||||
c.publicKeyAtomic.Store(tailcfg.NodeKeyFromNodePublic(newKey.Public()))
|
c.publicKeyAtomic.Store(newKey.Public().AsNodeKey())
|
||||||
}
|
}
|
||||||
|
|
||||||
if oldKey.IsZero() {
|
if oldKey.IsZero() {
|
||||||
|
@ -2818,7 +2818,7 @@ func (c *Conn) ParseEndpoint(nodeKeyStr string) (conn.Endpoint, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("magicsock: ParseEndpoint: parse failed on %q: %w", nodeKeyStr, err)
|
return nil, fmt.Errorf("magicsock: ParseEndpoint: parse failed on %q: %w", nodeKeyStr, err)
|
||||||
}
|
}
|
||||||
pk := tailcfg.NodeKeyFromNodePublic(k)
|
pk := k.AsNodeKey()
|
||||||
|
|
||||||
c.mu.Lock()
|
c.mu.Lock()
|
||||||
defer c.mu.Unlock()
|
defer c.mu.Unlock()
|
||||||
|
|
|
@ -247,7 +247,7 @@ func meshStacks(logf logger.Logf, mutateNetmap func(idx int, nm *netmap.NetworkM
|
||||||
me := ms[myIdx]
|
me := ms[myIdx]
|
||||||
nm := &netmap.NetworkMap{
|
nm := &netmap.NetworkMap{
|
||||||
PrivateKey: me.privateKey,
|
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)},
|
Addresses: []netaddr.IPPrefix{netaddr.IPPrefixFrom(netaddr.IPv4(1, 0, 0, byte(myIdx+1)), 32)},
|
||||||
}
|
}
|
||||||
for i, peer := range ms {
|
for i, peer := range ms {
|
||||||
|
@ -258,7 +258,7 @@ func meshStacks(logf logger.Logf, mutateNetmap func(idx int, nm *netmap.NetworkM
|
||||||
peer := &tailcfg.Node{
|
peer := &tailcfg.Node{
|
||||||
ID: tailcfg.NodeID(i + 1),
|
ID: tailcfg.NodeID(i + 1),
|
||||||
Name: fmt.Sprintf("node%d", 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()),
|
DiscoKey: tailcfg.DiscoKeyFromDiscoPublic(peer.conn.DiscoPublicKey()),
|
||||||
Addresses: addrs,
|
Addresses: addrs,
|
||||||
AllowedIPs: addrs,
|
AllowedIPs: addrs,
|
||||||
|
@ -1136,7 +1136,7 @@ func TestDiscoMessage(t *testing.T) {
|
||||||
peer1Pub := c.DiscoPublicKey()
|
peer1Pub := c.DiscoPublicKey()
|
||||||
peer1Priv := c.discoPrivate
|
peer1Priv := c.discoPrivate
|
||||||
n := &tailcfg.Node{
|
n := &tailcfg.Node{
|
||||||
Key: tailcfg.NodeKeyFromNodePublic(key.NewNode().Public()),
|
Key: key.NewNode().Public().AsNodeKey(),
|
||||||
DiscoKey: tailcfg.DiscoKeyFromDiscoPublic(peer1Pub),
|
DiscoKey: tailcfg.DiscoKeyFromDiscoPublic(peer1Pub),
|
||||||
}
|
}
|
||||||
c.peerMap.upsertEndpoint(&endpoint{
|
c.peerMap.upsertEndpoint(&endpoint{
|
||||||
|
@ -1229,7 +1229,7 @@ func addTestEndpoint(tb testing.TB, conn *Conn, sendConn net.PacketConn) (tailcf
|
||||||
// codepath.
|
// codepath.
|
||||||
discoKey := key.DiscoPublicFromRaw32(mem.B([]byte{31: 1}))
|
discoKey := key.DiscoPublicFromRaw32(mem.B([]byte{31: 1}))
|
||||||
nodeKey := key.NodePublicFromRaw32(mem.B([]byte{0: 'N', 1: 'K', 31: 0}))
|
nodeKey := key.NodePublicFromRaw32(mem.B([]byte{0: 'N', 1: 'K', 31: 0}))
|
||||||
tnk := tailcfg.NodeKeyFromNodePublic(nodeKey)
|
tnk := nodeKey.AsNodeKey()
|
||||||
conn.SetNetworkMap(&netmap.NetworkMap{
|
conn.SetNetworkMap(&netmap.NetworkMap{
|
||||||
Peers: []*tailcfg.Node{
|
Peers: []*tailcfg.Node{
|
||||||
{
|
{
|
||||||
|
|
|
@ -648,7 +648,7 @@ func (e *userspaceEngine) maybeReconfigWireguardLocked(discoChanged map[tailcfg.
|
||||||
for i := range full.Peers {
|
for i := range full.Peers {
|
||||||
p := &full.Peers[i]
|
p := &full.Peers[i]
|
||||||
nk := p.PublicKey
|
nk := p.PublicKey
|
||||||
tnk := tailcfg.NodeKeyFromNodePublic(nk)
|
tnk := nk.AsNodeKey()
|
||||||
if !isTrimmablePeer(p, len(full.Peers)) {
|
if !isTrimmablePeer(p, len(full.Peers)) {
|
||||||
min.Peers = append(min.Peers, *p)
|
min.Peers = append(min.Peers, *p)
|
||||||
if discoChanged[tnk] {
|
if discoChanged[tnk] {
|
||||||
|
@ -687,7 +687,7 @@ func (e *userspaceEngine) maybeReconfigWireguardLocked(discoChanged map[tailcfg.
|
||||||
minner.Peers = nil
|
minner.Peers = nil
|
||||||
numRemove := 0
|
numRemove := 0
|
||||||
for _, p := range min.Peers {
|
for _, p := range min.Peers {
|
||||||
if discoChanged[tailcfg.NodeKeyFromNodePublic(p.PublicKey)] {
|
if discoChanged[p.PublicKey.AsNodeKey()] {
|
||||||
numRemove++
|
numRemove++
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -807,7 +807,7 @@ func (e *userspaceEngine) Reconfig(cfg *wgcfg.Config, routerCfg *router.Config,
|
||||||
e.mu.Lock()
|
e.mu.Lock()
|
||||||
e.peerSequence = e.peerSequence[:0]
|
e.peerSequence = e.peerSequence[:0]
|
||||||
for _, p := range cfg.Peers {
|
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{}{}
|
peerSet[p.PublicKey] = struct{}{}
|
||||||
}
|
}
|
||||||
e.mu.Unlock()
|
e.mu.Unlock()
|
||||||
|
@ -845,7 +845,7 @@ func (e *userspaceEngine) Reconfig(cfg *wgcfg.Config, routerCfg *router.Config,
|
||||||
prevEP := make(map[tailcfg.NodeKey]key.DiscoPublic)
|
prevEP := make(map[tailcfg.NodeKey]key.DiscoPublic)
|
||||||
for i := range e.lastCfgFull.Peers {
|
for i := range e.lastCfgFull.Peers {
|
||||||
if p := &e.lastCfgFull.Peers[i]; !p.DiscoKey.IsZero() {
|
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 {
|
for i := range cfg.Peers {
|
||||||
|
@ -853,7 +853,7 @@ func (e *userspaceEngine) Reconfig(cfg *wgcfg.Config, routerCfg *router.Config,
|
||||||
if p.DiscoKey.IsZero() {
|
if p.DiscoKey.IsZero() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
pub := tailcfg.NodeKeyFromNodePublic(p.PublicKey)
|
pub := p.PublicKey.AsNodeKey()
|
||||||
if old, ok := prevEP[pub]; ok && old != p.DiscoKey {
|
if old, ok := prevEP[pub]; ok && old != p.DiscoKey {
|
||||||
discoChanged[pub] = true
|
discoChanged[pub] = true
|
||||||
e.logf("wgengine: Reconfig: %s changed from %q to %q", pub.ShortString(), old, p.DiscoKey)
|
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() {
|
if !p.NodeKey.IsZero() {
|
||||||
pp[p.NodeKey] = p
|
pp[p.NodeKey] = p
|
||||||
}
|
}
|
||||||
p = ipnstate.PeerStatusLite{NodeKey: tailcfg.NodeKeyFromNodePublic(pk)}
|
p = ipnstate.PeerStatusLite{NodeKey: pk.AsNodeKey()}
|
||||||
case "rx_bytes":
|
case "rx_bytes":
|
||||||
n, err = mem.ParseInt(v, 10, 64)
|
n, err = mem.ParseInt(v, 10, 64)
|
||||||
p.RxBytes = n
|
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() {
|
if best.IsZero() || cidr.Bits() > best.Bits() {
|
||||||
best = cidr
|
best = cidr
|
||||||
bestKey = tailcfg.NodeKeyFromNodePublic(p.PublicKey)
|
bestKey = p.PublicKey.AsNodeKey()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,7 @@ func TestNoteReceiveActivity(t *testing.T) {
|
||||||
}
|
}
|
||||||
ra := e.recvActivityAt
|
ra := e.recvActivityAt
|
||||||
|
|
||||||
nk := tailcfg.NodeKeyFromNodePublic(key.NewNode().Public())
|
nk := key.NewNode().Public().AsNodeKey()
|
||||||
|
|
||||||
// Activity on an untracked key should do nothing.
|
// Activity on an untracked key should do nothing.
|
||||||
e.noteRecvActivity(nk)
|
e.noteRecvActivity(nk)
|
||||||
|
@ -217,7 +217,7 @@ func nkFromHex(hex string) tailcfg.NodeKey {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(fmt.Sprintf("%q is not hex: %v", hex, err))
|
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
|
// an experiment to see if genLocalAddrFunc was worth it. As of Go
|
||||||
|
|
Loading…
Reference in New Issue