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: else:
raise Exception('single argument must be specified') raise Exception('single argument must be specified')
response = yield self._render_response(True) response = yield self._render_response(True)
defer.returnValue(response) defer.returnValue(response)
@ -2435,22 +2434,43 @@ class Daemon(AuthJSONRPCServer):
return d return d
@defer.inlineCallbacks @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: 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: 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) reflector_server = kwargs.get('reflector', None)
if lbry_file is None: lbry_files = yield self._get_lbry_files(**kwargs)
raise Exception('No file found for give sd hash')
yield reupload.reflect_stream(lbry_file) if len(lbry_files) > 1:
defer.returnValue("Reflect success") 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 @defer.inlineCallbacks
@AuthJSONRPCServer.flags(needed="-n", finished="-f") @AuthJSONRPCServer.flags(needed="-n", finished="-f")

View file

@ -29,7 +29,8 @@ def _reflect_stream(lbry_file, reflector_server):
factory = ClientFactory(lbry_file) factory = ClientFactory(lbry_file)
ip = yield 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 result = yield factory.finished_deferred
defer.returnValue(result)
@defer.inlineCallbacks @defer.inlineCallbacks
@ -38,14 +39,29 @@ def _reflect_blobs(blob_manager, blob_hashes, reflector_server):
factory = BlobClientFactory(blob_manager, blob_hashes) factory = BlobClientFactory(blob_manager, blob_hashes)
ip = yield 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 result = yield factory.finished_deferred
defer.returnValue(result)
def reflect_stream(lbry_file): def reflect_stream(lbry_file, reflector_server=None):
reflector_server = random.choice(conf.settings['reflector_servers']) 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) return _reflect_stream(lbry_file, reflector_server)
def reflect_blob_hashes(blob_hashes, blob_manager): def reflect_blob_hashes(blob_hashes, blob_manager, reflector_server=None):
reflector_server = random.choice(conf.settings['reflector_servers']) 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) return _reflect_blobs(blob_manager, blob_hashes, reflector_server)