Skip to content

Commit

Permalink
[client] Truncate V2 hashes when announcing to trackers
Browse files Browse the repository at this point in the history
  • Loading branch information
alanmcgovern committed Apr 2, 2022
1 parent ed563b6 commit 5f554db
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 ());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
{
Expand Down

0 comments on commit 5f554db

Please sign in to comment.