r316 - in /debtorrent/trunk: DebTorrent/BT1/AptListener.py DebTorrent/HTTPHandler.py debian/changelog test.py

camrdale-guest at users.alioth.debian.org camrdale-guest at users.alioth.debian.org
Mon Nov 5 07:32:41 UTC 2007


Author: camrdale-guest
Date: Mon Nov  5 07:32:40 2007
New Revision: 316

URL: http://svn.debian.org/wsvn/debtorrent/?sc=1&rev=316
Log:
  - send piece downloaded status messages

Modified:
    debtorrent/trunk/DebTorrent/BT1/AptListener.py
    debtorrent/trunk/DebTorrent/HTTPHandler.py
    debtorrent/trunk/debian/changelog
    debtorrent/trunk/test.py

Modified: debtorrent/trunk/DebTorrent/BT1/AptListener.py
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/trunk/DebTorrent/BT1/AptListener.py?rev=316&op=diff
==============================================================================
--- debtorrent/trunk/DebTorrent/BT1/AptListener.py (original)
+++ debtorrent/trunk/DebTorrent/BT1/AptListener.py Mon Nov  5 07:32:40 2007
@@ -197,6 +197,7 @@
                     if v[0].storagewrapper.do_I_have(piece):
                         logger.debug('queued request for file '+file+' got piece '+str(piece))
                         v[3].remove(piece)
+                        self.send_update(c, file, v[0], v[1], v[2], v[3])
                         
                 # If no more pieces are needed, return the answer and remove the request
                 if not v[3]:
@@ -461,6 +462,41 @@
         return None
         
     
+    def send_update(self, connection, file, d, f, httpreq, pieces_needed):
+        """Send a status 102 update message to the requester.
+        
+        @type connection: L{DebTorrent.HTTPHandler.HTTPConnection}
+        @param connection: the conection the request came in on
+        @type file: C{string}
+        @param file: the file to download, starting with the mirror name
+        @type d: L{DebTorrent.download_bt1.BT1Download}
+        @param d: the torrent download that has the file
+        @type f: C{int}
+        @param f: the index of the file in the torrent
+        @type httpreq: L{DebTorrent.HTTPHandler.HTTPRequest}
+        @param httpreq: the HTTP request object to answer (for queueing)
+        @type pieces_needed: C{list} of C{int}
+        @param pieces_needed: the list of pieces in the torrent that still 
+            need to be downloaded
+        
+        """
+
+        # Check to make sure the requester is still waiting
+        if connection.closed:
+            return
+
+        # Check if the file has been downloaded
+        file_needed = 0L
+        filename, length = d.fileselector.storage.files[f]
+        for piece in pieces_needed:
+            file_needed += d.storagewrapper.piece_sizes[piece]
+        
+        piece_string = 'bytes ' + str(length - file_needed) + '/' + str(length)
+        
+        connection.answer((102, 'Size Update', {'Server': VERSION, 'Content-Type': 'text/plain',
+                                                'Pieces-Downloaded': piece_string}, ''), httpreq)
+        return
+
     def answer_package(self, connection, file, d, f, httpreq):
         """Send the newly downloaded package file to the requester.
         

Modified: debtorrent/trunk/DebTorrent/HTTPHandler.py
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/trunk/DebTorrent/HTTPHandler.py?rev=316&op=diff
==============================================================================
--- debtorrent/trunk/DebTorrent/HTTPHandler.py (original)
+++ debtorrent/trunk/DebTorrent/HTTPHandler.py Mon Nov  5 07:32:40 2007
@@ -382,8 +382,10 @@
         if not self.requests:
             if httpreq is None:
                 # There's only one request allowed, so send the answer
-                self.send_answer(r, self.header, self.command, self.path,
-                                 self.encoding, self.headers)
+                if r[0] != 102 or (self.protocol == "DEBTORRENT" and 
+                                   self.version >= (0, 2)):
+                    self.send_answer(r, self.header, self.command, self.path,
+                                     self.encoding, self.headers)
             else:
                 logger.error('got answer for unknown request')
             return
@@ -394,12 +396,15 @@
             else:
                 if self.protocol == "DEBTORRENT":
                     # DEBTORRENT requests get sent immediately
-                    self.requests.remove(httpreq)
-                    self.send_answer(r, httpreq.header, httpreq.command,
-                                     httpreq.path, httpreq.encoding,
-                                     httpreq.headers)
+                    if r[0] != 102:
+                        self.requests.remove(httpreq)
+                    if r[0] != 102 or (self.version >= (0, 2)):
+                        self.send_answer(r, httpreq.header, httpreq.command,
+                                         httpreq.path, httpreq.encoding,
+                                         httpreq.headers)
                 else:
-                    httpreq.save_answer(r)
+                    if r[0] != 102:
+                        httpreq.save_answer(r)
 
         # Answer all possible requests
         while self.requests and self.requests[0].has_answer():
@@ -458,7 +463,7 @@
                                 req_headers.get('user-agent', '-') )
 
         logger.info('sending response: '+self.protocol+' '+str(responsecode)+' '+responsestring+
-                    ' ('+str(len(data))+' bytes)')
+                    ' ('+str(len(data))+' bytes)' + repr(headers))
         
         r = StringIO()
         
@@ -478,7 +483,7 @@
             r.write('\r\n')
             
         # Don't write the body if only the headers are requested
-        if command != 'HEAD':
+        if command != 'HEAD' or not data:
             r.write(data)
             
         self.connection.write(r.getvalue())

Modified: debtorrent/trunk/debian/changelog
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/trunk/debian/changelog?rev=316&op=diff
==============================================================================
--- debtorrent/trunk/debian/changelog (original)
+++ debtorrent/trunk/debian/changelog Mon Nov  5 07:32:40 2007
@@ -1,8 +1,9 @@
 debtorrent (0.1.5) unstable; urgency=low
 
   * Update to support apt debtorrent transport version 0.2
+    - send piece downloaded status messages
 
- -- Cameron Dale <camrdale at gmail.com>  Sun, 04 Nov 2007 11:15:37 -0800
+ -- Cameron Dale <camrdale at gmail.com>  Sun, 04 Nov 2007 23:31:20 -0800
 
 debtorrent (0.1.4.4) unstable; urgency=low
 

Modified: debtorrent/trunk/test.py
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/trunk/test.py?rev=316&op=diff
==============================================================================
--- debtorrent/trunk/test.py (original)
+++ debtorrent/trunk/test.py Mon Nov  5 07:32:40 2007
@@ -314,6 +314,7 @@
   NoLocking "false";
   Acquire::Ftp "false";    // Show ftp command traffic
   Acquire::Http "false";   // Show http command traffic
+  Acquire::Debtorrent "false";   // Show http command traffic
   Acquire::gpgv "false";   // Show the gpgv traffic
   aptcdrom "false";        // Show found package files
   IdentCdrom "false";
@@ -455,7 +456,7 @@
     print '************************** apt-get (' + str(num_down) + ') ' + ' '.join(cmd) + ' **************************'
     apt_conf = join([down_dir(num_down), 'etc', 'apt', 'apt.conf'])
     dpkg_status = join([down_dir(num_down), 'var', 'lib', 'dpkg', 'status'])
-    new_cmd = ['apt-get', '-d', '-q', '-c', apt_conf, '-o', 'Dir::state::status='+dpkg_status] + cmd
+    new_cmd = ['apt-get', '-d', '-c', apt_conf, '-o', 'Dir::state::status='+dpkg_status] + cmd
     pid = os.spawnvp(os.P_NOWAIT, new_cmd[0], new_cmd)
     return pid
 
@@ -659,7 +660,7 @@
             else:
                 print '********************** apt-get finished with status ' + str(r_value) + ' in ' +  str(elapsed) + ' sec. **************************'
         
-            sleep(5)
+            sleep(10)
             
     except:
         print '************************** Exception occurred **************************'




More information about the Debtorrent-commits mailing list