From: Cameron Dale <camrdale@gmail.com>
Date: Wed, 20 Feb 2008 04:44:54 +0000 (-0800)
Subject: Fix some minor bugs in the previous commits.
X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=5d68a1711b103cbae2d3801b991ac83ed89241d9;p=quix0rs-apt-p2p.git

Fix some minor bugs in the previous commits.

Improper hash_type use in AptPackages.
Use URL quoting and unquoting for peer downloads.
More and better log messages.
---

diff --git a/apt_dht/AptPackages.py b/apt_dht/AptPackages.py
index 1c38a00..3e1c035 100644
--- a/apt_dht/AptPackages.py
+++ b/apt_dht/AptPackages.py
@@ -158,7 +158,7 @@ class AptPackages:
         rel = deb822.Release(f, fields = ['MD5Sum', 'SHA1', 'SHA256'])
         for hash_type in rel:
             for file in rel[hash_type]:
-                self.indexrecords[cache_path].setdefault(file['name'], {})[hash_type.upper()] = (file['hash_type'], file['size'])
+                self.indexrecords[cache_path].setdefault(file['name'], {})[hash_type.upper()] = (file[hash_type], file['size'])
             
         f.close()
 
diff --git a/apt_dht/HTTPServer.py b/apt_dht/HTTPServer.py
index 266078e..5f4b4f2 100644
--- a/apt_dht/HTTPServer.py
+++ b/apt_dht/HTTPServer.py
@@ -1,4 +1,6 @@
 
+from urllib import unquote_plus
+
 from twisted.python import log
 from twisted.internet import defer
 from twisted.web2 import server, http, resource, channel
@@ -62,12 +64,13 @@ class TopLevel(resource.Resource):
             <p>TODO: eventually some stats will be shown here.</body></html>""")
 
     def locateChild(self, request, segments):
+        log.msg('Got HTTP request for %s from %s' % (request.uri, request.remoteAddr))
         name = segments[0]
         if name == '~':
             if len(segments) != 2:
                 log.msg('Got a malformed request from %s' % request.remoteAddr)
                 return None, ()
-            hash = segments[1]
+            hash = unquote_plus(segments[1])
             files = self.db.lookupHash(hash)
             if files:
                 log.msg('Sharing %s with %s' % (files[0]['path'].path, request.remoteAddr))
diff --git a/apt_dht/PeerManager.py b/apt_dht/PeerManager.py
index 8c193b7..16341c6 100644
--- a/apt_dht/PeerManager.py
+++ b/apt_dht/PeerManager.py
@@ -1,6 +1,7 @@
 
 from random import choice
 from urlparse import urlparse, urlunparse
+from urllib import quote_plus
 
 from twisted.internet import reactor, defer
 from twisted.python import log
@@ -24,7 +25,7 @@ class PeerManager:
             peer = choice(peers)
             log.msg('Downloading from peer %s' % peer)
             host, port = splitHostPort('http', peer)
-            path = '/~/' + hash
+            path = '/~/' + quote_plus(hash.expected())
         else:
             log.msg('Downloading (%s) from mirror %s' % (method, mirror))
             parsed = urlparse(mirror)
diff --git a/apt_dht/apt_dht.py b/apt_dht/apt_dht.py
index fd7b73d..f1732e5 100644
--- a/apt_dht/apt_dht.py
+++ b/apt_dht/apt_dht.py
@@ -171,5 +171,5 @@ class AptDHT:
         return None
 
     def store_done(self, result, hash):
-        log.msg('Added %s to the DHT: %r' % (hash, result))
+        log.msg('Added %s to the DHT: %r' % (hash.hexdigest(), result))
         
\ No newline at end of file