Skip to content

Commit 9fd01b0

Browse files
committed
feat: add def loadExternalTrackers() in config for network strength
1 parent 5286c1e commit 9fd01b0

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

src/Config.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,9 +317,39 @@ def createArguments(self):
317317

318318
return self.parser
319319

320+
def loadExternalTrackers(self):
321+
import urllib.request
322+
import logging
323+
324+
url = "https://raw.githubusercontent.com/ngosang/trackerslist/refs/heads/master/trackers_all_ip.txt"
325+
trackers_file_path = os.path.join(self.data_dir, "trackers_ext.txt")
326+
try:
327+
response = urllib.request.urlopen(url)
328+
trackers = [line.strip() for line in response.read().decode('utf-8').splitlines() if line.strip()]
329+
330+
os.makedirs(os.path.dirname(trackers_file_path), exist_ok=True)
331+
# Read existing trackers into a set
332+
if os.path.exists(trackers_file_path):
333+
with open(trackers_file_path, "r") as f:
334+
file_trackers = {line.strip() for line in f if "://" in line}
335+
else:
336+
file_trackers = set()
337+
338+
# Write only new trackers
339+
with open(trackers_file_path, "a") as f:
340+
for tracker in trackers:
341+
if tracker and tracker not in file_trackers:
342+
f.write(tracker + "\n")
343+
file_trackers.add(tracker) # Avoid duplicates in the same run
344+
except Exception as err:
345+
logging.error("Error loading external trackers: %s", err)
346+
raise
347+
320348
def loadTrackersFile(self):
349+
self.loadExternalTrackers() # Load external trackers
350+
321351
if not self.trackers_file:
322-
self.trackers_file = ["trackers.txt", "{data_dir}/1HELLoE3sFD9569CLCbHEAVqvqV7U2Ri9d/trackers.txt"]
352+
self.trackers_file = ["trackers.txt", "trackers_ext.txt", "{data_dir}/1HELLoE3sFD9569CLCbHEAVqvqV7U2Ri9d/trackers.txt"]
323353
self.trackers = self.arguments.trackers[:]
324354

325355
for trackers_file in self.trackers_file:

src/Test/TestConfig.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,13 @@ def testParse(self):
2929
assert "1.2.3.4" in config_test.ui_restrict
3030
assert not config_test.use_openssl
3131
assert config_test.inner_path == "users/content.json"
32+
33+
def testExternalTrackers(self):
34+
test = Config.Config("zeronet.py".split(" "))
35+
test.loadExternalTrackers()
36+
# Check if trackers_ext.txt exists in data directory
37+
trackers_file_path = test.data_dir + "/trackers_ext.txt"
38+
import os
39+
assert os.path.exists(trackers_file_path)
40+
# Check if trackers_ext.txt is not empty
41+
assert os.path.getsize(trackers_file_path) > 0

0 commit comments

Comments
 (0)