-
Notifications
You must be signed in to change notification settings - Fork 1
/
bootstrap.py
67 lines (56 loc) · 2.24 KB
/
bootstrap.py
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
import os
from socket import gethostbyname
from .candidate import BootstrapCandidate
from .revision import update_revision_information
# update version information directly from SVN
update_revision_information("$HeadURL$", "$Revision$")
_trackers = [(u"dispersy1.tribler.org", 6421),
(u"dispersy2.tribler.org", 6422),
(u"dispersy3.tribler.org", 6423),
(u"dispersy4.tribler.org", 6424),
(u"dispersy5.tribler.org", 6425),
(u"dispersy6.tribler.org", 6426),
(u"dispersy7.tribler.org", 6427),
(u"dispersy8.tribler.org", 6428),
(u"dispersy1b.tribler.org", 6421),
(u"dispersy2b.tribler.org", 6422),
(u"dispersy3b.tribler.org", 6423),
(u"dispersy4b.tribler.org", 6424),
(u"dispersy5b.tribler.org", 6425),
(u"dispersy6b.tribler.org", 6426),
(u"dispersy7b.tribler.org", 6427),
(u"dispersy8b.tribler.org", 6428)]
# _trackers = [(u"kayapo.tribler.org", 6431)]
def get_bootstrap_hosts(working_directory):
"""
Reads WORKING_DIRECTORY/bootstraptribler.txt and returns the hosts therein, otherwise it
returns _TRACKERS.
"""
trackers= []
filename = os.path.join(working_directory, "bootstraptribler.txt")
try:
for line in open(filename, "r"):
line = line.strip()
if not line.startswith("#"):
host, port = line.split()
trackers.append((host.decode("UTF-8"), int(port)))
except:
pass
if trackers:
return trackers
else:
return _trackers
def get_bootstrap_candidates(dispersy):
"""
Returns a list with all known bootstrap peers.
Bootstrap peers are retrieved from WORKING_DIRECTORY/bootstraptribler.txt if it exits.
Otherwise it is created using the trackers defined in _TRACKERS.
Each bootstrap peer gives either None or a Candidate. None values can be caused by
malfunctioning DNS.
"""
def get_candidate(host, port):
try:
return BootstrapCandidate((gethostbyname(host), port), False)
except:
return None
return [get_candidate(host, port) for host, port in get_bootstrap_hosts(dispersy.working_directory)]