Skip to content

Commit

Permalink
[core] Load hybrid torrents correctly
Browse files Browse the repository at this point in the history
Hybrid torrents aren't fully supported (yet). To support these the
engine will load them as either V1 or V2, and that is accomplished
by ensuring only the V1 hash, or the V2 hash is set after loading
the torrent.

In addition to this, we should also ensure that the PieceHashes
object is not set to non-null for both hashing schemes. A v2 only
torrent should only have a V2 hashes object.
  • Loading branch information
alanmcgovern committed Apr 2, 2022
1 parent 022c5a9 commit ed563b6
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/MonoTorrent.Client/MonoTorrent/Torrent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,6 @@ void LoadInternal (BEncodedDictionary torrentInformation, RawInfoHashes infoHash
}
}

PieceHashes = new PieceHashes (hashesV1, hashesV2);
if (SupportsV2Torrents && SupportsV1V2Torrents) {
InfoHashes = new InfoHashes (hashesV1 == null ? default : InfoHash.FromMemory (infoHashes.SHA1), Files[0].PiecesRoot.IsEmpty ? default : InfoHash.FromMemory (infoHashes.SHA256));
} else if (SupportsV2Torrents) {
Expand All @@ -614,6 +613,7 @@ void LoadInternal (BEncodedDictionary torrentInformation, RawInfoHashes infoHash
} else {
InfoHashes = new InfoHashes (InfoHash.FromMemory (infoHashes.SHA1), default);
}
PieceHashes = new PieceHashes (InfoHashes.V1 is null ? null : hashesV1, InfoHashes.V2 is null ? null : hashesV2);
}

static IList<ITorrentFile> LoadTorrentFilesV1 (BEncodedList list, int pieceLength)
Expand Down

0 comments on commit ed563b6

Please sign in to comment.