mirror of
https://github.com/tailscale/tailscale.git
synced 2025-08-12 05:37:32 +00:00
net/sockstats: remove explicit dependency on wgengine/monitor
Followup to #7177 to avoid adding extra dependencies to the CLI. We instead declare an interface for the link monitor. Signed-off-by: Mihai Parparita <mihai@tailscale.com>
This commit is contained in:
@@ -353,6 +353,12 @@ func (s *State) String() string {
|
||||
return sb.String()
|
||||
}
|
||||
|
||||
// ChangeFunc is a callback function (usually registered with
|
||||
// wgengine/monitor's Mon) that's called when the network
|
||||
// changed. The changed parameter is whether the network changed
|
||||
// enough for State to have changed since the last callback.
|
||||
type ChangeFunc func(changed bool, state *State)
|
||||
|
||||
// An InterfaceFilter indicates whether EqualFiltered should use i when deciding whether two States are equal.
|
||||
// ips are all the IPPrefixes associated with i.
|
||||
type InterfaceFilter func(i Interface, ips []netip.Prefix) bool
|
||||
|
@@ -11,7 +11,7 @@ package sockstats
|
||||
import (
|
||||
"context"
|
||||
|
||||
"tailscale.com/wgengine/monitor"
|
||||
"tailscale.com/net/interfaces"
|
||||
)
|
||||
|
||||
type SockStats struct {
|
||||
@@ -34,6 +34,13 @@ func Get() *SockStats {
|
||||
return get()
|
||||
}
|
||||
|
||||
func SetLinkMonitor(lm *monitor.Mon) {
|
||||
// LinkMonitor is the interface for the parts of wgengine/mointor's Mon that we
|
||||
// need, to avoid the dependency.
|
||||
type LinkMonitor interface {
|
||||
InterfaceState() *interfaces.State
|
||||
RegisterChangeCallback(interfaces.ChangeFunc) (unregister func())
|
||||
}
|
||||
|
||||
func SetLinkMonitor(lm LinkMonitor) {
|
||||
setLinkMonitor(lm)
|
||||
}
|
||||
|
@@ -7,8 +7,6 @@ package sockstats
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"tailscale.com/wgengine/monitor"
|
||||
)
|
||||
|
||||
func withSockStats(ctx context.Context, label string) context.Context {
|
||||
@@ -19,5 +17,5 @@ func get() *SockStats {
|
||||
return nil
|
||||
}
|
||||
|
||||
func setLinkMonitor(lm *monitor.Mon) {
|
||||
func setLinkMonitor(lm LinkMonitor) {
|
||||
}
|
||||
|
@@ -13,7 +13,6 @@ import (
|
||||
"sync/atomic"
|
||||
|
||||
"tailscale.com/net/interfaces"
|
||||
"tailscale.com/wgengine/monitor"
|
||||
)
|
||||
|
||||
type sockStatCounters struct {
|
||||
@@ -113,7 +112,7 @@ func get() *SockStats {
|
||||
return r
|
||||
}
|
||||
|
||||
func setLinkMonitor(lm *monitor.Mon) {
|
||||
func setLinkMonitor(lm LinkMonitor) {
|
||||
sockStats.mu.Lock()
|
||||
defer sockStats.mu.Unlock()
|
||||
|
||||
|
Reference in New Issue
Block a user