ipn: add Hostname override to Prefs
Overriding the hostname is required for Android, where os.Hostname is often just "localhost". Updates #409 Signed-off-by: Elias Naur <mail@eliasnaur.com>reviewable/pr430/r1
parent
73c40c77b0
commit
364a8508b2
|
@ -654,6 +654,9 @@ func (b *LocalBackend) SetPrefs(new *Prefs) {
|
||||||
oldHi := b.hiCache
|
oldHi := b.hiCache
|
||||||
newHi := oldHi.Clone()
|
newHi := oldHi.Clone()
|
||||||
newHi.RoutableIPs = append([]wgcfg.CIDR(nil), b.prefs.AdvertiseRoutes...)
|
newHi.RoutableIPs = append([]wgcfg.CIDR(nil), b.prefs.AdvertiseRoutes...)
|
||||||
|
if h := new.Hostname; h != "" {
|
||||||
|
newHi.Hostname = h
|
||||||
|
}
|
||||||
b.hiCache = newHi
|
b.hiCache = newHi
|
||||||
b.mu.Unlock()
|
b.mu.Unlock()
|
||||||
|
|
||||||
|
|
|
@ -51,6 +51,9 @@ type Prefs struct {
|
||||||
// the control server will allow you to take on the rights for that
|
// the control server will allow you to take on the rights for that
|
||||||
// tag.
|
// tag.
|
||||||
AdvertiseTags []string
|
AdvertiseTags []string
|
||||||
|
// Hostname is the hostname to use for identifying the node. If
|
||||||
|
// not set, os.Hostname is used.
|
||||||
|
Hostname string
|
||||||
|
|
||||||
// NotepadURLs is a debugging setting that opens OAuth URLs in
|
// NotepadURLs is a debugging setting that opens OAuth URLs in
|
||||||
// notepad.exe on Windows, rather than loading them in a browser.
|
// notepad.exe on Windows, rather than loading them in a browser.
|
||||||
|
@ -134,6 +137,7 @@ func (p *Prefs) Equals(p2 *Prefs) bool {
|
||||||
p.ShieldsUp == p2.ShieldsUp &&
|
p.ShieldsUp == p2.ShieldsUp &&
|
||||||
p.NoSNAT == p2.NoSNAT &&
|
p.NoSNAT == p2.NoSNAT &&
|
||||||
p.NetfilterMode == p2.NetfilterMode &&
|
p.NetfilterMode == p2.NetfilterMode &&
|
||||||
|
p.Hostname == p2.Hostname &&
|
||||||
compareIPNets(p.AdvertiseRoutes, p2.AdvertiseRoutes) &&
|
compareIPNets(p.AdvertiseRoutes, p2.AdvertiseRoutes) &&
|
||||||
compareStrings(p.AdvertiseTags, p2.AdvertiseTags) &&
|
compareStrings(p.AdvertiseTags, p2.AdvertiseTags) &&
|
||||||
p.Persist.Equals(p2.Persist)
|
p.Persist.Equals(p2.Persist)
|
||||||
|
|
|
@ -24,7 +24,7 @@ func fieldsOf(t reflect.Type) (fields []string) {
|
||||||
func TestPrefsEqual(t *testing.T) {
|
func TestPrefsEqual(t *testing.T) {
|
||||||
tstest.PanicOnLog()
|
tstest.PanicOnLog()
|
||||||
|
|
||||||
prefsHandles := []string{"ControlURL", "RouteAll", "AllowSingleHosts", "CorpDNS", "WantRunning", "ShieldsUp", "AdvertiseTags", "NotepadURLs", "DisableDERP", "AdvertiseRoutes", "NoSNAT", "NetfilterMode", "Persist"}
|
prefsHandles := []string{"ControlURL", "RouteAll", "AllowSingleHosts", "CorpDNS", "WantRunning", "ShieldsUp", "AdvertiseTags", "Hostname", "NotepadURLs", "DisableDERP", "AdvertiseRoutes", "NoSNAT", "NetfilterMode", "Persist"}
|
||||||
if have := fieldsOf(reflect.TypeOf(Prefs{})); !reflect.DeepEqual(have, prefsHandles) {
|
if have := fieldsOf(reflect.TypeOf(Prefs{})); !reflect.DeepEqual(have, prefsHandles) {
|
||||||
t.Errorf("Prefs.Equal check might be out of sync\nfields: %q\nhandled: %q\n",
|
t.Errorf("Prefs.Equal check might be out of sync\nfields: %q\nhandled: %q\n",
|
||||||
have, prefsHandles)
|
have, prefsHandles)
|
||||||
|
@ -126,6 +126,17 @@ func TestPrefsEqual(t *testing.T) {
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
&Prefs{Hostname: "android-host01"},
|
||||||
|
&Prefs{Hostname: "android-host02"},
|
||||||
|
false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
&Prefs{Hostname: ""},
|
||||||
|
&Prefs{Hostname: ""},
|
||||||
|
true,
|
||||||
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
&Prefs{NotepadURLs: true},
|
&Prefs{NotepadURLs: true},
|
||||||
&Prefs{NotepadURLs: false},
|
&Prefs{NotepadURLs: false},
|
||||||
|
|
Loading…
Reference in New Issue