Skip to content

Commit

Permalink
Add quic
Browse files Browse the repository at this point in the history
  • Loading branch information
flcl42 committed Oct 6, 2023
1 parent 57a5aac commit 5b6e16e
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 41 deletions.
20 changes: 15 additions & 5 deletions multidim-interop/impl/dotnet/v1.0/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,16 @@

int testTimeoutSeconds = int.Parse(Environment.GetEnvironmentVariable("test_timeout_seconds") ?? "180");

IPeerFactory peerFactory = new TestPlansPeerFactoryBuilder(transport, muxer, security).Build();
TestPlansPeerFactoryBuilder builder = new TestPlansPeerFactoryBuilder(transport, muxer, security);
IPeerFactory peerFactory = builder.Build();

Log($"Connecting to redis at {redisAddr}...");
ConnectionMultiplexer redis = ConnectionMultiplexer.Connect(redisAddr);
IDatabase db = redis.GetDatabase();

if (isDialer)
{
ILocalPeer localPeer = peerFactory.Create(localAddr: $"/ip4/0.0.0.0/tcp/0");
ILocalPeer localPeer = peerFactory.Create(localAddr: builder.MakeAddress());
string? listenerAddr = null;
while ((listenerAddr = db.ListRightPop("listenerAddr")) is null)
{
Expand Down Expand Up @@ -65,9 +66,9 @@
ip = addresses.First().Address.ToString()!;
}
Log("Starting to listen...");
ILocalPeer localPeer = peerFactory.Create(localAddr: $"/ip4/{ip}/tcp/0");
ILocalPeer localPeer = peerFactory.Create(localAddr: builder.MakeAddress(ip));
IListener listener = await localPeer.ListenAsync(localPeer.Address);
listener.OnConnection += async (peer) => Log($"Connected {peer.Address}");
listener.OnConnection += (peer) => { Log($"Connected {peer.Address}"); return Task.CompletedTask; };
Log($"Listening on {listener.Address}");
db.ListRightPush(new RedisKey("listenerAddr"), new RedisValue(localPeer.Address.ToString()));
await Task.Delay(testTimeoutSeconds * 1000);
Expand Down Expand Up @@ -116,12 +117,14 @@ protected override ProtocolStack BuildStack()
ProtocolStack stack = transport switch
{
"tcp" => Over<IpTcpProtocol>(),
"quic-v1" => Over<QuicProtocol>(),
_ => throw new NotImplementedException(),
};

stack = stack.Over<MultistreamProtocol>();

if (!stacklessProtocols.Contains(transport))
{
stack = stack.Over<MultistreamProtocol>();
stack = security switch
{
"noise" => stack.Over<NoiseProtocol>(),
Expand All @@ -139,4 +142,11 @@ protected override ProtocolStack BuildStack()
return stack.AddAppLayerProtocol<IdentifyProtocol>()
.AddAppLayerProtocol<PingProtocol>();
}

public string MakeAddress(string ip = "0.0.0.0", string port = "0") => transport switch
{
"tcp" => $"/ip4/{ip}/tcp/{port}",
"quic-v1" => $"/ip4/{ip}/udp/{port}/quic-v1",
_ => throw new NotImplementedException(),
};
}
16 changes: 9 additions & 7 deletions multidim-interop/impl/dotnet/v1.0/TestPlansApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<Nullable>enable</Nullable>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
<RestoreLockedMode>true</RestoreLockedMode>
<EnablePreviewFeatures>True</EnablePreviewFeatures>
</PropertyGroup>

<ItemGroup>
Expand All @@ -15,13 +16,14 @@
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.1" />

<PackageReference Include="Nethermind.Libp2p.Core" Version="1.0.0-preview.27" />
<PackageReference Include="Nethermind.Libp2p.Protocols.IpTcp" Version="1.0.0-preview.27" />
<PackageReference Include="Nethermind.Libp2p.Protocols.Noise" Version="1.0.0-preview.27" />
<PackageReference Include="Nethermind.Libp2p.Protocols.Ping" Version="1.0.0-preview.27" />
<PackageReference Include="Nethermind.Libp2p.Protocols.Yamux" Version="1.0.0-preview.27" />
<PackageReference Include="Nethermind.Libp2p.Protocols.Identify" Version="1.0.0-preview.27" />
<PackageReference Include="Nethermind.Libp2p.Protocols.Multistream" Version="1.0.0-preview.27" />
<PackageReference Include="Nethermind.Libp2p.Core" Version="1.0.0-preview.29" />
<PackageReference Include="Nethermind.Libp2p.Protocols.Quic" Version="1.0.0-preview.29" />
<PackageReference Include="Nethermind.Libp2p.Protocols.IpTcp" Version="1.0.0-preview.29" />
<PackageReference Include="Nethermind.Libp2p.Protocols.Noise" Version="1.0.0-preview.29" />
<PackageReference Include="Nethermind.Libp2p.Protocols.Ping" Version="1.0.0-preview.29" />
<PackageReference Include="Nethermind.Libp2p.Protocols.Yamux" Version="1.0.0-preview.29" />
<PackageReference Include="Nethermind.Libp2p.Protocols.Identify" Version="1.0.0-preview.29" />
<PackageReference Include="Nethermind.Libp2p.Protocols.Multistream" Version="1.0.0-preview.29" />
</ItemGroup>

</Project>
71 changes: 42 additions & 29 deletions multidim-interop/impl/dotnet/v1.0/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,79 +36,92 @@
},
"Nethermind.Libp2p.Core": {
"type": "Direct",
"requested": "[1.0.0-preview.27, )",
"resolved": "1.0.0-preview.27",
"contentHash": "QJ54Eokt+dFz9vVejXQiNeWX+Etw7z+zWLux5pgQoaQbwrtAUYfoqni8oGBUl6I94yCVQnqRv8mqg7wYODSiQg==",
"requested": "[1.0.0-preview.29, )",
"resolved": "1.0.0-preview.29",
"contentHash": "HMllE4gIxjYL/hpkC+bHPa2KFsrQFkFRYeO2mdIkaDbWY6UAs8nZ8mVe2gQ30QVYPBUPDxPoQZ7MtwpxcPnQEw==",
"dependencies": {
"BouncyCastle.Cryptography": "2.2.1",
"Google.Protobuf": "3.24.1",
"Microsoft.Extensions.DependencyInjection": "7.0.0",
"Microsoft.Extensions.DependencyInjection.Abstractions": "7.0.0",
"Microsoft.Extensions.Logging.Abstractions": "7.0.1",
"Multiformats.Hash": "1.5.0",
"Multiformats.Hash": "1.5.0-preview.29",
"SimpleBase": "4.0.0"
}
},
"Nethermind.Libp2p.Protocols.Identify": {
"type": "Direct",
"requested": "[1.0.0-preview.27, )",
"resolved": "1.0.0-preview.27",
"contentHash": "sZs4Wg7GPZQoeGs3WiwEWqdjtAv9+drVTrLm9/rs9BVARXuYdkuAVVZhz/i0CsMzpSy3oMQtz6BiQ784VqVZPg==",
"requested": "[1.0.0-preview.29, )",
"resolved": "1.0.0-preview.29",
"contentHash": "1LzFsm6xxq5nviLnXcjVUUe3AJrmwjykZoRUYSemGW229U+i/2lHHjPtJwY0/QNjKRxzcNJyNDmAfCQoZ5OM1A==",
"dependencies": {
"Google.Protobuf": "3.24.1",
"Microsoft.Extensions.Logging.Abstractions": "7.0.1",
"Nethermind.Libp2p.Core": "1.0.0-preview.27",
"Nethermind.Libp2p.Protocols.IpTcp": "1.0.0-preview.27"
"Nethermind.Libp2p.Core": "1.0.0-preview.29",
"Nethermind.Libp2p.Protocols.IpTcp": "1.0.0-preview.29"
}
},
"Nethermind.Libp2p.Protocols.IpTcp": {
"type": "Direct",
"requested": "[1.0.0-preview.27, )",
"resolved": "1.0.0-preview.27",
"contentHash": "w0JHXa4mN+O5bfiDeSXJb/NPdzNs7mLMgqZLWOrqt3rLkVCVIje0jWscNL1IN24QGr+0BWYAgPt7034NZBM7Hw==",
"requested": "[1.0.0-preview.29, )",
"resolved": "1.0.0-preview.29",
"contentHash": "cHIvnkbjr1fBxpONz0+LXHHPmqfGmdFSYfLrf1ZDzkcnE3IWhYa+NW2VbWpowC7Ys9hGT2h8fiidsopiXlRAzw==",
"dependencies": {
"Microsoft.Extensions.Logging.Abstractions": "7.0.1",
"Nethermind.Libp2p.Core": "1.0.0-preview.27"
"Nethermind.Libp2p.Core": "1.0.0-preview.29"
}
},
"Nethermind.Libp2p.Protocols.Multistream": {
"type": "Direct",
"requested": "[1.0.0-preview.27, )",
"resolved": "1.0.0-preview.27",
"contentHash": "ozEWB4ckQVb1W8R07AaDsge4yb1tp1k50jIoZyvVvE9EhYstchbP4HkjboTarJ2jae9iC2Xtc5Wd0lucI8f3OA==",
"requested": "[1.0.0-preview.29, )",
"resolved": "1.0.0-preview.29",
"contentHash": "155kz2rHX3JG1bGlWFwRxYBZ8Zq6HIoCpDPvuE7WMzqZIKINe8+iP6Ogqzjb2oHEQHH1z5k+PHfoqWkhdrNSAw==",
"dependencies": {
"Nethermind.Libp2p.Core": "1.0.0-preview.27"
"Nethermind.Libp2p.Core": "1.0.0-preview.29"
}
},
"Nethermind.Libp2p.Protocols.Noise": {
"type": "Direct",
"requested": "[1.0.0-preview.27, )",
"resolved": "1.0.0-preview.27",
"contentHash": "zsDrlevkXpdzJyDitR5WZOLovSPPgvMDmwVpqKBgOqxngy11kjXyjAIz6k9z8sbjcw9wRcgBGMtrpg4+T3h9EA==",
"requested": "[1.0.0-preview.29, )",
"resolved": "1.0.0-preview.29",
"contentHash": "7kg23PxfAcJzgOwIXwiG1GlCyP1i820VJTlSQ3l9u8Lplg3bM+UN1x8u6lmBQfFwUIkdbjv4WH6y9hKOFlMq3A==",
"dependencies": {
"BouncyCastle.Cryptography": "2.2.1",
"Google.Protobuf": "3.24.1",
"Nethermind.Libp2p.Core": "1.0.0-preview.27",
"Multiformats.Hash": "1.5.0-preview.29",
"Nethermind.Libp2p.Core": "1.0.0-preview.29",
"Noise.NET": "1.0.0"
}
},
"Nethermind.Libp2p.Protocols.Ping": {
"type": "Direct",
"requested": "[1.0.0-preview.27, )",
"resolved": "1.0.0-preview.27",
"contentHash": "lutGn++FJ3VdcAxD7VzLbrtORcVLi9+UKaokXzDI8nSOY9NEJyw8H4/I7QH9ZYhK4tscPOqeF7vDU7KSkboDEw==",
"requested": "[1.0.0-preview.29, )",
"resolved": "1.0.0-preview.29",
"contentHash": "gA3iscXDptJnQayGg9iSWnkkRnQ1UR15sgrxEDIKw7hQgV9tKG5vM7uxWJ/8tgbKOJSmf4f2SDqmEqj/u/1H2Q==",
"dependencies": {
"Nethermind.Libp2p.Core": "1.0.0-preview.27"
"Nethermind.Libp2p.Core": "1.0.0-preview.29"
}
},
"Nethermind.Libp2p.Protocols.Quic": {
"type": "Direct",
"requested": "[1.0.0-preview.29, )",
"resolved": "1.0.0-preview.29",
"contentHash": "eIAjkWo3FAnljyWX14WefvHDBH8kXGWDUNU1+m2pAU01352bDvx0mEZMxZvZkL9xtqMbeFyRFmewn38VMFNwYw==",
"dependencies": {
"BouncyCastle.Cryptography": "2.2.1",
"Microsoft.Extensions.Logging.Abstractions": "7.0.1",
"Multiformats.Hash": "1.5.0-preview.29",
"Nethermind.Libp2p.Core": "1.0.0-preview.29"
}
},
"Nethermind.Libp2p.Protocols.Yamux": {
"type": "Direct",
"requested": "[1.0.0-preview.27, )",
"resolved": "1.0.0-preview.27",
"contentHash": "ODwlrNc0Yz665wUSzXgCgNxXJ1y/jiCSCAmF1b0AtRTFpwbTClplGEZpDKcXQcnM+tQDzeHMX5VDrmNvELLToQ==",
"requested": "[1.0.0-preview.29, )",
"resolved": "1.0.0-preview.29",
"contentHash": "YesEdnovydPyPesPBdsRT+Uxcb28k2ho9nKlS28d7S8MC04LUiNZRnFxqQXPUUEPgB/qpILwDzDE0gqiTit+Rg==",
"dependencies": {
"Microsoft.Extensions.Logging.Abstractions": "7.0.1",
"Nethermind.Libp2p.Core": "1.0.0-preview.27"
"Nethermind.Libp2p.Core": "1.0.0-preview.29"
}
},
"NRedisStack": {
Expand Down

0 comments on commit 5b6e16e

Please sign in to comment.