forked from LBRYCommunity/lbry-sdk
fixes from rebase, install libtorrent from s3
This commit is contained in:
parent
a2f8e7068e
commit
abaac8ef48
6 changed files with 20 additions and 27 deletions
|
@ -313,9 +313,9 @@ class JSONResponseEncoder(JSONEncoder):
|
||||||
'height': tx_height,
|
'height': tx_height,
|
||||||
'confirmations': (best_height + 1) - tx_height if tx_height > 0 else tx_height,
|
'confirmations': (best_height + 1) - tx_height if tx_height > 0 else tx_height,
|
||||||
'timestamp': self.ledger.headers.estimated_timestamp(tx_height),
|
'timestamp': self.ledger.headers.estimated_timestamp(tx_height),
|
||||||
'is_fully_reflected': managed_stream.is_fully_reflected,
|
'is_fully_reflected': managed_stream.is_fully_reflected if is_stream else False,
|
||||||
'reflector_progress': managed_stream.reflector_progress,
|
'reflector_progress': managed_stream.reflector_progress if is_stream else False,
|
||||||
'uploading_to_reflector': managed_stream.uploading_to_reflector
|
'uploading_to_reflector': managed_stream.uploading_to_reflector if is_stream else False
|
||||||
}
|
}
|
||||||
|
|
||||||
def encode_claim(self, claim):
|
def encode_claim(self, claim):
|
||||||
|
|
|
@ -98,7 +98,7 @@ class StreamManager(SourceManager):
|
||||||
async def _load_stream(self, rowid: int, sd_hash: str, file_name: Optional[str],
|
async def _load_stream(self, rowid: int, sd_hash: str, file_name: Optional[str],
|
||||||
download_directory: Optional[str], status: str,
|
download_directory: Optional[str], status: str,
|
||||||
claim: Optional['StoredContentClaim'], content_fee: Optional['Transaction'],
|
claim: Optional['StoredContentClaim'], content_fee: Optional['Transaction'],
|
||||||
added_on: Optional[int]):
|
added_on: Optional[int], fully_reflected: Optional[bool]):
|
||||||
try:
|
try:
|
||||||
descriptor = await self.blob_manager.get_stream_descriptor(sd_hash)
|
descriptor = await self.blob_manager.get_stream_descriptor(sd_hash)
|
||||||
except InvalidStreamDescriptorError as err:
|
except InvalidStreamDescriptorError as err:
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
import binascii
|
import binascii
|
||||||
import os
|
import os
|
||||||
|
import logging
|
||||||
from hashlib import sha1
|
from hashlib import sha1
|
||||||
from tempfile import mkdtemp
|
from tempfile import mkdtemp
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
@ -33,6 +34,7 @@ NOTIFICATION_MASKS = [
|
||||||
"upload",
|
"upload",
|
||||||
"block_progress"
|
"block_progress"
|
||||||
]
|
]
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
DEFAULT_FLAGS = ( # fixme: somehow the logic here is inverted?
|
DEFAULT_FLAGS = ( # fixme: somehow the logic here is inverted?
|
||||||
|
@ -65,22 +67,19 @@ class TorrentHandle:
|
||||||
# fixme: cleanup
|
# fixme: cleanup
|
||||||
status = self._handle.status()
|
status = self._handle.status()
|
||||||
if status.has_metadata:
|
if status.has_metadata:
|
||||||
self.metadata_completed.set()
|
|
||||||
self._handle.pause()
|
|
||||||
self.size = status.total_wanted
|
self.size = status.total_wanted
|
||||||
self.total_wanted_done = status.total_wanted_done
|
self.total_wanted_done = status.total_wanted_done
|
||||||
self.name = status.name
|
self.name = status.name
|
||||||
# metadata: libtorrent.torrent_info = self._handle.get_torrent_info()
|
if not self.metadata_completed.is_set():
|
||||||
# print(metadata)
|
self.metadata_completed.set()
|
||||||
# print(metadata.files())
|
log.info("Metadata completed for btih:%s - %s", status.info_hash, self.name)
|
||||||
# print(type(self._handle))
|
|
||||||
if not status.is_seeding:
|
if not status.is_seeding:
|
||||||
print('%.2f%% complete (down: %.1f kB/s up: %.1f kB/s peers: %d seeds: %d) %s - %s' % (
|
log.debug('%.2f%% complete (down: %.1f kB/s up: %.1f kB/s peers: %d seeds: %d) %s - %s' % (
|
||||||
status.progress * 100, status.download_rate / 1000, status.upload_rate / 1000,
|
status.progress * 100, status.download_rate / 1000, status.upload_rate / 1000,
|
||||||
status.num_peers, status.num_seeds, status.state, status.save_path))
|
status.num_peers, status.num_seeds, status.state, status.save_path))
|
||||||
elif not self.finished.is_set():
|
elif not self.finished.is_set():
|
||||||
self.finished.set()
|
self.finished.set()
|
||||||
print("finished!")
|
log.info("Torrent finished: %s", self.name)
|
||||||
|
|
||||||
async def status_loop(self):
|
async def status_loop(self):
|
||||||
while True:
|
while True:
|
||||||
|
@ -125,7 +124,6 @@ class TorrentSession:
|
||||||
size = myfile.write(b'0' * 40 * 1024 * 1024)
|
size = myfile.write(b'0' * 40 * 1024 * 1024)
|
||||||
fs = libtorrent.file_storage()
|
fs = libtorrent.file_storage()
|
||||||
fs.add_file('tmp', size)
|
fs.add_file('tmp', size)
|
||||||
print(fs.file_path(0))
|
|
||||||
t = libtorrent.create_torrent(fs, 0, 4 * 1024 * 1024)
|
t = libtorrent.create_torrent(fs, 0, 4 * 1024 * 1024)
|
||||||
libtorrent.set_piece_hashes(t, dir)
|
libtorrent.set_piece_hashes(t, dir)
|
||||||
info = libtorrent.torrent_info(t.generate())
|
info = libtorrent.torrent_info(t.generate())
|
||||||
|
@ -158,7 +156,7 @@ class TorrentSession:
|
||||||
|
|
||||||
def _pop_alerts(self):
|
def _pop_alerts(self):
|
||||||
for alert in self._session.pop_alerts():
|
for alert in self._session.pop_alerts():
|
||||||
print("alert: ", alert)
|
log.info("torrent alert: %s", alert)
|
||||||
|
|
||||||
async def process_alerts(self):
|
async def process_alerts(self):
|
||||||
while True:
|
while True:
|
||||||
|
@ -182,13 +180,6 @@ class TorrentSession:
|
||||||
|
|
||||||
def _add_torrent(self, btih: str, download_directory: Optional[str]):
|
def _add_torrent(self, btih: str, download_directory: Optional[str]):
|
||||||
params = {'info_hash': binascii.unhexlify(btih.encode())}
|
params = {'info_hash': binascii.unhexlify(btih.encode())}
|
||||||
flags = DEFAULT_FLAGS
|
|
||||||
print(bin(flags))
|
|
||||||
flags ^= libtorrent.add_torrent_params_flags_t.flag_paused
|
|
||||||
flags ^= libtorrent.add_torrent_params_flags_t.flag_auto_managed
|
|
||||||
# flags ^= libtorrent.add_torrent_params_flags_t.flag_stop_when_ready
|
|
||||||
print(bin(flags))
|
|
||||||
# params['flags'] = flags
|
|
||||||
if download_directory:
|
if download_directory:
|
||||||
params['save_path'] = download_directory
|
params['save_path'] = download_directory
|
||||||
handle = self._handles[btih] = TorrentHandle(self._loop, self._executor, self._session.add_torrent(params))
|
handle = self._handles[btih] = TorrentHandle(self._loop, self._executor, self._session.add_torrent(params))
|
||||||
|
@ -208,9 +199,8 @@ class TorrentSession:
|
||||||
self._handles.pop(btih)
|
self._handles.pop(btih)
|
||||||
|
|
||||||
async def save_file(self, btih, download_directory):
|
async def save_file(self, btih, download_directory):
|
||||||
return
|
|
||||||
handle = self._handles[btih]
|
handle = self._handles[btih]
|
||||||
handle._handle.move_storage(download_directory)
|
await handle.resume()
|
||||||
|
|
||||||
def get_size(self, btih):
|
def get_size(self, btih):
|
||||||
return self._handles[btih].size
|
return self._handles[btih].size
|
||||||
|
@ -242,9 +232,7 @@ async def main():
|
||||||
btih = await session.add_fake_torrent()
|
btih = await session.add_fake_torrent()
|
||||||
session2._session.add_dht_node(('localhost', 4040))
|
session2._session.add_dht_node(('localhost', 4040))
|
||||||
await session2.add_torrent(btih, "/tmp/down")
|
await session2.add_torrent(btih, "/tmp/down")
|
||||||
print('added')
|
|
||||||
while True:
|
while True:
|
||||||
print("idling")
|
|
||||||
await asyncio.sleep(100)
|
await asyncio.sleep(100)
|
||||||
await session.pause()
|
await session.pause()
|
||||||
executor.shutdown()
|
executor.shutdown()
|
||||||
|
|
|
@ -59,6 +59,10 @@ class TorrentSource(ManagedDownloadSource):
|
||||||
def torrent_name(self):
|
def torrent_name(self):
|
||||||
return self.torrent_session.get_name(self.identifier)
|
return self.torrent_session.get_name(self.identifier)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def bt_infohash(self):
|
||||||
|
return self.identifier
|
||||||
|
|
||||||
def stop_tasks(self):
|
def stop_tasks(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ class FileCommands(CommandTestCase):
|
||||||
async def initialize_torrent(self):
|
async def initialize_torrent(self):
|
||||||
self.seeder_session = TorrentSession(self.loop, None)
|
self.seeder_session = TorrentSession(self.loop, None)
|
||||||
self.addCleanup(self.seeder_session.stop)
|
self.addCleanup(self.seeder_session.stop)
|
||||||
await self.seeder_session.bind('localhost', 4040)
|
await self.seeder_session.bind(port=4040)
|
||||||
self.btih = await self.seeder_session.add_fake_torrent()
|
self.btih = await self.seeder_session.add_fake_torrent()
|
||||||
address = await self.account.receiving.get_or_create_usable_address()
|
address = await self.account.receiving.get_or_create_usable_address()
|
||||||
claim = Claim()
|
claim = Claim()
|
||||||
|
@ -28,7 +28,7 @@ class FileCommands(CommandTestCase):
|
||||||
self.loop, self.daemon.conf, client_session, self.daemon.storage, self.daemon.analytics_manager
|
self.loop, self.daemon.conf, client_session, self.daemon.storage, self.daemon.analytics_manager
|
||||||
)
|
)
|
||||||
await self.daemon.file_manager.source_managers['torrent'].start()
|
await self.daemon.file_manager.source_managers['torrent'].start()
|
||||||
await client_session.bind('localhost', 4041)
|
await client_session.bind(port=4041)
|
||||||
client_session._session.add_dht_node(('localhost', 4040))
|
client_session._session.add_dht_node(('localhost', 4040))
|
||||||
|
|
||||||
async def test_download_torrent(self):
|
async def test_download_torrent(self):
|
||||||
|
|
1
tox.ini
1
tox.ini
|
@ -13,6 +13,7 @@ commands =
|
||||||
--global-option=fetch \
|
--global-option=fetch \
|
||||||
--global-option=--version --global-option=3.30.1 --global-option=--all \
|
--global-option=--version --global-option=3.30.1 --global-option=--all \
|
||||||
--global-option=build --global-option=--enable --global-option=fts5
|
--global-option=build --global-option=--enable --global-option=fts5
|
||||||
|
pip install https://s3.amazonaws.com/files.lbry.io/python_libtorrent-1.2.4-py2.py3-none-any.whl
|
||||||
orchstr8 download
|
orchstr8 download
|
||||||
blockchain: coverage run -p --source={envsitepackagesdir}/lbry -m unittest discover -vv integration.blockchain {posargs}
|
blockchain: coverage run -p --source={envsitepackagesdir}/lbry -m unittest discover -vv integration.blockchain {posargs}
|
||||||
datanetwork: coverage run -p --source={envsitepackagesdir}/lbry -m unittest discover -vv integration.datanetwork {posargs}
|
datanetwork: coverage run -p --source={envsitepackagesdir}/lbry -m unittest discover -vv integration.datanetwork {posargs}
|
||||||
|
|
Loading…
Reference in a new issue