diff --git a/lbrynet/daemon/Daemon.py b/lbrynet/daemon/Daemon.py index f6665ac6a..fc96f5ebf 100644 --- a/lbrynet/daemon/Daemon.py +++ b/lbrynet/daemon/Daemon.py @@ -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=) + file_reflect [--sd_hash=] [--file_name=] + [--stream_hash=] [--claim_id=] + [--outpoint=] [--rowid=] [--name=] + [--reflector=] + + Options: + --sd_hash= : get file with matching sd hash + --file_name= : get file with matching file name in the + downloads folder + --stream_hash= : get file with matching stream hash + --claim_id= : get file with matching claim id + --outpoint= : get file with matching claim outpoint + --rowid= : get file with matching row id + --name= : get file with matching associated name claim + --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") diff --git a/lbrynet/reflector/reupload.py b/lbrynet/reflector/reupload.py index a414d355b..39c6c1ba1 100644 --- a/lbrynet/reflector/reupload.py +++ b/lbrynet/reflector/reupload.py @@ -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)