Skip to content

Commit

Permalink
[Core] Support creating v2 torrents
Browse files Browse the repository at this point in the history
Add support for v2 torrents in create_torrent, but keep the old
default of only adding the v1 metadata.

Unify the single-file and directory cases to avoid code
duplication.

V2 torrents require files to be piece-aligned. The same for
hybrid v1/v2 ones. To handle both cases of piece-aligned and
non-aligned files, always read the files in piece-aligned
chunks. Re-slice the buffer if needed (for v1-only multi-file
torrents).

Also, had to adapt to progress event. It now depends on the
number of bytes hashed rather than the number of pieces. To
avoid sending and excessive amount of event when handling a
directory with many small files, add a mechanism to limit
event period at 1 per piece_length.
  • Loading branch information
rcarpa committed Aug 28, 2023
1 parent 46f2679 commit b18dbec
Show file tree
Hide file tree
Showing 3 changed files with 329 additions and 87 deletions.
9 changes: 8 additions & 1 deletion deluge/core/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import deluge.common
import deluge.component as component
from deluge import path_chooser_common
from deluge import metafile, path_chooser_common
from deluge._libtorrent import LT_VERSION, lt
from deluge.configmanager import ConfigManager, get_config_dir
from deluge.core.alertmanager import AlertManager
Expand Down Expand Up @@ -998,7 +998,11 @@ def create_torrent(
created_by=None,
trackers=None,
add_to_session=False,
torrent_format=metafile.TorrentFormat.V1,
):
if isinstance(torrent_format, str):
torrent_format = metafile.TorrentFormat(torrent_format)

log.debug('creating torrent..')
return threads.deferToThread(
self._create_torrent_thread,
Expand All @@ -1012,6 +1016,7 @@ def create_torrent(
created_by=created_by,
trackers=trackers,
add_to_session=add_to_session,
torrent_format=torrent_format,
)

def _create_torrent_thread(
Expand All @@ -1026,6 +1031,7 @@ def _create_torrent_thread(
created_by,
trackers,
add_to_session,
torrent_format,
):
from deluge import metafile

Expand All @@ -1038,6 +1044,7 @@ def _create_torrent_thread(
private=private,
created_by=created_by,
trackers=trackers,
torrent_format=torrent_format,
)

write_file = False
Expand Down
Loading

0 comments on commit b18dbec

Please sign in to comment.