mirror of
https://github.com/transmission/transmission
synced 2024-12-27 01:57:52 +00:00
parent
d5aead4b41
commit
f39a1e45a8
1 changed files with 22 additions and 27 deletions
|
@ -579,30 +579,37 @@ static void onTrackerResponse(tr_torrent* tor, tr_tracker_event const* event, vo
|
|||
****
|
||||
***/
|
||||
|
||||
static void tr_torrentInitFileOffsets(tr_torrent* tor)
|
||||
{
|
||||
auto offset = uint64_t{ 0 };
|
||||
static void torrentStart(tr_torrent* tor, bool bypass_queue);
|
||||
|
||||
static void tr_torrentFireMetadataCompleted(tr_torrent* tor);
|
||||
|
||||
static void torrentInitFromInfoDict(tr_torrent* tor)
|
||||
{
|
||||
tor->initSizes(tor->info.totalSize, tor->info.pieceSize);
|
||||
tor->completion = tr_completion{ tor, tor };
|
||||
tr_sha1(tor->obfuscatedHash, "req2", 4, tor->info.hash, SHA_DIGEST_LENGTH, nullptr);
|
||||
|
||||
// init file offsets
|
||||
auto offset = uint64_t{ 0 };
|
||||
for (tr_file_index_t i = 0, n = tor->fileCount(); i < n; ++i)
|
||||
{
|
||||
auto& file = tor->file(i);
|
||||
file.priv.offset = offset;
|
||||
offset += file.length;
|
||||
}
|
||||
|
||||
tor->fpm_.reset(tor->info);
|
||||
tor->file_priorities_.reset(&tor->fpm_);
|
||||
tor->files_wanted_.reset(&tor->fpm_);
|
||||
|
||||
tor->dnd_pieces_ = tr_bitfield{ tor->info.pieceCount };
|
||||
tor->checked_pieces_ = tr_bitfield{ tor->info.pieceCount };
|
||||
}
|
||||
|
||||
static void torrentStart(tr_torrent* tor, bool bypass_queue);
|
||||
|
||||
static void tr_torrentFireMetadataCompleted(tr_torrent* tor);
|
||||
|
||||
void tr_torrentGotNewInfoDict(tr_torrent* tor)
|
||||
{
|
||||
tor->initSizes(tor->info.totalSize, tor->info.pieceSize);
|
||||
tor->completion = tr_completion{ tor, tor };
|
||||
tr_torrentInitFileOffsets(tor);
|
||||
|
||||
torrentInitFromInfoDict(tor);
|
||||
tr_peerMgrOnTorrentGotMetainfo(tor);
|
||||
|
||||
tr_torrentFireMetadataCompleted(tor);
|
||||
}
|
||||
|
||||
|
@ -654,25 +661,17 @@ static void refreshCurrentDir(tr_torrent* tor);
|
|||
|
||||
static void torrentInit(tr_torrent* tor, tr_ctor const* ctor)
|
||||
{
|
||||
static auto next_unique_id = int{ 1 };
|
||||
auto const lock = tor->unique_lock();
|
||||
|
||||
tr_session* session = tr_ctorGetSession(ctor);
|
||||
TR_ASSERT(session != nullptr);
|
||||
|
||||
static int nextUniqueId = 1;
|
||||
|
||||
tor->fpm_.reset(tor->info);
|
||||
tor->file_priorities_.reset(&tor->fpm_);
|
||||
tor->files_wanted_.reset(&tor->fpm_);
|
||||
|
||||
tor->session = session;
|
||||
tor->uniqueId = nextUniqueId++;
|
||||
tor->uniqueId = next_unique_id++;
|
||||
tor->queuePosition = tr_sessionCountTorrents(session);
|
||||
|
||||
tor->dnd_pieces_ = tr_bitfield{ tor->info.pieceCount };
|
||||
tor->checked_pieces_ = tr_bitfield{ tor->info.pieceCount };
|
||||
|
||||
tr_sha1(tor->obfuscatedHash, "req2", 4, tor->info.hash, SHA_DIGEST_LENGTH, nullptr);
|
||||
torrentInitFromInfoDict(tor);
|
||||
|
||||
char const* dir = nullptr;
|
||||
if (tr_ctorGetDownloadDir(ctor, TR_FORCE, &dir) || tr_ctorGetDownloadDir(ctor, TR_FALLBACK, &dir))
|
||||
|
@ -703,10 +702,6 @@ static void torrentInit(tr_torrent* tor, tr_ctor const* ctor)
|
|||
|
||||
tr_torrentSetDateAdded(tor, tr_time()); /* this is a default value to be overwritten by the resume file */
|
||||
|
||||
tor->initSizes(tor->info.totalSize, tor->info.pieceSize);
|
||||
tor->completion = tr_completion{ tor, tor };
|
||||
tr_torrentInitFileOffsets(tor);
|
||||
|
||||
// tr_torrentLoadResume() calls a lot of tr_torrentSetFoo() methods
|
||||
// that set things as dirty, but... these settings being loaded are
|
||||
// the same ones that would be saved back again, so don't let them
|
||||
|
|
Loading…
Reference in a new issue