AnnounceShare: allow setting separate limits for each protocol; change the defaults: zero => 5 trackers, any other protocol => 2 trackers
This commit is contained in:
parent
61864ed2ab
commit
f64e57d2c2
|
@ -4,6 +4,7 @@ import os
|
||||||
import logging
|
import logging
|
||||||
import json
|
import json
|
||||||
import atexit
|
import atexit
|
||||||
|
import re
|
||||||
|
|
||||||
import gevent
|
import gevent
|
||||||
|
|
||||||
|
@ -21,16 +22,35 @@ class TrackerStorage(object):
|
||||||
self.tracker_down_time_interval = 60 * 60
|
self.tracker_down_time_interval = 60 * 60
|
||||||
self.tracker_discover_time_interval = 5 * 60
|
self.tracker_discover_time_interval = 5 * 60
|
||||||
|
|
||||||
|
self.working_shared_trackers_limit_per_protocol = {}
|
||||||
|
self.working_shared_trackers_limit_per_protocol["other"] = 2
|
||||||
|
|
||||||
self.file_path = "%s/trackers.json" % config.data_dir
|
self.file_path = "%s/trackers.json" % config.data_dir
|
||||||
self.load()
|
self.load()
|
||||||
self.time_discover = 0.0
|
self.time_discover = 0.0
|
||||||
self.time_success = 0.0
|
self.time_success = 0.0
|
||||||
atexit.register(self.save)
|
atexit.register(self.save)
|
||||||
|
|
||||||
|
def initTrackerLimitForProtocol(self):
|
||||||
|
for s in re.split("[,;]", config.working_shared_trackers_limit_per_protocol):
|
||||||
|
x = s.split("=", 1)
|
||||||
|
if len(x) == 1:
|
||||||
|
x = ["other", x[0]]
|
||||||
|
try:
|
||||||
|
self.working_shared_trackers_limit_per_protocol[x[0]] = int(x[1])
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
self.log.debug("Limits per protocol: %s" % self.working_shared_trackers_limit_per_protocol)
|
||||||
|
|
||||||
|
def getTrackerLimitForProtocol(self, protocol):
|
||||||
|
l = self.working_shared_trackers_limit_per_protocol
|
||||||
|
return l.get(protocol, l.get("other"))
|
||||||
|
|
||||||
def setSiteAnnouncer(self, site_announcer):
|
def setSiteAnnouncer(self, site_announcer):
|
||||||
if self.site_announcer == site_announcer:
|
if self.site_announcer:
|
||||||
return
|
return
|
||||||
self.site_announcer = site_announcer
|
self.site_announcer = site_announcer
|
||||||
|
self.initTrackerLimitForProtocol()
|
||||||
self.recheckValidTrackers()
|
self.recheckValidTrackers()
|
||||||
|
|
||||||
def isTrackerAddressValid(self, tracker_address):
|
def isTrackerAddressValid(self, tracker_address):
|
||||||
|
@ -153,7 +173,7 @@ class TrackerStorage(object):
|
||||||
nr_working_trackers = len(self.getWorkingTrackers())
|
nr_working_trackers = len(self.getWorkingTrackers())
|
||||||
|
|
||||||
error_limit = 30
|
error_limit = 30
|
||||||
if nr_working_trackers_for_protocol >= config.working_shared_trackers_limit_per_protocol:
|
if nr_working_trackers_for_protocol >= self.getTrackerLimitForProtocol(protocol):
|
||||||
error_limit = 10
|
error_limit = 10
|
||||||
if nr_working_trackers >= config.working_shared_trackers_limit:
|
if nr_working_trackers >= config.working_shared_trackers_limit:
|
||||||
error_limit = 5
|
error_limit = 5
|
||||||
|
@ -236,9 +256,9 @@ class TrackerStorage(object):
|
||||||
|
|
||||||
for protocol in supported_protocols:
|
for protocol in supported_protocols:
|
||||||
trackers = trackers_per_protocol.get(protocol, [])
|
trackers = trackers_per_protocol.get(protocol, [])
|
||||||
if len(trackers) < config.working_shared_trackers_limit_per_protocol:
|
if len(trackers) < self.getTrackerLimitForProtocol(protocol):
|
||||||
self.log.debug("Not enough working trackers for protocol %s: %s < %s" % (
|
self.log.debug("Not enough working trackers for protocol %s: %s < %s" % (
|
||||||
protocol, len(trackers), config.working_shared_trackers_limit_per_protocol))
|
protocol, len(trackers), self.getTrackerLimitForProtocol(protocol)))
|
||||||
return False
|
return False
|
||||||
total_nr += len(trackers)
|
total_nr += len(trackers)
|
||||||
|
|
||||||
|
@ -338,6 +358,6 @@ class ConfigPlugin(object):
|
||||||
def createArguments(self):
|
def createArguments(self):
|
||||||
group = self.parser.add_argument_group("AnnounceShare plugin")
|
group = self.parser.add_argument_group("AnnounceShare plugin")
|
||||||
group.add_argument('--working_shared_trackers_limit', help='Stop discovering new shared trackers after this number of shared trackers reached (total)', default=10, type=int, metavar='limit')
|
group.add_argument('--working_shared_trackers_limit', help='Stop discovering new shared trackers after this number of shared trackers reached (total)', default=10, type=int, metavar='limit')
|
||||||
group.add_argument('--working_shared_trackers_limit_per_protocol', help='Stop discovering new shared trackers after this number of shared trackers reached per each supported protocol', default=5, type=int, metavar='limit')
|
group.add_argument('--working_shared_trackers_limit_per_protocol', help='Stop discovering new shared trackers after this number of shared trackers reached per each supported protocol', default="zero=5,other=2", metavar='limit')
|
||||||
|
|
||||||
return super(ConfigPlugin, self).createArguments()
|
return super(ConfigPlugin, self).createArguments()
|
||||||
|
|
Loading…
Reference in New Issue