-
Notifications
You must be signed in to change notification settings - Fork 0
/
mongodb.go
60 lines (45 loc) · 1.23 KB
/
mongodb.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
package blacklist
import (
"fmt"
"runtime"
"github.com/activecm/rita/resources"
"github.com/activecm/rita/util"
"github.com/globalsign/mgo/bson"
)
type repo struct {
res *resources.Resources
}
//NewMongoRepository create new repository
func NewMongoRepository(res *resources.Resources) Repository {
return &repo{
res: res,
}
}
//Upsert loops through every domain ....
func (r *repo) Upsert() {
session := r.res.DB.Session.Copy()
defer session.Close()
iter := session.DB(r.res.DB.GetSelectedDB()).C(r.res.Config.T.Structure.HostTable).Find(bson.M{"blacklisted": true}).Iter()
//Create the workers
writerWorker := newWriter(r.res.Config.T.Structure.HostTable, r.res.DB, r.res.Config, r.res.Log)
analyzerWorker := newAnalyzer(
r.res.Config.S.Rolling.CurrentChunk,
r.res.DB,
r.res.Config,
writerWorker.collect,
writerWorker.close,
)
//kick off the threaded goroutines
for i := 0; i < util.Max(1, runtime.NumCPU()/2); i++ {
analyzerWorker.start()
writerWorker.start()
}
var res hostRes
fmt.Println("\t[-] Updating blacklisted peers ...")
// loop over map entries
for iter.Next(&res) {
analyzerWorker.collect(res)
}
// start the closing cascade (this will also close the other channels)
analyzerWorker.close()
}