Skip to content

Commit

Permalink
remove config for nb of workers + add messages chan in config object
Browse files Browse the repository at this point in the history
  • Loading branch information
Issif committed Jun 2, 2020
1 parent 660ea86 commit 3bfc5fb
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 11 deletions.
2 changes: 0 additions & 2 deletions README.md
Expand Up @@ -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
Expand All @@ -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

Expand Down
6 changes: 3 additions & 3 deletions lib/config.go
Expand Up @@ -20,15 +20,18 @@ type Configuration struct {
RegIP string
Regexp string
PreviousCerts *ring.Ring
Messages chan []byte
Buffer chan *Result
Homoglyph map[string]string
}

// 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),
}

Expand Down Expand Up @@ -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
}
7 changes: 2 additions & 5 deletions lib/lib.go
Expand Up @@ -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"

Expand All @@ -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)
Expand Down Expand Up @@ -156,7 +153,7 @@ func LoopCertStream(config *Configuration) {
log.Warn("Error reading message from CertStream")
break
}
MsgChan <- msg
config.Messages <- msg
}
}
}
Expand Down
1 change: 0 additions & 1 deletion main.go
Expand Up @@ -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)
}
Expand Down

0 comments on commit 3bfc5fb

Please sign in to comment.