-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
61 lines (51 loc) · 1.56 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package main
import (
"io/ioutil"
"os"
"time"
"github.com/dgraph-io/badger/v3"
"github.com/paulbellamy/ratecounter"
log "github.com/sirupsen/logrus"
)
func main() {
argumentParsing(os.Args)
// Open seencheck database
tempDir, err := ioutil.TempDir(arguments.TempDir, "strainer-")
if err != nil {
log.Fatal(err)
}
seencheck := new(Seencheck)
seencheck.SeenCount = new(ratecounter.Counter)
seencheck.SeenDB, err = badger.Open(badger.DefaultOptions(tempDir))
if err != nil {
log.Fatal(err)
}
// Show statistics
stats := new(Stats)
stats.URIsPerSecond = ratecounter.NewRateCounter(1 * time.Second)
stats.ParsedCounter = new(ratecounter.Counter)
stats.DuplicateCounter = new(ratecounter.Counter)
stats.ExcludedCounter = new(ratecounter.Counter)
stats.SeedsListSize = new(ratecounter.Counter)
stats.UniqueCounter = new(ratecounter.Counter)
stats.HostsCount = new(ratecounter.Counter)
stats.ParsingFailures = new(ratecounter.Counter)
stats.StartTime = time.Now()
stats.FilesCount = len(arguments.FrontierFiles)
go stats.printLiveStats()
// If the output file doesn't exist, create it, or append to the file
fileName := "strainer_" + time.Now().Format("20060102150405") + ".txt"
outFile, err := os.OpenFile(fileName, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
log.Fatal(err)
}
defer outFile.Close()
// Process frontier file(s)
for _, filePath := range arguments.FrontierFiles {
stats.FileProcessingCount++
stats.FilePath = filePath
process(filePath, outFile, seencheck, stats)
}
os.RemoveAll(tempDir)
time.Sleep(2 * time.Second)
}