diff --git a/CHANGELOG.md b/CHANGELOG.md index d5a4915c6..e95b5b105 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,7 @@ at anytime. ### Added * Added validation of currencies. - * + * Added blob_announce API command ### Fixed * Fixed incorrect formatting of "amount" fields diff --git a/lbrynet/daemon/Daemon.py b/lbrynet/daemon/Daemon.py index 6ff72b6bc..dfb67cbbe 100644 --- a/lbrynet/daemon/Daemon.py +++ b/lbrynet/daemon/Daemon.py @@ -2349,6 +2349,53 @@ class Daemon(AuthJSONRPCServer): d.addCallback(lambda r: self._render_response(r)) return d + @defer.inlineCallbacks + @AuthJSONRPCServer.flags(announce_all="-a") + def jsonrpc_blob_announce(self, announce_all=None, blob_hash=None, + stream_hash=None, sd_hash=None): + """ + Announce blobs to the DHT + + Usage: + blob_announce [-a] [ | --blob_hash=] + [ | --stream_hash=] + [ | --sd_hash=] + + Options: + -a : announce all the blobs possessed by user + , --blob_hash= : announce a blob, specified by blob_hash + , --stream_hash= : announce all blobs associated with + stream_hash + , --sd_hash= : announce all blobs associated with + sd_hash and the sd_hash itself + + Returns: + (bool) true if successful + """ + if announce_all: + yield self.session.blob_manager.immediate_announce_all_blobs() + elif blob_hash: + blob_hashes = [blob_hash] + yield self.session.blob_manager._immediate_announce(blob_hashes) + elif stream_hash: + blobs = yield self.get_blobs_for_stream_hash(stream_hash) + blobs = [blob for blob in blobs if blob.is_validated()] + blob_hashes = [blob.blob_hash for blob in blobs] + yield self.session.blob_manager._immediate_announce(blob_hashes) + elif sd_hash: + blobs = yield self.get_blobs_for_sd_hash(sd_hash) + blobs = [blob for blob in blobs if blob.is_validated()] + blob_hashes = [blob.blob_hash for blob in blobs] + blob_hashes.append(sd_hash) + yield self.session.blob_manager._immediate_announce(blob_hashes) + else: + raise Exception('single argument must be specified') + + + response = yield self._render_response(True) + defer.returnValue(response) + + # TODO: This command should be deprecated in favor of blob_announce def jsonrpc_blob_announce_all(self): """ Announce all blobs to the DHT