Skip to content

Commit

Permalink
Rename DomainTotals, fields
Browse files Browse the repository at this point in the history
DomainTotals -> AggregatedScan
(easier to pluralize and better mirrors the "scans" table)
MTASTS[mode] -> MTASTS[mode]List
(we won't want to store the full list when it starts hopefully getting
big, so the count should be the default)
  • Loading branch information
vbrown608 committed May 8, 2019
1 parent 87ef87d commit cd0d109
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 24 deletions.
2 changes: 1 addition & 1 deletion checker/cmd/starttls-check/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func main() {
c = checker.Checker{
CheckHostname: checker.NoopCheckHostname,
}
resultHandler = &checker.DomainTotals{
resultHandler = &checker.AggregatedScan{
Time: time.Now(),
Source: label,
}
Expand Down
2 changes: 1 addition & 1 deletion checker/cmd/starttls-check/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestUpdateStats(t *testing.T) {
// @TODO make this faster
main()
got := out.(*bytes.Buffer).String()
expected := checker.DomainTotals{
expected := checker.AggregatedScan{
Time: time.Time{},
Source: ts.URL,
Attempted: 3,
Expand Down
40 changes: 21 additions & 19 deletions checker/totals.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,45 +11,47 @@ import (
"time"
)

// DomainTotals compiled aggregated stats across domains.
// AggregatedScan compiles aggregated stats across domains.
// Implements ResultHandler.
type DomainTotals struct {
Time time.Time
Source string
Attempted int
WithMXs int
MTASTSTesting []string
MTASTSEnforce []string
type AggregatedScan struct {
Time time.Time
Source string
Attempted int
WithMXs int
MTASTSTesting int
MTASTSTestingList []string
MTASTSEnforce int
MTASTSEnforceList []string
}

// HandleDomain adds the result of a single domain scan to aggregated stats.
func (t *DomainTotals) HandleDomain(r DomainResult) {
t.Attempted++
func (a *AggregatedScan) HandleDomain(r DomainResult) {
a.Attempted++
// Show progress.
if t.Attempted%1000 == 0 {
log.Printf("\n%v\n", t)
log.Println(t.MTASTSTesting)
log.Println(t.MTASTSEnforce)
if a.Attempted%1000 == 0 {
log.Printf("\n%v\n", a)
log.Println(a.MTASTSTestingList)
log.Println(a.MTASTSEnforceList)
}

if len(r.HostnameResults) == 0 {
// No MX records - assume this isn't an email domain.
return
}
t.WithMXs++
a.WithMXs++
if r.MTASTSResult != nil {
switch r.MTASTSResult.Mode {
case "enforce":
t.MTASTSEnforce = append(t.MTASTSEnforce, r.Domain)
a.MTASTSEnforceList = append(a.MTASTSEnforceList, r.Domain)
case "testing":
t.MTASTSTesting = append(t.MTASTSTesting, r.Domain)
a.MTASTSTestingList = append(a.MTASTSTestingList, r.Domain)
}
}
}

func (t DomainTotals) String() string {
func (a AggregatedScan) String() string {
s := strings.Join([]string{"time", "source", "attempted", "with_mxs", "mta_sts_testing", "mta_sts_enforce"}, "\t") + "\n"
s += fmt.Sprintf("%v\t%s\t%d\t%d\t%d\t%d\n", t.Time, t.Source, t.Attempted, t.WithMXs, len(t.MTASTSTesting), len(t.MTASTSEnforce))
s += fmt.Sprintf("%v\t%s\t%d\t%d\t%d\t%d\n", a.Time, a.Source, a.Attempted, a.WithMXs, len(a.MTASTSTestingList), len(a.MTASTSEnforceList))
return s
}

Expand Down
6 changes: 3 additions & 3 deletions checker/totals_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func TestCheckCSV(t *testing.T) {
CheckHostname: mockCheckHostname,
checkMTASTSOverride: mockCheckMTASTS,
}
totals := DomainTotals{}
totals := AggregatedScan{}
c.CheckCSV(reader, &totals, 0)

if totals.Attempted != 6 {
Expand All @@ -26,7 +26,7 @@ func TestCheckCSV(t *testing.T) {
if totals.WithMXs != 5 {
t.Errorf("Expected 5 domains with MXs, got %d", totals.WithMXs)
}
if len(totals.MTASTSTesting) != 5 {
t.Errorf("Expected 5 domains in MTA-STS testing mode, got %d", len(totals.MTASTSTesting))
if len(totals.MTASTSTestingList) != 5 {
t.Errorf("Expected 5 domains in MTA-STS testing mode, got %d", len(totals.MTASTSTestingList))
}
}
2 changes: 2 additions & 0 deletions db/scripts/init_tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,5 @@ ALTER TABLE domain_totals DROP COLUMN IF EXISTS connected;
ALTER TABLE domain_totals ADD COLUMN IF NOT EXISTS with_mxs INTEGER DEFAULT 0;

ALTER TABLE domains ADD COLUMN IF NOT EXISTS mta_sts BOOLEAN DEFAULT FALSE;

ALTER TABLE domain_totals RENAME TO aggregated_scans;
2 changes: 2 additions & 0 deletions db/sqldb.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,3 +379,5 @@ func (db *SQLDatabase) PutHostnameScan(hostname string, result checker.HostnameR
VALUES($1, $2, $3)`, hostname, result.Status, string(data))
return err
}

// func (db *SQLDatabase) PutAggregatedScan

0 comments on commit cd0d109

Please sign in to comment.