Skip to content

Commit

Permalink
save resume data on stop, remove/replace deprecated calls
Browse files Browse the repository at this point in the history
  • Loading branch information
shyba committed Sep 9, 2022
1 parent 2ef3027 commit bd2de69
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions lbry/torrent/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def largest_file_index(self):
return index

def stop_tasks(self):
self._handle.save_resume_data()
while self.tasks:
self.tasks.pop().cancel()

Expand Down Expand Up @@ -152,13 +153,13 @@ def __init__(self, loop, executor):

async def add_fake_torrent(self):
tmpdir = mkdtemp()
info, btih = _create_fake_torrent(tmpdir)
info = _create_fake_torrent(tmpdir)
flags = libtorrent.add_torrent_params_flags_t.flag_seed_mode
handle = self._session.add_torrent({
'ti': info, 'save_path': tmpdir, 'flags': flags
})
self._handles[btih] = TorrentHandle(self._loop, self._executor, handle)
return btih
self._handles[str(info.info_hash())] = TorrentHandle(self._loop, self._executor, handle)
return str(info.info_hash())

async def bind(self, interface: str = '0.0.0.0', port: int = 10889):
settings = {
Expand All @@ -172,14 +173,12 @@ async def bind(self, interface: str = '0.0.0.0', port: int = 10889):
self.tasks.append(self._loop.create_task(self.process_alerts()))

def stop(self):
while self._handles:
self._handles.popitem()[1].stop_tasks()
while self.tasks:
self.tasks.pop().cancel()
self._session.save_state()
self._session.pause()
self._session.stop_dht()
self._session.stop_lsd()
self._session.stop_natpmp()
self._session.stop_upnp()
self._session = None

def _pop_alerts(self):
Expand Down Expand Up @@ -271,9 +270,7 @@ def _create_fake_torrent(tmpdir):
file_storage.add_file('tmp', size)
t = libtorrent.create_torrent(file_storage, 0, 4 * 1024 * 1024)
libtorrent.set_piece_hashes(t, tmpdir)
info = libtorrent.torrent_info(t.generate())
btih = sha1(info.metadata()).hexdigest()
return info, btih
return libtorrent.torrent_info(t.generate())


async def main():
Expand Down

0 comments on commit bd2de69

Please sign in to comment.