package fed import ( "context" "encoding/json" "fmt" "sync" ) // EgressFor asks the online peers (or one) for their egress analysis of the // window [from, to] (unix seconds). The raw answers are untrusted: the caller // decodes and sanitizes them. func (h *Hub) EgressFor(ctx context.Context, from, to int64, only string) map[string]json.RawMessage { out := map[string]json.RawMessage{} var mu sync.Mutex var wg sync.WaitGroup for _, p := range h.Peers { if only != "" && only != p.Name { continue } h.mu.RLock() st := h.state[p.Name] online := st != nil && st.online h.mu.RUnlock() if !online { continue } wg.Add(1) go func(p Peer) { defer wg.Done() var raw json.RawMessage if _, err := h.get(ctx, p, fmt.Sprintf("/api/v1/peer/egress?from=%d&to=%d", from, to), &raw); err != nil { return } mu.Lock() out[p.Name] = raw mu.Unlock() }(p) } wg.Wait() return out }