]> git.mxchange.org Git - quix0rs-apt-p2p.git/blobdiff - apt_dht/PeerManager.py
Remove an unneeded khashmir file.
[quix0rs-apt-p2p.git] / apt_dht / PeerManager.py
index 8c193b7f453f9a79608f6647d6aa2214441918c1..b561b8ea9ce8d3fcb7898068b9b84f6662998f3a 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
@@ -9,6 +10,7 @@ from twisted.web2 import stream as stream_mod
 from twisted.web2.http import splitHostPort
 
 from HTTPDownloader import HTTPClientManager
+from util import uncompact
 
 class PeerManager:
     def __init__(self):
@@ -21,10 +23,11 @@ class PeerManager:
         @param peers: a list of the peers where the file can be found
         """
         if peers:
-            peer = choice(peers)
-            log.msg('Downloading from peer %s' % peer)
-            host, port = splitHostPort('http', peer)
-            path = '/~/' + hash
+            compact_peer = choice(peers)
+            peer = uncompact(compact_peer['c'])
+            log.msg('Downloading from peer %r' % (peer, ))
+            host, port = peer
+            path = '/~/' + quote_plus(hash.expected())
         else:
             log.msg('Downloading (%s) from mirror %s' % (method, mirror))
             parsed = urlparse(mirror)