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
David Anderson 5 years ago committed by Dave Anderson
parent f6f154193f
commit 21280ca2d1

@ -90,7 +90,7 @@ func main() {
bc := ipn.NewBackendClient(log.Printf, clientToServer) bc := ipn.NewBackendClient(log.Printf, clientToServer)
opts := ipn.Options{ opts := ipn.Options{
Prefs: prefs, Prefs: &prefs,
ServerURL: *server, ServerURL: *server,
Notify: func(n ipn.Notify) { Notify: func(n ipn.Notify) {
log.Printf("Notify: %v\n", n) log.Printf("Notify: %v\n", n)

@ -53,7 +53,7 @@ type Notify struct {
type Options struct { type Options struct {
FrontendLogID string // public logtail id used by frontend FrontendLogID string // public logtail id used by frontend
ServerURL string ServerURL string
Prefs Prefs Prefs *Prefs
Notify func(n Notify) `json:"-"` Notify func(n Notify) `json:"-"`
} }

@ -170,7 +170,7 @@ func newNode(t *testing.T, prefix string, https *httptest.Server) testNode {
n.Start(Options{ n.Start(Options{
FrontendLogID: prefix + "-f", FrontendLogID: prefix + "-f",
ServerURL: https.URL, ServerURL: https.URL,
Prefs: Prefs{ Prefs: &Prefs{
RouteAll: true, RouteAll: true,
AllowSingleHosts: true, AllowSingleHosts: true,
CorpDNS: true, CorpDNS: true,

@ -21,7 +21,7 @@ func (b *FakeBackend) Start(opts Options) error {
log.Fatalf("FakeBackend.Start: opts.Notify is nil\n") log.Fatalf("FakeBackend.Start: opts.Notify is nil\n")
} }
b.notify = opts.Notify b.notify = opts.Notify
b.notify(Notify{Prefs: &opts.Prefs}) b.notify(Notify{Prefs: opts.Prefs})
nl := NeedsLogin nl := NeedsLogin
b.notify(Notify{State: &nl}) b.notify(Notify{State: &nl})
return nil return nil

@ -49,7 +49,9 @@ func (h *Handle) Start(opts Options) error {
h.netmapCache = nil h.netmapCache = nil
h.engineStatusCache = EngineStatus{} h.engineStatusCache = EngineStatus{}
h.stateCache = NoState h.stateCache = NoState
h.prefsCache = opts.Prefs if opts.Prefs != nil {
h.prefsCache = *opts.Prefs
}
xopts := opts xopts := opts
xopts.Notify = h.notify xopts.Notify = h.notify
return h.b.Start(xopts) return h.b.Start(xopts)

@ -53,7 +53,6 @@ type LocalBackend struct {
} }
func NewLocalBackend(logf logger.Logf, logid string, e wgengine.Engine) (*LocalBackend, error) { func NewLocalBackend(logf logger.Logf, logid string, e wgengine.Engine) (*LocalBackend, error) {
if e == nil { if e == nil {
panic("ipn.NewLocalBackend: wgengine must not be 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 { func (b *LocalBackend) Start(opts Options) error {
if opts.Prefs == nil {
panic("Prefs can't be nil yet")
}
if b.c != nil { if b.c != nil {
// TODO(apenwarr): avoid the need to reinit controlclient. // TODO(apenwarr): avoid the need to reinit controlclient.
// This will trigger a full relogin/reconfigure cycle every // This will trigger a full relogin/reconfigure cycle every
@ -136,7 +139,9 @@ func (b *LocalBackend) Start(opts Options) error {
b.hiCache = hi b.hiCache = hi
b.state = NoState b.state = NoState
b.serverURL = opts.ServerURL b.serverURL = opts.ServerURL
b.prefs = opts.Prefs if opts.Prefs != nil {
b.prefs = *opts.Prefs
}
b.notify = opts.Notify b.notify = opts.Notify
b.netMapCache = nil b.netMapCache = nil
b.mu.Unlock() b.mu.Unlock()

@ -96,6 +96,7 @@ func TestClientServer(t *testing.T) {
ch := make(chan Notify, 256) ch := make(chan Notify, 256)
h, err := NewHandle(bc, clogf, Options{ h, err := NewHandle(bc, clogf, Options{
ServerURL: "http://example.com/fake", ServerURL: "http://example.com/fake",
Prefs: &Prefs{},
Notify: func(n Notify) { Notify: func(n Notify) {
ch <- n ch <- n
}, },

@ -103,7 +103,7 @@ func (uc *Prefs) Copy() *Prefs {
return &uc2 return &uc2
} }
func LoadPrefs(filename string, enforceDefaults bool) Prefs { func LoadPrefs(filename string, enforceDefaults bool) *Prefs {
log.Printf("Loading prefs %v\n", filename) log.Printf("Loading prefs %v\n", filename)
data, err := ioutil.ReadFile(filename) data, err := ioutil.ReadFile(filename)
uc := NewPrefs() uc := NewPrefs()
@ -136,7 +136,7 @@ post:
uc.WantRunning = true uc.WantRunning = true
} }
log.Printf("Loaded prefs %v %v\n", filename, uc.Pretty()) log.Printf("Loaded prefs %v %v\n", filename, uc.Pretty())
return uc return &uc
} }
func SavePrefs(filename string, uc *Prefs) { func SavePrefs(filename string, uc *Prefs) {

Loading…
Cancel
Save