-
Notifications
You must be signed in to change notification settings - Fork 47
Add .NET version of tcp/noise/yamux #298
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
Draft
flcl42
wants to merge
18
commits into
libp2p:master
Choose a base branch
from
flcl42:add-dotnet
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 11 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
93c53c4
Add dotnet tcp/noise/yamux
flcl42 d7ec962
Fix run; clean up .gitignore
flcl42 57a5aac
Lock dependencies
flcl42 bf6f881
Add quic
flcl42 274d899
Merge remote-tracking branch 'origin/master' into add-dotnet
flcl42 6432044
Move
flcl42 bd8638e
Fix subdirs
flcl42 db8684c
Add quic deps to dockerfile
flcl42 b5b3c8f
Update with fixes for dotnet-js-tcp and quic
flcl42 2602a87
Merge branch 'libp2p:master' into add-dotnet
flcl42 46a190f
Remove logging
flcl42 9f7fd11
Merge remote-tracking branch 'origin/master' into add-dotnet
flcl42 45dc066
Merge branch 'add-dotnet' of github.com:flcl42/libp2p-test-plans into…
flcl42 fd26bae
Remove quic; use .NET 8
flcl42 7e05b0b
Merge origin/master into add-dotnet
flcl42 0303809
Load impl from release
flcl42 3a21628
Merge remote-tracking branch 'src/master' into add-dotnet
flcl42 67674e0
Clean up
flcl42 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
bin/ | ||
obj/ | ||
image.json |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build-env | ||
WORKDIR /app | ||
|
||
COPY . ./ | ||
RUN dotnet restore | ||
RUN dotnet publish -c Release -o out | ||
|
||
FROM mcr.microsoft.com/dotnet/runtime:7.0-jammy | ||
WORKDIR /app | ||
|
||
RUN apt update -y && \ | ||
apt install curl -y && \ | ||
curl -sSL -O https://packages.microsoft.com/config/ubuntu/22.04/packages-microsoft-prod.deb && \ | ||
dpkg -i packages-microsoft-prod.deb && \ | ||
apt update -y && \ | ||
apt install libmsquic -y && \ | ||
ln -s /usr/lib/x86_64-linux-gnu/libmsquic.so.2 /bin | ||
|
||
COPY --from=build-env /app/out . | ||
ENTRYPOINT ["dotnet", "TestPlansApp.dll"] | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
image_name := dotnet-v1.0 | ||
|
||
all: image.json | ||
|
||
image.json: Dockerfile Program.cs packages.lock.json TestPlansApp.csproj TestPlansApp.sln | ||
IMAGE_NAME=${image_name} ../../../dockerBuildWrapper.sh . | ||
docker image inspect ${image_name} -f "{{.Id}}" | \ | ||
xargs -I {} echo "{\"imageID\": \"{}\"}" > $@ | ||
|
||
.PHONY: clean all | ||
|
||
clean: | ||
rm -f bin/ obj/ |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For all other implementations, we keep the actual test within the respective libp2p repository so it can be atomically updated with the library code. Unless there is a strong reason to not do that for |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
// SPDX-FileCopyrightText: 2023 Demerzel Solutions Limited | ||
// SPDX-License-Identifier: MIT | ||
|
||
using Microsoft.Extensions.DependencyInjection; | ||
using Nethermind.Libp2p.Core; | ||
using Nethermind.Libp2p.Protocols; | ||
using StackExchange.Redis; | ||
using System.Diagnostics; | ||
using System.Net.NetworkInformation; | ||
using Microsoft.Extensions.Logging; | ||
|
||
try | ||
{ | ||
string transport = Environment.GetEnvironmentVariable("transport")!; | ||
string muxer = Environment.GetEnvironmentVariable("muxer")!; | ||
string security = Environment.GetEnvironmentVariable("security")!; | ||
|
||
bool isDialer = bool.Parse(Environment.GetEnvironmentVariable("is_dialer")!); | ||
string ip = Environment.GetEnvironmentVariable("ip") ?? "0.0.0.0"; | ||
|
||
string redisAddr = Environment.GetEnvironmentVariable("redis_addr") ?? "redis:6379"; | ||
|
||
int testTimeoutSeconds = int.Parse(Environment.GetEnvironmentVariable("test_timeout_seconds") ?? "180"); | ||
|
||
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: builder.MakeAddress()); | ||
string? listenerAddr = null; | ||
while ((listenerAddr = db.ListRightPop("listenerAddr")) is null) | ||
{ | ||
await Task.Delay(20); | ||
} | ||
|
||
Log($"Dialing {listenerAddr}..."); | ||
Stopwatch handshakeStartInstant = Stopwatch.StartNew(); | ||
IRemotePeer remotePeer = await localPeer.DialAsync(listenerAddr); | ||
|
||
Stopwatch pingIstant = Stopwatch.StartNew(); | ||
await remotePeer.DialAsync<PingProtocol>(); | ||
long pingRTT = pingIstant.ElapsedMilliseconds; | ||
|
||
long handshakePlusOneRTT = handshakeStartInstant.ElapsedMilliseconds; | ||
|
||
PrintResult($"{{\"handshakePlusOneRTTMillis\": {handshakePlusOneRTT}, \"pingRTTMilllis\": {pingRTT}}}"); | ||
Log("Done"); | ||
return 0; | ||
} | ||
else | ||
{ | ||
if (ip == "0.0.0.0") | ||
{ | ||
IEnumerable<UnicastIPAddressInformation> addresses = NetworkInterface.GetAllNetworkInterfaces()! | ||
.FirstOrDefault(i => i.Name == "eth0")! | ||
.GetIPProperties() | ||
.UnicastAddresses | ||
.Where(a => a.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork); | ||
|
||
Log("Available addresses detected, picking the first: " + string.Join(",", addresses.Select(a => a.Address))); | ||
ip = addresses.First().Address.ToString()!; | ||
} | ||
Log("Starting to listen..."); | ||
ILocalPeer localPeer = peerFactory.Create(localAddr: builder.MakeAddress(ip)); | ||
IListener listener = await localPeer.ListenAsync(localPeer.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); | ||
await listener.DisconnectAsync(); | ||
return -1; | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
Log(ex.Message); | ||
return -1; | ||
} | ||
|
||
static void Log(string info) => Console.Error.WriteLine(info); | ||
static void PrintResult(string info) => Console.WriteLine(info); | ||
|
||
class TestPlansPeerFactoryBuilder : PeerFactoryBuilderBase<TestPlansPeerFactoryBuilder, PeerFactory> | ||
{ | ||
private readonly string transport; | ||
private readonly string? muxer; | ||
private readonly string? security; | ||
private static IPeerFactoryBuilder? defaultPeerFactoryBuilder; | ||
|
||
public TestPlansPeerFactoryBuilder(string transport, string? muxer, string? security) | ||
: base(new ServiceCollection() | ||
.AddScoped(_ => defaultPeerFactoryBuilder!) | ||
.BuildServiceProvider()) | ||
{ | ||
defaultPeerFactoryBuilder = this; | ||
this.transport = transport; | ||
this.muxer = muxer; | ||
this.security = security; | ||
} | ||
|
||
private static readonly string[] stacklessProtocols = new[] { "quic", "quic-v1", "webtransport" }; | ||
|
||
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 = security switch | ||
{ | ||
"noise" => stack.Over<NoiseProtocol>(), | ||
_ => throw new NotImplementedException(), | ||
}; | ||
stack = stack.Over<MultistreamProtocol>(); | ||
stack = muxer switch | ||
{ | ||
"yamux" => stack.Over<YamuxProtocol>(), | ||
_ => throw new NotImplementedException(), | ||
}; | ||
stack = stack.Over<MultistreamProtocol>(); | ||
} | ||
|
||
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(), | ||
}; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile> | ||
<RestoreLockedMode>true</RestoreLockedMode> | ||
<EnablePreviewFeatures>True</EnablePreviewFeatures> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="NRedisStack" Version="0.8.1" /> | ||
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" /> | ||
<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.3" /> | ||
<PackageReference Include="Nethermind.Libp2p.Protocols.Quic" Version="1.0.0-preview.3" /> | ||
<PackageReference Include="Nethermind.Libp2p.Protocols.IpTcp" Version="1.0.0-preview.3" /> | ||
<PackageReference Include="Nethermind.Libp2p.Protocols.Noise" Version="1.0.0-preview.3" /> | ||
<PackageReference Include="Nethermind.Libp2p.Protocols.Ping" Version="1.0.0-preview.3" /> | ||
<PackageReference Include="Nethermind.Libp2p.Protocols.Yamux" Version="1.0.0-preview.3" /> | ||
<PackageReference Include="Nethermind.Libp2p.Protocols.Identify" Version="1.0.0-preview.3" /> | ||
<PackageReference Include="Nethermind.Libp2p.Protocols.Multistream" Version="1.0.0-preview.3" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
| ||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.7.34018.315 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestPlansApp", "TestPlansApp.csproj", "{4B9D7919-740C-4EF0-8890-AB43E6102952}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{4B9D7919-740C-4EF0-8890-AB43E6102952}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{4B9D7919-740C-4EF0-8890-AB43E6102952}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{4B9D7919-740C-4EF0-8890-AB43E6102952}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{4B9D7919-740C-4EF0-8890-AB43E6102952}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {7BF72338-A0C5-4E70-A0F1-54B1EB8BB378} | ||
EndGlobalSection | ||
EndGlobal |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.