Beispiel #1
0
 def __init__(self, span, interval):
     self.max_len = int(span / (interval / 1000))
     self.interval = interval
     self.upload_data = SizedList(self.max_len)
     self.download_data = SizedList(self.max_len)
     self.max_upload_rate = 0
     self.max_download_rate = 0
     self.variance = 0
     self.max_variance = 1
     self.viewer = None
Beispiel #2
0
    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")