handle ip addresses given as reflector servers
This commit is contained in:
parent
0bdcab1166
commit
d5f2481af5
1 changed files with 20 additions and 2 deletions
|
@ -5,11 +5,29 @@ from lbrynet import conf
|
||||||
from lbrynet.reflector import ClientFactory, BlobClientFactory
|
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
|
@defer.inlineCallbacks
|
||||||
def _reflect_stream(lbry_file, reflector_server):
|
def _reflect_stream(lbry_file, reflector_server):
|
||||||
reflector_address, reflector_port = reflector_server[0], reflector_server[1]
|
reflector_address, reflector_port = reflector_server[0], reflector_server[1]
|
||||||
factory = ClientFactory(lbry_file)
|
factory = ClientFactory(lbry_file)
|
||||||
ip = yield reactor.resolve(reflector_address)
|
ip = yield resolve(reflector_address)
|
||||||
yield reactor.connectTCP(ip, reflector_port, factory)
|
yield reactor.connectTCP(ip, reflector_port, factory)
|
||||||
yield factory.finished_deferred
|
yield factory.finished_deferred
|
||||||
|
|
||||||
|
@ -18,7 +36,7 @@ def _reflect_stream(lbry_file, reflector_server):
|
||||||
def _reflect_blobs(blob_manager, blob_hashes, reflector_server):
|
def _reflect_blobs(blob_manager, blob_hashes, reflector_server):
|
||||||
reflector_address, reflector_port = reflector_server[0], reflector_server[1]
|
reflector_address, reflector_port = reflector_server[0], reflector_server[1]
|
||||||
factory = BlobClientFactory(blob_manager, blob_hashes)
|
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 reactor.connectTCP(ip, reflector_port, factory)
|
||||||
yield factory.finished_deferred
|
yield factory.finished_deferred
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue