Exemplo n.º 1
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()
Exemplo n.º 2
0
 def testCreation(self):
     policy = RankingPolicy.selectRankingSource('geoip')
     self.assertTrue(isinstance(policy, RankingPolicy.GeoIPPolicy))
Exemplo n.º 3
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)
Exemplo n.º 4
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 testCreation(self):
     policy = RankingPolicy.selectRankingSource('geoip')
     self.assertTrue(isinstance(policy, RankingPolicy.GeoIPPolicy))