r225 - in /debtorrent/branches/unique: DebTorrent/launchmanycore.py btshowmetainfo.py

camrdale-guest at users.alioth.debian.org camrdale-guest at users.alioth.debian.org
Sun Aug 12 17:58:58 UTC 2007


Author: camrdale-guest
Date: Sun Aug 12 17:58:57 2007
New Revision: 225

URL: http://svn.debian.org/wsvn/debtorrent/?sc=1&rev=225
Log:
Switch to using the new torrent identifier instead of the info hash.

Modified:
    debtorrent/branches/unique/DebTorrent/launchmanycore.py
    debtorrent/branches/unique/btshowmetainfo.py

Modified: debtorrent/branches/unique/DebTorrent/launchmanycore.py
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/branches/unique/DebTorrent/launchmanycore.py?rev=225&op=diff
==============================================================================
--- debtorrent/branches/unique/DebTorrent/launchmanycore.py (original)
+++ debtorrent/branches/unique/DebTorrent/launchmanycore.py Sun Aug 12 17:58:57 2007
@@ -73,6 +73,8 @@
     @ivar controller: the manager for all torrent downloads
     @type hash: C{string}
     @ivar hash: the info hash of the torrent
+    @type identifier: C{string}
+    @ivar identifier: the identifier of the torrent
     @type response: C{dictionary}
     @ivar response: the meta info for the torrent
     @type config: C{dictionary}
@@ -109,13 +111,15 @@
     
     """
     
-    def __init__(self, controller, hash, response, config, myid):
+    def __init__(self, controller, hash, identifier, response, config, myid):
         """Initialize the instance and start a new downloader.
         
         @type controller: L{LaunchMany}
         @param controller: the manager for all torrent downloads
         @type hash: C{string}
         @param hash: the info hash of the torrent
+        @type identifier: C{string}
+        @param identifier: the identifier of the torrent
         @type response: C{dictionary}
         @param response: the meta info for the torrent
         @type config: C{dictionary}
@@ -127,6 +131,7 @@
         
         self.controller = controller
         self.hash = hash
+        self.identifier = identifier
         self.response = response
         self.config = config
         
@@ -142,11 +147,11 @@
         self.status_errtime = 0
         self.status_done = 0.0
 
-        self.rawserver = controller.handler.newRawServer(hash, self.doneflag)
+        self.rawserver = controller.handler.newRawServer(identifier, self.doneflag)
 
         d = BT1Download(self.update_status, self.finished, self.error,
-                        self.doneflag, config, response,
-                        hash, myid, self.rawserver, controller.listen_port, 
+                        self.doneflag, config, response, identifier,
+                        myid, self.rawserver, controller.listen_port, 
                         self.controller.configdir)
         self.d = d
 
@@ -526,7 +531,9 @@
             # Stop any running previous versions of the same torrent
             same_names = []
             for old_hash in self.torrent_list:
-                if self.torrent_cache[old_hash]['name'] == data['name']:
+                if (self.torrent_cache[old_hash]['name'] == data['name'] or
+                    self.torrent_cache[old_hash]['metainfo'].get('identifier', old_hash) == 
+                        data['metainfo'].get('identifier', hash)):
                     same_names.append(old_hash)
             for old_hash in same_names:
                 self.remove(old_hash)
@@ -545,7 +552,15 @@
             logger.error('Asked to start a torrent that is not in the cache')
             return
         
-        logger.info('Starting torrent: '+str(binascii.b2a_hex(hash)))
+        # Assign the torrent identifier from the metainfo data
+        if "identifier" in self.torrent_cache[hash]['metainfo']:
+            id = self.torrent_cache[hash]['metainfo']['identifier']
+            logger.info('Starting torrent: '+str(binascii.b2a_hex(hash)) + 
+                        ' identified by: '+str(binascii.b2a_hex(id)))
+        else:
+            id = hash
+            logger.info('Starting torrent: '+str(binascii.b2a_hex(hash)))
+
         c = self.counter
         self.counter += 1
         x = ''
@@ -553,7 +568,8 @@
             x = mapbase64[c & 0x3F]+x
             c >>= 6
         peer_id = createPeerID(x)
-        d = SingleDownload(self, hash, self.torrent_cache[hash]['metainfo'], self.config, peer_id)
+        d = SingleDownload(self, hash, id, self.torrent_cache[hash]['metainfo'],
+                           self.config, peer_id)
         self.torrent_list.append(hash)
         self.downloads[hash] = d
         d.start()

Modified: debtorrent/branches/unique/btshowmetainfo.py
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/branches/unique/btshowmetainfo.py?rev=225&op=diff
==============================================================================
--- debtorrent/branches/unique/btshowmetainfo.py (original)
+++ debtorrent/branches/unique/btshowmetainfo.py Sun Aug 12 17:58:57 2007
@@ -35,10 +35,11 @@
         
 #    print metainfo
     info = metainfo['info']
-    info_hash = sha(bencode(info))
+    info_hash = sha(bencode(info)).hexdigest()
 
     print 'metainfo file.: %s' % basename(metainfo_name)
-    print 'info hash.....: %s' % info_hash.hexdigest()
+    print 'identifier....: %s' % metainfo.get("identifier", info_hash)
+    print 'info hash.....: %s' % info_hash
     piece_lengths = info['piece lengths']
     print 'directory name: %s' % metainfo['name']
     print 'files.........: '




More information about the Debtorrent-commits mailing list