mirror of
https://github.com/juanfont/headscale.git
synced 2026-04-24 17:48:49 +02:00
batcher: send endpoint and derp only updates. (#2856)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package mapper
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/netip"
|
||||
"strings"
|
||||
@@ -21,6 +22,8 @@ import (
|
||||
"zgo.at/zcache/v2"
|
||||
)
|
||||
|
||||
var errNodeNotFoundAfterAdd = errors.New("node not found after adding to batcher")
|
||||
|
||||
// batcherTestCase defines a batcher function with a descriptive name for testing.
|
||||
type batcherTestCase struct {
|
||||
name string
|
||||
@@ -50,7 +53,12 @@ func (t *testBatcherWrapper) AddNode(id types.NodeID, c chan<- *tailcfg.MapRespo
|
||||
|
||||
// Send the online notification that poll.go would normally send
|
||||
// This ensures other nodes get notified about this node coming online
|
||||
t.AddWork(change.NodeOnline(id))
|
||||
node, ok := t.state.GetNodeByID(id)
|
||||
if !ok {
|
||||
return fmt.Errorf("%w: %d", errNodeNotFoundAfterAdd, id)
|
||||
}
|
||||
|
||||
t.AddWork(change.NodeOnline(node))
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -65,7 +73,10 @@ func (t *testBatcherWrapper) RemoveNode(id types.NodeID, c chan<- *tailcfg.MapRe
|
||||
|
||||
// Send the offline notification that poll.go would normally send
|
||||
// Do this BEFORE removing from batcher so the change can be processed
|
||||
t.AddWork(change.NodeOffline(id))
|
||||
node, ok := t.state.GetNodeByID(id)
|
||||
if ok {
|
||||
t.AddWork(change.NodeOffline(node))
|
||||
}
|
||||
|
||||
// Finally remove from the real batcher
|
||||
removed := t.Batcher.RemoveNode(id, c)
|
||||
|
||||
Reference in New Issue
Block a user