34
34
import operator
35
35
import os
36
36
import random
37
- import requests
38
37
import sys
39
38
import time
40
39
from collections import defaultdict
41
40
from ConfigParser import ConfigParser
42
- from ipaddress import ip_address , ip_network
43
41
44
42
from utils import new_redis_conn
45
43
@@ -58,16 +56,12 @@ def __init__(self):
58
56
self .nodes = []
59
57
self .addresses = defaultdict (list )
60
58
self .now = 0
61
- self .blocklist = set ()
62
- self .blocklist_timestamp = 0
63
59
64
60
def export_nodes (self , dump ):
65
61
"""
66
62
Exports nodes to generate A and AAAA records from the latest snapshot.
67
63
"""
68
64
self .now = int (time .time ())
69
- if self .now - self .blocklist_timestamp > 3600 :
70
- self .update_blocklist ()
71
65
if dump != self .dump :
72
66
try :
73
67
self .nodes = json .loads (open (dump , "r" ).read (),
@@ -157,7 +151,6 @@ def filter_nodes(self):
157
151
2) Uptime must be equal or greater than the configured min. age
158
152
3) Max. one node per ASN
159
153
4) Uses default port
160
- 5) Not listed in blocklist
161
154
"""
162
155
consensus_height = self .get_consensus_height ()
163
156
min_age = self .get_min_age ()
@@ -169,10 +162,7 @@ def filter_nodes(self):
169
162
services = node [5 ]
170
163
height = node [6 ]
171
164
asn = node [13 ]
172
- if (port != CONF ['port' ] or
173
- asn is None or
174
- age < min_age or
175
- self .is_blocked (address )):
165
+ if port != CONF ['port' ] or asn is None or age < min_age :
176
166
continue
177
167
if consensus_height and abs (consensus_height - height ) > 2 :
178
168
continue
@@ -205,49 +195,6 @@ def get_min_age(self):
205
195
logging .info ("Min. age: %d" , min_age )
206
196
return min_age
207
197
208
- def is_blocked (self , address ):
209
- """
210
- Returns True if address is found in blocklist, False if otherwise.
211
- """
212
- if address .endswith (".onion" ) or ":" in address :
213
- return False
214
- for network in self .blocklist :
215
- if ip_address (address ) in network :
216
- logging .debug ("Blocked: %s" , address )
217
- return True
218
- return False
219
-
220
- def update_blocklist (self ):
221
- """
222
- Fetches the latest DROP (don't route or peer) list from Spamhaus:
223
- http://www.spamhaus.org/faq/section/DROP%20FAQ
224
- """
225
- urls = [
226
- "http://www.spamhaus.org/drop/drop.txt" ,
227
- "http://www.spamhaus.org/drop/edrop.txt" ,
228
- ]
229
- self .blocklist .clear ()
230
- for url in urls :
231
- try :
232
- response = requests .get (url , timeout = 15 )
233
- except requests .exceptions .RequestException as err :
234
- logging .warning (err )
235
- continue
236
- if response .status_code == 200 :
237
- for line in response .content .strip ().split ("\n " ):
238
- if line .startswith (";" ):
239
- continue
240
- network = line .split (";" )[0 ].strip ()
241
- try :
242
- self .blocklist .add (ip_network (unicode (network )))
243
- except ValueError :
244
- continue
245
- else :
246
- logging .warning ("HTTP%d: %s (%s)" ,
247
- response .status_code , url , response .content )
248
- logging .debug ("Blocklist entries: %d" , len (self .blocklist ))
249
- self .blocklist_timestamp = self .now
250
-
251
198
252
199
def cron ():
253
200
"""
0 commit comments