Merge branch 'improve-reflector-commands'

This commit is contained in:
Jack Robison 2017-08-04 16:09:43 -04:00
commit b725906c95
No known key found for this signature in database
GPG key ID: 284699E7404E3CFF
3 changed files with 77 additions and 25 deletions

View file

@ -14,7 +14,8 @@ at anytime.
### Added
* Added `claim_send_tip`, a command to tip the owner of a claim via a support transaction
*
* Added `reflector` keyword parameter to `file_reflect` command
* Added configuration options for auto re-reflect
### Fixed
*
@ -25,12 +26,9 @@ at anytime.
*
### Changed
*
*
### Added
* Added configuration options for auto re-reflect
*
* Renamed `reflect` command to `file_reflect`
* Allow IP addresses to be configured as reflector servers, not just host names.
* Return list of blobs that were reflected from `file_reflect`
### Removed
*

View file

@ -2414,7 +2414,6 @@ class Daemon(AuthJSONRPCServer):
else:
raise Exception('single argument must be specified')
response = yield self._render_response(True)
defer.returnValue(response)
@ -2435,22 +2434,43 @@ class Daemon(AuthJSONRPCServer):
return d
@defer.inlineCallbacks
def jsonrpc_reflect(self, sd_hash):
def jsonrpc_file_reflect(self, **kwargs):
"""
Reflect a stream
Reflect all the blobs in a file matching the filter criteria
Usage:
reflect (<sd_hash> | --sd_hash=<sd_hash>)
file_reflect [--sd_hash=<sd_hash>] [--file_name=<file_name>]
[--stream_hash=<stream_hash>] [--claim_id=<claim_id>]
[--outpoint=<outpoint>] [--rowid=<rowid>] [--name=<name>]
[--reflector=<reflector>]
Options:
--sd_hash=<sd_hash> : get file with matching sd hash
--file_name=<file_name> : get file with matching file name in the
downloads folder
--stream_hash=<stream_hash> : get file with matching stream hash
--claim_id=<claim_id> : get file with matching claim id
--outpoint=<outpoint> : get file with matching claim outpoint
--rowid=<rowid> : get file with matching row id
--name=<name> : get file with matching associated name claim
--reflector=<reflector> : reflector server, ip address or url
by default choose a server from the config
Returns:
(bool) true if successful
(list) list of blobs reflected
"""
lbry_file = yield self._get_lbry_file(FileID.SD_HASH, sd_hash, return_json=False)
if lbry_file is None:
raise Exception('No file found for give sd hash')
yield reupload.reflect_stream(lbry_file)
defer.returnValue("Reflect success")
reflector_server = kwargs.get('reflector', None)
lbry_files = yield self._get_lbry_files(**kwargs)
if len(lbry_files) > 1:
raise Exception('Too many (%i) files found, need one' % len(lbry_files))
elif not lbry_files:
raise Exception('No file found')
lbry_file = lbry_files[0]
results = yield reupload.reflect_stream(lbry_file, reflector_server=reflector_server)
defer.returnValue(results)
@defer.inlineCallbacks
@AuthJSONRPCServer.flags(needed="-n", finished="-f")

View file

@ -5,29 +5,63 @@ 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
result = yield factory.finished_deferred
defer.returnValue(result)
@defer.inlineCallbacks
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
result = yield factory.finished_deferred
defer.returnValue(result)
def reflect_stream(lbry_file):
reflector_server = random.choice(conf.settings['reflector_servers'])
def reflect_stream(lbry_file, reflector_server=None):
if reflector_server:
if len(reflector_server.split(":")) == 2:
host, port = tuple(reflector_server.split(":"))
reflector_server = host, int(port)
else:
reflector_server = reflector_server, 5566
else:
reflector_server = random.choice(conf.settings['reflector_servers'])
return _reflect_stream(lbry_file, reflector_server)
def reflect_blob_hashes(blob_hashes, blob_manager):
reflector_server = random.choice(conf.settings['reflector_servers'])
def reflect_blob_hashes(blob_hashes, blob_manager, reflector_server=None):
if reflector_server:
if len(reflector_server.split(":")) == 2:
host, port = tuple(reflector_server.split(":"))
reflector_server = host, int(port)
else:
reflector_server = reflector_server, 5566
else:
reflector_server = random.choice(conf.settings['reflector_servers'])
return _reflect_blobs(blob_manager, blob_hashes, reflector_server)