From 3bfc5fb56324490f17b5902acabbec11d1d5b231 Mon Sep 17 00:00:00 2001 From: Issif Date: Tue, 2 Jun 2020 23:31:56 +0200 Subject: [PATCH] remove config for nb of workers + add messages chan in config object --- README.md | 2 -- lib/config.go | 6 +++--- lib/lib.go | 7 ++----- main.go | 1 - 4 files changed, 5 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 16f2ac5..54ca37d 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,6 @@ SlackWebhookURL: "" #Slack Webhook URL SlackIconURL: "" #Slack Icon (Avatar) URL SlackUsername: "" #Slack Username Regexp: ".*\\.fr$" #Regexp to match. Can't be empty. It uses Golang regexp format -Workers: 20 #Number of workers for consuming feed from CertStream ``` ### With env vars @@ -36,7 +35,6 @@ Workers: 20 #Number of workers for consuming feed from CertStream - **SLACKICONURL**: Slack Icon (Avatar) URL - **SLACKUSERNAME**: Slack Username - **REGEXP**: Regexp to match, if empty, '.*' is used. Use Golang regexp format -- **WORKERS**: Number of workers for consuming feed from CertStream ## Run diff --git a/lib/config.go b/lib/config.go index 8eb301a..ed74615 100644 --- a/lib/config.go +++ b/lib/config.go @@ -20,6 +20,7 @@ type Configuration struct { RegIP string Regexp string PreviousCerts *ring.Ring + Messages chan []byte Buffer chan *Result Homoglyph map[string]string } @@ -27,8 +28,10 @@ type Configuration struct { // GetConfig provides a Configuration func GetConfig() *Configuration { c := &Configuration{ + Workers: 50, Homoglyph: GetHomoglyphMap(), PreviousCerts: ring.New(20), + Messages: make(chan []byte, 50), Buffer: make(chan *Result, 50), } @@ -68,9 +71,6 @@ func GetConfig() *Configuration { if _, err := regexp.Compile(c.Regexp); err != nil { log.Fatal("Bad regexp") } - if c.Workers < 1 { - log.Fatal("Workers must be strictly a positive number") - } return c } diff --git a/lib/lib.go b/lib/lib.go index dda8826..224cb29 100644 --- a/lib/lib.go +++ b/lib/lib.go @@ -51,9 +51,6 @@ type leafCert struct { AllDomains []string `json:"all_domains"` } -// MsgChan is the communication channel between certCheckWorkers and LoopCertStream -var MsgChan chan []byte - // the websocket stream from calidog const certInput = "wss://certstream.calidog.io" @@ -62,7 +59,7 @@ func CertCheckWorker(config *Configuration) { reg, _ := regexp.Compile(config.Regexp) for { - msg := <-MsgChan + msg := <-config.Messages result, err := ParseResultCertificate(msg) if err != nil { log.Warnf("Error parsing message: %s", err) @@ -156,7 +153,7 @@ func LoopCertStream(config *Configuration) { log.Warn("Error reading message from CertStream") break } - MsgChan <- msg + config.Messages <- msg } } } diff --git a/main.go b/main.go index b67fc86..e76a38c 100644 --- a/main.go +++ b/main.go @@ -15,7 +15,6 @@ func init() { func main() { go http.ListenAndServe("localhost:6060", nil) - lib.MsgChan = make(chan []byte, 10) for i := 0; i < config.Workers; i++ { go lib.CertCheckWorker(config) }