X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=apt_dht%2FPeerManager.py;h=75c135d2b946c0dca0c26daaf9d4a3e2a0088f61;hb=ef16875cd9e8b3452deeff8b13768d4c10b0e9ad;hp=33c0688e0875ae3cd2cb492c39b7f6c9bf79f589;hpb=1d77fd96b30e7ef69fe83961b305e6814e1c0a31;p=quix0rs-apt-p2p.git diff --git a/apt_dht/PeerManager.py b/apt_dht/PeerManager.py index 33c0688..75c135d 100644 --- a/apt_dht/PeerManager.py +++ b/apt_dht/PeerManager.py @@ -3,8 +3,10 @@ from random import choice from urlparse import urlparse, urlunparse from twisted.internet import reactor, defer +from twisted.python import log from twisted.trial import unittest from twisted.web2 import stream as stream_mod +from twisted.web2.http import splitHostPort from HTTPDownloader import HTTPClientManager @@ -19,17 +21,12 @@ class PeerManager: @var locations: a list of the locations where the file can be found """ url = choice(locations) + log.msg('Downloading %s' % url) parsed = urlparse(url) - assert(parsed[0] == "http", "Only HTTP is supported, not '%s'" % parsed[0]) - host = parsed[1] + assert parsed[0] == "http", "Only HTTP is supported, not '%s'" % parsed[0] + host, port = splitHostPort(parsed[0], parsed[1]) path = urlunparse(('', '') + parsed[2:]) - - # Make sure a port is included for consistency - if host.find(':') >= 0: - host, port = host.split(':', 1) - port = int(port) - else: - port = 80 + return self.getPeer(host, port, path, method, modtime) def getPeer(self, host, port, path, method="GET", modtime=None): @@ -91,11 +88,11 @@ class TestPeerManager(unittest.TestCase): d.addBoth(lastDefer.callback) newRequest('www.camrdale.org', "/", 1, 3433) - newRequest('www.camrdale.org', "/blog/", 2, 37121) + newRequest('www.camrdale.org', "/blog/", 2, 39152) newRequest('www.google.ca', "/", 3, None) self.pending_calls.append(reactor.callLater(1, newRequest, 'www.sfu.ca', '/', 4, None)) self.pending_calls.append(reactor.callLater(10, newRequest, 'www.camrdale.org', '/wikilink.html', 5, 3084)) - self.pending_calls.append(reactor.callLater(30, newRequest, 'www.camrdale.org', '/sitemap.html', 6, 4750)) + self.pending_calls.append(reactor.callLater(30, newRequest, 'www.camrdale.org', '/sitemap.html', 6, 4756)) self.pending_calls.append(reactor.callLater(31, newRequest, 'www.sfu.ca', '/studentcentral/index.html', 7, None)) self.pending_calls.append(reactor.callLater(32, newRequest, 'www.camrdale.org', '/openid.html', 8, 2525)) self.pending_calls.append(reactor.callLater(32, newRequest, 'www.camrdale.org', '/subpage.html', 9, 2381))