Make ipn.Options.Prefs a pointer.
This is a prelude to making it truly optional, once state management has moved into the backend. For now though, it's still required. This change is just isolating the bubbling-up of the pointerification into other layers. Signed-Off-By: David Anderson <dave@natulte.net>pull/10/head
parent
f6f154193f
commit
21280ca2d1
|
@ -90,7 +90,7 @@ func main() {
|
|||
|
||||
bc := ipn.NewBackendClient(log.Printf, clientToServer)
|
||||
opts := ipn.Options{
|
||||
Prefs: prefs,
|
||||
Prefs: &prefs,
|
||||
ServerURL: *server,
|
||||
Notify: func(n ipn.Notify) {
|
||||
log.Printf("Notify: %v\n", n)
|
||||
|
|
|
@ -53,7 +53,7 @@ type Notify struct {
|
|||
type Options struct {
|
||||
FrontendLogID string // public logtail id used by frontend
|
||||
ServerURL string
|
||||
Prefs Prefs
|
||||
Prefs *Prefs
|
||||
Notify func(n Notify) `json:"-"`
|
||||
}
|
||||
|
||||
|
|
|
@ -170,7 +170,7 @@ func newNode(t *testing.T, prefix string, https *httptest.Server) testNode {
|
|||
n.Start(Options{
|
||||
FrontendLogID: prefix + "-f",
|
||||
ServerURL: https.URL,
|
||||
Prefs: Prefs{
|
||||
Prefs: &Prefs{
|
||||
RouteAll: true,
|
||||
AllowSingleHosts: true,
|
||||
CorpDNS: true,
|
||||
|
|
|
@ -21,7 +21,7 @@ func (b *FakeBackend) Start(opts Options) error {
|
|||
log.Fatalf("FakeBackend.Start: opts.Notify is nil\n")
|
||||
}
|
||||
b.notify = opts.Notify
|
||||
b.notify(Notify{Prefs: &opts.Prefs})
|
||||
b.notify(Notify{Prefs: opts.Prefs})
|
||||
nl := NeedsLogin
|
||||
b.notify(Notify{State: &nl})
|
||||
return nil
|
||||
|
|
|
@ -49,7 +49,9 @@ func (h *Handle) Start(opts Options) error {
|
|||
h.netmapCache = nil
|
||||
h.engineStatusCache = EngineStatus{}
|
||||
h.stateCache = NoState
|
||||
h.prefsCache = opts.Prefs
|
||||
if opts.Prefs != nil {
|
||||
h.prefsCache = *opts.Prefs
|
||||
}
|
||||
xopts := opts
|
||||
xopts.Notify = h.notify
|
||||
return h.b.Start(xopts)
|
||||
|
|
|
@ -53,7 +53,6 @@ type LocalBackend struct {
|
|||
}
|
||||
|
||||
func NewLocalBackend(logf logger.Logf, logid string, e wgengine.Engine) (*LocalBackend, error) {
|
||||
|
||||
if e == nil {
|
||||
panic("ipn.NewLocalBackend: wgengine must not be nil")
|
||||
}
|
||||
|
@ -114,6 +113,10 @@ func (b *LocalBackend) SetCmpDiff(cmpDiff func(x, y interface{}) string) {
|
|||
}
|
||||
|
||||
func (b *LocalBackend) Start(opts Options) error {
|
||||
if opts.Prefs == nil {
|
||||
panic("Prefs can't be nil yet")
|
||||
}
|
||||
|
||||
if b.c != nil {
|
||||
// TODO(apenwarr): avoid the need to reinit controlclient.
|
||||
// This will trigger a full relogin/reconfigure cycle every
|
||||
|
@ -136,7 +139,9 @@ func (b *LocalBackend) Start(opts Options) error {
|
|||
b.hiCache = hi
|
||||
b.state = NoState
|
||||
b.serverURL = opts.ServerURL
|
||||
b.prefs = opts.Prefs
|
||||
if opts.Prefs != nil {
|
||||
b.prefs = *opts.Prefs
|
||||
}
|
||||
b.notify = opts.Notify
|
||||
b.netMapCache = nil
|
||||
b.mu.Unlock()
|
||||
|
|
|
@ -96,6 +96,7 @@ func TestClientServer(t *testing.T) {
|
|||
ch := make(chan Notify, 256)
|
||||
h, err := NewHandle(bc, clogf, Options{
|
||||
ServerURL: "http://example.com/fake",
|
||||
Prefs: &Prefs{},
|
||||
Notify: func(n Notify) {
|
||||
ch <- n
|
||||
},
|
||||
|
|
|
@ -103,7 +103,7 @@ func (uc *Prefs) Copy() *Prefs {
|
|||
return &uc2
|
||||
}
|
||||
|
||||
func LoadPrefs(filename string, enforceDefaults bool) Prefs {
|
||||
func LoadPrefs(filename string, enforceDefaults bool) *Prefs {
|
||||
log.Printf("Loading prefs %v\n", filename)
|
||||
data, err := ioutil.ReadFile(filename)
|
||||
uc := NewPrefs()
|
||||
|
@ -136,7 +136,7 @@ post:
|
|||
uc.WantRunning = true
|
||||
}
|
||||
log.Printf("Loaded prefs %v %v\n", filename, uc.Pretty())
|
||||
return uc
|
||||
return &uc
|
||||
}
|
||||
|
||||
func SavePrefs(filename string, uc *Prefs) {
|
||||
|
|
Loading…
Reference in New Issue