X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=apt_dht%2FPeerManager.py;h=b561b8ea9ce8d3fcb7898068b9b84f6662998f3a;hb=f67d1f47283729722ac1b3f528a78063b4b36a14;hp=8c193b7f453f9a79608f6647d6aa2214441918c1;hpb=1461780708c6ce0562ec0a27062b13b32d7dc348;p=quix0rs-apt-p2p.git diff --git a/apt_dht/PeerManager.py b/apt_dht/PeerManager.py index 8c193b7..b561b8e 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 @@ -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)