Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add session #92

Merged
merged 27 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 5 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ jobs:
TEST_OPTS: -c ${{ env.BUILD_CONFIG }} --no-restore
run: |
dotnet test Libp2p.Core.Tests ${{ env.PACK_OPTS }}
#dotnet test Libp2p.Protocols.Multistream.Tests ${{ env.PACK_OPTS }}
dotnet test Libp2p.Protocols.Multistream.Tests ${{ env.PACK_OPTS }}
dotnet test Libp2p.Protocols.Noise.Tests ${{ env.PACK_OPTS }}
dotnet test Libp2p.Protocols.Pubsub.Tests ${{ env.PACK_OPTS }}
dotnet test Libp2p.Protocols.Quic.Tests ${{ env.PACK_OPTS }}
dotnet test Libp2p.Protocols.Yamux.Tests ${{ env.PACK_OPTS }}
dotnet test Libp2p.E2eTests ${{ env.PACK_OPTS }}
dotnet test Libp2p.Protocols.Pubsub.E2eTests ${{ env.PACK_OPTS }}
dotnet test Libp2p.Protocols.PubsubPeerDiscovery.E2eTests ${{ env.PACK_OPTS }}
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,26 @@ The target is to provide a performant well-tested implementation of a wide range
| Protocol | Version | Status |
|--------------------|--------------------|-----------------|
| TCP | tcp | ✅ |
| QUIC | quic-v1 | |
| QUIC | quic-v1 | 🚧 |
| multistream-select | /multistream/1.0.0 | ✅ |
| plaintext | /plaintext/2.0.0 | ✅ |
| noise | /noise | ✅ |
| tls | /tls/1.0.0 | 🚧 |
| WebTransport | | ⬜ help wanted |
| yamux | /yamux/1.0.0 | ✅ |
| Circuit Relay | /libp2p/circuit/relay/0.2.0/* | ⬜ help wanted |
| Circuit Relay | /libp2p/circuit/relay/0.2.0/* | 🚧 |
| hole punching | | ⬜ help wanted |
| **Application layer**
| Identify | /ipfs/id/1.0.0 | ✅ |
| ping | /ipfs/ping/1.0.0 | ✅ |
| pubsub | /floodsub/1.0.0 | ✅ |
| | /meshsub/1.0.0 | ✅ |
| | /meshsub/1.1.0 | 🚧 |
| | /meshsub/1.2.0 | |
| | /meshsub/1.2.0 | 🚧 |
| **Discovery**
| mDns | basic | ✅ |
| | DNS-SD | 🚧 |
| [discv5](https://github.com/Pier-Two/Lantern.Discv5) | 5.1 | 🚧 help wanted |
| [discv5](https://github.com/Pier-Two/Lantern.Discv5) (wrapper) | 5.1 | 🚧 help wanted |

⬜ - not yet implemented<br>
🚧 - work in progress<br>
Expand Down
4 changes: 2 additions & 2 deletions src/libp2p/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<PackageVersion Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
<PackageVersion Include="Nethermind.Multiformats.Address" Version="1.1.5" />
<PackageVersion Include="Nethermind.Multiformats.Address" Version="1.1.8" />
<PackageVersion Include="NLog.Extensions.Logging" Version="5.3.12" />
<PackageVersion Include="Noise.NET" Version="1.0.0" />
<PackageVersion Include="NSubstitute" Version="5.1.0" />
Expand All @@ -34,4 +34,4 @@
<PackageVersion Include="SimpleBase" Version="4.0.0" />
<PackageVersion Include="System.Runtime.Caching" Version="7.0.0" />
</ItemGroup>
</Project>
</Project>
52 changes: 52 additions & 0 deletions src/libp2p/Libp2p.Core.Tests/TaskHelperTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited
// SPDX-License-Identifier: MIT

using Nethermind.Libp2p.Core.Extensions;

namespace Nethermind.Libp2p.Core.Tests;
internal class TaskHelperTests
{

[Test]
public async Task Test_AllExceptions_RaiseAggregateException()
{
TaskCompletionSource tcs1 = new();
TaskCompletionSource tcs2 = new();
TaskCompletionSource<bool> tcs3 = new();

Task<Task> t = TaskHelper.FirstSuccess(tcs1.Task, tcs2.Task, tcs3.Task);

tcs1.SetException(new Exception());
tcs2.SetException(new Exception());
tcs3.SetException(new Exception());

await t.ContinueWith((t) =>
{
Assert.Multiple(() =>
{
Assert.That(t.IsFaulted, Is.True);
Assert.That(t.Exception?.InnerException, Is.TypeOf<AggregateException>());
Assert.That((t.Exception?.InnerException as AggregateException)?.InnerExceptions, Has.Count.EqualTo(3));
});
});
}

[Test]
public async Task Test_SingleSuccess_ReturnsCompletedTask()
{
TaskCompletionSource tcs1 = new();
TaskCompletionSource tcs2 = new();
TaskCompletionSource<bool> tcs3 = new();

Task<Task> t = TaskHelper.FirstSuccess(tcs1.Task, tcs2.Task, tcs3.Task);

tcs1.SetException(new Exception());
tcs2.SetException(new Exception());
_ = Task.Delay(100).ContinueWith(t => tcs3.SetResult(true));

Task result = await t;

Assert.That(result, Is.EqualTo(tcs3.Task));
Assert.That((result as Task<bool>)!.Result, Is.EqualTo(true));
}
}
3 changes: 1 addition & 2 deletions src/libp2p/Libp2p.Core.TestsBase/E2e/ChannelBus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// SPDX-License-Identifier: MIT

using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using System.Threading.Channels;

namespace Nethermind.Libp2p.Core.TestsBase.E2e;
Expand Down Expand Up @@ -30,7 +29,7 @@ public async IAsyncEnumerable<IChannel> GetIncomingRequests(PeerId serverId)

logger?.LogDebug($"Listen {serverId}");

await foreach (var item in col.Reader.ReadAllAsync())
await foreach (ClientChannel item in col.Reader.ReadAllAsync())
{
logger?.LogDebug($"New request from {item.Client} to {serverId}");
yield return item.Channel;
Expand Down
40 changes: 36 additions & 4 deletions src/libp2p/Libp2p.Core.TestsBase/E2e/TestBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,45 @@
// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited
// SPDX-License-Identifier: MIT

using Microsoft.Extensions.Logging;
using Nethermind.Libp2p.Core.Discovery;
using Nethermind.Libp2p.Protocols;
using System.Collections.Concurrent;

namespace Nethermind.Libp2p.Core.TestsBase.E2e;

public class TestBuilder(ChannelBus? commmonBus = null, IServiceProvider? serviceProvider = null) : PeerFactoryBuilderBase<TestBuilder, PeerFactory>(serviceProvider)
public class TestBuilder(IServiceProvider? serviceProvider = null) : PeerFactoryBuilderBase<TestBuilder, TestPeerFactory>(serviceProvider)
{
protected override ProtocolRef[] BuildStack(IEnumerable<ProtocolRef> additionalProtocols)
{
ProtocolRef root = Get<TestMuxerProtocol>();

Connect([root],
[
Get<TestPingProtocol>(),
Get<IdentifyProtocol>(),
.. additionalProtocols
]);

return [root];
}
}

public class TestPeerFactory(IProtocolStackSettings protocolStackSettings, PeerStore peerStore, ILoggerFactory? loggerFactory = null) : PeerFactory(protocolStackSettings, peerStore)

Check warning on line 28 in src/libp2p/Libp2p.Core.TestsBase/E2e/TestBuilder.cs

View workflow job for this annotation

GitHub Actions / Test

Parameter 'PeerStore peerStore' is captured into the state of the enclosing type and its value is also passed to the base constructor. The value might be captured by the base class as well.
{
ConcurrentDictionary<PeerId, ILocalPeer> peers = new();

public override ILocalPeer Create(Identity? identity = default)
{
ArgumentNullException.ThrowIfNull(identity);
return peers.GetOrAdd(identity.PeerId, (p) => new TestLocalPeer(identity, protocolStackSettings, peerStore, loggerFactory));
}
}

internal class TestLocalPeer(Identity id, IProtocolStackSettings protocolStackSettings, PeerStore peerStore, ILoggerFactory? loggerFactory = null) : LocalPeer(id, peerStore, protocolStackSettings, loggerFactory)
{
protected override ProtocolStack BuildStack()
protected override async Task ConnectedTo(ISession session, bool isDialer)
{
return Over(new TestMuxerProtocol(commmonBus ?? new ChannelBus(), new TestContextLoggerFactory()))
.AddAppLayerProtocol<TestPingProtocol>();
await session.DialAsync<IdentifyProtocol>();
}
}
22 changes: 0 additions & 22 deletions src/libp2p/Libp2p.Core.TestsBase/E2e/TestLocalPeer.cs

This file was deleted.

Loading
Loading