This repository was archived by the owner on Dec 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdnsBlockOperation.js
More file actions
94 lines (90 loc) · 2.4 KB
/
dnsBlockOperation.js
File metadata and controls
94 lines (90 loc) · 2.4 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
* Copyright (c) 2021 RethinkDNS and its authors.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
export default class DNSBlockOperation {
checkDomainBlocking(
userBlocklistFlagUint,
userServiceListUint,
flagVersion,
blocklistMap,
blocklistFilter,
domainName,
) {
let response;
try {
response = checkDomainNameUserFlagIntersection(
userBlocklistFlagUint,
flagVersion,
blocklistMap,
blocklistFilter,
domainName,
);
if (response.isBlocked) {
return response;
}
if (userServiceListUint) {
let dnSplit = domainName.split(".");
let dnJoin = "";
let wildCardResponse;
while (dnSplit.shift() != undefined) {
dnJoin = dnSplit.join(".");
wildCardResponse = checkDomainNameUserFlagIntersection(
userServiceListUint,
flagVersion,
blocklistMap,
blocklistFilter,
dnJoin,
);
if (wildCardResponse.isBlocked) {
return wildCardResponse;
}
}
}
} catch (e) {
throw e;
}
return response;
}
}
function checkDomainNameUserFlagIntersection(
userBlocklistFlagUint,
flagVersion,
blocklistMap,
blocklistFilter,
domainName,
) {
let response = {};
try {
response.isBlocked = false;
response.blockedB64Flag = "";
response.blockedTag = [];
if (blocklistMap.has(domainName)) {
let domainNameInBlocklistUint = blocklistMap.get(domainName);
let blockedUint = blocklistFilter.flagIntersection(
userBlocklistFlagUint,
domainNameInBlocklistUint,
);
if (blockedUint) {
response.isBlocked = true;
response.blockedB64Flag = blocklistFilter.getB64FlagFromUint16(
blockedUint,
flagVersion,
);
} else {
blockedUint = new Uint16Array(domainNameInBlocklistUint);
response.blockedB64Flag = blocklistFilter.getB64FlagFromUint16(
blockedUint,
flagVersion,
);
}
//response.blockedTag = blocklistFilter.getTag(blockedUint);
}
} catch (e) {
throw e;
}
return response;
}