types/persist: add PublicNodeKey helper

Signed-off-by: Maisem Ali <maisem@tailscale.com>
andrew/monitor-link-change
Maisem Ali 2 years ago committed by Maisem Ali
parent 0957bc5af2
commit a2d15924fb

@ -821,7 +821,7 @@ func (c *Direct) sendMapRequest(ctx context.Context, maxPolls int, readOnly bool
request := &tailcfg.MapRequest{ request := &tailcfg.MapRequest{
Version: tailcfg.CurrentCapabilityVersion, Version: tailcfg.CurrentCapabilityVersion,
KeepAlive: c.keepAlive, KeepAlive: c.keepAlive,
NodeKey: persist.PrivateNodeKey.Public(), NodeKey: persist.PublicNodeKey(),
DiscoKey: c.discoPubKey, DiscoKey: c.discoPubKey,
Endpoints: epStrs, Endpoints: epStrs,
EndpointTypes: epTypes, EndpointTypes: epTypes,

@ -3396,7 +3396,7 @@ func (b *LocalBackend) TestOnlyPublicKeys() (machineKey key.MachinePublic, nodeK
} }
mk := machinePrivKey.Public() mk := machinePrivKey.Public()
nk := prefs.Persist().PrivateNodeKey.Public() nk := prefs.Persist().PublicNodeKey()
return mk, nk return mk, nk
} }
@ -3506,7 +3506,7 @@ func (b *LocalBackend) SetDNS(ctx context.Context, name, value string) error {
b.mu.Lock() b.mu.Lock()
cc := b.ccAuto cc := b.ccAuto
if b.prefs.Valid() { if b.prefs.Valid() {
req.NodeKey = b.prefs.Persist().PrivateNodeKey.Public() req.NodeKey = b.prefs.Persist().PublicNodeKey()
} }
b.mu.Unlock() b.mu.Unlock()
if cc == nil { if cc == nil {

@ -100,7 +100,7 @@ func (b *LocalBackend) tkaSyncIfNeeded(nm *netmap.NetworkMap) error {
b.mu.Lock() // take mu to protect access to synchronized fields. b.mu.Lock() // take mu to protect access to synchronized fields.
defer b.mu.Unlock() defer b.mu.Unlock()
ourNodeKey := b.prefs.Persist().PrivateNodeKey.Public() ourNodeKey := b.prefs.Persist().PublicNodeKey()
isEnabled := b.tka != nil isEnabled := b.tka != nil
wantEnabled := nm.TKAEnabled wantEnabled := nm.TKAEnabled
@ -342,7 +342,7 @@ func (b *LocalBackend) NetworkLockInit(keys []tka.Key) error {
var ourNodeKey key.NodePublic var ourNodeKey key.NodePublic
b.mu.Lock() b.mu.Lock()
if b.prefs.Valid() { if b.prefs.Valid() {
ourNodeKey = b.prefs.Persist().PrivateNodeKey.Public() ourNodeKey = b.prefs.Persist().PublicNodeKey()
} }
b.mu.Unlock() b.mu.Unlock()
if ourNodeKey.IsZero() { if ourNodeKey.IsZero() {
@ -453,7 +453,7 @@ func (b *LocalBackend) NetworkLockModify(addKeys, removeKeys []tka.Key) (err err
return nil return nil
} }
ourNodeKey := b.prefs.Persist().PrivateNodeKey.Public() ourNodeKey := b.prefs.Persist().PublicNodeKey()
b.mu.Unlock() b.mu.Unlock()
resp, err := b.tkaDoSyncSend(ourNodeKey, aums, true) resp, err := b.tkaDoSyncSend(ourNodeKey, aums, true)
b.mu.Lock() b.mu.Lock()

@ -36,6 +36,11 @@ type Persist struct {
LoginName string LoginName string
} }
// PublicNodeKey returns the public key for the node key.
func (p *Persist) PublicNodeKey() key.NodePublic {
return p.PrivateNodeKey.Public()
}
func (p *Persist) Equals(p2 *Persist) bool { func (p *Persist) Equals(p2 *Persist) bool {
if p == nil && p2 == nil { if p == nil && p2 == nil {
return true return true
@ -63,7 +68,7 @@ func (p *Persist) Pretty() string {
ok = p.OldPrivateNodeKey.Public() ok = p.OldPrivateNodeKey.Public()
} }
if !p.PrivateNodeKey.IsZero() { if !p.PrivateNodeKey.IsZero() {
nk = p.PrivateNodeKey.Public() nk = p.PublicNodeKey()
} }
return fmt.Sprintf("Persist{lm=%v, o=%v, n=%v u=%#v}", return fmt.Sprintf("Persist{lm=%v, o=%v, n=%v u=%#v}",
mk.ShortString(), ok.ShortString(), nk.ShortString(), p.LoginName) mk.ShortString(), ok.ShortString(), nk.ShortString(), p.LoginName)

Loading…
Cancel
Save