PeerGuardian Binary Lists version 3

Suggestions and discussion of future versions
Post Reply
anonymous_user
Member
Member
Posts: 40
Joined: Sat Jan 31, 2009 7:28 am

PeerGuardian Binary Lists version 3

Post by anonymous_user »

I am new to python, but i did an attempt to add the support for the PeerGuardian Binary Lists version 3

Here's my non-working patch

Code: Select all

diff -ruN deluge-1.3.11-old/deluge/plugins/blocklist/blocklist/peerguardian.py deluge-1.3.11-new/deluge/plugins/blocklist/blocklist/peerguardian.py
--- deluge-1.3.11-old/deluge/plugins/blocklist/blocklist/peerguardian.py	2014-11-30 22:53:46.000000000 +0100
+++ deluge-1.3.11-new/deluge/plugins/blocklist/blocklist/peerguardian.py	2015-09-01 12:26:31.000000000 +0000
@@ -12,8 +12,8 @@
 class PGException(Exception):
     pass
 
-# Incrementally reads PeerGuardian blocklists v1 and v2.
-# See http://wiki.phoenixlabs.org/wiki/P2B_Format
+# Incrementally reads PeerGuardian blocklists v1, v2 and v3.
+# See http://sourceforge.net/p/peerguardian/wiki/dev-blocklist-format-p2b/
 class PGReader:
 
     def __init__(self, filename):
@@ -36,9 +36,33 @@
 
         buf = self.fd.read(1)
         ver = ord(buf)
-        if ver != 1 and ver != 2:
+        if ver < 1 or ver > 3:
             raise PGException(_("Invalid version") + " %d" % ver)
 
+        if ver == 3:
+            num = self.fd.read(4)
+            while num > 0:
+                num -= 1
+                buf = -1
+                while buf != 0:
+                    buf = self.fd.read(1)
+                    if buf == "":  # EOF
+                        raise PGException(_("Unexpected end of file"))
+                    buf = ord(buf)
+            ranges = self.fd.read(4)
+
+    def next3(self): #how to call this for "ranges" times?
+
+        # Skip over the string index
+        buf = self.fd.read(4)
+
+        buf = self.fd.read(4)
+        start = socket.inet_ntoa(buf)
+
+        buf = self.fd.read(4)
+        end = socket.inet_ntoa(buf)
+
+        return (start, end)
 
     def next(self):
 
I would like if somebody could make it working, the version reference on sourceforge: http://sourceforge.net/p/peerguardian/w ... #version-3
http://www.bugmenot.com
Post Reply