chore: ignore own machine id when notifying an update

This commit is contained in:
Johan Siebens
2024-01-04 10:09:56 +01:00
parent 473c3370ce
commit dd2e783d8e
2 changed files with 8 additions and 5 deletions
+6 -3
View File
@@ -1,6 +1,7 @@
package core
import (
"slices"
"sync"
"time"
)
@@ -11,7 +12,7 @@ type PollMapSessionManager interface {
Register(tailnetID uint64, machineID uint64, ch chan *Ping)
Deregister(tailnetID uint64, machineID uint64)
HasSession(tailnetID uint64, machineID uint64) bool
NotifyAll(tailnetID uint64)
NotifyAll(tailnetID uint64, ignoreMachineIDs ...uint64)
}
func NewPollMapSessionManager() PollMapSessionManager {
@@ -82,13 +83,15 @@ func (n *pollMapSessionManager) HasSession(tailnetID uint64, machineID uint64) b
return false
}
func (n *pollMapSessionManager) NotifyAll(tailnetID uint64) {
func (n *pollMapSessionManager) NotifyAll(tailnetID uint64, ignoreMachineIDs ...uint64) {
n.RLock()
defer n.RUnlock()
if ss := n.data[tailnetID]; ss != nil {
for _, p := range ss {
for i, p := range ss {
if !slices.Contains(ignoreMachineIDs, i) {
p <- &Ping{}
}
}
}
}
+1 -1
View File
@@ -82,7 +82,7 @@ func (h *PollNetMapHandler) handleUpdate(c echo.Context, binder bind.Binder, m *
tailnetID := m.TailnetID
machineID := m.ID
h.sessionManager.NotifyAll(tailnetID)
h.sessionManager.NotifyAll(tailnetID, m.ID)
if !mapRequest.Stream {
return c.String(http.StatusOK, "")