all: replace tailcfg.DiscoKey with key.DiscoPublic.

Signed-off-by: David Anderson <danderson@tailscale.com>
This commit is contained in:
David Anderson
2021-11-02 14:41:56 -07:00
committed by Brad Fitzpatrick
parent f771327f0c
commit 0532eb30db
16 changed files with 51 additions and 95 deletions

View File

@@ -2269,7 +2269,7 @@ func (c *Conn) SetNetworkMap(nm *netmap.NetworkMap) {
endpointState: map[netaddr.IPPort]*endpointState{},
}
if !n.DiscoKey.IsZero() {
ep.discoKey = key.DiscoPublicFromRaw32(mem.B(n.DiscoKey[:]))
ep.discoKey = n.DiscoKey
ep.discoShort = n.DiscoKey.ShortString()
}
ep.wgEndpoint = n.Key.UntypedHexString()
@@ -3609,10 +3609,9 @@ func (de *endpoint) updateFromNode(n *tailcfg.Node) {
de.mu.Lock()
defer de.mu.Unlock()
tnk := key.DiscoPublicFromRaw32(mem.B(n.DiscoKey[:]))
if de.discoKey != tnk {
if de.discoKey != n.DiscoKey {
de.c.logf("[v1] magicsock: disco: node %s changed from discokey %s to %s", de.publicKey.ShortString(), de.discoKey, n.DiscoKey)
de.discoKey = tnk
de.discoKey = n.DiscoKey
de.discoShort = de.discoKey.ShortString()
de.resetLocked()
}

View File

@@ -259,7 +259,7 @@ func meshStacks(logf logger.Logf, mutateNetmap func(idx int, nm *netmap.NetworkM
ID: tailcfg.NodeID(i + 1),
Name: fmt.Sprintf("node%d", i+1),
Key: peer.privateKey.Public(),
DiscoKey: tailcfg.DiscoKeyFromDiscoPublic(peer.conn.DiscoPublicKey()),
DiscoKey: peer.conn.DiscoPublicKey(),
Addresses: addrs,
AllowedIPs: addrs,
Endpoints: epStrings(eps[i]),
@@ -618,7 +618,7 @@ func TestNoDiscoKey(t *testing.T) {
removeDisco := func(idx int, nm *netmap.NetworkMap) {
for _, p := range nm.Peers {
p.DiscoKey = tailcfg.DiscoKey{}
p.DiscoKey = key.DiscoPublic{}
}
}
@@ -680,7 +680,7 @@ func TestDiscokeyChange(t *testing.T) {
}
mu.Lock()
defer mu.Unlock()
nm.Peers[0].DiscoKey = tailcfg.DiscoKeyFromDiscoPublic(m1DiscoKey)
nm.Peers[0].DiscoKey = m1DiscoKey
}
cleanupMesh := meshStacks(t.Logf, setm1Key, m1, m2)
@@ -1137,11 +1137,11 @@ func TestDiscoMessage(t *testing.T) {
peer1Priv := c.discoPrivate
n := &tailcfg.Node{
Key: key.NewNode().Public(),
DiscoKey: tailcfg.DiscoKeyFromDiscoPublic(peer1Pub),
DiscoKey: peer1Pub,
}
c.peerMap.upsertEndpoint(&endpoint{
publicKey: n.Key,
discoKey: key.DiscoPublicFromRaw32(mem.B(n.DiscoKey[:])),
discoKey: n.DiscoKey,
})
const payload = "why hello"
@@ -1233,7 +1233,7 @@ func addTestEndpoint(tb testing.TB, conn *Conn, sendConn net.PacketConn) (key.No
Peers: []*tailcfg.Node{
{
Key: nodeKey,
DiscoKey: tailcfg.DiscoKeyFromDiscoPublic(discoKey),
DiscoKey: discoKey,
Endpoints: []string{sendConn.LocalAddr().String()},
},
},
@@ -1411,7 +1411,7 @@ func TestSetNetworkMapChangingNodeKey(t *testing.T) {
Peers: []*tailcfg.Node{
{
Key: nodeKey1,
DiscoKey: tailcfg.DiscoKeyFromDiscoPublic(discoKey),
DiscoKey: discoKey,
Endpoints: []string{"192.168.1.2:345"},
},
},
@@ -1426,7 +1426,7 @@ func TestSetNetworkMapChangingNodeKey(t *testing.T) {
Peers: []*tailcfg.Node{
{
Key: nodeKey2,
DiscoKey: tailcfg.DiscoKeyFromDiscoPublic(discoKey),
DiscoKey: discoKey,
Endpoints: []string{"192.168.1.2:345"},
},
},

View File

@@ -331,7 +331,7 @@ func NewUserspaceEngine(logf logger.Logf, conf Config) (_ Engine, reterr error)
closePool.add(e.magicConn)
e.magicConn.SetNetworkUp(e.linkMon.InterfaceState().AnyInterfaceUp())
tsTUNDev.SetDiscoKey(tailcfg.DiscoKeyFromDiscoPublic(e.magicConn.DiscoPublicKey()))
tsTUNDev.SetDiscoKey(e.magicConn.DiscoPublicKey())
if conf.RespondToPing {
e.tundev.PostFilterIn = echoRespondToAll
@@ -1230,8 +1230,8 @@ func (e *userspaceEngine) SetNetworkMap(nm *netmap.NetworkMap) {
}
}
func (e *userspaceEngine) DiscoPublicKey() tailcfg.DiscoKey {
return tailcfg.DiscoKeyFromDiscoPublic(e.magicConn.DiscoPublicKey())
func (e *userspaceEngine) DiscoPublicKey() key.DiscoPublic {
return e.magicConn.DiscoPublicKey()
}
func (e *userspaceEngine) UpdateStatus(sb *ipnstate.StatusBuilder) {

View File

@@ -17,6 +17,7 @@ import (
"tailscale.com/net/dns"
"tailscale.com/net/tstun"
"tailscale.com/tailcfg"
"tailscale.com/types/key"
"tailscale.com/types/netmap"
"tailscale.com/wgengine/filter"
"tailscale.com/wgengine/magicsock"
@@ -112,7 +113,7 @@ func (e *watchdogEngine) AddNetworkMapCallback(callback NetworkMapCallback) func
e.watchdog("AddNetworkMapCallback", func() { fn = e.wrap.AddNetworkMapCallback(callback) })
return func() { e.watchdog("RemoveNetworkMapCallback", fn) }
}
func (e *watchdogEngine) DiscoPublicKey() (k tailcfg.DiscoKey) {
func (e *watchdogEngine) DiscoPublicKey() (k key.DiscoPublic) {
e.watchdog("DiscoPublicKey", func() { k = e.wrap.DiscoPublicKey() })
return k
}

View File

@@ -10,11 +10,9 @@ import (
"fmt"
"strings"
"go4.org/mem"
"inet.af/netaddr"
"tailscale.com/net/tsaddr"
"tailscale.com/tailcfg"
"tailscale.com/types/key"
"tailscale.com/types/logger"
"tailscale.com/types/netmap"
"tailscale.com/wgengine/wgcfg"
@@ -74,7 +72,7 @@ func WGCfg(nm *netmap.NetworkMap, logf logger.Logf, flags netmap.WGConfigFlags,
}
cfg.Peers = append(cfg.Peers, wgcfg.Peer{
PublicKey: peer.Key,
DiscoKey: key.DiscoPublicFromRaw32(mem.B(peer.DiscoKey[:])),
DiscoKey: peer.DiscoKey,
})
cpeer := &cfg.Peers[len(cfg.Peers)-1]
if peer.KeepAlive {

View File

@@ -11,6 +11,7 @@ import (
"tailscale.com/ipn/ipnstate"
"tailscale.com/net/dns"
"tailscale.com/tailcfg"
"tailscale.com/types/key"
"tailscale.com/types/netmap"
"tailscale.com/wgengine/filter"
"tailscale.com/wgengine/monitor"
@@ -127,7 +128,7 @@ type Engine interface {
// DiscoPublicKey gets the public key used for path discovery
// messages.
DiscoPublicKey() tailcfg.DiscoKey
DiscoPublicKey() key.DiscoPublic
// UpdateStatus populates the network state using the provided
// status builder.