diff --git a/src/MonoTorrent.Client/MonoTorrent.Client.Tracker/TrackerRequestFactory.cs b/src/MonoTorrent.Client/MonoTorrent.Client.Tracker/TrackerRequestFactory.cs index 19426015b..044935dff 100644 --- a/src/MonoTorrent.Client/MonoTorrent.Client.Tracker/TrackerRequestFactory.cs +++ b/src/MonoTorrent.Client/MonoTorrent.Client.Tracker/TrackerRequestFactory.cs @@ -71,13 +71,13 @@ public AnnounceRequest CreateAnnounce (TorrentEvent clientEvent) return new AnnounceRequest (Manager.Monitor.DataBytesReceived, Manager.Monitor.DataBytesSent, bytesLeft, - clientEvent, (Manager.InfoHashes.V1OrV2), requireEncryption, Manager.Engine!.PeerId.AsMemory (), + clientEvent, Manager.InfoHashes.V1OrV2.Truncate (), requireEncryption, Manager.Engine!.PeerId.AsMemory (), ip, port, supportsEncryption); } public ScrapeRequest CreateScrape () { - return new ScrapeRequest (Manager.InfoHashes.V1OrV2); + return new ScrapeRequest (Manager.InfoHashes.V1OrV2.Truncate ()); } } } diff --git a/src/Tests/Tests.MonoTorrent.Client/MonoTorrent.Client.Modes/DownloadModeTests.cs b/src/Tests/Tests.MonoTorrent.Client/MonoTorrent.Client.Modes/DownloadModeTests.cs index 381c4c39e..19e60539f 100644 --- a/src/Tests/Tests.MonoTorrent.Client/MonoTorrent.Client.Modes/DownloadModeTests.cs +++ b/src/Tests/Tests.MonoTorrent.Client/MonoTorrent.Client.Modes/DownloadModeTests.cs @@ -190,6 +190,31 @@ public void AddConnection () Assert.IsFalse (Manager.Peers.ConnectedPeers.Contains (Peer), "#3"); } + + [Test] + public async Task AnnounceWithTruncatedInfoHash () + { + var link = new MagnetLink (new InfoHashes (null, new InfoHash (new byte[32]))); + using var engine = new ClientEngine (EngineSettingsBuilder.CreateForTests ()); + var manager = await engine.AddAsync (link, ""); + var args = new TrackerRequestFactory (manager).CreateAnnounce (TorrentEvent.None); + Assert.AreEqual (20, args.InfoHash.Span.Length); + Assert.IsTrue (manager.InfoHashes.Contains (args.InfoHash)); + Assert.IsNull (manager.InfoHashes.V1); + } + + [Test] + public async Task ScrapeWithTruncatedInfoHash () + { + var link = new MagnetLink (new InfoHashes (null, new InfoHash (new byte[32]))); + using var engine = new ClientEngine (EngineSettingsBuilder.CreateForTests ()); + var manager = await engine.AddAsync (link, ""); + var args = new TrackerRequestFactory (manager).CreateScrape (); + Assert.AreEqual (20, args.InfoHash.Span.Length); + Assert.IsTrue (manager.InfoHashes.Contains (args.InfoHash)); + Assert.IsNull (manager.InfoHashes.V1); + } + [Test] public async Task AnnounceWhenComplete () {