|
|
|
@ -111,15 +111,16 @@ type userspaceEngine struct {
|
|
|
|
|
sentActivityAt map[netaddr.IP]*int64 // value is atomic int64 of unixtime
|
|
|
|
|
destIPActivityFuncs map[netaddr.IP]func()
|
|
|
|
|
|
|
|
|
|
mu sync.Mutex // guards following; see lock order comment below
|
|
|
|
|
closing bool // Close was called (even if we're still closing)
|
|
|
|
|
statusCallback StatusCallback
|
|
|
|
|
linkChangeCallback func(major bool, newState *interfaces.State)
|
|
|
|
|
peerSequence []wgkey.Key
|
|
|
|
|
endpoints []string
|
|
|
|
|
pingers map[wgkey.Key]*pinger // legacy pingers for pre-discovery peers
|
|
|
|
|
linkState *interfaces.State
|
|
|
|
|
pendOpen map[flowtrack.Tuple]*pendingOpenFlow // see pendopen.go
|
|
|
|
|
mu sync.Mutex // guards following; see lock order comment below
|
|
|
|
|
closing bool // Close was called (even if we're still closing)
|
|
|
|
|
statusCallback StatusCallback
|
|
|
|
|
linkChangeCallback func(major bool, newState *interfaces.State)
|
|
|
|
|
peerSequence []wgkey.Key
|
|
|
|
|
endpoints []string
|
|
|
|
|
pingers map[wgkey.Key]*pinger // legacy pingers for pre-discovery peers
|
|
|
|
|
linkState *interfaces.State
|
|
|
|
|
pendOpen map[flowtrack.Tuple]*pendingOpenFlow // see pendopen.go
|
|
|
|
|
networkMapCallbacks map[*someHandle]NetworkMapCallback
|
|
|
|
|
|
|
|
|
|
// Lock ordering: magicsock.Conn.mu, wgLock, then mu.
|
|
|
|
|
}
|
|
|
|
@ -1290,6 +1291,21 @@ func (e *userspaceEngine) SetLinkChangeCallback(cb func(major bool, newState *in
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (e *userspaceEngine) AddNetworkMapCallback(cb NetworkMapCallback) func() {
|
|
|
|
|
e.mu.Lock()
|
|
|
|
|
defer e.mu.Unlock()
|
|
|
|
|
if e.networkMapCallbacks == nil {
|
|
|
|
|
e.networkMapCallbacks = make(map[*someHandle]NetworkMapCallback)
|
|
|
|
|
}
|
|
|
|
|
h := new(someHandle)
|
|
|
|
|
e.networkMapCallbacks[h] = cb
|
|
|
|
|
return func() {
|
|
|
|
|
e.mu.Lock()
|
|
|
|
|
defer e.mu.Unlock()
|
|
|
|
|
delete(e.networkMapCallbacks, h)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func getLinkState() (*interfaces.State, error) {
|
|
|
|
|
s, err := interfaces.GetState()
|
|
|
|
|
if s != nil {
|
|
|
|
@ -1308,6 +1324,15 @@ func (e *userspaceEngine) SetDERPMap(dm *tailcfg.DERPMap) {
|
|
|
|
|
|
|
|
|
|
func (e *userspaceEngine) SetNetworkMap(nm *controlclient.NetworkMap) {
|
|
|
|
|
e.magicConn.SetNetworkMap(nm)
|
|
|
|
|
e.mu.Lock()
|
|
|
|
|
callbacks := make([]NetworkMapCallback, 0, 4)
|
|
|
|
|
for _, fn := range e.networkMapCallbacks {
|
|
|
|
|
callbacks = append(callbacks, fn)
|
|
|
|
|
}
|
|
|
|
|
e.mu.Unlock()
|
|
|
|
|
for _, fn := range callbacks {
|
|
|
|
|
fn(nm)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (e *userspaceEngine) DiscoPublicKey() tailcfg.DiscoKey {
|
|
|
|
|