mirror of
https://github.com/tailscale/tailscale.git
synced 2025-03-03 12:40:23 +00:00
tailcfg: add Hostinfo.BasicallyEqual
Change-Id: I4fd82dea9bb3618f3a93d8b2d2486f3eabbbd915 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
parent
0aa4c6f147
commit
850a603caa
@ -571,12 +571,31 @@ func (h *Hostinfo) Equal(h2 *Hostinfo) bool {
|
||||
if h == nil && h2 == nil {
|
||||
return true
|
||||
}
|
||||
if (h == nil) != (h2 == nil) {
|
||||
if h == nil || h2 == nil {
|
||||
return false
|
||||
}
|
||||
return reflect.DeepEqual(h, h2)
|
||||
}
|
||||
|
||||
// BasicallyEqual reports whether h and h2 are equal other than the
|
||||
// NetInfo DERP latency timing. (see NetInfo.BasicallyEqual).
|
||||
func (h *Hostinfo) BasicallyEqual(h2 *Hostinfo) bool {
|
||||
if h == nil && h2 == nil {
|
||||
return true
|
||||
}
|
||||
if h == nil || h2 == nil {
|
||||
return false
|
||||
}
|
||||
a := *h
|
||||
b := *h2
|
||||
if !a.NetInfo.BasicallyEqual(b.NetInfo) {
|
||||
return false
|
||||
}
|
||||
a.NetInfo = nil
|
||||
b.NetInfo = nil
|
||||
return a.Equal(&b)
|
||||
}
|
||||
|
||||
// SignatureType specifies a scheme for signing RegisterRequest messages. It
|
||||
// specifies the crypto algorithms to use, the contents of what is signed, and
|
||||
// any other relevant details. Historically, requests were unsigned so the zero
|
||||
|
@ -190,6 +190,75 @@ func TestHostinfoEqual(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestHostinfoBasicallyEqual(t *testing.T) {
|
||||
tests := []struct {
|
||||
a, b *Hostinfo
|
||||
want bool
|
||||
}{
|
||||
{
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
a: new(Hostinfo),
|
||||
b: new(Hostinfo),
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
a: &Hostinfo{},
|
||||
b: &Hostinfo{
|
||||
NetInfo: &NetInfo{},
|
||||
},
|
||||
want: false, // one's nil, the other's not
|
||||
},
|
||||
{
|
||||
a: &Hostinfo{
|
||||
NetInfo: &NetInfo{},
|
||||
},
|
||||
b: &Hostinfo{
|
||||
NetInfo: &NetInfo{},
|
||||
},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
a: &Hostinfo{
|
||||
NetInfo: &NetInfo{},
|
||||
},
|
||||
b: &Hostinfo{
|
||||
NetInfo: &NetInfo{
|
||||
DERPLatency: map[string]float64{ // ignored
|
||||
"1": 1.0,
|
||||
"2": 2.0,
|
||||
},
|
||||
},
|
||||
},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
a: &Hostinfo{
|
||||
NetInfo: &NetInfo{
|
||||
PreferredDERP: 1,
|
||||
},
|
||||
},
|
||||
b: &Hostinfo{
|
||||
NetInfo: &NetInfo{
|
||||
PreferredDERP: 2, // differs
|
||||
DERPLatency: map[string]float64{ // ignored
|
||||
"1": 1.0,
|
||||
"2": 2.0,
|
||||
},
|
||||
},
|
||||
},
|
||||
want: false,
|
||||
},
|
||||
}
|
||||
for i, tt := range tests {
|
||||
got := tt.a.BasicallyEqual(tt.b)
|
||||
if got != tt.want {
|
||||
t.Errorf("%d. BasicallyEqual = %v; want %v", i, got, tt.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestNodeEqual(t *testing.T) {
|
||||
nodeHandles := []string{
|
||||
"ID", "StableID", "Name", "User", "Sharer",
|
||||
|
Loading…
x
Reference in New Issue
Block a user