Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
62351a2
Add and improve tests (#13)
xBaank Jan 14, 2026
6e6fcab
wip
xBaank Jan 14, 2026
e40a830
wip
xBaank Jan 14, 2026
b7cffbf
wip
xBaank Jan 14, 2026
a5f2d0f
wip
xBaank Jan 14, 2026
f8345f5
wip
xBaank Jan 14, 2026
375e2cd
wip
xBaank Jan 14, 2026
5dff639
wip
xBaank Jan 14, 2026
93a9080
Revert "wip"
xBaank Jan 14, 2026
e062a1c
Create dependabot.yml
xBaank Jan 14, 2026
d7c2f7d
wip
xBaank Jan 14, 2026
ab5665f
wip
xBaank Jan 14, 2026
fe4fb20
wip
xBaank Jan 14, 2026
3a6a730
wip
xBaank Jan 14, 2026
da8029e
wip
xBaank Jan 14, 2026
7bbd15b
wip
xBaank Jan 14, 2026
c921e42
wip
xBaank Jan 14, 2026
c45fd99
Merge branch 'master' into develop
xBaank Jan 14, 2026
b9648a7
wip
xBaank Jan 14, 2026
a488227
wip
xBaank Jan 14, 2026
ee36661
Bump CSharpier.MsBuild from 1.2.1 to 1.2.5 (#33)
dependabot[bot] Jan 14, 2026
41a8ebe
Bump Microsoft.Extensions.Logging.Abstractions from 10.0.1 to 10.0.2 …
dependabot[bot] Jan 14, 2026
3f8e6ca
Bump Microsoft.Extensions.Logging and Microsoft.Extensions.Logging.Co…
dependabot[bot] Jan 14, 2026
8d59c9c
Bump Testcontainers from 4.9.0 to 4.10.0 (#37)
dependabot[bot] Jan 14, 2026
d03f03f
Bump TUnit from 1.11.18 to 1.11.28 (#38)
dependabot[bot] Jan 14, 2026
8dbdcf1
Merge branch 'master' into develop
xBaank Jan 14, 2026
c9b5ff6
wip
xBaank Jan 14, 2026
f7ceea6
Bump actions/checkout from 4 to 6 (#40)
dependabot[bot] Jan 14, 2026
3e52df0
Bump actions/github-script from 7 to 8 (#41)
dependabot[bot] Jan 14, 2026
467725d
Bump actions/upload-artifact from 4 to 6 (#44)
dependabot[bot] Jan 14, 2026
3956226
Bump actions/setup-dotnet from 4 to 5 (#42)
dependabot[bot] Jan 14, 2026
4c6302e
Bump actions/download-artifact from 4 to 7 (#43)
dependabot[bot] Jan 14, 2026
3081979
wip
xBaank Jan 15, 2026
42013d6
Bump actions/cache from 4 to 5 (#45)
dependabot[bot] Jan 15, 2026
0ad161e
wip
xBaank Jan 15, 2026
d9d562d
wip
xBaank Jan 15, 2026
5718cbe
wip
xBaank Jan 16, 2026
f9f58f9
wip
xBaank Jan 16, 2026
c63904f
Bump TUnit from 1.11.28 to 1.11.45 (#48)
dependabot[bot] Jan 16, 2026
fd64006
Merge branch 'master' into develop
xBaank Jan 16, 2026
83701e3
Add ListenAddressIpv4 And ListenAddressIpv6 (#50)
xBaank Jan 18, 2026
fa19bd2
wip
xBaank Jan 18, 2026
059d6d0
Bump TUnit from 1.11.45 to 1.12.3 (#52)
dependabot[bot] Jan 19, 2026
0213e11
Implement cancellation handling on upload (#53)
xBaank Jan 19, 2026
2b92692
Bump TUnit from 1.12.3 to 1.12.15 (#54)
dependabot[bot] Jan 20, 2026
d322768
Add endgame (#55)
xBaank Jan 20, 2026
7b01ca3
Respect tiers of bep_0012 (#56)
xBaank Jan 21, 2026
925cc37
Announce `completed` when all pieces are downloaded and fix torrent c…
xBaank Jan 21, 2026
1f9adfa
Merge remote-tracking branch 'origin/master' into develop
xBaank Jan 21, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Netorrent.Example/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ await AnsiConsole
RemainingStyle = new Style(Color.Grey),
},
new PercentageColumn(),
new TransferSpeedColumn(),
new RemainingTimeColumn(),
new SpinnerColumn()
)
Expand Down
2 changes: 1 addition & 1 deletion Netorrent.Tests.Integration/Torrents/TorrentTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ CancellationToken cancellationToken
var seederTorrent = await seeder.CreateTorrentAsync(
path,
_fixture.AnnounceUrl,
[.. _fixture.AnnounceUrls]
[_fixture.AnnounceUrls]
);

yield return (seederTorrent, seeder);
Expand Down
2 changes: 1 addition & 1 deletion Netorrent.Tests/Fakes/FakePeerConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public ulong DecrementRequestedBlock()

public ulong DecrementUploadRequested() => _uploadRequestedCount--;

public ValueTask DisposeAsync() => ValueTask.CompletedTask;
public async ValueTask DisposeAsync() => SentBlocks.OnCompleted();

public ulong IncrementRequestedBlock()
{
Expand Down
19 changes: 6 additions & 13 deletions Netorrent.Tests/Fakes/FakePiecePicker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,15 @@ internal class FakePiecePicker : IPiecePicker
{
public int BlockSize => 16 * 1024;

public void CompletePiece(int index)
{
throw new NotImplementedException();
}
public bool IsEndGame => throw new NotImplementedException();

public void CompleteRequestBlock(RequestBlock requestBlock)
public void CompletePiece(int index)
{
throw new NotImplementedException();
}

public void DecreaseRarity(int index) { }

public ValueTask DisposeAsync() => ValueTask.CompletedTask;

public long GetBitfieldSize()
{
throw new NotImplementedException();
Expand Down Expand Up @@ -55,12 +50,10 @@ public IEnumerable<RequestBlock> GetTimeoutRequestBlocks()

public void IncreaseRarity(int index) { }

public void SetBlockToPending(RequestBlock requestBlock)
{
throw new NotImplementedException();
}

public void SetBlockToRequested(RequestBlock requestBlock, IPeerConnection peerConnection)
public bool TryGetRequestBlock(
IPeerConnection peerConnection,
[NotNullWhen(true)] out RequestBlock? requestBlock
)
{
throw new NotImplementedException();
}
Expand Down
2 changes: 1 addition & 1 deletion Netorrent.Tests/Netorrent.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Shouldly" Version="4.3.0" />
<PackageReference Include="TUnit" Version="1.11.45" />
<PackageReference Include="TUnit" Version="1.12.15" />
<PackageReference Include="PublicApiGenerator" Version="11.5.4" />
</ItemGroup>
<ItemGroup>
Expand Down
33 changes: 32 additions & 1 deletion Netorrent.Tests/P2P/UploadSchedulerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class UploadSchedulerTests
{
//TODO use matrix to create multiple peers
[Test]
public async Task Should_Upload_To_Peer(CancellationToken cancellationToken)
public async Task Should_Upload_Block_To_Peer(CancellationToken cancellationToken)
{
var logger = NullLogger.Instance;
var bitfield = new Bitfield(5, true);
Expand Down Expand Up @@ -42,4 +42,35 @@ public async Task Should_Upload_To_Peer(CancellationToken cancellationToken)
block.Payload.Length.ShouldBe(0);
chokeState.ShouldBe(false);
}

[Test]
public async Task Should_Cancel_Block_To_Peer(CancellationToken cancellationToken)
{
var logger = NullLogger.Instance;
var bitfield = new Bitfield(5, true);
var peerConnection = new FakePeerConnection(bitfield);
await using var uploadScheduler = new UploadScheduler(
new Dictionary<PeerEndpoint, IPeerConnection>()
{
[peerConnection.PeerEndpoint] = peerConnection,
},
new FakePieceStorage(),
bitfield,
new DataStatistics(10),
logger
);
var requestBlock = new RequestBlock(0, 0, 0);
var amChokingTask = peerConnection.AmChoking.FirstAsync(i => i == false, cancellationToken);
var isEmptyTask = peerConnection.SentBlocks.IsEmptyAsync(cancellationToken);
peerConnection.PeerInterested.Value = true;
requestBlock.RequestedFrom.Add(peerConnection);
var uploadTask = uploadScheduler.StartAsync(cancellationToken);
var chokeState = await amChokingTask;
await uploadScheduler.AddRequestAsync(requestBlock, cancellationToken);
uploadScheduler.CancelRequest(requestBlock);
await Task.Delay(1000, cancellationToken);
await peerConnection.DisposeAsync();
(await isEmptyTask).ShouldBe(true);
chokeState.ShouldBe(false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -207,16 +207,16 @@ namespace Netorrent.TorrentFile.FileStructure
}
public class MetaInfo : System.IEquatable<Netorrent.TorrentFile.FileStructure.MetaInfo>
{
public MetaInfo(Netorrent.TorrentFile.FileStructure.Info Info, string Announce, System.Collections.Generic.List<string>? AnnounceList = null, long? CreationDate = default, string? Comment = null, string? CreatedBy = null, string? Encoding = null, string? Title = null, System.Collections.Generic.List<string>? UrlList = null) { }
public MetaInfo(Netorrent.TorrentFile.FileStructure.Info Info, string Announce, System.Collections.Generic.IReadOnlyList<string[]>? AnnounceList = null, long? CreationDate = default, string? Comment = null, string? CreatedBy = null, string? Encoding = null, string? Title = null, System.Collections.Generic.IReadOnlyList<string>? UrlList = null) { }
public string Announce { get; init; }
public System.Collections.Generic.List<string>? AnnounceList { get; init; }
public System.Collections.Generic.IReadOnlyList<string[]>? AnnounceList { get; init; }
public string? Comment { get; init; }
public string? CreatedBy { get; init; }
public long? CreationDate { get; init; }
public string? Encoding { get; init; }
public Netorrent.TorrentFile.FileStructure.Info Info { get; init; }
public string? Title { get; init; }
public System.Collections.Generic.List<string>? UrlList { get; init; }
public System.Collections.Generic.IReadOnlyList<string>? UrlList { get; init; }
public Netorrent.Bencoding.Structs.BDictionary ToBDictionary() { }
}
}
Expand Down Expand Up @@ -265,7 +265,7 @@ namespace Netorrent.TorrentFile
public sealed class TorrentClient : System.IAsyncDisposable
{
public TorrentClient(System.Func<Netorrent.TorrentFile.Options.TorrentClientOptions, Netorrent.TorrentFile.Options.TorrentClientOptions>? action = null) { }
public System.Threading.Tasks.ValueTask<Netorrent.TorrentFile.Torrent> CreateTorrentAsync(string path, string announceUrl, System.Collections.Generic.List<string>? announceUrls = null, System.Collections.Generic.List<string>? webUrls = null, int pieceLength = 262144, System.Threading.CancellationToken cancellationToken = default) { }
public System.Threading.Tasks.ValueTask<Netorrent.TorrentFile.Torrent> CreateTorrentAsync(string path, string announceUrl, System.Collections.Generic.List<string[]>? announceUrls = null, System.Collections.Generic.List<string>? webUrls = null, int pieceLength = 262144, System.Threading.CancellationToken cancellationToken = default) { }
public System.Threading.Tasks.ValueTask DisposeAsync() { }
public Netorrent.TorrentFile.Torrent LoadTorrent(Netorrent.TorrentFile.FileStructure.MetaInfo metaInfo, string outputDirectory, int[]? downloadedPieces = null) { }
public System.Threading.Tasks.ValueTask<Netorrent.TorrentFile.Torrent> LoadTorrentAsync(string path, string outputDirectory, int[]? downloadedPieces = null, System.Threading.CancellationToken cancellationToken = default) { }
Expand Down
24 changes: 18 additions & 6 deletions Netorrent.Tests/Torrents/TorrentFileTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ public async Task Should_Create_Torrent_File_From_Directory(CancellationToken ca
await using var torrent = await torrentClient.CreateTorrentAsync(
"Data/MultifileTest",
"http://test.com",
["http://test.com"],
[
["http://test.com"],
],
["http://test.com"],
cancellationToken: cancellationToken
);
Expand All @@ -90,7 +92,9 @@ public async Task Should_Create_Torrent_File_From_File(CancellationToken cancell
await using var torrent = await torrentClient.CreateTorrentAsync(
"Data/MultifileTest/test.txt",
"http://test.com",
["http://test.com"],
[
["http://test.com"],
],
["http://test.com"],
cancellationToken: cancellationToken
);
Expand All @@ -112,7 +116,9 @@ await torrentClient
.CreateTorrentAsync(
"Data/ASdasd",
"http://test.com",
["http://test.com"],
[
["http://test.com"],
],
["http://test.com"],
cancellationToken: cancellationToken
)
Expand All @@ -128,7 +134,9 @@ await torrentClient
.CreateTorrentAsync(
"Data/MultifileTest/adasdasd.txt",
"http://test.com",
["http://test.com"],
[
["http://test.com"],
],
["http://test.com"],
cancellationToken: cancellationToken
)
Expand All @@ -146,7 +154,9 @@ public async Task Should_Verify_File(string path, CancellationToken cancellation
await using var torrent = await torrentClient.CreateTorrentAsync(
path,
"http://test.com",
["http://test.com"],
[
["http://test.com"],
],
["http://test.com"],
pieceLength: pieceLength,
cancellationToken: cancellationToken
Expand Down Expand Up @@ -177,7 +187,9 @@ CancellationToken cancellationToken
await using var torrent = await torrentClient.CreateTorrentAsync(
path,
"http://test.com",
["http://test.com"],
[
["http://test.com"],
],
["http://test.com"],
pieceLength: pieceLength,
cancellationToken: cancellationToken
Expand Down
Loading