@ -5,7 +5,6 @@
package ipn
package ipn
import (
import (
"log"
"time"
"time"
"tailscale.com/ipn/ipnstate"
"tailscale.com/ipn/ipnstate"
@ -21,18 +20,28 @@ type FakeBackend struct {
func ( b * FakeBackend ) Start ( opts Options ) error {
func ( b * FakeBackend ) Start ( opts Options ) error {
b . serverURL = opts . Prefs . ControlURL
b . serverURL = opts . Prefs . ControlURL
if opts. N otify == nil {
if b. n otify == nil {
log . Fatalf ( "FakeBackend.Start: opts.Notify is nil\n ")
panic ( "FakeBackend.Start: SetNotifyCallback not called ")
}
}
b . notify = opts . Notify
b . notify ( Notify { Prefs : opts . Prefs } )
nl := NeedsLogin
nl := NeedsLogin
if b . notify != nil {
b . notify ( Notify { Prefs : opts . Prefs } )
b . notify ( Notify { State : & nl } )
b . notify ( Notify { State : & nl } )
}
return nil
return nil
}
}
func ( b * FakeBackend ) SetNotifyCallback ( notify func ( Notify ) ) {
if notify == nil {
panic ( "FakeBackend.SetNotifyCallback: notify is nil" )
}
b . notify = notify
}
func ( b * FakeBackend ) newState ( s State ) {
func ( b * FakeBackend ) newState ( s State ) {
if b . notify != nil {
b . notify ( Notify { State : & s } )
b . notify ( Notify { State : & s } )
}
if s == Running {
if s == Running {
b . live = true
b . live = true
} else {
} else {
@ -42,7 +51,9 @@ func (b *FakeBackend) newState(s State) {
func ( b * FakeBackend ) StartLoginInteractive ( ) {
func ( b * FakeBackend ) StartLoginInteractive ( ) {
u := b . serverURL + "/this/is/fake"
u := b . serverURL + "/this/is/fake"
if b . notify != nil {
b . notify ( Notify { BrowseToURL : & u } )
b . notify ( Notify { BrowseToURL : & u } )
}
b . login ( )
b . login ( )
}
}
@ -54,10 +65,14 @@ func (b *FakeBackend) login() {
b . newState ( NeedsMachineAuth )
b . newState ( NeedsMachineAuth )
b . newState ( Stopped )
b . newState ( Stopped )
// TODO(apenwarr): Fill in a more interesting netmap here.
// TODO(apenwarr): Fill in a more interesting netmap here.
if b . notify != nil {
b . notify ( Notify { NetMap : & netmap . NetworkMap { } } )
b . notify ( Notify { NetMap : & netmap . NetworkMap { } } )
}
b . newState ( Starting )
b . newState ( Starting )
// TODO(apenwarr): Fill in a more interesting status.
// TODO(apenwarr): Fill in a more interesting status.
if b . notify != nil {
b . notify ( Notify { Engine : & EngineStatus { } } )
b . notify ( Notify { Engine : & EngineStatus { } } )
}
b . newState ( Running )
b . newState ( Running )
}
}
@ -70,7 +85,9 @@ func (b *FakeBackend) SetPrefs(new *Prefs) {
panic ( "FakeBackend.SetPrefs got nil prefs" )
panic ( "FakeBackend.SetPrefs got nil prefs" )
}
}
if b . notify != nil {
b . notify ( Notify { Prefs : new . Clone ( ) } )
b . notify ( Notify { Prefs : new . Clone ( ) } )
}
if new . WantRunning && ! b . live {
if new . WantRunning && ! b . live {
b . newState ( Starting )
b . newState ( Starting )
b . newState ( Running )
b . newState ( Running )
@ -87,13 +104,19 @@ func (b *FakeBackend) EditPrefs(mp *MaskedPrefs) {
}
}
func ( b * FakeBackend ) RequestEngineStatus ( ) {
func ( b * FakeBackend ) RequestEngineStatus ( ) {
if b . notify != nil {
b . notify ( Notify { Engine : & EngineStatus { } } )
b . notify ( Notify { Engine : & EngineStatus { } } )
}
}
}
func ( b * FakeBackend ) FakeExpireAfter ( x time . Duration ) {
func ( b * FakeBackend ) FakeExpireAfter ( x time . Duration ) {
if b . notify != nil {
b . notify ( Notify { NetMap : & netmap . NetworkMap { } } )
b . notify ( Notify { NetMap : & netmap . NetworkMap { } } )
}
}
}
func ( b * FakeBackend ) Ping ( ip string , useTSMP bool ) {
func ( b * FakeBackend ) Ping ( ip string , useTSMP bool ) {
if b . notify != nil {
b . notify ( Notify { PingResult : & ipnstate . PingResult { } } )
b . notify ( Notify { PingResult : & ipnstate . PingResult { } } )
}
}
}