Beispiel #1
0
    def testFromWuerzburg(self):
        own_ip = wuerzburg
        self.policy = RankingPolicy.GeoIPPolicy(own_ip)

        ips = [own_ip]
        res = self.policy.getRankedPeers(ips)
        self.assertTrue(res[own_ip]) > 0

        ips2 = [own_ip, "193.99.144.85"]
        res = self.policy.getRankedPeers(ips2)
        self.assertTrue(res[own_ip] > res["193.99.144.85"])

        # now try a list
        ips3 = [munich, wuerzburg, kaiserlautern, karlsruhe, darmstadt]
        res = self.policy.getRankedPeers(ips3)

        city = [ip for (ip, rank) in res.items() if rank == 1000]  #same city
        region = [ip for (ip, rank) in res.items() if rank == 500]  #same city
        country = [ip for (ip, rank) in res.items()
                   if rank == 250]  #same country

        self.assertEquals([wuerzburg], city)
        self.assertEquals([munich], region)
        ref = ips3
        ref.remove(wuerzburg)
        ref.remove(munich)
        self.assertEquals(set(ref), set(country))
    def testOddEvenRanking(self):
        mech = BiasedUnchoking.SISFiltering(RankingPolicy.OddEvenPolicy())

        connections = [DummyConnection('209.34.91.45')]
        self.assertEquals(connections,
                          mech.selectConnections(connections, number=-1))

        connections = [
            DummyConnection('209.34.91.45'),
            DummyConnection('209.34.91.46')
        ]
        ref = [
            DummyConnection('209.34.91.46'),
            DummyConnection('209.34.91.45')
        ]
        self.assertEquals(ref, mech.selectConnections(connections, number=-1))

        connections = [
            DummyConnection('209.34.91.45'),
            DummyConnection('209.34.91.46'),
            DummyConnection('209.34.91.47'),
            DummyConnection('209.34.91.48')
        ]
        ref = [
            DummyConnection('209.34.91.46'),
            DummyConnection('209.34.91.48')
        ]
        # enough numbers
        self.assertEquals(ref, mech.selectConnections(connections, number=2))
Beispiel #3
0
    def testWholeList(self):
        self.policy = RankingPolicy.GeoIPPolicy(
            '130.83.139.168')  # test from Darmstadt

        f = open('resources/glab-ips.txt', 'r')
        list = []
        for line in f:
            #print line[:-1]
            list.append(line[:-1])

        ranked = self.policy.getRankedPeers(list)

        grouped = dict()

        for ref_rank in [0, 250, 500, 1000]:
            #print "For %d" % ref_rank
            group = [ip for (ip, rank) in ranked.items() if rank == ref_rank]
            #print group
            grouped[ref_rank] = group
            #print "length %d" % len(group)
            #print sorted(group)

        self.assertEquals(0, len(grouped[0]))
        self.assertEquals(128, len(grouped[250]))
        self.assertEquals(0, len(grouped[500]))
        self.assertEquals(24, len(grouped[1000]))
Beispiel #4
0
 def _init_before_session(self):
     self.ranking = RankingPolicy.selectRankingSource(self._cache_config.get_ranking_source(),
                                                 conf=self._cache_config)
     self._logger.warning("Ranking source is %s" % self.ranking)
     
     exclude_below = 1# allow only non-remote connections!
     self.filtering = NeighborSelection.createMechanism(self._cache_config.get_ns_mode(),
                                                         self.ranking,
                                                         exclude_below=exclude_below,
                                                         locality_pref=self._cache_config.get_locality_preference())
     self._logger.warning("Neighbor selection is %s" % self.filtering)
     self.max_downloads = self._cache_config.get_max_downloads()
Beispiel #5
0
    def testFromDarmstadt(self):
        own_ip = '130.83.139.168'
        self.policy = RankingPolicy.GeoIPPolicy(own_ip)

        ips = [own_ip]
        res = self.policy.getRankedPeers(ips)
        self.assertTrue(res[own_ip]) > 0

        ips2 = [own_ip, "193.99.144.85"]
        res = self.policy.getRankedPeers(ips2)
        self.assertTrue(res[own_ip] > res["193.99.144.85"])

        ips3 = [munich, wuerzburg, kaiserlautern, karlsruhe, darmstadt]
        res = self.policy.getRankedPeers(ips3)
        city = [ip for (ip, rank) in res.items() if rank == 1000]  #same city
        country = [ip for (ip, rank) in res.items()
                   if rank == 250]  #same country
        self.assertEquals([darmstadt], city)
        ref = ips3
        ref.remove(darmstadt)
        self.assertEquals(set(ref), set(country))
Beispiel #6
0
 def testCreation(self):
     policy = RankingPolicy.selectRankingSource('geoip')
     self.assertTrue(isinstance(policy, RankingPolicy.GeoIPPolicy))
Beispiel #7
0
    def _setup_client(self):
        def setup_directories():
            if not os.access(self._config.get_directory(), os.F_OK):
                os.mkdir(self._config.get_directory())
            if self._config.get_state_directory():
                if not os.access(self._config.get_state_directory(), os.F_OK):
                    os.mkdir(self._config.get_state_directory())
            else:
                state_dir = tempfile.mkdtemp()
                self._config.set_state_directory(state_dir)

        def setup_scfg():
            scfg = SessionStartupConfig()
            scfg.set_state_dir(self._config.get_state_directory())
            scfg.set_listen_port(self._config.get_port())
            scfg.set_overlay(False)
            scfg.set_megacache(False)
            scfg.set_upnp_mode(UPNPMODE_DISABLED)
            return scfg

        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())
                    )

        setup_directories()
        self._logger.info("Client directory is at %s" %
                          self._config.get_directory())
        self._logger.info("Client state directory is at %s" %
                          self._config.get_state_directory())
        scfg = setup_scfg()
        self._session = Session(scfg)
        self._session.set_supporter_seed(
            self._config.is_supporter_seed())  #TODO: parameterize!!!
        self._logger.error("Supporter IPs are: " +
                           self._config.get_supporter_ip())
        self._session.set_supporter_ips(self._config.get_supporter_ip())
        setup_callback_handlers(self._session, scfg)

        source = self._config.get_ranking_source()
        endpoint = self._config.get_sis_client_endpoint()
        ranking = RankingPolicy.selectRankingSource(source, conf=self._config)
        NeighborSelection.createMechanism(
            self._config.get_ns_mode(),
            ranking,
            locality_pref=self._config.get_locality_preference())
        BiasedUnchoking.BiasedUnchoking(self._config.get_peer_selection_mode(),
                                        ranking)
 def _setup_client(self):
     def setup_directories():
         if not os.access(self._config.get_directory(), os.F_OK):
             os.mkdir(self._config.get_directory())
         if self._config.get_state_directory():
             if not os.access(self._config.get_state_directory(), os.F_OK):
                 os.mkdir(self._config.get_state_directory())
         else:
             state_dir = tempfile.mkdtemp()
             self._config.set_state_directory(state_dir)
     
     def setup_scfg():
         scfg = SessionStartupConfig()
         scfg.set_state_dir(self._config.get_state_directory())
         scfg.set_listen_port(self._config.get_port())
         scfg.set_overlay(False)
         scfg.set_megacache(False)
         scfg.set_upnp_mode(UPNPMODE_DISABLED)
         return scfg
     
     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()))
             
     setup_directories()
     self._logger.info("Client directory is at %s" % self._config.get_directory())
     self._logger.info("Client state directory is at %s" % self._config.get_state_directory())
     scfg = setup_scfg()
     self._session = Session(scfg)
     self._session.set_supporter_seed(self._config.is_supporter_seed())#TODO: parameterize!!!
     self._logger.error("Supporter IPs are: "+self._config.get_supporter_ip())
     self._session.set_supporter_ips(self._config.get_supporter_ip())
     setup_callback_handlers(self._session, scfg)
     
     source = self._config.get_ranking_source()
     endpoint = self._config.get_sis_client_endpoint()
     ranking = RankingPolicy.selectRankingSource(source, conf=self._config)
     NeighborSelection.createMechanism(self._config.get_ns_mode(), ranking,
                                       locality_pref=self._config.get_locality_preference())
     BiasedUnchoking.BiasedUnchoking(self._config.get_peer_selection_mode(), ranking) 
 def testCreation(self):
     policy = RankingPolicy.selectRankingSource('geoip')
     self.assertTrue(isinstance(policy, RankingPolicy.GeoIPPolicy))