r223 - in /debtorrent/branches/unique/DebTorrent: BT1/Connecter.py bitfield.py

camrdale-guest at users.alioth.debian.org camrdale-guest at users.alioth.debian.org
Sun Aug 12 01:25:46 UTC 2007


Author: camrdale-guest
Date: Sun Aug 12 01:25:46 2007
New Revision: 223

URL: http://svn.debian.org/wsvn/debtorrent/?sc=1&rev=223
Log:
Adjust bitfield messages to their proper length, and don't drop connections due to unknown Have messages.

Modified:
    debtorrent/branches/unique/DebTorrent/BT1/Connecter.py
    debtorrent/branches/unique/DebTorrent/bitfield.py

Modified: debtorrent/branches/unique/DebTorrent/BT1/Connecter.py
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/branches/unique/DebTorrent/BT1/Connecter.py?rev=223&op=diff
==============================================================================
--- debtorrent/branches/unique/DebTorrent/BT1/Connecter.py (original)
+++ debtorrent/branches/unique/DebTorrent/BT1/Connecter.py Sun Aug 12 01:25:46 2007
@@ -569,8 +569,7 @@
                 return
             i = toint(message[1:])
             if i >= self.numpieces:
-                logger.warning(c.get_ip()+': bad piece number, closing connection')
-                connection.close()
+                logger.debug(c.get_ip()+': dropping an unknown piece number')
                 return
             if c.download.got_have(i):
                 c.upload.got_not_interested()

Modified: debtorrent/branches/unique/DebTorrent/bitfield.py
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/branches/unique/DebTorrent/bitfield.py?rev=223&op=diff
==============================================================================
--- debtorrent/branches/unique/DebTorrent/bitfield.py (original)
+++ debtorrent/branches/unique/DebTorrent/bitfield.py Sun Aug 12 01:25:46 2007
@@ -90,17 +90,22 @@
             raise ValueError, "length must be provided unless copying from another array"
         self.length = length
         if bitstring is not None:
-            extra = len(bitstring) * 8 - length
-            if extra < 0 or extra >= 8:
-                raise ValueError
+            # Construct the bitfield
             t = lookup_table
             r = []
             for c in bitstring:
                 r.extend(t[ord(c)])
-            if extra > 0:
-                if r[-extra:] != [0] * extra:
-                    raise ValueError
-                del r[-extra:]
+                if len(r) > length:
+                    # Stop if enough bits have been found
+                    break
+                
+            if len(r) > length:
+                # Remove any extra bits that were added
+                del r[length:]
+            elif len(r) < length:
+                # Add any missing bits as all False
+                r.extend([False]*(length - len(r)))
+                
             self.array = r
             self.numfalse = negsum(r)
         else:




More information about the Debtorrent-commits mailing list