def testLocalFolder(self):
        #build request
        #rated = self._tryRanking(iplist = ['209.34.91.45', '81.19.23.42'])
        #self.assertTrue(rated['81.19.23.42']>rated['209.34.91.45'])
        
        # dummy test
        self.selector.report_activity("foo", "bar", None)
        
        # test limited number
        torrents = self.selector.retrieve_torrent_stats(5)
        assert len(torrents) == 5, "torrents are %s" % torrents
        
        # test all
        torrents = self.selector.retrieve_torrent_stats(1000)
        assert len(torrents) == 7
        ids = []
#        print "torrents are: ", torrents
        for (id, url, rate) in torrents:
            tdef = TorrentDef.load(url)
            assert get_id(tdef) == id
            #print "%s with rating %s" % (tdef.get_name(), rate)
            assert rate == 100
            ids.append(id)
            
        # test local peers
        peers = self.selector.retrieve_local_peers_for_active_torrents(ids, 100, True)
        assert len(peers) == 0
        
        # dummy test for config parameters
        params = self.selector.retrieve_configuration_parameters("localhost")
        assert len(params) == 0
Beispiel #2
0
 def testRetrieveLocalPeersForActiveTorrents(self):
     tdef = TorrentDef.load("torrents/ubuntu.torrent")
     infohash_hex = common_utils.get_id(tdef)
     torrent_dict = self.wsclient.retrieve_local_peers_for_active_torrents(list_of_torrent_ids=[infohash_hex],
                                                            maximum_number_of_peers=10,
                                                            include_seeds=False)
     assert len(torrent_dict) >= 0, torrent_dict
Beispiel #3
0
    def testLocalFolder(self):
        #build request
        #rated = self._tryRanking(iplist = ['209.34.91.45', '81.19.23.42'])
        #self.assertTrue(rated['81.19.23.42']>rated['209.34.91.45'])

        # dummy test
        self.selector.report_activity("foo", "bar", None)

        # test limited number
        torrents = self.selector.retrieve_torrent_stats(5)
        assert len(torrents) == 5, "torrents are %s" % torrents

        # test all
        torrents = self.selector.retrieve_torrent_stats(1000)
        assert len(torrents) == 7
        ids = []
        #        print "torrents are: ", torrents
        for (id, url, rate) in torrents:
            tdef = TorrentDef.load(url)
            assert get_id(tdef) == id
            #print "%s with rating %s" % (tdef.get_name(), rate)
            assert rate == 100
            ids.append(id)

        # test local peers
        peers = self.selector.retrieve_local_peers_for_active_torrents(
            ids, 100, True)
        assert len(peers) == 0

        # dummy test for config parameters
        params = self.selector.retrieve_configuration_parameters("localhost")
        assert len(params) == 0
Beispiel #4
0
 def add(self, params):
     ''' adds a new download. '''
     if len(params) == 0:
         print >> sys.stderr, "Please provide torrent path."
     else:  
         path = params[1]
         tdef = TorrentDef.load(path)
         t_id = get_id(tdef)
         if not self.cache.is_running(t_id):
             self.cache.join_swarm(tdef, t_id)
Beispiel #5
0
    def testFIFO(self):
        #policy = ReplacementStrategy.create_policy(None, constants.RP_FIFO)
        policy = ReplacementStrategy.FIFO(self.started_at)
        candidate_downloads = self.downloads

#        print "candidates=", candidate_downloads
        selected = policy.free_up_download_slots(0, candidate_downloads)
#        print "selected=", candidate_downloads
        self.assertEquals(0, len(selected))
     
        selected = policy.free_up_download_slots(1, candidate_downloads)
        self.assertEquals(1, len(selected))
        # start times are sorted in rverse oder of downloads!!!
        self.assertEquals(get_id(self.downloads[0]), get_id(selected[0]))
     
        max_torrents = len(self.downloads)
        # test max number  
        selected = policy.free_up_download_slots(max_torrents, candidate_downloads)
        self.assertEquals(max_torrents, len(selected))
        
        selected = policy.free_up_download_slots(max_torrents+1, candidate_downloads)
        self.assertEquals(max_torrents, len(selected))
    def state_callback(self, ds):

        torrent_id = common_utils.get_id(ds.get_download().get_def())

        if not ds.get_peerlist() is None:
            for peer in ds.get_peerlist():
                self._update_volume(torrent_id, peer['ip'], peer['dtotal'],
                                    peer['utotal'])

        # only send the report if a waiting period of hap_interval seconds passed by
        if not abs(self._last_report_sent -
                   time.time()) >= self._client_config.get_hap_interval():
            return

        neighbour_stats = []
        new_last_period_peer_total = {}
        for peer in self._neighbour_ips:
            (download_volume,
             upload_volume) = self.aggregate_total_peer_traffic(peer)

            if download_volume == 0 and upload_volume == 0:
                continue

            if self._last_period_peer_total.has_key(peer):
                # we have old statistics for this peer
                old_dl, old_ul = self._last_period_peer_total[peer]

                if download_volume - old_dl == 0 and upload_volume - old_ul == 0:
                    continue

                neighbour_stats.append(
                    HAPNeighbourStatisticsDTO(download_volume - old_dl, peer,
                                              upload_volume - old_ul))
                new_last_period_peer_total[peer] = (download_volume,
                                                    upload_volume)
            else:
                # the peer must have joined during the current period
                neighbour_stats.append(
                    HAPNeighbourStatisticsDTO(download_volume, peer,
                                              upload_volume))
                new_last_period_peer_total[peer] = (download_volume,
                                                    upload_volume)

        # dont send a report if there are no neighbour stats
        if len(neighbour_stats) == 0:
            self._start_next_cycle(new_last_period_peer_total)
            return

        self._logger.info("Sending statistics to HAP...")
        self._hap_client.report_activity(neighbour_stats)
        self._start_next_cycle(new_last_period_peer_total)
    def state_callback(self, ds):

        torrent_id = common_utils.get_id(ds.get_download().get_def())
        
        if not ds.get_peerlist() is None:
            for peer in ds.get_peerlist():
                self._update_volume(torrent_id, peer['ip'], peer['dtotal'], peer['utotal'])
                
        # only send the report if a waiting period of hap_interval seconds passed by
        if not abs(self._last_report_sent - time.time()) >= self._client_config.get_hap_interval():
            return
        
        neighbour_stats = []
        new_last_period_peer_total = {}
        for peer in self._neighbour_ips:
            (download_volume, upload_volume) = self.aggregate_total_peer_traffic(peer)
            
            if download_volume == 0 and upload_volume == 0:
                continue
            
            if self._last_period_peer_total.has_key(peer):
                # we have old statistics for this peer
                old_dl, old_ul = self._last_period_peer_total[peer]
                
                if download_volume - old_dl == 0 and upload_volume - old_ul == 0:
                    continue
                
                neighbour_stats.append(HAPNeighbourStatisticsDTO(download_volume-old_dl, peer, upload_volume-old_ul))
                new_last_period_peer_total[peer] = (download_volume, upload_volume)
            else:
                # the peer must have joined during the current period
                neighbour_stats.append(HAPNeighbourStatisticsDTO(download_volume, peer, upload_volume))
                new_last_period_peer_total[peer] = (download_volume, upload_volume)
                
        # dont send a report if there are no neighbour stats
        if len(neighbour_stats) == 0:
            self._start_next_cycle(new_last_period_peer_total)
            return
        
        self._logger.info("Sending statistics to HAP...")
        self._hap_client.report_activity(neighbour_stats)
        self._start_next_cycle(new_last_period_peer_total)
 def state_callback(self, ds):
     self._logger.debug("state_callback called")
     ts = time.time()
     #self._logger.info("ts is %s" % str(ts))
     # check if we have to file an activity report right now
     # if not, just return
     if not ts - self._last_timestamp >= self._emit_interval:
         return
     
     try:
         d = ds.get_download()
         self._logger.info("torrent: %s" % ds.get_download().get_def().get_name_as_unicode())
         torrent_id = get_id(d.get_def())
         torrent_url = "unknown"
         torrent_progress = int(ds.get_progress()*100)
         torrent_size = d.get_def().get_length()
         downloads = [ ( torrent_id, torrent_url, torrent_size, torrent_progress ) ]
     
         self._ws.report_activity(self._own_address[0], self._own_address[1], downloads)
         self._last_timestamp = ts
     except:
         self._logger.error("an error occured: could not retrieve torrent stats from resp. download object")