From 8f54a2bd6f90a031a9ef4fc9a636676a28d5c46b Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Wed, 19 Dec 2018 14:54:55 +0100 Subject: [PATCH] autopilot/manager: add QueryHeuristics Proxies a query request to the active agent. --- autopilot/manager.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/autopilot/manager.go b/autopilot/manager.go index 9327d6e3..80c99435 100644 --- a/autopilot/manager.go +++ b/autopilot/manager.go @@ -1,6 +1,7 @@ package autopilot import ( + "fmt" "sync" "sync/atomic" @@ -267,3 +268,22 @@ func (m *Manager) StopAgent() error { return nil } + +// QueryHeuristics queries the active autopilot agent for node scores. +func (m *Manager) QueryHeuristics(nodes []NodeID) (HeuristicScores, error) { + m.Lock() + defer m.Unlock() + + // Not active, so we can return early. + if m.pilot == nil { + return nil, fmt.Errorf("autopilot not active") + } + + n := make(map[NodeID]struct{}) + for _, node := range nodes { + n[node] = struct{}{} + } + + log.Debugf("Querying heuristics for %d nodes", len(n)) + return m.pilot.queryHeuristics(n) +}