]> git.mxchange.org Git - quix0rs-apt-p2p.git/commitdiff
Fix some minor bugs in the previous commits.
authorCameron Dale <camrdale@gmail.com>
Wed, 20 Feb 2008 04:44:54 +0000 (20:44 -0800)
committerCameron Dale <camrdale@gmail.com>
Wed, 20 Feb 2008 04:44:54 +0000 (20:44 -0800)
Improper hash_type use in AptPackages.
Use URL quoting and unquoting for peer downloads.
More and better log messages.

apt_dht/AptPackages.py
apt_dht/HTTPServer.py
apt_dht/PeerManager.py
apt_dht/apt_dht.py

index 1c38a003c4776ded668544d94a88167b110cea87..3e1c035bba9edfae08579e073aaeeec4410c85e4 100644 (file)
@@ -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()
 
index 266078ec718da4d33ab029015d1ecd9be40478f6..5f4b4f2352282bd78341b6cc2da8f5a7bc7f00f3 100644 (file)
@@ -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))
index 8c193b7f453f9a79608f6647d6aa2214441918c1..16341c66cba36c1d5472461af5ca863c6bb6789b 100644 (file)
@@ -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)
index fd7b73d81ce5ba8053431578491dbc31a5424222..f1732e5ee1cc55be2daf0a8aa1f5f3410e3ad7a8 100644 (file)
@@ -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