Rev395, Trackers_file parameter that allows to specify dynamically loaded bottstrap trackers

This commit is contained in:
HelloZeroNet 2015-09-12 17:13:34 +02:00
parent cf5a4f902b
commit fa37f58982
2 changed files with 15 additions and 9 deletions

View file

@ -8,7 +8,7 @@ class Config(object):
def __init__(self, argv): def __init__(self, argv):
self.version = "0.3.2" self.version = "0.3.2"
self.rev = 394 self.rev = 395
self.argv = argv self.argv = argv
self.action = None self.action = None
self.createParser() self.createParser()
@ -132,6 +132,7 @@ class Config(object):
self.parser.add_argument('--proxy', help='Socks proxy address', metavar='ip:port') self.parser.add_argument('--proxy', help='Socks proxy address', metavar='ip:port')
self.parser.add_argument('--ip_external', help='Set reported external ip (tested on start if None)', metavar='ip') self.parser.add_argument('--ip_external', help='Set reported external ip (tested on start if None)', metavar='ip')
self.parser.add_argument('--trackers', help='Bootstraping torrent trackers', default=trackers, metavar='protocol://address', nargs='*') self.parser.add_argument('--trackers', help='Bootstraping torrent trackers', default=trackers, metavar='protocol://address', nargs='*')
self.parser.add_argument('--trackers_file', help='Load torrent trackers dynamically from a file', default=False, metavar='path')
self.parser.add_argument('--use_openssl', help='Use OpenSSL liblary for speedup', self.parser.add_argument('--use_openssl', help='Use OpenSSL liblary for speedup',
type='bool', choices=[True, False], default=use_openssl) type='bool', choices=[True, False], default=use_openssl)
self.parser.add_argument('--disable_encryption', help='Disable connection encryption', action='store_true') self.parser.add_argument('--disable_encryption', help='Disable connection encryption', action='store_true')
@ -151,7 +152,13 @@ class Config(object):
return self.parser return self.parser
# Find arguments specificed for current action def loadTrackersFile(self):
self.trackers = []
for tracker in open(self.trackers_file):
if "://" in tracker:
self.trackers.append(tracker.strip())
# Find arguments specified for current action
def getActionArguments(self): def getActionArguments(self):
back = {} back = {}
arguments = self.parser._subparsers._group_actions[0].choices[self.action]._actions[1:] # First is --version arguments = self.parser._subparsers._group_actions[0].choices[self.action]._actions[1:] # First is --version

View file

@ -173,6 +173,8 @@ class FileServer(ConnectionServer):
first_announce = True # First start first_announce = True # First start
while 1: while 1:
# Sites healthcare # Sites healthcare
if config.trackers_file:
config.loadTrackersFile()
for address, site in self.sites.items(): for address, site in self.sites.items():
if site.settings["serving"]: if site.settings["serving"]:
if first_announce: # Announce to all trackers on startup if first_announce: # Announce to all trackers on startup
@ -202,17 +204,14 @@ class FileServer(ConnectionServer):
# Find new peers # Find new peers
for tracker_i in range(len(config.trackers)): for tracker_i in range(len(config.trackers)):
time.sleep(60 * 20 / len(config.trackers)) # Query all trackers one-by-one in 20 minutes evenly distributed time.sleep(60 * 20 / len(config.trackers)) # Query all trackers one-by-one in 20 minutes evenly distributed
if config.trackers_file:
config.loadTrackersFile()
for address, site in self.sites.items(): for address, site in self.sites.items():
site.announce(num = 1, pex = False) site.announce(num=1, pex=False)
time.sleep(2) time.sleep(2)
first_announce = False first_announce = False
# Detects if computer back from wakeup # Detects if computer back from wakeup
def wakeupWatcher(self): def wakeupWatcher(self):
last_time = time.time() last_time = time.time()