forked from LBRYCommunity/lbry-sdk
Merge branch 'add_more_session_info'
This commit is contained in:
commit
cdc65d36b0
4 changed files with 35 additions and 2 deletions
|
@ -40,6 +40,7 @@ at anytime.
|
||||||
* Refactored and pruned blob related classes into `lbrynet.blobs`
|
* Refactored and pruned blob related classes into `lbrynet.blobs`
|
||||||
* Changed several `assert`s to raise more useful errors
|
* Changed several `assert`s to raise more useful errors
|
||||||
* Added ability for reflector to store stream information for head blob announce
|
* Added ability for reflector to store stream information for head blob announce
|
||||||
|
* Added blob announcement information to API call status with session flag
|
||||||
|
|
||||||
### Removed
|
### Removed
|
||||||
* Removed `TempBlobFile`
|
* Removed `TempBlobFile`
|
||||||
|
|
|
@ -88,6 +88,9 @@ class DiskBlobManager(DHTHashSupplier):
|
||||||
def hashes_to_announce(self):
|
def hashes_to_announce(self):
|
||||||
return self._get_blobs_to_announce()
|
return self._get_blobs_to_announce()
|
||||||
|
|
||||||
|
def count_should_announce_blobs(self):
|
||||||
|
return self._count_should_announce_blobs()
|
||||||
|
|
||||||
def set_should_announce(self, blob_hash, should_announce):
|
def set_should_announce(self, blob_hash, should_announce):
|
||||||
if blob_hash in self.blobs:
|
if blob_hash in self.blobs:
|
||||||
blob = self.blobs[blob_hash]
|
blob = self.blobs[blob_hash]
|
||||||
|
@ -215,6 +218,12 @@ class DiskBlobManager(DHTHashSupplier):
|
||||||
(blob_hash,))
|
(blob_hash,))
|
||||||
defer.returnValue(result[0][0])
|
defer.returnValue(result[0][0])
|
||||||
|
|
||||||
|
@rerun_if_locked
|
||||||
|
@defer.inlineCallbacks
|
||||||
|
def _count_should_announce_blobs(self):
|
||||||
|
result = yield self.db_conn.runQuery("select count(*) from blobs where should_announce=1")
|
||||||
|
defer.returnValue(result[0][0])
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def _completed_blobs(self, blobhashes_to_check):
|
def _completed_blobs(self, blobhashes_to_check):
|
||||||
"""Returns of the blobhashes_to_check, which are valid"""
|
"""Returns of the blobhashes_to_check, which are valid"""
|
||||||
|
|
|
@ -1029,6 +1029,8 @@ class Daemon(AuthJSONRPCServer):
|
||||||
'session_status': {
|
'session_status': {
|
||||||
'managed_blobs': count of blobs in the blob manager,
|
'managed_blobs': count of blobs in the blob manager,
|
||||||
'managed_streams': count of streams in the file manager
|
'managed_streams': count of streams in the file manager
|
||||||
|
'announce_queue_size': number of blobs currently queued to be announced
|
||||||
|
'should_announce_blobs': number of blobs that should be announced
|
||||||
}
|
}
|
||||||
|
|
||||||
If given the dht status option:
|
If given the dht status option:
|
||||||
|
@ -1077,9 +1079,13 @@ class Daemon(AuthJSONRPCServer):
|
||||||
}
|
}
|
||||||
if session_status:
|
if session_status:
|
||||||
blobs = yield self.session.blob_manager.get_all_verified_blobs()
|
blobs = yield self.session.blob_manager.get_all_verified_blobs()
|
||||||
|
announce_queue_size = self.session.hash_announcer.hash_queue_size()
|
||||||
|
should_announce_blobs = yield self.session.blob_manager.count_should_announce_blobs()
|
||||||
response['session_status'] = {
|
response['session_status'] = {
|
||||||
'managed_blobs': len(blobs),
|
'managed_blobs': len(blobs),
|
||||||
'managed_streams': len(self.lbry_file_manager.lbry_files),
|
'managed_streams': len(self.lbry_file_manager.lbry_files),
|
||||||
|
'announce_queue_size': announce_queue_size,
|
||||||
|
'should_announce_blobs': should_announce_blobs,
|
||||||
}
|
}
|
||||||
if dht_status:
|
if dht_status:
|
||||||
response['dht_status'] = self.session.dht_node.get_bandwidth_stats()
|
response['dht_status'] = self.session.dht_node.get_bandwidth_stats()
|
||||||
|
|
|
@ -32,7 +32,7 @@ class BlobManagerTest(unittest.TestCase):
|
||||||
shutil.rmtree(self.db_dir)
|
shutil.rmtree(self.db_dir)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def _create_and_add_blob(self):
|
def _create_and_add_blob(self, should_announce=False):
|
||||||
# create and add blob to blob manager
|
# create and add blob to blob manager
|
||||||
data_len = random.randint(1, 1000)
|
data_len = random.randint(1, 1000)
|
||||||
data = ''.join(random.choice(string.lowercase) for data_len in range(data_len))
|
data = ''.join(random.choice(string.lowercase) for data_len in range(data_len))
|
||||||
|
@ -48,7 +48,7 @@ class BlobManagerTest(unittest.TestCase):
|
||||||
|
|
||||||
writer, finished_d = yield blob.open_for_writing(self.peer)
|
writer, finished_d = yield blob.open_for_writing(self.peer)
|
||||||
yield writer.write(data)
|
yield writer.write(data)
|
||||||
yield self.bm.blob_completed(blob)
|
yield self.bm.blob_completed(blob, should_announce)
|
||||||
yield self.bm.add_blob_to_upload_history(blob_hash, 'test', len(data))
|
yield self.bm.add_blob_to_upload_history(blob_hash, 'test', len(data))
|
||||||
|
|
||||||
# check to see if blob is there
|
# check to see if blob is there
|
||||||
|
@ -112,3 +112,20 @@ class BlobManagerTest(unittest.TestCase):
|
||||||
self.assertEqual(len(blobs), 10)
|
self.assertEqual(len(blobs), 10)
|
||||||
self.assertTrue(blob_hashes[-1] in blobs)
|
self.assertTrue(blob_hashes[-1] in blobs)
|
||||||
self.assertTrue(os.path.isfile(os.path.join(self.blob_dir, blob_hashes[-1])))
|
self.assertTrue(os.path.isfile(os.path.join(self.blob_dir, blob_hashes[-1])))
|
||||||
|
|
||||||
|
@defer.inlineCallbacks
|
||||||
|
def test_should_announce(self):
|
||||||
|
# create blob with should announce
|
||||||
|
blob_hash = yield self._create_and_add_blob(should_announce=True)
|
||||||
|
out = yield self.bm.get_should_announce(blob_hash)
|
||||||
|
self.assertTrue(out)
|
||||||
|
count = yield self.bm.count_should_announce_blobs()
|
||||||
|
self.assertEqual(1, count)
|
||||||
|
|
||||||
|
# set should annouce to False
|
||||||
|
out = yield self.bm.set_should_announce(blob_hash, should_announce=False)
|
||||||
|
out = yield self.bm.get_should_announce(blob_hash)
|
||||||
|
self.assertFalse(out)
|
||||||
|
count = yield self.bm.count_should_announce_blobs()
|
||||||
|
self.assertEqual(0, count)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue