mirror of
https://github.com/tailscale/tailscale.git
synced 2025-01-05 23:07:44 +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:
parent
7b73c9628d
commit
3e71e0ef68
@ -12,7 +12,7 @@ tailscale.com/cmd/derper dependencies: (generated by github.com/tailscale/depawa
|
||||
github.com/golang/groupcache/lru from tailscale.com/net/dnscache
|
||||
github.com/hdevalence/ed25519consensus from tailscale.com/tka
|
||||
L github.com/josharian/native from github.com/mdlayher/netlink+
|
||||
L 💣 github.com/jsimonetti/rtnetlink from tailscale.com/net/interfaces+
|
||||
L 💣 github.com/jsimonetti/rtnetlink from tailscale.com/net/interfaces
|
||||
L github.com/jsimonetti/rtnetlink/internal/unix from github.com/jsimonetti/rtnetlink
|
||||
github.com/klauspost/compress/flate from nhooyr.io/websocket
|
||||
L 💣 github.com/mdlayher/netlink from github.com/jsimonetti/rtnetlink+
|
||||
@ -85,14 +85,13 @@ tailscale.com/cmd/derper dependencies: (generated by github.com/tailscale/depawa
|
||||
tailscale.com/util/lineread from tailscale.com/hostinfo+
|
||||
tailscale.com/util/mak from tailscale.com/syncs+
|
||||
tailscale.com/util/multierr from tailscale.com/health
|
||||
tailscale.com/util/set from tailscale.com/health+
|
||||
tailscale.com/util/set from tailscale.com/health
|
||||
tailscale.com/util/singleflight from tailscale.com/net/dnscache
|
||||
tailscale.com/util/vizerror from tailscale.com/tsweb
|
||||
W 💣 tailscale.com/util/winutil from tailscale.com/hostinfo+
|
||||
tailscale.com/version from tailscale.com/derp+
|
||||
tailscale.com/version/distro from tailscale.com/hostinfo+
|
||||
tailscale.com/wgengine/filter from tailscale.com/types/netmap
|
||||
tailscale.com/wgengine/monitor from tailscale.com/net/sockstats
|
||||
golang.org/x/crypto/acme from golang.org/x/crypto/acme/autocert
|
||||
golang.org/x/crypto/acme/autocert from tailscale.com/cmd/derper
|
||||
golang.org/x/crypto/argon2 from tailscale.com/tka
|
||||
|
@ -13,7 +13,7 @@ tailscale.com/cmd/tailscale dependencies: (generated by github.com/tailscale/dep
|
||||
github.com/google/uuid from tailscale.com/util/quarantine+
|
||||
github.com/hdevalence/ed25519consensus from tailscale.com/tka
|
||||
L github.com/josharian/native from github.com/mdlayher/netlink+
|
||||
L 💣 github.com/jsimonetti/rtnetlink from tailscale.com/net/interfaces+
|
||||
L 💣 github.com/jsimonetti/rtnetlink from tailscale.com/net/interfaces
|
||||
L github.com/jsimonetti/rtnetlink/internal/unix from github.com/jsimonetti/rtnetlink
|
||||
github.com/kballard/go-shellquote from tailscale.com/cmd/tailscale/cli
|
||||
github.com/klauspost/compress/flate from nhooyr.io/websocket
|
||||
@ -127,7 +127,6 @@ tailscale.com/cmd/tailscale dependencies: (generated by github.com/tailscale/dep
|
||||
tailscale.com/version/distro from tailscale.com/cmd/tailscale/cli+
|
||||
tailscale.com/wgengine/capture from tailscale.com/cmd/tailscale/cli
|
||||
tailscale.com/wgengine/filter from tailscale.com/types/netmap
|
||||
tailscale.com/wgengine/monitor from tailscale.com/net/sockstats
|
||||
golang.org/x/crypto/argon2 from tailscale.com/tka
|
||||
golang.org/x/crypto/blake2b from golang.org/x/crypto/nacl/box+
|
||||
golang.org/x/crypto/blake2s from tailscale.com/control/controlbase+
|
||||
|
@ -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 @@
|
||||
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 @@
|
||||
|
||||
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 @@
|
||||
"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()
|
||||
|
||||
|
@ -48,12 +48,6 @@ type osMon interface {
|
||||
IsInterestingInterface(iface string) bool
|
||||
}
|
||||
|
||||
// ChangeFunc is a callback function that's called when the network
|
||||
// changed. The changed parameter is whether the network changed
|
||||
// enough for interfaces.State to have changed since the last
|
||||
// callback.
|
||||
type ChangeFunc func(changed bool, state *interfaces.State)
|
||||
|
||||
// Mon represents a monitoring instance.
|
||||
type Mon struct {
|
||||
logf logger.Logf
|
||||
@ -62,7 +56,7 @@ type Mon struct {
|
||||
stop chan struct{} // closed on Stop
|
||||
|
||||
mu sync.Mutex // guards all following fields
|
||||
cbs set.HandleSet[ChangeFunc]
|
||||
cbs set.HandleSet[interfaces.ChangeFunc]
|
||||
ruleDelCB set.HandleSet[RuleDeleteCallback]
|
||||
ifState *interfaces.State
|
||||
gwValid bool // whether gw and gwSelfIP are valid
|
||||
@ -139,7 +133,7 @@ func (m *Mon) GatewayAndSelfIP() (gw, myIP netip.Addr, ok bool) {
|
||||
// RegisterChangeCallback adds callback to the set of parties to be
|
||||
// notified (in their own goroutine) when the network state changes.
|
||||
// To remove this callback, call unregister (or close the monitor).
|
||||
func (m *Mon) RegisterChangeCallback(callback ChangeFunc) (unregister func()) {
|
||||
func (m *Mon) RegisterChangeCallback(callback interfaces.ChangeFunc) (unregister func()) {
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
handle := m.cbs.Add(callback)
|
||||
|
Loading…
x
Reference in New Issue
Block a user