types/netmap: use key.NodePublic instead of tailcfg.NodeKey.

Update #3206

Signed-off-by: David Anderson <danderson@tailscale.com>
This commit is contained in:
David Anderson 2021-10-29 18:01:03 -07:00
parent 408b0923a6
commit d6e7cec6a7
5 changed files with 30 additions and 27 deletions

View File

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

View File

@ -26,7 +26,7 @@ type NetworkMap struct {
// Core networking // Core networking
SelfNode *tailcfg.Node SelfNode *tailcfg.Node
NodeKey tailcfg.NodeKey NodeKey key.NodePublic
PrivateKey key.NodePrivate PrivateKey key.NodePrivate
Expiry time.Time Expiry time.Time
// Name is the DNS name assigned to this node. // Name is the DNS name assigned to this node.

View File

@ -8,15 +8,18 @@
"encoding/hex" "encoding/hex"
"testing" "testing"
"go4.org/mem"
"inet.af/netaddr" "inet.af/netaddr"
"tailscale.com/tailcfg" "tailscale.com/tailcfg"
"tailscale.com/types/key"
) )
func testNodeKey(b byte) (ret tailcfg.NodeKey) { func testNodeKey(b byte) (ret key.NodePublic) {
for i := range ret { var bs [key.NodePublicRawLen]byte
ret[i] = b for i := range bs {
bs[i] = b
} }
return return key.NodePublicFromRaw32(mem.B(bs[:]))
} }
func testDiscoKey(hexPrefix string) (ret tailcfg.DiscoKey) { func testDiscoKey(hexPrefix string) (ret tailcfg.DiscoKey) {
@ -40,12 +43,12 @@ func TestNetworkMapConcise(t *testing.T) {
NodeKey: testNodeKey(1), NodeKey: testNodeKey(1),
Peers: []*tailcfg.Node{ Peers: []*tailcfg.Node{
{ {
Key: testNodeKey(2), Key: testNodeKey(2).AsNodeKey(),
DERP: "127.3.3.40:2", DERP: "127.3.3.40:2",
Endpoints: []string{"192.168.0.100:12", "192.168.0.100:12354"}, Endpoints: []string{"192.168.0.100:12", "192.168.0.100:12354"},
}, },
{ {
Key: testNodeKey(3), Key: testNodeKey(3).AsNodeKey(),
DERP: "127.3.3.40:4", DERP: "127.3.3.40:4",
Endpoints: []string{"10.2.0.100:12", "10.1.0.100:12345"}, Endpoints: []string{"10.2.0.100:12", "10.1.0.100:12345"},
}, },
@ -95,7 +98,7 @@ func TestConciseDiffFrom(t *testing.T) {
NodeKey: testNodeKey(1), NodeKey: testNodeKey(1),
Peers: []*tailcfg.Node{ Peers: []*tailcfg.Node{
{ {
Key: testNodeKey(2), Key: testNodeKey(2).AsNodeKey(),
DERP: "127.3.3.40:2", DERP: "127.3.3.40:2",
Endpoints: []string{"192.168.0.100:12", "192.168.0.100:12354"}, Endpoints: []string{"192.168.0.100:12", "192.168.0.100:12354"},
}, },
@ -105,7 +108,7 @@ func TestConciseDiffFrom(t *testing.T) {
NodeKey: testNodeKey(1), NodeKey: testNodeKey(1),
Peers: []*tailcfg.Node{ Peers: []*tailcfg.Node{
{ {
Key: testNodeKey(2), Key: testNodeKey(2).AsNodeKey(),
DERP: "127.3.3.40:2", DERP: "127.3.3.40:2",
Endpoints: []string{"192.168.0.100:12", "192.168.0.100:12354"}, Endpoints: []string{"192.168.0.100:12", "192.168.0.100:12354"},
}, },
@ -119,7 +122,7 @@ func TestConciseDiffFrom(t *testing.T) {
NodeKey: testNodeKey(1), NodeKey: testNodeKey(1),
Peers: []*tailcfg.Node{ Peers: []*tailcfg.Node{
{ {
Key: testNodeKey(2), Key: testNodeKey(2).AsNodeKey(),
DERP: "127.3.3.40:2", DERP: "127.3.3.40:2",
Endpoints: []string{"192.168.0.100:12", "192.168.0.100:12354"}, Endpoints: []string{"192.168.0.100:12", "192.168.0.100:12354"},
}, },
@ -129,7 +132,7 @@ func TestConciseDiffFrom(t *testing.T) {
NodeKey: testNodeKey(2), NodeKey: testNodeKey(2),
Peers: []*tailcfg.Node{ Peers: []*tailcfg.Node{
{ {
Key: testNodeKey(2), Key: testNodeKey(2).AsNodeKey(),
DERP: "127.3.3.40:2", DERP: "127.3.3.40:2",
Endpoints: []string{"192.168.0.100:12", "192.168.0.100:12354"}, Endpoints: []string{"192.168.0.100:12", "192.168.0.100:12354"},
}, },
@ -144,7 +147,7 @@ func TestConciseDiffFrom(t *testing.T) {
Peers: []*tailcfg.Node{ Peers: []*tailcfg.Node{
{ {
ID: 2, ID: 2,
Key: testNodeKey(2), Key: testNodeKey(2).AsNodeKey(),
DERP: "127.3.3.40:2", DERP: "127.3.3.40:2",
Endpoints: []string{"192.168.0.100:12", "192.168.0.100:12354"}, Endpoints: []string{"192.168.0.100:12", "192.168.0.100:12354"},
}, },
@ -155,19 +158,19 @@ func TestConciseDiffFrom(t *testing.T) {
Peers: []*tailcfg.Node{ Peers: []*tailcfg.Node{
{ {
ID: 1, ID: 1,
Key: testNodeKey(1), Key: testNodeKey(1).AsNodeKey(),
DERP: "127.3.3.40:1", DERP: "127.3.3.40:1",
Endpoints: []string{"192.168.0.100:12", "192.168.0.100:12354"}, Endpoints: []string{"192.168.0.100:12", "192.168.0.100:12354"},
}, },
{ {
ID: 2, ID: 2,
Key: testNodeKey(2), Key: testNodeKey(2).AsNodeKey(),
DERP: "127.3.3.40:2", DERP: "127.3.3.40:2",
Endpoints: []string{"192.168.0.100:12", "192.168.0.100:12354"}, Endpoints: []string{"192.168.0.100:12", "192.168.0.100:12354"},
}, },
{ {
ID: 3, ID: 3,
Key: testNodeKey(3), Key: testNodeKey(3).AsNodeKey(),
DERP: "127.3.3.40:3", DERP: "127.3.3.40:3",
Endpoints: []string{"192.168.0.100:12", "192.168.0.100:12354"}, Endpoints: []string{"192.168.0.100:12", "192.168.0.100:12354"},
}, },
@ -182,19 +185,19 @@ func TestConciseDiffFrom(t *testing.T) {
Peers: []*tailcfg.Node{ Peers: []*tailcfg.Node{
{ {
ID: 1, ID: 1,
Key: testNodeKey(1), Key: testNodeKey(1).AsNodeKey(),
DERP: "127.3.3.40:1", DERP: "127.3.3.40:1",
Endpoints: []string{"192.168.0.100:12", "192.168.0.100:12354"}, Endpoints: []string{"192.168.0.100:12", "192.168.0.100:12354"},
}, },
{ {
ID: 2, ID: 2,
Key: testNodeKey(2), Key: testNodeKey(2).AsNodeKey(),
DERP: "127.3.3.40:2", DERP: "127.3.3.40:2",
Endpoints: []string{"192.168.0.100:12", "192.168.0.100:12354"}, Endpoints: []string{"192.168.0.100:12", "192.168.0.100:12354"},
}, },
{ {
ID: 3, ID: 3,
Key: testNodeKey(3), Key: testNodeKey(3).AsNodeKey(),
DERP: "127.3.3.40:3", DERP: "127.3.3.40:3",
Endpoints: []string{"192.168.0.100:12", "192.168.0.100:12354"}, Endpoints: []string{"192.168.0.100:12", "192.168.0.100:12354"},
}, },
@ -205,7 +208,7 @@ func TestConciseDiffFrom(t *testing.T) {
Peers: []*tailcfg.Node{ Peers: []*tailcfg.Node{
{ {
ID: 2, ID: 2,
Key: testNodeKey(2), Key: testNodeKey(2).AsNodeKey(),
DERP: "127.3.3.40:2", DERP: "127.3.3.40:2",
Endpoints: []string{"192.168.0.100:12", "192.168.0.100:12354"}, Endpoints: []string{"192.168.0.100:12", "192.168.0.100:12354"},
}, },
@ -220,7 +223,7 @@ func TestConciseDiffFrom(t *testing.T) {
Peers: []*tailcfg.Node{ Peers: []*tailcfg.Node{
{ {
ID: 2, ID: 2,
Key: testNodeKey(2), Key: testNodeKey(2).AsNodeKey(),
DERP: "127.3.3.40:2", DERP: "127.3.3.40:2",
Endpoints: []string{"192.168.0.100:12", "1.1.1.1:1"}, Endpoints: []string{"192.168.0.100:12", "1.1.1.1:1"},
}, },
@ -231,7 +234,7 @@ func TestConciseDiffFrom(t *testing.T) {
Peers: []*tailcfg.Node{ Peers: []*tailcfg.Node{
{ {
ID: 2, ID: 2,
Key: testNodeKey(2), Key: testNodeKey(2).AsNodeKey(),
DERP: "127.3.3.40:2", DERP: "127.3.3.40:2",
Endpoints: []string{"192.168.0.100:12", "1.1.1.1:2"}, Endpoints: []string{"192.168.0.100:12", "1.1.1.1:2"},
}, },
@ -246,7 +249,7 @@ func TestConciseDiffFrom(t *testing.T) {
Peers: []*tailcfg.Node{ Peers: []*tailcfg.Node{
{ {
ID: 2, ID: 2,
Key: testNodeKey(2), Key: testNodeKey(2).AsNodeKey(),
DERP: "127.3.3.40:2", DERP: "127.3.3.40:2",
Endpoints: []string{"192.168.0.100:41641", "1.1.1.1:41641"}, Endpoints: []string{"192.168.0.100:41641", "1.1.1.1:41641"},
DiscoKey: testDiscoKey("f00f00f00f"), DiscoKey: testDiscoKey("f00f00f00f"),
@ -259,7 +262,7 @@ func TestConciseDiffFrom(t *testing.T) {
Peers: []*tailcfg.Node{ Peers: []*tailcfg.Node{
{ {
ID: 2, ID: 2,
Key: testNodeKey(2), Key: testNodeKey(2).AsNodeKey(),
DERP: "127.3.3.40:2", DERP: "127.3.3.40:2",
Endpoints: []string{"192.168.0.100:41641", "1.1.1.1:41641"}, Endpoints: []string{"192.168.0.100:41641", "1.1.1.1:41641"},
DiscoKey: testDiscoKey("ba4ba4ba4b"), DiscoKey: testDiscoKey("ba4ba4ba4b"),

View File

@ -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: k2.Public().AsNodeKey(), NodeKey: k2.Public(),
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: k1.Public().AsNodeKey(), NodeKey: k1.Public(),
PrivateKey: k1, PrivateKey: k1,
Peers: []*tailcfg.Node{&n}, Peers: []*tailcfg.Node{&n},
}) })

View File

@ -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: me.privateKey.Public().AsNodeKey(), NodeKey: me.privateKey.Public(),
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 {