def testAggregateTotalTraffic(self):
        torrent_id_a = "some_torrent"
        torrent_id_b = "another_torrent"
        peer_id = "127.0.0.1"

        hap_handler = ClientHAPHandler()
        hap_handler._update_volume(torrent_id_a, peer_id, 1024.0, 1024.0)
        hap_handler._update_volume(torrent_id_b, peer_id, 2048.0, 2048.0)

        dtotal, utotal = hap_handler.aggregate_total_peer_traffic(peer_id)

        self.assertEquals(3, dtotal)
        self.assertEquals(3, utotal)
        self.assertTrue(peer_id in hap_handler._neighbour_ips)
        self.assertTrue(len(hap_handler._neighbour_ips) == 1)
Пример #2
0
    def testAggregateTotalTraffic(self):
        torrent_id_a = "some_torrent"
        torrent_id_b = "another_torrent"
        peer_id = "127.0.0.1"

        hap_handler = ClientHAPHandler()
        hap_handler._update_volume(torrent_id_a, peer_id, 1024.0, 1024.0)
        hap_handler._update_volume(torrent_id_b, peer_id, 2048.0, 2048.0)

        dtotal, utotal = hap_handler.aggregate_total_peer_traffic(peer_id)

        self.assertEquals(3, dtotal)
        self.assertEquals(3, utotal)
        self.assertTrue(peer_id in hap_handler._neighbour_ips)
        self.assertTrue(len(hap_handler._neighbour_ips) == 1)
Пример #3
0
        def setup_callback_handlers(session, scfg):
            self._handlers = PeerCallbackHandlers(
                self._get_name(), self._config.get_report_interval())
            self._handlers.register_handler(PeerReporter(self._get_name()))
            self._handlers.register_handler(
                ClientStatistics(self._config.get_directory(),
                                 self._config.get_id()))

            if self._config.is_hap_enabled():
                self._logger.info("HAP support enabled")
                self._handlers.register_handler(ClientHAPHandler(self._config))

            if self._config.get_sis_url() != None:
                ip_addr = net_utils.get_own_ip_addr()
                self._handlers.register_handler(
                    PeerActivityReportEmitter(
                        (ip_addr, self._config.get_port()),
                        self._config.get_activity_report_interval(),
                        sis_iop_endpoint_url=self._config.get_sis_iop_url()))

            if self._config.get_exit_on() == constants.EXIT_ON_ALL_FINISHED:
                self._handlers.register_handler(
                    ClientUptimeHandler(session,
                                        method=constants.EXIT_ON_ALL_FINISHED,
                                        callback=self._on_exit))
            elif self._config.get_exit_on() == constants.EXIT_ON_PLAYBACK_DONE:
                self._handlers.register_handler(
                    ClientUptimeHandler(session,
                                        method=constants.EXIT_ON_PLAYBACK_DONE,
                                        callback=self._on_exit))
            elif self._config.get_exit_on() == constants.EXIT_ON_SEEDING_TIME:
                self._handlers.register_handler(
                    ClientUptimeHandler(
                        session,
                        method=constants.EXIT_ON_SEEDING_TIME,
                        max_seeding_time=self._config.get_seeding_time(),
                        callback=self._on_exit))

            if self._config.get_report_to() is not None:
                if self._config.get_report_to() == 'local_report':
                    self._local_reporter = PeerLocalReporter(
                        self._get_name(), self._config.get_id(), session,
                        self._config.get_directory())
                    self._handlers.register_handler(self._local_reporter)
                else:
                    self._handlers.register_handler(
                        PeerHTTPReporter(
                            self._get_name(),
                            self._config.get_id(),
                            self._config.get_report_to(),
                            scfg,
                            self._config.get_compress_xml_reports(),
                            self._config.get_serialization_method(),
                            report_interval=self._config.get_report_interval())
                    )
Пример #4
0
    def testCorrectDictUpdate(self):

        torrent_id = "some_torrent"
        peer_id_a = "127.0.0.1"
        peer_id_b = "183.132.13.39"

        hap_handler = ClientHAPHandler()
        hap_handler._update_volume(torrent_id, peer_id_a, 1024.0, 2048.0)
        hap_handler._update_volume(torrent_id, peer_id_b, 512.0, 512.0)

        self.assertTrue(len(hap_handler._neighbour_ips) == 2)
        self.assertTrue(peer_id_a in hap_handler._neighbour_ips)
        self.assertTrue(peer_id_b in hap_handler._neighbour_ips)

        self.assertTrue(hap_handler._neighbours.has_key(torrent_id))
        self.assertTrue(hap_handler._neighbours[torrent_id].has_key(peer_id_a))
        self.assertTrue(hap_handler._neighbours[torrent_id].has_key(peer_id_b))
        self.assertEquals(1, len(hap_handler._neighbours))
        self.assertEquals(2, len(hap_handler._neighbours[torrent_id]))
        self.assertEquals(
            2, hap_handler._neighbours[torrent_id][peer_id_a]['upload'])
        self.assertEquals(
            1, hap_handler._neighbours[torrent_id][peer_id_a]['download'])
        self.assertEquals(
            0, hap_handler._neighbours[torrent_id][peer_id_b]['upload'])
        self.assertEquals(
            0, hap_handler._neighbours[torrent_id][peer_id_b]['download'])

        hap_handler._update_volume(torrent_id, peer_id_a, 2048.0, 4096.0)
        hap_handler._update_volume(torrent_id, peer_id_b, 2048.0, 4096.0)

        # new reports for already seen IP addresses should have no effect on the
        # neighbour ips list
        self.assertTrue(len(hap_handler._neighbour_ips) == 2)
        self.assertTrue(peer_id_a in hap_handler._neighbour_ips)
        self.assertTrue(peer_id_b in hap_handler._neighbour_ips)

        self.assertEquals(
            4, hap_handler._neighbours[torrent_id][peer_id_a]['upload'])
        self.assertEquals(
            2, hap_handler._neighbours[torrent_id][peer_id_a]['download'])
        self.assertEquals(
            4, hap_handler._neighbours[torrent_id][peer_id_b]['upload'])
        self.assertEquals(
            2, hap_handler._neighbours[torrent_id][peer_id_b]['download'])
    def testCorrectDictUpdate(self):

        torrent_id = "some_torrent"
        peer_id_a = "127.0.0.1"
        peer_id_b = "183.132.13.39"

        hap_handler = ClientHAPHandler()
        hap_handler._update_volume(torrent_id, peer_id_a, 1024.0, 2048.0)
        hap_handler._update_volume(torrent_id, peer_id_b, 512.0, 512.0)

        self.assertTrue(len(hap_handler._neighbour_ips) == 2)
        self.assertTrue(peer_id_a in hap_handler._neighbour_ips)
        self.assertTrue(peer_id_b in hap_handler._neighbour_ips)

        self.assertTrue(hap_handler._neighbours.has_key(torrent_id))
        self.assertTrue(hap_handler._neighbours[torrent_id].has_key(peer_id_a))
        self.assertTrue(hap_handler._neighbours[torrent_id].has_key(peer_id_b))
        self.assertEquals(1, len(hap_handler._neighbours))
        self.assertEquals(2, len(hap_handler._neighbours[torrent_id]))
        self.assertEquals(2, hap_handler._neighbours[torrent_id][peer_id_a]["upload"])
        self.assertEquals(1, hap_handler._neighbours[torrent_id][peer_id_a]["download"])
        self.assertEquals(0, hap_handler._neighbours[torrent_id][peer_id_b]["upload"])
        self.assertEquals(0, hap_handler._neighbours[torrent_id][peer_id_b]["download"])

        hap_handler._update_volume(torrent_id, peer_id_a, 2048.0, 4096.0)
        hap_handler._update_volume(torrent_id, peer_id_b, 2048.0, 4096.0)

        # new reports for already seen IP addresses should have no effect on the
        # neighbour ips list
        self.assertTrue(len(hap_handler._neighbour_ips) == 2)
        self.assertTrue(peer_id_a in hap_handler._neighbour_ips)
        self.assertTrue(peer_id_b in hap_handler._neighbour_ips)

        self.assertEquals(4, hap_handler._neighbours[torrent_id][peer_id_a]["upload"])
        self.assertEquals(2, hap_handler._neighbours[torrent_id][peer_id_a]["download"])
        self.assertEquals(4, hap_handler._neighbours[torrent_id][peer_id_b]["upload"])
        self.assertEquals(2, hap_handler._neighbours[torrent_id][peer_id_b]["download"])