-
Notifications
You must be signed in to change notification settings - Fork 0
/
hosts.go
62 lines (47 loc) · 1.08 KB
/
hosts.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
62
package main
import "github.com/paulbellamy/ratecounter"
var hosts []Host
type Host struct {
Value string
Counter *ratecounter.Counter
}
func isHostExcluded(targetHost string, stats *Stats) bool {
var found = false
// Check if the host is simply excluded
for _, excludedHost := range arguments.ExcludedHosts {
if excludedHost == targetHost {
stats.ExcludedCounter.Incr(1)
for _, host := range hosts {
if host.Value == targetHost {
found = true
}
}
if !found {
stats.HostsCount.Incr(1)
}
return true
}
}
for _, host := range hosts {
if host.Value == targetHost {
found = true
// Check if the number of occurrence of the host reached the --max-host-occurrence limit
if host.Counter.Value() >= arguments.MaxHostOccurrence {
host.Counter.Incr(1)
stats.ExcludedCounter.Incr(1)
return true
}
host.Counter.Incr(1)
}
}
if !found {
newHost := Host{
Value: targetHost,
Counter: new(ratecounter.Counter),
}
stats.HostsCount.Incr(1)
newHost.Counter.Incr(1)
hosts = append(hosts, newHost)
}
return false
}