magicsock, wgengine, ipn, controlclient: plumb regular netchecks to map poll
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
committed by
Brad Fitzpatrick
parent
4cf5ac3060
commit
b27d4c017a
@@ -260,6 +260,17 @@ type NetInfo struct {
|
||||
// WorkingUDP is whether UDP works.
|
||||
WorkingUDP opt.Bool
|
||||
|
||||
// PreferredDERP is this node's preferred DERP server
|
||||
// for incoming traffic. The node might be be temporarily
|
||||
// connected to multiple DERP servers (to send to other nodes)
|
||||
// but PreferredDERP is the instance number that the node
|
||||
// subscribes to traffic at.
|
||||
// Zero means disconnected or unknown.
|
||||
PreferredDERP int
|
||||
|
||||
// LinkType is the current link type, if known.
|
||||
LinkType string // "wired", "wifi", "mobile" (LTE, 4G, 3G, etc)
|
||||
|
||||
// DERPLatency is the fastest recent time to reach various
|
||||
// DERP STUN servers, in seconds. The map key is the DERP
|
||||
// server's STUN host:port.
|
||||
@@ -268,6 +279,25 @@ type NetInfo struct {
|
||||
// material change, as any change here also gets uploaded to
|
||||
// the control plane.
|
||||
DERPLatency map[string]float64 `json:",omitempty"`
|
||||
|
||||
// Update Clone and BasicallyEqual when adding fields.
|
||||
}
|
||||
|
||||
// BasicallyEqual reports whether ni and ni2 are basically equal, ignoring
|
||||
// changes in DERPLatency.
|
||||
func (ni *NetInfo) BasicallyEqual(ni2 *NetInfo) bool {
|
||||
if (ni == nil) != (ni2 == nil) {
|
||||
return false
|
||||
}
|
||||
if ni == nil {
|
||||
return true
|
||||
}
|
||||
return ni.MappingVariesByDestIP == ni2.MappingVariesByDestIP &&
|
||||
ni.HairPinning == ni2.HairPinning &&
|
||||
ni.WorkingIPv6 == ni2.WorkingIPv6 &&
|
||||
ni.WorkingUDP == ni2.WorkingUDP &&
|
||||
ni.PreferredDERP == ni2.PreferredDERP &&
|
||||
ni.LinkType == ni2.LinkType
|
||||
}
|
||||
|
||||
func (ni *NetInfo) Clone() (res *NetInfo) {
|
||||
|
||||
@@ -304,3 +304,19 @@ func TestNodeEqual(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestNetInfoFields(t *testing.T) {
|
||||
handled := []string{
|
||||
"MappingVariesByDestIP",
|
||||
"HairPinning",
|
||||
"WorkingIPv6",
|
||||
"WorkingUDP",
|
||||
"PreferredDERP",
|
||||
"LinkType",
|
||||
"DERPLatency",
|
||||
}
|
||||
if have := fieldsOf(reflect.TypeOf(NetInfo{})); !reflect.DeepEqual(have, handled) {
|
||||
t.Errorf("NetInfo.Clone/BasicallyEqually check might be out of sync\nfields: %q\nhandled: %q\n",
|
||||
have, handled)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user