add blob_announce API command, to eventually replace blob_announce_all

This commit is contained in:
Kay Kurokawa 2017-07-21 14:05:08 -04:00
parent cc7a3d3dcc
commit 4e05eac854

View file

@ -2351,6 +2351,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> | --blob_hash=<blob_hash>]
[<stream_hash> | --stream_hash=<stream_hash>]
[<sd_hash> | --sd_hash=<sd_hash>]
Options:
-a : announce all the blobs possessed by user
<blob_hash>, --blob_hash=<blob_hash> : announce a blob, specified by blob_hash
<stream_hash>, --stream_hash=<stream_hash> : announce all blobs associated with
stream_hash
<sd_hash>, --sd_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