feat: switch agent to a periodic dump rather than long running process

This commit is contained in:
Aarnav Tale
2026-03-27 13:19:16 -04:00
parent 2c57187628
commit ee59a2d06d
17 changed files with 521 additions and 464 deletions
+8 -6
View File
@@ -69,17 +69,17 @@ func (s *TSAgent) GetStatusForPeer(id string) (*tailcfg.HostinfoView, error) {
return &whois.Node.Hostinfo, nil
}
// Dispatches ALL the HostInfo entries in our Tailnet to the master
func (s *TSAgent) DispatchHostInfo(ctx context.Context) error {
// FetchAllHostInfo fetches hostinfo for all peers and returns them as a map
// keyed by node public key (e.g., "nodekey:abc123...").
func (s *TSAgent) FetchAllHostInfo(ctx context.Context) (map[string]json.RawMessage, error) {
log := util.GetLogger()
stat, err := s.Lc.Status(ctx)
if err != nil {
log.Debug("Failed to get status: %s", err)
return fmt.Errorf("failed to get status: %w", err)
return nil, fmt.Errorf("failed to get status: %w", err)
}
// Do lookups for all peers with a hint of parallelism for speed!
const maxParallel = 8
sema := make(chan struct{}, maxParallel)
var wg sync.WaitGroup
@@ -96,6 +96,8 @@ func (s *TSAgent) DispatchHostInfo(ctx context.Context) error {
nodeMap[nodeKey] = peer
}
result := make(map[string]json.RawMessage)
for nodeKey, peer := range nodeMap {
idBytes, err := nodeKey.MarshalText()
if err != nil {
@@ -138,11 +140,11 @@ func (s *TSAgent) DispatchHostInfo(ctx context.Context) error {
}
mu.Lock()
fmt.Println("HOSTINFO " + nodeID + " " + string(data))
result[nodeID] = json.RawMessage(data)
mu.Unlock()
}()
}
wg.Wait()
return nil
return result, nil
}