From d5f2481af50fe1ed39a517c39b85bdd0b06d796e Mon Sep 17 00:00:00 2001 From: Jack Robison Date: Thu, 3 Aug 2017 22:06:12 -0400 Subject: [PATCH] handle ip addresses given as reflector servers --- lbrynet/reflector/reupload.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/lbrynet/reflector/reupload.py b/lbrynet/reflector/reupload.py index 9c7432f48..a414d355b 100644 --- a/lbrynet/reflector/reupload.py +++ b/lbrynet/reflector/reupload.py @@ -5,11 +5,29 @@ from lbrynet import conf from lbrynet.reflector import ClientFactory, BlobClientFactory +def _is_ip(host): + try: + if len(host.split(".")) == 4 and all([0 <= int(x) <= 255 for x in host.split(".")]): + return True + return False + except ValueError: + return False + + +@defer.inlineCallbacks +def resolve(host): + if _is_ip(host): + ip = host + else: + ip = yield reactor.resolve(host) + defer.returnValue(ip) + + @defer.inlineCallbacks def _reflect_stream(lbry_file, reflector_server): reflector_address, reflector_port = reflector_server[0], reflector_server[1] factory = ClientFactory(lbry_file) - ip = yield reactor.resolve(reflector_address) + ip = yield resolve(reflector_address) yield reactor.connectTCP(ip, reflector_port, factory) yield factory.finished_deferred @@ -18,7 +36,7 @@ def _reflect_stream(lbry_file, reflector_server): def _reflect_blobs(blob_manager, blob_hashes, reflector_server): reflector_address, reflector_port = reflector_server[0], reflector_server[1] factory = BlobClientFactory(blob_manager, blob_hashes) - ip = yield reactor.resolve(reflector_address) + ip = yield resolve(reflector_address) yield reactor.connectTCP(ip, reflector_port, factory) yield factory.finished_deferred