From cf219fb6f6feac735725ce9d04b3d3ac8c399007 Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Sat, 19 Mar 2022 23:38:14 -0400 Subject: cmd/cmd.go: add getFeeds() --- cmd/cmd.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/cmd/cmd.go b/cmd/cmd.go index fd195aa..f70eaae 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -142,6 +142,30 @@ func getFeed(path string) nvd_feed.Feed { return feed } +// Load CVE feeds in parallel. +func getFeeds(cacheDir string, updates []nvdmirror.Update) []nvd_feed.Feed { + numFeeds := 0 + + // load feeds in parallel + ch := make(chan nvd_feed.Feed) + for _, row := range(updates) { + if row.Type == nvdmirror.UpdateCveYear { + numFeeds += 1 + go func(path string) { + ch <- getFeed(path) + }(filepath.Join(cacheDir, row.Path)) + } + } + + // collect feeds + feeds := make([]nvd_feed.Feed, numFeeds) + for i := 0; i < numFeeds; i++ { + feeds[i] = <-ch + } + + return feeds +} + // Read cpe matches from file. func getCpeMatches(path string) cpematch.Matches { var matches cpematch.Matches -- cgit v1.2.3