mirror of
https://github.com/tailscale/tailscale.git
synced 2025-08-11 13:18:53 +00:00
ipn/ipnlocal: keep internal map updated of latest Nodes post mutations
We have some flaky integration tests elsewhere that have no one place to ask about the state of the world. This makes LocalBackend be that place (as it's basically there anyway) but doesn't yet add the ForTest accessor method. This adds a LocalBackend.peers map[NodeID]NodeView that is incrementally updated as mutations arrive. And then we start moving away from using NetMap.Peers at runtime (UpdateStatus no longer uses it now). And remove another copy of NodeView in the LocalBackend nodeByAddr map. Change that to point into b.peers instead. Future changes will then start streaming whole-node-granularity peer change updates to WatchIPNBus clients, tracking statefully per client what each has seen. This will get the GUI clients from receiving less of a JSON storm of updates all the time. Updates #1909 Change-Id: I14a976ca9f493bdf02ba7e6e05217363dcf422e5 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:

committed by
Brad Fitzpatrick

parent
926c990a09
commit
9538e9f970
@@ -4,6 +4,7 @@
|
||||
package netmap
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/netip"
|
||||
"reflect"
|
||||
"slices"
|
||||
@@ -11,6 +12,7 @@ import (
|
||||
"time"
|
||||
|
||||
"tailscale.com/tailcfg"
|
||||
"tailscale.com/types/ptr"
|
||||
"tailscale.com/util/cmpx"
|
||||
)
|
||||
|
||||
@@ -18,6 +20,7 @@ import (
|
||||
// the change of a node's state.
|
||||
type NodeMutation interface {
|
||||
NodeIDBeingMutated() tailcfg.NodeID
|
||||
Apply(*tailcfg.Node)
|
||||
}
|
||||
|
||||
type mutatingNodeID tailcfg.NodeID
|
||||
@@ -31,12 +34,24 @@ type NodeMutationDERPHome struct {
|
||||
DERPRegion int
|
||||
}
|
||||
|
||||
func (m NodeMutationDERPHome) Apply(n *tailcfg.Node) {
|
||||
n.DERP = fmt.Sprintf("127.3.3.40:%v", m.DERPRegion)
|
||||
}
|
||||
|
||||
// NodeMutation is a NodeMutation that says a node's endpoints have changed.
|
||||
type NodeMutationEndpoints struct {
|
||||
mutatingNodeID
|
||||
Endpoints []netip.AddrPort
|
||||
}
|
||||
|
||||
func (m NodeMutationEndpoints) Apply(n *tailcfg.Node) {
|
||||
eps := make([]string, len(m.Endpoints))
|
||||
for i, ep := range m.Endpoints {
|
||||
eps[i] = ep.String()
|
||||
}
|
||||
n.Endpoints = eps
|
||||
}
|
||||
|
||||
// NodeMutationOnline is a NodeMutation that says a node is now online or
|
||||
// offline.
|
||||
type NodeMutationOnline struct {
|
||||
@@ -44,6 +59,10 @@ type NodeMutationOnline struct {
|
||||
Online bool
|
||||
}
|
||||
|
||||
func (m NodeMutationOnline) Apply(n *tailcfg.Node) {
|
||||
n.Online = ptr.To(m.Online)
|
||||
}
|
||||
|
||||
// NodeMutationLastSeen is a NodeMutation that says a node's LastSeen
|
||||
// value should be set to the current time.
|
||||
type NodeMutationLastSeen struct {
|
||||
@@ -51,6 +70,10 @@ type NodeMutationLastSeen struct {
|
||||
LastSeen time.Time
|
||||
}
|
||||
|
||||
func (m NodeMutationLastSeen) Apply(n *tailcfg.Node) {
|
||||
n.LastSeen = ptr.To(m.LastSeen)
|
||||
}
|
||||
|
||||
var peerChangeFields = sync.OnceValue(func() []reflect.StructField {
|
||||
var fields []reflect.StructField
|
||||
rt := reflect.TypeOf((*tailcfg.PeerChange)(nil)).Elem()
|
||||
|
Reference in New Issue
Block a user