ipn: rename 'new' variable to 'newp'

Both to avoid shadowing new and because new is a little vague for such
a long method handling multiple new & old things.
pull/842/head
Brad Fitzpatrick 4 years ago
parent 5b1d03f016
commit 66d196326f

@ -959,8 +959,8 @@ func (b *LocalBackend) SetWantRunning(wantRunning bool) {
// SetPrefs saves new user preferences and propagates them throughout // SetPrefs saves new user preferences and propagates them throughout
// the system. Implements Backend. // the system. Implements Backend.
func (b *LocalBackend) SetPrefs(new *Prefs) { func (b *LocalBackend) SetPrefs(newp *Prefs) {
if new == nil { if newp == nil {
panic("SetPrefs got nil prefs") panic("SetPrefs got nil prefs")
} }
@ -969,16 +969,16 @@ func (b *LocalBackend) SetPrefs(new *Prefs) {
netMap := b.netMap netMap := b.netMap
stateKey := b.stateKey stateKey := b.stateKey
old := b.prefs oldp := b.prefs
new.Persist = old.Persist // caller isn't allowed to override this newp.Persist = oldp.Persist // caller isn't allowed to override this
b.prefs = new b.prefs = newp
// We do this to avoid holding the lock while doing everything else. // We do this to avoid holding the lock while doing everything else.
new = b.prefs.Clone() newp = b.prefs.Clone()
oldHi := b.hostinfo oldHi := b.hostinfo
newHi := oldHi.Clone() newHi := oldHi.Clone()
newHi.RoutableIPs = append([]wgcfg.CIDR(nil), b.prefs.AdvertiseRoutes...) newHi.RoutableIPs = append([]wgcfg.CIDR(nil), b.prefs.AdvertiseRoutes...)
applyPrefsToHostinfo(newHi, new) applyPrefsToHostinfo(newHi, newp)
b.hostinfo = newHi b.hostinfo = newHi
hostInfoChanged := !oldHi.Equal(newHi) hostInfoChanged := !oldHi.Equal(newHi)
userID := b.userID userID := b.userID
@ -986,12 +986,12 @@ func (b *LocalBackend) SetPrefs(new *Prefs) {
b.mu.Unlock() b.mu.Unlock()
if stateKey != "" { if stateKey != "" {
if err := b.store.WriteState(stateKey, new.ToBytes()); err != nil { if err := b.store.WriteState(stateKey, newp.ToBytes()); err != nil {
b.logf("Failed to save new controlclient state: %v", err) b.logf("Failed to save new controlclient state: %v", err)
} }
} }
if userID != "" { // e.g. on Windows if userID != "" { // e.g. on Windows
if new.ForceDaemon { if newp.ForceDaemon {
stateKey := StateKey("user-" + userID) stateKey := StateKey("user-" + userID)
if err := b.store.WriteState(ServerModeStartKey, []byte(stateKey)); err != nil { if err := b.store.WriteState(ServerModeStartKey, []byte(stateKey)); err != nil {
b.logf("WriteState error: %v", err) b.logf("WriteState error: %v", err)
@ -1001,7 +1001,7 @@ func (b *LocalBackend) SetPrefs(new *Prefs) {
// check block above. That one won't fire in the case // check block above. That one won't fire in the case
// where the Windows client started up in client mode. // where the Windows client started up in client mode.
// This happens when we transition into server mode: // This happens when we transition into server mode:
if err := b.store.WriteState(stateKey, new.ToBytes()); err != nil { if err := b.store.WriteState(stateKey, newp.ToBytes()); err != nil {
b.logf("WriteState error: %v", err) b.logf("WriteState error: %v", err)
} }
} else { } else {
@ -1012,25 +1012,25 @@ func (b *LocalBackend) SetPrefs(new *Prefs) {
} }
// [GRINDER STATS LINE] - please don't remove (used for log parsing) // [GRINDER STATS LINE] - please don't remove (used for log parsing)
b.logf("SetPrefs: %v", new.Pretty()) b.logf("SetPrefs: %v", newp.Pretty())
if old.ShieldsUp != new.ShieldsUp || hostInfoChanged { if oldp.ShieldsUp != newp.ShieldsUp || hostInfoChanged {
b.doSetHostinfoFilterServices(newHi) b.doSetHostinfoFilterServices(newHi)
} }
b.updateFilter(netMap, new) b.updateFilter(netMap, newp)
if netMap != nil { if netMap != nil {
b.e.SetDERPMap(netMap.DERPMap) b.e.SetDERPMap(netMap.DERPMap)
} }
if old.WantRunning != new.WantRunning { if oldp.WantRunning != newp.WantRunning {
b.stateMachine() b.stateMachine()
} else { } else {
b.authReconfig() b.authReconfig()
} }
b.send(Notify{Prefs: new}) b.send(Notify{Prefs: newp})
} }
// doSetHostinfoFilterServices calls SetHostinfo on the controlclient, // doSetHostinfoFilterServices calls SetHostinfo on the controlclient,

Loading…
Cancel
Save