@ -1623,7 +1623,6 @@ func (b *LocalBackend) startIsNoopLocked(opts ipn.Options) bool {
return b . state == ipn . Running &&
return b . state == ipn . Running &&
b . hostinfo != nil &&
b . hostinfo != nil &&
b . hostinfo . FrontendLogID == opts . FrontendLogID &&
b . hostinfo . FrontendLogID == opts . FrontendLogID &&
opts . LegacyMigrationPrefs == nil &&
opts . UpdatePrefs == nil &&
opts . UpdatePrefs == nil &&
opts . AuthKey == ""
opts . AuthKey == ""
}
}
@ -1639,28 +1638,15 @@ func (b *LocalBackend) startIsNoopLocked(opts ipn.Options) bool {
// actually a supported operation (it should be, but it's very unclear
// actually a supported operation (it should be, but it's very unclear
// from the following whether or not that is a safe transition).
// from the following whether or not that is a safe transition).
func ( b * LocalBackend ) Start ( opts ipn . Options ) error {
func ( b * LocalBackend ) Start ( opts ipn . Options ) error {
if opts . LegacyMigrationPrefs != nil {
b . logf ( "Start" )
b . logf ( "Start: %v" , opts . LegacyMigrationPrefs . Pretty ( ) )
} else {
b . logf ( "Start" )
}
b . mu . Lock ( )
b . mu . Lock ( )
if opts . LegacyMigrationPrefs == nil && ! b . pm . CurrentPrefs ( ) . Valid ( ) {
b . mu . Unlock ( )
return errors . New ( "no prefs provided" )
}
if opts . UpdatePrefs != nil {
if opts . UpdatePrefs != nil {
if err := b . checkPrefsLocked ( opts . UpdatePrefs ) ; err != nil {
if err := b . checkPrefsLocked ( opts . UpdatePrefs ) ; err != nil {
b . mu . Unlock ( )
b . mu . Unlock ( )
return err
return err
}
}
} else if opts . LegacyMigrationPrefs != nil {
if err := b . checkPrefsLocked ( opts . LegacyMigrationPrefs ) ; err != nil {
b . mu . Unlock ( )
return err
}
}
}
profileID := b . pm . CurrentProfile ( ) . ID
profileID := b . pm . CurrentProfile ( ) . ID
if b . state != ipn . Running && b . conf != nil && b . conf . Parsed . AuthKey != nil && opts . AuthKey == "" {
if b . state != ipn . Running && b . conf != nil && b . conf . Parsed . AuthKey != nil && opts . AuthKey == "" {
@ -1720,11 +1706,6 @@ func (b *LocalBackend) Start(opts ipn.Options) error {
b . hostinfo = hostinfo
b . hostinfo = hostinfo
b . state = ipn . NoState
b . state = ipn . NoState
if err := b . migrateStateLocked ( opts . LegacyMigrationPrefs ) ; err != nil {
b . mu . Unlock ( )
return fmt . Errorf ( "loading requested state: %v" , err )
}
if opts . UpdatePrefs != nil {
if opts . UpdatePrefs != nil {
oldPrefs := b . pm . CurrentPrefs ( )
oldPrefs := b . pm . CurrentPrefs ( )
newPrefs := opts . UpdatePrefs . Clone ( )
newPrefs := opts . UpdatePrefs . Clone ( )
@ -1737,6 +1718,8 @@ func (b *LocalBackend) Start(opts ipn.Options) error {
b . logf ( "failed to save UpdatePrefs state: %v" , err )
b . logf ( "failed to save UpdatePrefs state: %v" , err )
}
}
b . setAtomicValuesFromPrefsLocked ( pv )
b . setAtomicValuesFromPrefsLocked ( pv )
} else {
b . setAtomicValuesFromPrefsLocked ( b . pm . CurrentPrefs ( ) )
}
}
prefs := b . pm . CurrentPrefs ( )
prefs := b . pm . CurrentPrefs ( )
@ -1799,9 +1782,9 @@ func (b *LocalBackend) Start(opts ipn.Options) error {
}
}
// TODO(apenwarr): The only way to change the ServerURL is to
// TODO(apenwarr): The only way to change the ServerURL is to
// re-run b.Start () , because this is the only place we create a
// re-run b.Start , because this is the only place we create a
// new controlclient. SetPrefs() allows you to overwrite ServerURL,
// new controlclient. EditPrefs allows you to overwrite ServerURL,
// but it won't take effect until the next Start () .
// but it won't take effect until the next Start .
cc , err := b . getNewControlClientFunc ( ) ( controlclient . Options {
cc , err := b . getNewControlClientFunc ( ) ( controlclient . Options {
GetMachinePrivateKey : b . createGetMachinePrivateKeyFunc ( ) ,
GetMachinePrivateKey : b . createGetMachinePrivateKeyFunc ( ) ,
Logf : logger . WithPrefix ( b . logf , "control: " ) ,
Logf : logger . WithPrefix ( b . logf , "control: " ) ,
@ -2681,30 +2664,6 @@ func (b *LocalBackend) clearMachineKeyLocked() error {
return nil
return nil
}
}
// migrateStateLocked migrates state from the frontend to the backend.
// It is a no-op if prefs is nil
// b.mu must be held.
func ( b * LocalBackend ) migrateStateLocked ( prefs * ipn . Prefs ) ( err error ) {
if prefs == nil && ! b . pm . CurrentPrefs ( ) . Valid ( ) {
return fmt . Errorf ( "no prefs provided and no current profile" )
}
if prefs != nil {
// Backend owns the state, but frontend is trying to migrate
// state into the backend.
b . logf ( "importing frontend prefs into backend store; frontend prefs: %s" , prefs . Pretty ( ) )
if err := b . pm . SetPrefs ( prefs . View ( ) , ipn . NetworkProfile {
MagicDNSName : b . netMap . MagicDNSSuffix ( ) ,
DomainName : b . netMap . DomainName ( ) ,
} ) ; err != nil {
return fmt . Errorf ( "store.WriteState: %v" , err )
}
}
b . setAtomicValuesFromPrefsLocked ( b . pm . CurrentPrefs ( ) )
return nil
}
// setTCPPortsIntercepted populates b.shouldInterceptTCPPortAtomic with an
// setTCPPortsIntercepted populates b.shouldInterceptTCPPortAtomic with an
// efficient func for ShouldInterceptTCPPort to use, which is called on every
// efficient func for ShouldInterceptTCPPort to use, which is called on every
// incoming packet.
// incoming packet.