def __init__(self, external_add_task, config, set_option, get_remote_endpoints, get_rates): if debug: if config['bandwidth_management']: print "bandwidth management is up." else: print "!@#!@#!@#!@#!@# bandwidth management is down." self.external_add_task = external_add_task self.config = config self.set_option = set_option self.get_rates = get_rates # Next few lines were added by David Harrison to use RTTMonitor2 #if os.name == 'nt': # icmp_impl = Win32Icmp() #elif os.name == 'posix': # icmp_impl = UnixIcmp(external_add_task, config['xicmp_port']) def got_new_rtt(rtt): self.external_add_task(0, self._inspect_rates, rtt) #self.rttmonitor = RTTMonitor(got_new_rtt, icmp_impl) self.rttmonitor = RTTMonitor(got_new_rtt) self.nodefeeder = NodeFeeder(external_add_task=external_add_task, get_remote_endpoints=get_remote_endpoints, rttmonitor=self.rttmonitor) self.start_time = None self.max_samples = 10 # hmm... self.u = SizedList(self.max_samples) self.d = SizedList(self.max_samples) self.t = SizedList(self.max_samples * 10) self.ur = SizedList(self.max_samples) self.dr = SizedList(self.max_samples) self.current_std = 0.001 self.max_std = 0.001 self.max_rates = {} self.max_rates["upload"] = 1.0 self.max_rates["download"] = 1.0 self.max_p = 1.0 self.min_p = 2**500 self.mid_p = ((self.max_p - self.min_p) / 2.0) + self.min_p self.old_p = None # I pulled these numbers out of my ass. if stats: tmp_dir = platform.get_temp_dir() timestr = "%d_%d_%d_%d_%d" % time.localtime()[1:6] stats_dir = os.path.join( tmp_dir, "bittorrent%s_%d" % (timestr, os.getpid()) ) os.mkdir(stats_dir) if debug: print "BandwidthManager: stats_dir = %s" % stats_dir rate_vs_time = os.path.join( stats_dir, "rate_vs_time.plotdata" ) self.rfp = open( rate_vs_time, "w" ) delay_vs_time = os.path.join( stats_dir, "delay_vs_time.plotdata" ) self.dfp = open( delay_vs_time, "w" ) sdev_vs_time = os.path.join( stats_dir, "stddev_vs_time.plotdata" ) self.sdevfp = open( sdev_vs_time, "w" )
def calc_installer_dir(self): if hasattr(self, 'installer_dir'): return self.installer_dir temp_dir = get_temp_dir() if temp_dir is not None: return temp_dir else: self.errorfunc(WARNING, _("Could not find a suitable temporary location to " "save the %s %s installer.") % (app_name, self.version))
def calc_installer_dir(self): if hasattr(self, 'installer_dir'): return self.installer_dir temp_dir = get_temp_dir() if temp_dir is not None: return temp_dir else: self.errorfunc( WARNING, _("Could not find a suitable temporary location to " "save the %s %s installer.") % (app_name, self.version))
def _calc_installer_dir(self): """Find a place to store the installer while it's being downloaded.""" temp_dir = get_temp_dir() return temp_dir
defaults = get_defaults('bittorrent-tracker') # hard-coded defaults. try: config, files = parse_configuration_and_args(defaults, 'bittorrent-tracker', args, 0, 0 ) except ValueError, e: print _("error: ") + str_exc(e) print _("run with -? for parameter explanations") return except BTFailure, e: print _("error: ") + str_exc(e) print _("run with -? for parameter explanations") return if config['dfile']=="": config['dfile'] = decode_from_filesystem( os.path.join(platform.get_temp_dir(), efs2(u"dfile") + str(os.getpid()))) config = Preferences().initWithDict(config) ef = lambda e: errorfunc(logging.WARNING, e) platform.write_pid_file(config['pid'], ef) t = None try: r = RawServer(config) t = Tracker(config, r) try: #DEBUG print "track: create_serversocket, port=", config['port'] #END s = r.create_serversocket(config['port'], config['bind'])
def get_temp_dir(): return decode_from_filesystem(platform.get_temp_dir())
def __init__(self, external_add_task, config, set_option, get_remote_endpoints, get_rates): if debug: if config['bandwidth_management']: print "bandwidth management is up." else: print "!@#!@#!@#!@#!@# bandwidth management is down." self.external_add_task = external_add_task self.config = config self.set_option = set_option self.get_rates = get_rates # Next few lines were added by David Harrison to use RTTMonitor2 #if os.name == 'nt': # icmp_impl = Win32Icmp() #elif os.name == 'posix': # icmp_impl = UnixIcmp(external_add_task, config['xicmp_port']) def got_new_rtt(rtt): self.external_add_task(0, self._inspect_rates, rtt) #self.rttmonitor = RTTMonitor(got_new_rtt, icmp_impl) self.rttmonitor = RTTMonitor(got_new_rtt) self.nodefeeder = NodeFeeder(external_add_task=external_add_task, get_remote_endpoints=get_remote_endpoints, rttmonitor=self.rttmonitor) self.start_time = None self.max_samples = 10 # hmm... self.u = SizedList(self.max_samples) self.d = SizedList(self.max_samples) self.t = SizedList(self.max_samples * 2) self.ur = SizedList(self.max_samples) self.dr = SizedList(self.max_samples) self.current_std = 0.001 self.max_std = 0.001 self.last_max = bttime() self.max_rates = {} self.max_rates["upload"] = 1.0 self.max_rates["download"] = 1.0 self.max_p = 1.0 self.min_p = 2**500 self.mid_p = ((self.max_p - self.min_p) / 2.0) + self.min_p self.old_p = None # I pulled these numbers out of my ass. if stats: tmp_dir = platform.get_temp_dir() timestr = "%d_%d_%d_%d_%d" % time.localtime()[1:6] stats_dir = os.path.join( tmp_dir, "bittorrent%s_%d" % (timestr, os.getpid())) os.mkdir(stats_dir) if debug: print "BandwidthManager: stats_dir = %s" % stats_dir rate_vs_time = os.path.join(stats_dir, "rate_vs_time.plotdata") self.rfp = open(rate_vs_time, "w") delay_vs_time = os.path.join(stats_dir, "delay_vs_time.plotdata") self.dfp = open(delay_vs_time, "w") sdev_vs_time = os.path.join(stats_dir, "stddev_vs_time.plotdata") self.sdevfp = open(sdev_vs_time, "w")
try: config, files = parse_configuration_and_args(defaults, 'bittorrent-tracker', args, 0, 0) except ValueError, e: print _("error: ") + str_exc(e) print _("run with -? for parameter explanations") return except BTFailure, e: print _("error: ") + str_exc(e) print _("run with -? for parameter explanations") return if config['dfile'] == "": config['dfile'] = decode_from_filesystem( os.path.join(platform.get_temp_dir(), efs2(u"dfile") + str(os.getpid()))) config = Preferences().initWithDict(config) ef = lambda e: errorfunc(logging.WARNING, e) platform.write_pid_file(config['pid'], ef) t = None try: r = RawServer(config) t = Tracker(config, r) try: #DEBUG print "track: create_serversocket, port=", config['port'] #END s = r.create_serversocket(config['port'], config['bind'])