Commit d1d38748 authored by ale's avatar ale
Browse files

get rid of the extra errCh now that mx error handling is performed directly in the Scanner

parent 1ef15997
......@@ -74,7 +74,6 @@ func main() {
flag.Parse()
ch := make(chan string, 100)
errCh := make(chan string, 100)
// Setup the interface to Postfix.
pmap := tlswatch.NewPostfixPolicyMap(*tlsPolicyMapFile)
......@@ -85,13 +84,16 @@ func main() {
// Initialize the database.
db := tlswatch.NewLevelDbDatabase(*dbPath)
defer db.Close()
// Create the main PolicyWatcher object.
pw := tlswatch.NewPolicyWatcher(
policy,
pmap,
db,
tlswatch.Batch(ch, *updatePeriod),
tlswatch.Batch(errCh, *updatePeriod))
tlswatch.Batch(ch, *updatePeriod))
// Setup the Scanner.
var domainWl tlswatch.RegexpList
if *whitelistFile != "" {
domainWl = tlswatch.ParseWildcardsFromFile(*whitelistFile)
......@@ -101,7 +103,7 @@ func main() {
domainBl = tlswatch.ParseWildcardsFromFile(*blacklistFile)
}
scanner := tlswatch.NewScanner(db, ch, errCh, domainWl, domainBl)
scanner := tlswatch.NewScanner(db, ch, domainWl, domainBl)
if *fifoPath != "" {
runFifo(scanner)
......@@ -110,12 +112,6 @@ func main() {
}
close(ch)
close(errCh)
pw.Wait()
pmap.Save()
//log.Printf("%+v\n", pw)
db.Close()
}
......@@ -124,16 +124,15 @@ type PolicyWatcher struct {
grabber *CertGrabber
}
func NewPolicyWatcher(policy TlsPolicy, policyMap PolicyMap, db Database, inCh chan UpdateBatch, errCh chan UpdateBatch) *PolicyWatcher {
func NewPolicyWatcher(policy TlsPolicy, policyMap PolicyMap, db Database, inCh chan UpdateBatch) *PolicyWatcher {
pw := &PolicyWatcher{
policy: policy,
policyMap: policyMap,
grabber: NewCertGrabber(db, 5),
db: db,
}
pw.wg.Add(2)
pw.wg.Add(1)
go pw.watchUpdates(inCh)
go pw.watchErrors(errCh)
return pw
}
......@@ -218,17 +217,6 @@ func (pw *PolicyWatcher) watchUpdates(ch chan UpdateBatch) {
pw.wg.Done()
}
func (pw *PolicyWatcher) watchErrors(ch chan UpdateBatch) {
for batch := range ch {
log.Printf("batch/err: %+v", batch)
for mx, _ := range batch {
pw.wg.Add(1)
go pw.handleError(mx)
}
}
pw.wg.Done()
}
func (pw *PolicyWatcher) handleDomain(domain string) {
session := pw.db.Session()
defer session.Close()
......
......@@ -61,16 +61,14 @@ type MxInfo struct {
type Scanner struct {
db Database
outCh chan string
mxErrCh chan string
domainWhitelist RegexpList
domainBlacklist RegexpList
}
func NewScanner(db Database, outCh chan string, mxErrCh chan string, whitelist RegexpList, blacklist RegexpList) *Scanner {
func NewScanner(db Database, outCh chan string, whitelist RegexpList, blacklist RegexpList) *Scanner {
return &Scanner{
db: db,
outCh: outCh,
mxErrCh: mxErrCh,
domainWhitelist: whitelist,
domainBlacklist: blacklist,
}
......@@ -105,10 +103,6 @@ func (s *Scanner) handleTlsError(m []string) {
s.outCh <-domain
}
}
if s.mxErrCh != nil {
s.mxErrCh <- m[1]
}
}
func (s *Scanner) handleRelay(m []string) {
......
......@@ -31,7 +31,7 @@ func TestScanner_Scan(t *testing.T) {
wg.Done()
}()
NewScanner(db, ch, nil, nil, nil).Scan(strings.NewReader(scannerTestData))
NewScanner(db, ch, nil, nil).Scan(strings.NewReader(scannerTestData))
close(ch)
wg.Wait()
......@@ -84,7 +84,7 @@ func TestScanner_Whitelist(t *testing.T) {
}()
wl := ParseWildcardList([]string{"gmail.com", "another-domain.com"})
NewScanner(db, ch, nil, wl, nil).Scan(strings.NewReader(scannerTestData))
NewScanner(db, ch, wl, nil).Scan(strings.NewReader(scannerTestData))
close(ch)
wg.Wait()
......@@ -109,7 +109,7 @@ func TestScanner_Blacklist(t *testing.T) {
}()
bl := ParseWildcardList([]string{"kindle.com", "another-domain.com"})
NewScanner(db, ch, nil, nil, bl).Scan(strings.NewReader(scannerTestData))
NewScanner(db, ch, nil, bl).Scan(strings.NewReader(scannerTestData))
close(ch)
wg.Wait()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment