Exemplo n.º 1
0
    def subtest_add_content_dir(self,merkle=True):
        """ Add a single dir to a TorrentDef """
        t = TorrentDef()
        t.set_create_merkle_torrent(merkle)
        dn = os.path.join(os.getcwd(),"contentdir")
        t.add_content(dn,"dirintorrent")
        t.set_tracker(TRACKER)
        t.finalize()

        exps = 0L
        for f in os.listdir("contentdir"):
            if f.startswith('.'):
                continue
            p = os.path.join("contentdir",f)
            s = os.path.getsize(p)
            exps += s
            print "test: expected size",f,s

        print "test: expected total size of files in torrent",exps

        metainfo = t.get_metainfo()
        self.general_check(metainfo)
        
        self.assert_(metainfo['info']['name'] == 'dirintorrent')
        reals = 0L
        for file in metainfo['info']['files']:
            s = file['length']
            print "test: real size",file['path'],s
            reals += s
            
        print "test: real size of files in torrent",reals
            
        self.assert_(exps == reals)
Exemplo n.º 2
0
    def _start_download(self, torrent):
        tdef = TorrentDef.load(torrent)
        dscfg = DownloadStartupConfig()
        #disable PEX protocol, otherwise it will crash if two clients are running on the same machine!
        #dscfg.set_ut_pex_max_addrs_from_peer(0)

        dscfg.set_dest_dir(self._config.get_directory())
        if common_utils.has_torrent_video_files(
                tdef) and not self._config.is_supporter_seed():
            dscfg.set_video_event_callback(self._handlers.video_event_callback)
        self._logger.warn("Download directory: " + dscfg.get_dest_dir())
        dscfg.set_max_speed(UPLOAD, self._config.get_upload_limit())
        dscfg.set_max_speed(DOWNLOAD, self._config.get_download_limit())
        con_lim = self._config.get_connection_limit()
        dscfg.set_max_conns(con_lim)
        dscfg.set_max_conns_to_initiate((con_lim + 1) / 2)
        dscfg.set_min_peers((con_lim + 2) / 3)
        dscfg.set_max_uploads(self._config.get_max_upload_slots_per_download())
        dscfg.set_peer_type("G")

        self._logger.warn("Files available: %s" % tdef.get_files())

        if dscfg.get_mode() == DLMODE_VOD:
            self._logger.warn("RUN in streaming mode")
            if tdef.is_multifile_torrent():
                for file in tdef.get_files():
                    if file.endswith(".avi"):
                        dscfg.set_selected_files([file])
                        break
        else:
            self._logger.warn("RUN in file sharing mode")

        d = self._session.start_download(tdef, dscfg)
        d.set_state_callback(self._handlers.state_callback, getpeerlist=True)
Exemplo n.º 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
    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
Exemplo n.º 5
0
 def _start_download(self, torrent):
     tdef = TorrentDef.load(torrent)
     dscfg = DownloadStartupConfig()
     #disable PEX protocol, otherwise it will crash if two clients are running on the same machine!
     #dscfg.set_ut_pex_max_addrs_from_peer(0)
     
     dscfg.set_dest_dir(self._config.get_directory())
     if common_utils.has_torrent_video_files(tdef) and not self._config.is_supporter_seed():
         dscfg.set_video_event_callback(self._handlers.video_event_callback)
     self._logger.warn("Download directory: " + dscfg.get_dest_dir())
     dscfg.set_max_speed(UPLOAD, self._config.get_upload_limit())
     dscfg.set_max_speed(DOWNLOAD, self._config.get_download_limit())
     con_lim = self._config.get_connection_limit()
     dscfg.set_max_conns(con_lim)
     dscfg.set_max_conns_to_initiate((con_lim+1)/2)
     dscfg.set_min_peers((con_lim+2)/3)
     dscfg.set_max_uploads(self._config.get_max_upload_slots_per_download())
     dscfg.set_peer_type("G")
     
     self._logger.warn("Files available: %s" % tdef.get_files())
     
     if dscfg.get_mode() == DLMODE_VOD:
         self._logger.warn("RUN in streaming mode")
         if tdef.is_multifile_torrent():
             for file in tdef.get_files():
                 if file.endswith(".avi"):
                     dscfg.set_selected_files([file])
                     break
     else:
         self._logger.warn("RUN in file sharing mode")
         
     d = self._session.start_download(tdef, dscfg)
     d.set_state_callback(self._handlers.state_callback, getpeerlist=True)
Exemplo n.º 6
0
 def subtest_add_content_file(self,merkle=True):
     """ Add a single file to a TorrentDef """
     t = TorrentDef()
     t.set_create_merkle_torrent(merkle)
     fn = os.path.join(os.getcwd(),"file.wmv")
     t.add_content(fn)
     t.set_tracker(TRACKER)
     t.finalize()
     
     s = os.path.getsize("file.wmv")
     
     metainfo = t.get_metainfo()
     self.general_check(metainfo)
     
     self.assert_(metainfo['info']['name'] == "file.wmv")
     self.assert_(metainfo['info']['length'] == s)
     
     """
Exemplo n.º 7
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)
Exemplo n.º 8
0
 def subtest_add_content_file_playtime(self,merkle=True):
     """ Add a single file with playtime to a TorrentDef """
     t = TorrentDef()
     t.set_create_merkle_torrent(merkle)
     fn = os.path.join(os.getcwd(),"file.wmv")
     t.add_content(fn,playtime=PLAYTIME)
     t.set_tracker(TRACKER)
     t.finalize()
     
     s = os.path.getsize("file.wmv")
     
     metainfo = t.get_metainfo()
     self.general_check(metainfo)
     self.assert_(metainfo['info']['playtime']==PLAYTIME)
     azprop = metainfo['azureus_properties']
     content = azprop['Content']
     realspeedbps = content['Speed Bps']
     expspeedbps = s/PLAYTIME_SECS
     self.assert_(realspeedbps == expspeedbps)
Exemplo n.º 9
0
import binascii

from BaseLib.Core.API import TorrentDef
from BaseLib.Core.Overlay.permid import verify_torrent_signature

if len(argv) == 1:
    print '%s file1.torrent file2.torrent file3.torrent ...' % argv[0]
    print
    exit(2)  # common exit code for syntax error

for metainfo_name in argv[1:]:
    if metainfo_name.endswith(".url"):
        f = open(metainfo_name, "rb")
        url = f.read()
        f.close()
        tdef = TorrentDef.load_from_url(url)
    else:
        tdef = TorrentDef.load(metainfo_name)
    metainfo = tdef.get_metainfo()
    infohash = tdef.get_infohash()

    print "metainfo:", metainfo.keys()
    #print "metainfo creation date",metainfo['creation date']
    if 'azureus_properties' in metainfo:
        azprop = metainfo['azureus_properties']
        print "azprop:", azprop.keys()
        if 'Content' in azprop:
            content = azprop['Content']
            print "content:", content.keys()
            for key in content.keys():
                if key.lower() != 'thumbnail':
Exemplo n.º 10
0
    def subtest_add_content_file_save(self,merkle=True):
        """ Add a single file to a TorrentDef and save the latter"""
        t = TorrentDef()
        t.set_create_merkle_torrent(merkle)
        fn = os.path.join(os.getcwd(),"file.wmv")
        t.add_content(fn)
        t.set_tracker(TRACKER)
        t.finalize()

        tfn = os.path.join(os.getcwd(),"gen.torrent")
        t.save(tfn)
        
        f = open(tfn,"rb")
        bdata = f.read()
        f.close()
        os.remove(tfn)
        
        data = bdecode(bdata)
        metainfo = t.get_metainfo()
        self.general_check(metainfo)
        self.assert_(metainfo == data)
Exemplo n.º 11
0
    def test_ns_metadata(self):
        dummydata = "HalloWereld"
        t = TorrentDef()
        t.set_metadata(dummydata)
        fn = os.path.join(os.getcwd(),"file.wmv")
        t.add_content(fn)
        t.set_tracker(TRACKER)
        t.finalize()

        [handle,filename] = tempfile.mkstemp()
        os.close(handle)
        t.save(filename)
        
        t2 = TorrentDef.load(filename)
        self.assert_(t2.get_metadata() == dummydata)
Exemplo n.º 12
0
    def subtest_add_content_torrentsig(self,merkle=True):
        """ Add a single file to a TorrentDef and sign it """
        t = TorrentDef()
        t.set_create_merkle_torrent(merkle)
        fn = os.path.join(os.getcwd(),"file.wmv")
        kpfn = os.path.join(os.getcwd(),"ec.pem")
        t.add_content(fn)
        t.set_signature_keypair_filename(kpfn)
        t.set_tracker(TRACKER)
        t.finalize()

        metainfo = t.get_metainfo()
        self.general_check(metainfo)
        ret = verify_torrent_signature(metainfo)
        self.assert_(ret == True)
Exemplo n.º 13
0
    def subtest_add_content_piece_length(self,merkle=True):
        """ Add a single file with piece length to a TorrentDef """
        t = TorrentDef()
        t.set_create_merkle_torrent(merkle)
        fn = os.path.join(os.getcwd(),"file.wmv")
        t.add_content(fn)
        t.set_piece_length(2 ** 16)
        t.set_tracker(TRACKER)
        t.finalize()

        metainfo = t.get_metainfo()
        self.general_check(metainfo)
        self.assert_(metainfo['info']['piece length'] == 2 ** 16)
Exemplo n.º 14
0
    def subtest_add_content_announce_list(self,merkle=True):
        """ Add a single file with announce-list to a TorrentDef """
        t = TorrentDef()
        t.set_create_merkle_torrent(merkle)
        fn = os.path.join(os.getcwd(),"file.wmv")
        t.add_content(fn)
        t.set_tracker(TRACKER)
        exphier = [[TRACKER],['http://tracker1.tribler.org:6969/announce','http://tracker2.tribler.org:7070/ann'],['http://www.cs.vu.nl','http://www.st.ewi.tudelft.nl','http://www.vuze.com']]
        t.set_tracker_hierarchy(exphier)
        t.finalize()

        metainfo = t.get_metainfo()
        self.general_check(metainfo)
        realhier = metainfo['announce-list']
        self.assert_(realhier == exphier)
Exemplo n.º 15
0
    def subtest_add_content_httpseeds(self,merkle=True):
        """ Add a single file with BitTornado httpseeds to a TorrentDef """
        t = TorrentDef()
        t.set_create_merkle_torrent(merkle)
        fn = os.path.join(os.getcwd(),"file.wmv")
        t.add_content(fn)
        t.set_tracker(TRACKER)
        expseeds = ['http://www.cs.vu.nl/index.html','http://www.st.ewi.tudelft.nl/index.html']
        t.set_httpseeds(expseeds)
        t.finalize()

        metainfo = t.get_metainfo()
        self.general_check(metainfo)
        realseeds = metainfo['httpseeds']
        self.assert_(realseeds == expseeds)
Exemplo n.º 16
0
    def subtest_add_content_file_thumbnail(self,merkle=True):
        """ Add a single file with thumbnail to a TorrentDef """
        t = TorrentDef()
        t.set_create_merkle_torrent(merkle)
        fn = os.path.join(os.getcwd(),"file.wmv")
        thumbfn = os.path.join(os.getcwd(),"thumb.jpg")
        t.add_content(fn)
        t.set_thumbnail(thumbfn)
        t.set_tracker(TRACKER)
        t.finalize()

        f = open(thumbfn,"rb")
        expthumb = f.read()
        f.close()
        
        metainfo = t.get_metainfo()
        self.general_check(metainfo)
        azprop = metainfo['azureus_properties']
        content = azprop['Content']
        realthumb = content['Thumbnail']
        self.assert_(realthumb == expthumb)
Exemplo n.º 17
0
    def subtest_add_content_dir_playtime(self,merkle=True):
        """ Add a single dir to a TorrentDef """
        t = TorrentDef()
        t.set_create_merkle_torrent(merkle)
        fn1 = os.path.join(os.getcwd(),"contentdir","file.avi")
        fn2 = os.path.join(os.getcwd(),"contentdir","file.txt")
        t.add_content(fn1,os.path.join("dirintorrent","file.avi"),playtime=PLAYTIME)
        t.add_content(fn2,os.path.join("dirintorrent","file.txt"))
        t.set_tracker(TRACKER)
        t.finalize()

        metainfo = t.get_metainfo()
        self.general_check(metainfo)
        self.assert_(metainfo['info']['name'] == 'dirintorrent')

        s = os.path.getsize(fn1)
        
        files = metainfo['info']['files']
        for file in files:
            if file['path'][0] == "file.avi":
                self.assert_(file['playtime']==PLAYTIME)
        
        azprop = metainfo['azureus_properties']
        content = azprop['Content']
        realspeedbps = content['Speed Bps']
        expspeedbps = s/PLAYTIME_SECS
        self.assert_(realspeedbps == expspeedbps)
 def load_torrent_by_path(self, t_url):
     ''' Helper method to let the selector decide whether we should load from disc or from web.
     '''
     tdef = TorrentDef.load(t_url) #TODO: could also du id-based! self.torrents[id]
     return tdef
Exemplo n.º 19
0
    def subtest_add_content_dir_and_file(self,merkle=True):
        """ Add a single dir and single file to a TorrentDef """
        t = TorrentDef()
        t.set_create_merkle_torrent(merkle)
        
        dn = os.path.join(os.getcwd(),"contentdir")
        t.add_content(dn,"dirintorrent")
        
        fn = os.path.join(os.getcwd(),"file.wmv")
        t.add_content(fn,os.path.join("dirintorrent","file.wmv"))
        
        t.set_tracker(TRACKER)
        t.finalize()

        # Check
        exps = os.path.getsize(fn)
        for f in os.listdir("contentdir"):
            if f.startswith('.'):
                continue
            p = os.path.join("contentdir",f)
            exps += os.path.getsize(p) 

        metainfo = t.get_metainfo()
        self.general_check(metainfo)
        self.assert_(metainfo['info']['name'] == 'dirintorrent')
        
        reals = 0L
        for file in metainfo['info']['files']:
            reals += file['length']
        self.assert_(exps == reals)
Exemplo n.º 20
0
from BaseLib.Core.API import TorrentDef
from BaseLib.Core.Overlay.permid import verify_torrent_signature
from JSI.RichMetadata.RichMetadata import RichMetadataGenerator

if len(argv) == 1:
    print '%s file1.torrent file2.torrent file3.torrent ...' % argv[0]
    print
    exit(2) # common exit code for syntax error

for metainfo_name in argv[1:]:
    if metainfo_name.endswith(".url"):
        f = open(metainfo_name,"rb")
        url = f.read()
        f.close()
        tdef = TorrentDef.load_from_url(url)
    else:
        tdef = TorrentDef.load(metainfo_name)
    metainfo = tdef.get_metainfo()
    infohash = tdef.get_infohash()
    metadata = tdef.get_metadata()
    
    print "metainfo:",metainfo.keys()
    #print "metainfo creation date",metainfo['creation date']
    if 'azureus_properties' in metainfo:
        azprop = metainfo['azureus_properties']
        print "azprop:",azprop.keys()
        if 'Content' in azprop:
                content = azprop['Content']
                print "content:",content.keys()
                for key in content.keys():