mirror of
https://github.com/juanfont/headscale.git
synced 2024-11-23 18:15:26 +00:00
improve debug logging, rw lock for notifier
Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com>
This commit is contained in:
parent
3bef63bb80
commit
217ccd6540
@ -23,6 +23,7 @@ func (ns *noiseServer) NoiseRegistrationHandler(
|
|||||||
|
|
||||||
log.Trace().
|
log.Trace().
|
||||||
Any("headers", req.Header).
|
Any("headers", req.Header).
|
||||||
|
Caller().
|
||||||
Msg("Headers")
|
Msg("Headers")
|
||||||
|
|
||||||
body, _ := io.ReadAll(req.Body)
|
body, _ := io.ReadAll(req.Body)
|
||||||
|
@ -9,7 +9,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Notifier struct {
|
type Notifier struct {
|
||||||
l sync.Mutex
|
l sync.RWMutex
|
||||||
nodes map[string]chan<- types.StateUpdate
|
nodes map[string]chan<- types.StateUpdate
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -18,6 +18,9 @@ func NewNotifier() *Notifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (n *Notifier) AddNode(machineKey string, c chan<- types.StateUpdate) {
|
func (n *Notifier) AddNode(machineKey string, c chan<- types.StateUpdate) {
|
||||||
|
log.Trace().Caller().Str("key", machineKey).Msg("acquiring lock to add node")
|
||||||
|
defer log.Trace().Caller().Str("key", machineKey).Msg("releasing lock to add node")
|
||||||
|
|
||||||
n.l.Lock()
|
n.l.Lock()
|
||||||
defer n.l.Unlock()
|
defer n.l.Unlock()
|
||||||
|
|
||||||
@ -34,6 +37,9 @@ func (n *Notifier) AddNode(machineKey string, c chan<- types.StateUpdate) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (n *Notifier) RemoveNode(machineKey string) {
|
func (n *Notifier) RemoveNode(machineKey string) {
|
||||||
|
log.Trace().Caller().Str("key", machineKey).Msg("acquiring lock to remove node")
|
||||||
|
defer log.Trace().Caller().Str("key", machineKey).Msg("releasing lock to remove node")
|
||||||
|
|
||||||
n.l.Lock()
|
n.l.Lock()
|
||||||
defer n.l.Unlock()
|
defer n.l.Unlock()
|
||||||
|
|
||||||
@ -54,14 +60,21 @@ func (n *Notifier) NotifyAll(update types.StateUpdate) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (n *Notifier) NotifyWithIgnore(update types.StateUpdate, ignore ...string) {
|
func (n *Notifier) NotifyWithIgnore(update types.StateUpdate, ignore ...string) {
|
||||||
n.l.Lock()
|
log.Trace().Caller().Interface("type", update.Type).Msg("acquiring lock to notify")
|
||||||
defer n.l.Unlock()
|
defer log.Trace().
|
||||||
|
Caller().
|
||||||
|
Interface("type", update.Type).
|
||||||
|
Msg("releasing lock, finished notifing")
|
||||||
|
|
||||||
|
n.l.RLock()
|
||||||
|
defer n.l.RUnlock()
|
||||||
|
|
||||||
for key, c := range n.nodes {
|
for key, c := range n.nodes {
|
||||||
if util.IsStringInSlice(ignore, key) {
|
if util.IsStringInSlice(ignore, key) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Trace().Caller().Str("machine", key).Strs("ignoring", ignore).Msg("sending update")
|
||||||
c <- update
|
c <- update
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,7 @@ func (ns *noiseServer) NoisePollNetMapHandler(
|
|||||||
|
|
||||||
log.Trace().
|
log.Trace().
|
||||||
Any("headers", req.Header).
|
Any("headers", req.Header).
|
||||||
|
Caller().
|
||||||
Msg("Headers")
|
Msg("Headers")
|
||||||
|
|
||||||
body, _ := io.ReadAll(req.Body)
|
body, _ := io.ReadAll(req.Body)
|
||||||
|
Loading…
Reference in New Issue
Block a user