init
Some checks failed
release-tag / release-image (push) Failing after 1m28s

This commit is contained in:
2025-09-24 10:32:22 +02:00
parent b851b57e28
commit dc3abf661f
17 changed files with 1008 additions and 0 deletions

46
internal/mesh/catalog.go Normal file
View File

@@ -0,0 +1,46 @@
package mesh
import "sync"
type Catalog struct {
mu sync.RWMutex
byID map[string]NodeInfo
}
func NewCatalog() *Catalog { return &Catalog{byID: map[string]NodeInfo{}} }
func (c *Catalog) Set(n NodeInfo) { c.mu.Lock(); c.byID[n.NodeID] = n; c.mu.Unlock() }
func (c *Catalog) Replace(nodes []NodeInfo) {
c.mu.Lock()
defer c.mu.Unlock()
c.byID = map[string]NodeInfo{}
for _, n := range nodes {
c.byID[n.NodeID] = n
}
}
func (c *Catalog) All() []NodeInfo {
c.mu.RLock()
defer c.mu.RUnlock()
out := make([]NodeInfo, 0, len(c.byID))
for _, n := range c.byID {
out = append(out, n)
}
return out
}
func (c *Catalog) IDs() []string {
c.mu.RLock()
defer c.mu.RUnlock()
out := make([]string, 0, len(c.byID))
for id := range c.byID {
out = append(out, id)
}
return out
}
func (c *Catalog) ByID(id string) (NodeInfo, bool) {
c.mu.RLock()
defer c.mu.RUnlock()
n, ok := c.byID[id]
return n, ok
}