[Debtorrent-commits] r23 - in /debtorrent/trunk: DebTorrent/BT1/btformats.py DebTorrent/BT1/makemetafile.py DebTorrent/download_bt1.py DebTorrent/parsedir.py README.txt TODO btrename.py btshowmetainfo.py

camrdale-guest at users.alioth.debian.org camrdale-guest at users.alioth.debian.org
Sun Apr 29 05:09:28 UTC 2007


Author: camrdale-guest
Date: Sun Apr 29 05:09:27 2007
New Revision: 23

URL: http://svn.debian.org/wsvn/debtorrent/?sc=1&rev=23
Log:
Moved the metainfo name field outside the info dictionary

Modified:
    debtorrent/trunk/DebTorrent/BT1/btformats.py
    debtorrent/trunk/DebTorrent/BT1/makemetafile.py
    debtorrent/trunk/DebTorrent/download_bt1.py
    debtorrent/trunk/DebTorrent/parsedir.py
    debtorrent/trunk/README.txt
    debtorrent/trunk/TODO
    debtorrent/trunk/btrename.py
    debtorrent/trunk/btshowmetainfo.py

Modified: debtorrent/trunk/DebTorrent/BT1/btformats.py
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/trunk/DebTorrent/BT1/btformats.py?rev=23&op=diff
==============================================================================
--- debtorrent/trunk/DebTorrent/BT1/btformats.py (original)
+++ debtorrent/trunk/DebTorrent/BT1/btformats.py Sun Apr 29 05:09:27 2007
@@ -20,35 +20,25 @@
     for length in piecelengths:
         if type(length) not in ints or length <= 0:
             raise ValueError, 'bad metainfo - bad piece length'
-    name = info.get('name')
-    if type(name) != StringType:
-        raise ValueError, 'bad metainfo - bad name'
-    if not reg.match(name):
-        raise ValueError, 'name %s disallowed for security reasons' % name
     if info.has_key('files') == info.has_key('length'):
         raise ValueError, 'single/multiple file mix'
-    if info.has_key('length'):
-        length = info.get('length')
+    files = info.get('files')
+    if type(files) != ListType:
+        raise ValueError
+    for f in files:
+        if type(f) != DictType:
+            raise ValueError, 'bad metainfo - bad file value'
+        length = f.get('length')
         if type(length) not in ints or length < 0:
             raise ValueError, 'bad metainfo - bad length'
-    else:
-        files = info.get('files')
-        if type(files) != ListType:
-            raise ValueError
-        for f in files:
-            if type(f) != DictType:
-                raise ValueError, 'bad metainfo - bad file value'
-            length = f.get('length')
-            if type(length) not in ints or length < 0:
-                raise ValueError, 'bad metainfo - bad length'
-            path = f.get('path')
-            if type(path) != ListType or path == []:
-                raise ValueError, 'bad metainfo - bad path'
-            for p in path:
-                if type(p) != StringType:
-                    raise ValueError, 'bad metainfo - bad path dir'
-                if not reg.match(p):
-                    raise ValueError, 'path %s disallowed for security reasons' % p
+        path = f.get('path')
+        if type(path) != ListType or path == []:
+            raise ValueError, 'bad metainfo - bad path'
+        for p in path:
+            if type(p) != StringType:
+                raise ValueError, 'bad metainfo - bad path dir'
+            if not reg.match(p):
+                raise ValueError, 'path %s disallowed for security reasons' % p
 # Removed to speed up checking of large files
 #        for i in xrange(len(files)):
 #            for j in xrange(i):
@@ -61,6 +51,11 @@
     check_info(message.get('info'))
     if type(message.get('announce')) != StringType:
         raise ValueError
+    name = message.get('name')
+    if type(name) != StringType:
+        raise ValueError, 'bad metainfo - bad name'
+    if not reg.match(name):
+        raise ValueError, 'name %s disallowed for security reasons' % name
 
 def check_peers(message):
     if type(message) != DictType:

Modified: debtorrent/trunk/DebTorrent/BT1/makemetafile.py
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/trunk/DebTorrent/BT1/makemetafile.py?rev=23&op=diff
==============================================================================
--- debtorrent/trunk/DebTorrent/BT1/makemetafile.py (original)
+++ debtorrent/trunk/DebTorrent/BT1/makemetafile.py Sun Apr 29 05:09:27 2007
@@ -59,6 +59,22 @@
     print ('    httpseeds = optional list of http-seed URLs, in the format:')
     print ('            url[|url...]')
     
+def uniconvertl(l, e):
+    r = []
+    try:
+        for s in l:
+            r.append(uniconvert(s, e))
+    except UnicodeError:
+        raise UnicodeError('bad filename: '+join(l))
+    return r
+
+def uniconvert(s, e):
+    try:
+        s = unicode(s,e)
+    except UnicodeError:
+        raise UnicodeError('bad filename: '+s)
+    return s.encode('utf-8')
+
 def make_meta_file(file, url, params = {}, flag = Event(),
                    progress = lambda x: None, progress_percent = 1):
     if params.has_key('piece_size_pow2'):
@@ -105,7 +121,9 @@
         return
     check_info(info)
     h = open(f, 'wb')
-    data = {'info': info, 'announce': strip(url), 'creation date': long(time())}
+    data = {'info': info, 'announce': strip(url), 
+        'name': uniconvert(split(file)[1], encoding),
+        'creation date': long(time())}
     
     if params.has_key('comment') and params['comment']:
         data['comment'] = params['comment']
@@ -133,23 +151,6 @@
     for s in subfiles(abspath(file)):
         total += getsize(s[1])
     return total
-
-
-def uniconvertl(l, e):
-    r = []
-    try:
-        for s in l:
-            r.append(uniconvert(s, e))
-    except UnicodeError:
-        raise UnicodeError('bad filename: '+join(l))
-    return r
-
-def uniconvert(s, e):
-    try:
-        s = unicode(s,e)
-    except UnicodeError:
-        raise UnicodeError('bad filename: '+s)
-    return s.encode('utf-8')
 
 def makeinfo(file, piece_length, encoding, flag, progress, progress_percent=1):
     file = abspath(file)
@@ -183,8 +184,7 @@
     f.close()
     
     return {'pieces': ''.join(pieces),
-        'piece lengths': lengths, 'files': fs, 
-        'name': uniconvert(split(file)[1], encoding) }
+        'piece lengths': lengths, 'files': fs}
 
 def subfiles(d):
     r = []

Modified: debtorrent/trunk/DebTorrent/download_bt1.py
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/trunk/DebTorrent/download_bt1.py?rev=23&op=diff
==============================================================================
--- debtorrent/trunk/DebTorrent/download_bt1.py (original)
+++ debtorrent/trunk/DebTorrent/download_bt1.py Sun Apr 29 05:09:27 2007
@@ -119,7 +119,7 @@
         'maximum kB/s to upload at (0 = no limit, -1 = automatic)'),
     ('max_download_rate', 0,
         'maximum kB/s to download at (0 = no limit)'),
-    ('alloc_type', 'normal',
+    ('alloc_type', 'pre-allocate',
         'allocation type (may be normal, background, pre-allocate or sparse)'),
     ('alloc_rate', 2.0,
         'rate (in MiB/s) to allocate space at using background allocation'),
@@ -373,9 +373,9 @@
                 p[2] = binascii.a2b_hex(line[6:])
         
         response = {'info': {'pieces': ''.join(pieces),
-            'piece lengths': lengths, 'files': fs, 
-            'name': uniconvert(split(file)[1], encoding) },
-            'announce': 'http://dttracker.debian.net:6969/announce' }
+            'piece lengths': lengths, 'files': fs },
+            'announce': 'http://dttracker.debian.net:6969/announce', 
+            'name': uniconvert(split(file)[1], encoding) }
     
     except IOError, e:
         errorfunc('problem getting Packages info - ' + str(e))
@@ -467,7 +467,7 @@
 
             if self.info.has_key('length'):
                 file_length = self.info['length']
-                file = filefunc(self.info['name'], file_length,
+                file = filefunc(self.response['name'], file_length,
                                 self.config['saveas'], False)
                 if file is None:
                     return None
@@ -477,7 +477,7 @@
                 file_length = 0L
                 for x in self.info['files']:
                     file_length += x['length']
-                file = filefunc(self.info['name'], file_length,
+                file = filefunc(self.response['name'], file_length,
                                 self.config['saveas'], True)
                 if file is None:
                     return None
@@ -494,12 +494,12 @@
                             if path.exists(path.join(file, x['path'][0])):
                                 existing = 1
                         if not existing:
-                            file = path.join(file, self.info['name'])
+                            file = path.join(file, self.response['name'])
                             if path.exists(file) and not path.isdir(file):
                                 if file[-8:] == '.dtorrent':
                                     file = file[:-8]
                                 if path.exists(file) and not path.isdir(file):
-                                    self.errorfunc("Can't create dir - " + self.info['name'])
+                                    self.errorfunc("Can't create dir - " + self.response['name'])
                                     return None
                 make(file, True)
 

Modified: debtorrent/trunk/DebTorrent/parsedir.py
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/trunk/DebTorrent/parsedir.py?rev=23&op=diff
==============================================================================
--- debtorrent/trunk/DebTorrent/parsedir.py (original)
+++ debtorrent/trunk/DebTorrent/parsedir.py Sun Apr 29 05:09:27 2007
@@ -116,7 +116,7 @@
                         l += li['length']
             a['numfiles'] = nf
             a['length'] = l
-            a['name'] = i.get('name', f)
+            a['name'] = d.get('name', f)
             def setkey(k, d = d, a = a):
                 if d.has_key(k):
                     a[k] = d[k]

Modified: debtorrent/trunk/README.txt
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/trunk/README.txt?rev=23&op=diff
==============================================================================
--- debtorrent/trunk/README.txt (original)
+++ debtorrent/trunk/README.txt Sun Apr 29 05:09:27 2007
@@ -1,110 +1,47 @@
-BitTorrent is a tool for distributing files. It's extremely 
-easy to use - downloads are started by clicking on hyperlinks.
-Whenever more than one person is downloading at once 
-they send pieces of the file(s) to each other, thus relieving 
-the central server's bandwidth burden. Even with many 
-simultaneous downloads, the upload burden on the central server 
-remains quite small, since each new downloader introduces new 
-upload capacity.
+To start testing DebTorrent, do the following:
 
-Windows web browser support is added by running an installer. 
-A prebuilt one is available, but instructions for building it 
-yourself are in BUILD.windows.txt
+1. Export the debtorrent source from subversion:
 
-Instructions for Unix installation are in INSTALL.unix.txt
+   svn export svn://svn.debian.org/svn/debtorrent/debtorrent/trunk debtorrent
 
-To start hosting -
+2. Change into the debtorrent directory:
 
-1) start running a tracker
+   cd debtorrent
 
-First, you need a tracker. If you're on a dynamic IP or otherwise 
-unreliable connection, you should find someone else's tracker and 
-use that. Otherwise, follow the rest of this step.
+3. Get a .dtorrent file:
 
-Trackers refer downloaders to each other. The load on the tracker 
-is very small, so you only need one for all your files.
+   a) Choose one from the dtorrents directory
+   
+      You can view the contents of the file using the btshowmetainfo.py command
+      
+      To determine if the dtorrent has peers/seeds, go to 
+      
+         http://dttracker.debian.net:6969
+         
+      and look for the info hash shown by btshowmetainfo.
 
-To run a tracker, execute the command bttrack.py Here is an example -
+   b) Or, create one using btmakemetafile from a Packages file:
 
-./bttrack.py --port 6969 --dfile dstate
+      btmakemetafile.py http://dttracker.debian.net:6969 \
+          /var/lib/apt/lists/<mirror>_debian_dists_<suite>_<section>_binary-<arch>_Packages \
+          --target test.dtorrent
 
---dfile is where persistent information is kept on the tracker across 
-invocations. It makes everything start working again immediately if 
-you restart the tracker. A new one will be created if it doesn't exist 
-already.
+      The recommended Packages file to use is from the stable suite (as it 
+      doesn't change much), and section contrib (as it's the smallest).
 
-The tracker must be on a net-addressible box, and you must know the 
-ip number or dns name of it.
+4. Start the download:
 
-The tracker outputs web logs to standard out. You can get information 
-about the files it's currently serving by getting its index page. 
+   btdownloadheadless.py test.dtorrent
 
-2) create a metainfo file using btmakemetafile.py
+   You can use some of the options to btdownloadheadless (to see them, run it
+   without arguments) but most are untested, and some will break the download
+   (e.g. alloc_type).
 
-To generate a metainfo file, run the publish btmakemetafile and give 
-it the file you want metainfo for and the url of the tracker
 
-./btmakemetafile.py http://my.tracker:6969/announce myfile.ext
+If you have any problems downloading, go to 
 
-This will generate a file called myfile.ext.torrent
-
-Make sure to include the port number in the tracker url if it isn't 80.
-
-This command may take a while to scan over the whole file hashing it.
-
-The /announce path is special and hard-coded into the tracker. 
-Make sure to give the domain or ip your tracker is on instead of 
-my.tracker.
-
-You can use either a dns name or an IP address in the tracker url.
-
-3) associate .torrent with application/x-bittorrent on your web server
-
-The way you do this is dependent on the particular web server you're using.
-
-You must have a web server which can serve ordinary static files and is 
-addressable from the internet at large.
-
-4) put the newly made .torrent file on your web server
-
-Note that the file name you choose on the server must end in .torrent, so 
-it gets associated with the right mimetype.
-
-5) put up a static page which links to the location you uploaded to in step 4
-
-The file you uploaded in step 4 is linked to using an ordinary url.
-
-6) start a downloader as a resume on the complete file
-
-You have to run a downloader which already has the complete file, 
-so new downloaders have a place to get it from. Here's an example -
-
-./btdownloadheadless.py --url http://my.server/myfile.torrent --saveas myfile.ext
-
-Make sure the saveas argument points to the already complete file.
-
-If you're running the complete downloader on the same machine or LAN as 
-the tracker, give a --ip parameter to the complete downloader. The --ip 
-parameter can be either an IP address or DNS name.
-
-BitTorrent defaults to port 6881. If it can't use 6881, (probably because 
-another download is happening) it tries 6882, then 6883, etc. It gives up 
-after 6889.
-
-7) you're done!
-
-Now you just have to get people downloading! Refer them to the page you 
-created in step 5.
-
-BitTorrent can also publish whole directories - simply point 
-btmakemetafile.py at the directory with files in it, they'll be published 
-as one unit. All files in subdirectories will be included, although files 
-and directories named 'CVS' and 'core' are ignored.
-
-If you have any questions, try the web site or mailing list -
-
-http://bitconjurer.org/BitTorrent/
-
-http://groups.yahoo.com/group/BitTorrent
-
-You can also often find me, Bram, in #bittorrent of irc.freenode.net
+   http://dttracker.debian.net:6969
+   
+to check if your torrent is active. If it is, but you still can't download,
+or if you get errors from running any of the programs, please post the
+problem/error to debtorrent-devel at lists.alioth.debian.org

Modified: debtorrent/trunk/TODO
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/trunk/TODO?rev=23&op=diff
==============================================================================
--- debtorrent/trunk/TODO (original)
+++ debtorrent/trunk/TODO Sun Apr 29 05:09:27 2007
@@ -1,10 +1,4 @@
 Below are some things that still need to be done, in order of priority.
-
-
-Remove the 'name' entry from the info hash (or make it mirror-independent)
-
-
-Add pre-created dtorrents to the distribution
 
 
 Move the data cache from ~/.DebTorrent
@@ -17,9 +11,8 @@
 the pieces no longer being the same size, and so data cannot be moved around 
 between them like it was previously. This may not be an issue after a maximum 
 piece size is introduced, though pre-allocation may still be necessary to serve 
-downloaded files while other downloads continue. Pre-allocation will need to be 
-checked with priorities enabled, so that the entire archive does not need to be 
-pre-allocated to download a single package.
+downloaded files while other downloads continue. Pre-allocation with priorities 
+enabled does not pre=allocate the entire archive.
 
 
 Comments

Modified: debtorrent/trunk/btrename.py
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/trunk/btrename.py?rev=23&op=diff
==============================================================================
--- debtorrent/trunk/btrename.py (original)
+++ debtorrent/trunk/btrename.py Sun Apr 29 05:09:27 2007
@@ -11,20 +11,20 @@
 NAME, EXT = splitext(basename(argv[0]))
 VERSION = '20021119'
 
-print '%s %s - change the suggested filename in a .torrent file' % (NAME, VERSION)
+print '%s %s - change the suggested filename in a .dtorrent file' % (NAME, VERSION)
 print
 
 if len(argv) != 3:
-  print '%s file.torrent new.filename.ext' % argv[0]
+  print '%s file.dtorrent new.filename.ext' % argv[0]
   print
   exit(2) # common exit code for syntax error
 
 metainfo_file = open(argv[1], 'rb')
 metainfo = bdecode(metainfo_file.read())
 metainfo_file.close()
-print 'old filename: %s' % metainfo['info']['name']
-metainfo['info']['name'] = argv[2]
-print 'new filename: %s' % metainfo['info']['name']
+print 'old filename: %s' % metainfo['name']
+metainfo['name'] = argv[2]
+print 'new filename: %s' % metainfo['name']
 metainfo_file = open(argv[1], 'wb')
 metainfo_file.write(bencode(metainfo))
 metainfo_file.close

Modified: debtorrent/trunk/btshowmetainfo.py
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/trunk/btshowmetainfo.py?rev=23&op=diff
==============================================================================
--- debtorrent/trunk/btshowmetainfo.py (original)
+++ debtorrent/trunk/btshowmetainfo.py Sun Apr 29 05:09:27 2007
@@ -30,7 +30,7 @@
     print 'metainfo file.: %s' % basename(metainfo_name)
     print 'info hash.....: %s' % info_hash.hexdigest()
     piece_lengths = info['piece lengths']
-    print 'directory name: %s' % info['name']
+    print 'directory name: %s' % metainfo['name']
     print 'files.........: '
     file_length = 0;
     for file in info['files']:




More information about the Debtorrent-commits mailing list