From ed563b6da29a01d2a7deb5096d2db2f5460c75b9 Mon Sep 17 00:00:00 2001 From: Alan McGovern Date: Sun, 3 Apr 2022 00:23:16 +0100 Subject: [PATCH] [core] Load hybrid torrents correctly 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. --- src/MonoTorrent.Client/MonoTorrent/Torrent.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MonoTorrent.Client/MonoTorrent/Torrent.cs b/src/MonoTorrent.Client/MonoTorrent/Torrent.cs index 9038e9e3f..2703f3e4d 100644 --- a/src/MonoTorrent.Client/MonoTorrent/Torrent.cs +++ b/src/MonoTorrent.Client/MonoTorrent/Torrent.cs @@ -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) { @@ -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 LoadTorrentFilesV1 (BEncodedList list, int pieceLength)