file_reflect

This commit is contained in:
Jack Robison 2017-08-04 14:48:35 -04:00
parent d5f2481af5
commit c971cce717
No known key found for this signature in database
GPG key ID: 284699E7404E3CFF
2 changed files with 52 additions and 16 deletions

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

@ -29,7 +29,8 @@ def _reflect_stream(lbry_file, reflector_server):
factory = ClientFactory(lbry_file)
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
@ -38,14 +39,29 @@ def _reflect_blobs(blob_manager, blob_hashes, reflector_server):
factory = BlobClientFactory(blob_manager, blob_hashes)
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)