-
-
Notifications
You must be signed in to change notification settings - Fork 40
/
all.go
43 lines (36 loc) · 1.11 KB
/
all.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
package blockbuilder
import (
"context"
"net/netip"
)
func (b *Builder) BuildAll(ctx context.Context) (result Result) {
chHostnames := make(chan []string)
chIPs := make(chan []netip.Addr)
chIPPrefixes := make(chan []netip.Prefix)
chHostnamesErrors := make(chan []error)
chIPsErrors := make(chan []error)
go func() {
blockedHostnames, errs := b.buildHostnames(ctx,
b.blockMalicious, b.blockAds, b.blockSurveillance,
b.addBlockedHosts, b.allowedHosts)
chHostnames <- blockedHostnames
chHostnamesErrors <- errs
}()
go func() {
blockedIPs, blockedIPPrefixes, errs := b.buildIPs(ctx,
b.blockMalicious, b.blockAds, b.blockSurveillance,
b.allowedIPs, b.addBlockedIPs,
b.allowedIPPrefixes, b.addBlockedIPPrefixes)
chIPs <- blockedIPs
chIPPrefixes <- blockedIPPrefixes
chIPsErrors <- errs
}()
result.BlockedHostnames = <-chHostnames
result.BlockedIPs = <-chIPs
result.BlockedIPPrefixes = <-chIPPrefixes
hostnamesErrors := <-chHostnamesErrors
result.Errors = append(result.Errors, hostnamesErrors...)
ipsErrors := <-chIPsErrors
result.Errors = append(result.Errors, ipsErrors...)
return result
}