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

Exp/libp2p #3996

Draft
wants to merge 28 commits into
base: 5.3-maintenance
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
7ae48cf
Added dotnet-libp2p as submodule
greymistcube Oct 29, 2024
c36b208
Patched dotnet-libp2p
greymistcube Oct 29, 2024
c92a752
Removed Exception serialization
greymistcube Oct 29, 2024
142d5a7
Build fix
greymistcube Oct 29, 2024
06f348e
Remove BinaryFormatter serialization
greymistcube Oct 29, 2024
e135e36
Added CryptoKeyConverter helper class
greymistcube Oct 30, 2024
567da63
Initial implementation of Libp2pPeer
greymistcube Nov 1, 2024
90ed73b
Refactored BoundPeer
greymistcube Nov 4, 2024
52f6e40
Changed IProtocol to IPeerDiscoveryProtocol to avoid name collision
greymistcube Nov 7, 2024
99c9b97
Changed IMessageCodec to make it more symmetrical
greymistcube Nov 11, 2024
eb4021f
Changed Message encoding to be flat
greymistcube Nov 12, 2024
c181443
Cleanup
greymistcube Nov 12, 2024
d516159
Fixed flaky tests
greymistcube Nov 12, 2024
0c1882d
AsyncDelegate updated
greymistcube Nov 18, 2024
7f549c4
Transport updated
greymistcube Nov 18, 2024
cb5704c
Updated Kademlia
greymistcube Nov 18, 2024
7218fd0
Updated Swarm
greymistcube Nov 18, 2024
d90acf6
Updated Gossip
greymistcube Nov 18, 2024
dafaf03
Updated TestTransport
greymistcube Nov 18, 2024
cdf3cb7
Initial implementation
greymistcube Nov 18, 2024
bab045e
Cleanup
greymistcube Nov 18, 2024
04a6d36
Added tests for Libp2pTransport
greymistcube Nov 21, 2024
3f82877
Fixed transport; more cleanup
greymistcube Nov 21, 2024
0f51c43
Patched dotnet-libp2p
greymistcube Nov 21, 2024
273487c
Validate message
greymistcube Nov 21, 2024
158ac72
Fixed CryptoKeyConverter
greymistcube Nov 22, 2024
bff5f7f
Cleanup
greymistcube Nov 22, 2024
58a4a6b
Added tests
greymistcube Nov 22, 2024
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
Prev Previous commit
Next Next commit
Cleanup
greymistcube committed Nov 25, 2024
commit bff5f7f7f5dcf58d4893692b9321aa68561760b7
8 changes: 6 additions & 2 deletions src/Libplanet.Net/Transports/Libp2pTransport.cs
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@
using Microsoft.Extensions.DependencyInjection;
using Multiformats.Address;
using Nethermind.Libp2p.Core;
using Nethermind.Libp2p.Stack;
using Serilog;

namespace Libplanet.Net.Transports
@@ -91,7 +92,6 @@ public Libp2pTransport(
_appProtocolVersionOptions.DifferentAppProtocolVersionEncountered;

public static async Task<Libp2pTransport> Create(
IServiceProvider serviceProvider,
PrivateKey privateKey,
AppProtocolVersionOptions appProtocolVersionOptions,
HostOptions hostOptions,
@@ -102,6 +102,10 @@ public static async Task<Libp2pTransport> Create(
appProtocolVersionOptions,
hostOptions,
messageTimestampBuffer);
var serviceProvider = new ServiceCollection()
.AddLibp2p(builder => builder
.AddAppLayerProtocol<ReqRepProtocol>(new ReqRepProtocol(transport)))
.BuildServiceProvider();
await transport.Initialize(serviceProvider);
return transport;
}
@@ -288,7 +292,7 @@ public void Dispose()
_disposed = true;
}

public async Task Initialize(
private async Task Initialize(
IServiceProvider serviceProvider,
CancellationToken cancellationToken = default)
{
31 changes: 10 additions & 21 deletions test/Libplanet.Net.Tests/Transports/Libp2pTransportTest.cs
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ namespace Libplanet.Net.Tests.Transports
public class Libp2pTransportTest : IDisposable
{
private bool _disposed;
private Serilog.ILogger _logger;
private ILogger _logger;

public Libp2pTransportTest(ITestOutputHelper testOutputHelper)
{
@@ -49,14 +49,17 @@ public async Task Initialize()
HostOptions hostOptions = new HostOptions("127.0.0.1", new IceServer[] { }, freePort);
Libp2pTransport transport = new Libp2pTransport(
privateKey,
default,
new AppProtocolVersionOptions(),
hostOptions);
Assert.Throws<NullReferenceException>(() => transport.AsPeer);
Assert.Throws<NullReferenceException>(() => transport.LocalPeer);
Assert.Throws<NullReferenceException>(() => transport.Listener);
Assert.Throws<NullReferenceException>(() => transport.ListenerAddress);

await transport.Initialize(GetServiceProvider(transport));
transport = await Libp2pTransport.Create(
privateKey,
new AppProtocolVersionOptions(),
hostOptions);
BoundPeer expected = new BoundPeer(
CryptoKeyConverter.ToLibplanetPublicKey(
CryptoKeyConverter.ToLibp2pIdentity(privateKey).PublicKey),
@@ -121,19 +124,12 @@ public async Task DialToTransports()
.ToList();
List<Libp2pTransport> transports = Enumerable
.Range(0, 2)
.Select(i => new Libp2pTransport(
.Select(async i => await Libp2pTransport.Create(
privateKeys[i],
new AppProtocolVersionOptions(),
hosts[i]))
.Select(task => task.Result)
.ToList();
List<IServiceProvider> serviceProviders = transports
.Select(transport => GetServiceProvider(transport))
.ToList();

for (int i = 0; i < count; i++)
{
await transports[i].Initialize(serviceProviders[i]);
}

IRemotePeer remote0 = await transports[0].LocalPeer.DialAsync(
transports[1].ListenerAddress, default);
@@ -155,19 +151,12 @@ public async Task RequestReply()
List<int> freePorts = TestUtils.GetFreePorts(2);
List<Libp2pTransport> transports = Enumerable
.Range(0, count)
.Select(i => new Libp2pTransport(
.Select(async i => await Libp2pTransport.Create(
privateKeys[i],
new AppProtocolVersionOptions(),
new HostOptions("127.0.0.1", new IceServer[] { }, freePorts[i])))
.Select(task => task.Result)
.ToList();
List<IServiceProvider> serviceProviders = transports
.Select(transport => GetServiceProvider(transport))
.ToList();

for (int i = 0; i < count; i++)
{
await transports[i].Initialize(serviceProviders[i]);
}

transports[1].ProcessMessageHandler.Register(async (message, channel) =>
{