From 10c3a15fd448f39b09de77630e118c71cc51abf9 Mon Sep 17 00:00:00 2001 From: Alexey Date: Wed, 27 Sep 2023 16:56:46 +0300 Subject: [PATCH] Add multihash project; update deps; clean up (#44) --- .github/workflows/format.yml | 6 ++++-- .github/workflows/pubish.yml | 8 +++++--- .github/workflows/test.yml | 8 +++++--- .gitmodules | 3 +++ README.md | 11 +++++++++++ src/cs-multihash | 1 + src/libp2p/Directory.Packages.props | 1 - src/libp2p/Libp2p.Core.Benchmarks/Program.cs | 1 - src/libp2p/Libp2p.Core/IChannelFactory.cs | 1 - src/libp2p/Libp2p.Core/Identity.cs | 12 ++++++------ src/libp2p/Libp2p.Core/IsExternalInit.cs | 1 - src/libp2p/Libp2p.Core/Libp2p.Core.csproj | 4 ++-- src/libp2p/Libp2p.Core/PeerFactoryBuilderBase.cs | 4 +--- .../Libp2p.Generators.Enums/EnumsGenerator.cs | 1 - .../Libp2p.Generators.Enums/IsExternalInit.cs | 1 - src/libp2p/Libp2p.Protocols.IpTcp/IpTcpProtocol.cs | 6 +++--- .../Libp2p.Protocols.MDns/MDnsDiscoveryProtocol.cs | 2 +- .../Libp2p.Protocols.Noise.csproj | 3 ++- src/libp2p/Libp2p.Protocols.Noise/NoiseProtocol.cs | 6 ++---- .../GossipsubProtocolTests.cs | 1 - .../Libp2p.Protocols.Pubsub.csproj | 3 ++- .../Libp2p.Protocols.Pubsub/PubsubProtocol.cs | 1 - .../Libp2p.Protocols.Pubsub/RpcExtensions.cs | 3 +-- src/libp2p/Libp2p.Protocols.Pubsub/Usings.cs | 1 - .../Libp2p.Protocols.Quic.csproj | 1 + src/libp2p/Libp2p.sln | 6 ++++++ src/samples/chat/Chat.csproj | 2 +- src/samples/perf-benchmarks/PerfBenchmarks.csproj | 2 +- src/samples/perf-benchmarks/PerfProtocol.cs | 2 -- src/samples/pubsub-chat/Program.cs | 14 ++++++-------- 30 files changed, 64 insertions(+), 52 deletions(-) create mode 160000 src/cs-multihash diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml index 9691c19d..5fac162e 100644 --- a/.github/workflows/format.yml +++ b/.github/workflows/format.yml @@ -10,10 +10,12 @@ jobs: env: WORKING_DIR: src/libp2p steps: - + - name: Check out repository uses: actions/checkout@v3 - + with: + submodules: true + - name: Set up .NET uses: actions/setup-dotnet@v3 with: diff --git a/.github/workflows/pubish.yml b/.github/workflows/pubish.yml index 80433f0d..24228f53 100644 --- a/.github/workflows/pubish.yml +++ b/.github/workflows/pubish.yml @@ -20,10 +20,12 @@ jobs: BUILD_CONFIG: Release WORKING_DIR: src/libp2p steps: - + - name: Check out repository uses: actions/checkout@v3 - + with: + submodules: true + - name: Set up .NET uses: actions/setup-dotnet@v3 with: @@ -40,7 +42,7 @@ jobs: -p:ContinuousIntegrationBuild=true \ -p:Commit=${{ github.sha }} \ -p:VersionSuffix=preview.${{ github.run_number }} - + - name: Test working-directory: ${{ env.WORKING_DIR }} run: | diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8b0a1e61..7effae83 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,10 +11,12 @@ jobs: BUILD_CONFIG: release WORKING_DIR: src/libp2p steps: - + - name: Check out repository uses: actions/checkout@v3 - + with: + submodules: true + - name: Set up .NET uses: actions/setup-dotnet@v3 with: @@ -27,7 +29,7 @@ jobs: - name: Build working-directory: ${{ env.WORKING_DIR }} run: dotnet build -c ${{ env.BUILD_CONFIG }} --no-restore -p:ContinuousIntegrationBuild=true -p:Commit=${{ github.sha }} - + - name: Test working-directory: ${{ env.WORKING_DIR }} run: | diff --git a/.gitmodules b/.gitmodules index 63036d07..db669783 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "src/multicodec"] path = src/multicodec url = https://github.com/multiformats/multicodec.git +[submodule "src/cs-multihash"] + path = src/cs-multihash + url = https://github.com/flcl42/cs-multihash.git diff --git a/README.md b/README.md index bcc73331..6060a6c3 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,17 @@ As a stack implementer, you may be interested in [more advanced tutorials](./doc **Contributions are welcome**, kindly check the [issues](https://github.com/NethermindEth/dotnet-libp2p/issues) tab, everything there if not assigned to a person can be taken into work. More details in [CONTRIBUTING.md](./CONTRIBUTING.md). +## Building the solution + +The solution depends on external repositories. + +```sh +git clone https://github.com/NethermindEth/dotnet-libp2p.git --recursive +cd ./src/libp2p/ +dotnet build +dotnet test +``` + ## Roadmap From the beginning, the target is to provide a performant well-tested implementation that works on multiple platforms, with high throughput and low memory profile. diff --git a/src/cs-multihash b/src/cs-multihash new file mode 160000 index 00000000..6dad4522 --- /dev/null +++ b/src/cs-multihash @@ -0,0 +1 @@ +Subproject commit 6dad45222d609f0e6a8ea73d15d2f917c86e575f diff --git a/src/libp2p/Directory.Packages.props b/src/libp2p/Directory.Packages.props index 917469e6..932aec45 100644 --- a/src/libp2p/Directory.Packages.props +++ b/src/libp2p/Directory.Packages.props @@ -21,7 +21,6 @@ - diff --git a/src/libp2p/Libp2p.Core.Benchmarks/Program.cs b/src/libp2p/Libp2p.Core.Benchmarks/Program.cs index a9025eb6..766e08ae 100644 --- a/src/libp2p/Libp2p.Core.Benchmarks/Program.cs +++ b/src/libp2p/Libp2p.Core.Benchmarks/Program.cs @@ -7,7 +7,6 @@ using System.Buffers; using System.Diagnostics; - Channel chan = new(); IChannel revChan = ((Channel)chan).Reverse; diff --git a/src/libp2p/Libp2p.Core/IChannelFactory.cs b/src/libp2p/Libp2p.Core/IChannelFactory.cs index 56105d02..22a36808 100644 --- a/src/libp2p/Libp2p.Core/IChannelFactory.cs +++ b/src/libp2p/Libp2p.Core/IChannelFactory.cs @@ -14,7 +14,6 @@ public interface IChannelFactory IChannel SubListenAndBind(IChannel parentChannel, IPeerContext context, IChannelRequest? request = null); - IChannel SubDial(IPeerContext context, IProtocol protocol) { return SubDial(context, new ChannelRequest { SubProtocol = protocol }); diff --git a/src/libp2p/Libp2p.Core/Identity.cs b/src/libp2p/Libp2p.Core/Identity.cs index 248a7f0e..8bc07e1e 100644 --- a/src/libp2p/Libp2p.Core/Identity.cs +++ b/src/libp2p/Libp2p.Core/Identity.cs @@ -1,15 +1,15 @@ // SPDX-FileCopyrightText: 2023 Demerzel Solutions Limited // SPDX-License-Identifier: MIT -extern alias BouncyCastleCryptography; -using BouncyCastleCryptography::Org.BouncyCastle.Asn1.X9; -using BouncyCastleCryptography::Org.BouncyCastle.Math; +using Org.BouncyCastle.Asn1.X9; +using Org.BouncyCastle.Math; using Google.Protobuf; using Nethermind.Libp2p.Core.Dto; -using BouncyCastleCryptography::Org.BouncyCastle.Math.EC.Rfc8032; -using BouncyCastleCryptography::Org.BouncyCastle.Security; +using Org.BouncyCastle.Math.EC.Rfc8032; +using Org.BouncyCastle.Security; using System.Security.Cryptography; using System.Buffers; +using Org.BouncyCastle.Crypto.Parameters; namespace Nethermind.Libp2p.Core; @@ -73,7 +73,7 @@ private static PublicKey GetPublicKey(PrivateKey privateKey) case KeyType.Secp256K1: { X9ECParameters curve = ECNamedCurveTable.GetByName("secp256k1"); - BouncyCastleCryptography::Org.BouncyCastle.Math.EC.ECPoint pointQ + Org.BouncyCastle.Math.EC.ECPoint pointQ = curve.G.Multiply(new BigInteger(1, privateKey.Data.Span)); publicKeyData = ByteString.CopyFrom(pointQ.GetEncoded(true)); } diff --git a/src/libp2p/Libp2p.Core/IsExternalInit.cs b/src/libp2p/Libp2p.Core/IsExternalInit.cs index 7845e18f..eaf7a077 100644 --- a/src/libp2p/Libp2p.Core/IsExternalInit.cs +++ b/src/libp2p/Libp2p.Core/IsExternalInit.cs @@ -1,7 +1,6 @@ // SPDX-FileCopyrightText: 2023 Demerzel Solutions Limited // SPDX-License-Identifier: MIT - namespace System.Runtime.CompilerServices; internal static class IsExternalInit diff --git a/src/libp2p/Libp2p.Core/Libp2p.Core.csproj b/src/libp2p/Libp2p.Core/Libp2p.Core.csproj index c1eeb5f3..d6f32ebe 100644 --- a/src/libp2p/Libp2p.Core/Libp2p.Core.csproj +++ b/src/libp2p/Libp2p.Core/Libp2p.Core.csproj @@ -19,12 +19,13 @@ + - + @@ -33,7 +34,6 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - diff --git a/src/libp2p/Libp2p.Core/PeerFactoryBuilderBase.cs b/src/libp2p/Libp2p.Core/PeerFactoryBuilderBase.cs index 8f69b0a9..bf73982d 100644 --- a/src/libp2p/Libp2p.Core/PeerFactoryBuilderBase.cs +++ b/src/libp2p/Libp2p.Core/PeerFactoryBuilderBase.cs @@ -1,4 +1,4 @@ -extern alias BouncyCastleCryptography; + // SPDX-FileCopyrightText: 2023 Demerzel Solutions Limited // SPDX-License-Identifier: MIT @@ -113,7 +113,6 @@ public ProtocolStack Over(ProtocolStack stack) return stack; } - public ProtocolStack Or(ProtocolStack stack) { if (Parent is null) @@ -130,7 +129,6 @@ public override string ToString() } } - protected abstract ProtocolStack BuildStack(); public IPeerFactory Build() diff --git a/src/libp2p/Libp2p.Generators.Enums/EnumsGenerator.cs b/src/libp2p/Libp2p.Generators.Enums/EnumsGenerator.cs index 4c4971f8..8f12f253 100644 --- a/src/libp2p/Libp2p.Generators.Enums/EnumsGenerator.cs +++ b/src/libp2p/Libp2p.Generators.Enums/EnumsGenerator.cs @@ -57,7 +57,6 @@ public void Execute(GeneratorExecutionContext context) $"namespace Nethermind.Libp2p.Core.Enums;\npublic enum {e}\n{{\n{string.Join("", vs)}}}\n"); } - string? Cap(string? s) { return string.IsNullOrEmpty(s) diff --git a/src/libp2p/Libp2p.Generators.Enums/IsExternalInit.cs b/src/libp2p/Libp2p.Generators.Enums/IsExternalInit.cs index 7845e18f..eaf7a077 100644 --- a/src/libp2p/Libp2p.Generators.Enums/IsExternalInit.cs +++ b/src/libp2p/Libp2p.Generators.Enums/IsExternalInit.cs @@ -1,7 +1,6 @@ // SPDX-FileCopyrightText: 2023 Demerzel Solutions Limited // SPDX-License-Identifier: MIT - namespace System.Runtime.CompilerServices; internal static class IsExternalInit diff --git a/src/libp2p/Libp2p.Protocols.IpTcp/IpTcpProtocol.cs b/src/libp2p/Libp2p.Protocols.IpTcp/IpTcpProtocol.cs index fffe3480..5e65bb11 100644 --- a/src/libp2p/Libp2p.Protocols.IpTcp/IpTcpProtocol.cs +++ b/src/libp2p/Libp2p.Protocols.IpTcp/IpTcpProtocol.cs @@ -26,7 +26,7 @@ public async Task ListenAsync(IChannel channel, IChannelFactory? channelFactory, _logger?.LogInformation("ListenAsync({contextId})", context.Id); Socket srv = new(SocketType.Stream, ProtocolType.Tcp); - Core.Multiaddr addr = context.LocalPeer.Address; + Multiaddr addr = context.LocalPeer.Address; Core.Enums.Multiaddr ipProtocol = addr.Has(Core.Enums.Multiaddr.Ip4) ? Core.Enums.Multiaddr.Ip4 : Core.Enums.Multiaddr.Ip6; IPAddress ipAddress = IPAddress.Parse(addr.At(ipProtocol)!); int tcpPort = int.Parse(addr.At(Core.Enums.Multiaddr.Tcp)!); @@ -73,7 +73,7 @@ await Task.Run(async () => .Replace( Core.Enums.Multiaddr.Tcp, remoteIpEndpoint.Port.ToString()); - clientContext.RemotePeer.Address = new Core.Multiaddr() + clientContext.RemotePeer.Address = new Multiaddr() .Append(remoteIpEndpoint.AddressFamily == AddressFamily.InterNetwork ? Core.Enums.Multiaddr.Ip4 : Core.Enums.Multiaddr.Ip6, remoteIpEndpoint.Address.ToString()) @@ -130,7 +130,7 @@ public async Task DialAsync(IChannel channel, IChannelFactory channelFactory, IP TaskCompletionSource waitForStop = new(TaskCreationOptions.RunContinuationsAsynchronously); Socket client = new(SocketType.Stream, ProtocolType.Tcp); - Core.Multiaddr addr = context.RemotePeer.Address; + Multiaddr addr = context.RemotePeer.Address; Core.Enums.Multiaddr ipProtocol = addr.Has(Core.Enums.Multiaddr.Ip4) ? Core.Enums.Multiaddr.Ip4 : Core.Enums.Multiaddr.Ip6; IPAddress ipAddress = IPAddress.Parse(addr.At(ipProtocol)!); int tcpPort = int.Parse(addr.At(Core.Enums.Multiaddr.Tcp)!); diff --git a/src/libp2p/Libp2p.Protocols.MDns/MDnsDiscoveryProtocol.cs b/src/libp2p/Libp2p.Protocols.MDns/MDnsDiscoveryProtocol.cs index fa6382f8..80d4fbfc 100644 --- a/src/libp2p/Libp2p.Protocols.MDns/MDnsDiscoveryProtocol.cs +++ b/src/libp2p/Libp2p.Protocols.MDns/MDnsDiscoveryProtocol.cs @@ -75,7 +75,7 @@ public async Task DiscoverAsync(Core.Multiaddr localPeerAddr, CancellationToken .Select(x => x.Strings.Where(x => x.StartsWith("dnsaddr"))) .SelectMany(x => x).Select(x => new Core.Multiaddr(x.Replace("dnsaddr=", ""))).ToArray(); _logger?.LogTrace("Inst disc {0}, nmsg: {1}", e.ServiceInstanceName, e.Message); - if (Enumerable.Any(records) && !peers.Contains(Enumerable.First(records)) && localPeerAddr.At(Core.Enums.Multiaddr.P2p) != Enumerable.First(records).At(Core.Enums.Multiaddr.P2p)) + if (Enumerable.Any(records) && !peers.Contains(Enumerable.First(records)) && localPeerAddr.At(Core.Enums.Multiaddr.P2p) != Enumerable.First(records).At(Core.Enums.Multiaddr.P2p)) { List peerAddresses = new(); foreach (Core.Multiaddr peer in records) diff --git a/src/libp2p/Libp2p.Protocols.Noise/Libp2p.Protocols.Noise.csproj b/src/libp2p/Libp2p.Protocols.Noise/Libp2p.Protocols.Noise.csproj index 7fd79574..7275c4fc 100644 --- a/src/libp2p/Libp2p.Protocols.Noise/Libp2p.Protocols.Noise.csproj +++ b/src/libp2p/Libp2p.Protocols.Noise/Libp2p.Protocols.Noise.csproj @@ -19,12 +19,13 @@ + - + all diff --git a/src/libp2p/Libp2p.Protocols.Noise/NoiseProtocol.cs b/src/libp2p/Libp2p.Protocols.Noise/NoiseProtocol.cs index 97377d84..8844ae01 100644 --- a/src/libp2p/Libp2p.Protocols.Noise/NoiseProtocol.cs +++ b/src/libp2p/Libp2p.Protocols.Noise/NoiseProtocol.cs @@ -1,18 +1,17 @@ // SPDX-FileCopyrightText: 2023 Demerzel Solutions Limited // SPDX-License-Identifier: MIT -extern alias BouncyCastleCryptography; using System.Buffers; using System.Buffers.Binary; using Google.Protobuf; using Nethermind.Libp2p.Core; using Noise; using System.Text; -using BouncyCastleCryptography::Org.BouncyCastle.Math.EC.Rfc8032; +using Org.BouncyCastle.Math.EC.Rfc8032; using Microsoft.Extensions.Logging; using Nethermind.Libp2p.Protocols.Noise.Dto; using PublicKey = Nethermind.Libp2p.Core.Dto.PublicKey; -using BouncyCastleCryptography::Org.BouncyCastle.Utilities.Encoders; +using Org.BouncyCastle.Utilities.Encoders; namespace Nethermind.Libp2p.Protocols; @@ -50,7 +49,6 @@ public async Task DialAsync(IChannel downChannel, IChannelFactory upChannelFacto await downChannel.WriteAsync(new ReadOnlySequence(lenBytes)); await downChannel.WriteAsync(new ReadOnlySequence(buffer, 0, msg0.BytesWritten)); - lenBytes = (await downChannel.ReadAsync(2)).ToArray(); int len = (int)BinaryPrimitives.ReadInt16BigEndian(lenBytes.AsSpan()); ReadOnlySequence received = await downChannel.ReadAsync(len); diff --git a/src/libp2p/Libp2p.Protocols.Pubsub.Tests/GossipsubProtocolTests.cs b/src/libp2p/Libp2p.Protocols.Pubsub.Tests/GossipsubProtocolTests.cs index 037f831a..b8ed140f 100644 --- a/src/libp2p/Libp2p.Protocols.Pubsub.Tests/GossipsubProtocolTests.cs +++ b/src/libp2p/Libp2p.Protocols.Pubsub.Tests/GossipsubProtocolTests.cs @@ -6,7 +6,6 @@ namespace Nethermind.Libp2p.Protocols.Multistream.Tests; - [TestFixture] public class GossipsubProtocolTests { diff --git a/src/libp2p/Libp2p.Protocols.Pubsub/Libp2p.Protocols.Pubsub.csproj b/src/libp2p/Libp2p.Protocols.Pubsub/Libp2p.Protocols.Pubsub.csproj index e6620ac6..7f73ecb9 100644 --- a/src/libp2p/Libp2p.Protocols.Pubsub/Libp2p.Protocols.Pubsub.csproj +++ b/src/libp2p/Libp2p.Protocols.Pubsub/Libp2p.Protocols.Pubsub.csproj @@ -20,13 +20,14 @@ + - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/libp2p/Libp2p.Protocols.Pubsub/PubsubProtocol.cs b/src/libp2p/Libp2p.Protocols.Pubsub/PubsubProtocol.cs index 47f7f71c..1ad684bb 100644 --- a/src/libp2p/Libp2p.Protocols.Pubsub/PubsubProtocol.cs +++ b/src/libp2p/Libp2p.Protocols.Pubsub/PubsubProtocol.cs @@ -30,7 +30,6 @@ public async Task DialAsync(IChannel channel, IChannelFactory? channelFactory, string peerId = context.RemotePeer.Address.At(MultiaddrEnum.P2p)!; _logger?.LogDebug($"Dialed({context.Id}) {context.RemotePeer.Address}"); - CancellationToken token = router.OutboundConnection(peerId, Id, (rpc) => { _ = channel.WritePrefixedProtobufAsync(rpc); diff --git a/src/libp2p/Libp2p.Protocols.Pubsub/RpcExtensions.cs b/src/libp2p/Libp2p.Protocols.Pubsub/RpcExtensions.cs index 2b7828c4..821d5b64 100644 --- a/src/libp2p/Libp2p.Protocols.Pubsub/RpcExtensions.cs +++ b/src/libp2p/Libp2p.Protocols.Pubsub/RpcExtensions.cs @@ -1,9 +1,8 @@ // SPDX-FileCopyrightText: 2023 Demerzel Solutions Limited // SPDX-License-Identifier: MIT -extern alias BouncyCastleCryptography; using Google.Protobuf; -using BouncyCastleCryptography::Org.BouncyCastle.Math.EC.Rfc8032; +using Org.BouncyCastle.Math.EC.Rfc8032; using System.Buffers.Binary; using System.Text; using Multiformats.Hash; diff --git a/src/libp2p/Libp2p.Protocols.Pubsub/Usings.cs b/src/libp2p/Libp2p.Protocols.Pubsub/Usings.cs index 4b2f5e6a..f545c927 100644 --- a/src/libp2p/Libp2p.Protocols.Pubsub/Usings.cs +++ b/src/libp2p/Libp2p.Protocols.Pubsub/Usings.cs @@ -1,7 +1,6 @@ // SPDX-FileCopyrightText: 2023 Demerzel Solutions Limited // SPDX-License-Identifier: MIT - global using Multiaddr = Nethermind.Libp2p.Core.Multiaddr; global using MultiaddrEnum = Nethermind.Libp2p.Core.Enums.Multiaddr; using System.Runtime.CompilerServices; diff --git a/src/libp2p/Libp2p.Protocols.Quic/Libp2p.Protocols.Quic.csproj b/src/libp2p/Libp2p.Protocols.Quic/Libp2p.Protocols.Quic.csproj index d7253425..4a949953 100644 --- a/src/libp2p/Libp2p.Protocols.Quic/Libp2p.Protocols.Quic.csproj +++ b/src/libp2p/Libp2p.Protocols.Quic/Libp2p.Protocols.Quic.csproj @@ -16,6 +16,7 @@ + diff --git a/src/libp2p/Libp2p.sln b/src/libp2p/Libp2p.sln index b707d60f..13453f2b 100644 --- a/src/libp2p/Libp2p.sln +++ b/src/libp2p/Libp2p.sln @@ -53,6 +53,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Libp2p.Protocols.Pubsub.Tes EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Libp2p.Protocols.Ping", "Libp2p.Protocols.Ping\Libp2p.Protocols.Ping.csproj", "{FC0E9BCE-2848-45DC-AE20-FB7E862A199E}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Multiformats.Hash", "..\cs-multihash\src\Multiformats.Hash\Multiformats.Hash.csproj", "{064158B8-C0A0-4CE5-8D6A-77FE657788FE}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -151,6 +153,10 @@ Global {FC0E9BCE-2848-45DC-AE20-FB7E862A199E}.Debug|Any CPU.Build.0 = Debug|Any CPU {FC0E9BCE-2848-45DC-AE20-FB7E862A199E}.Release|Any CPU.ActiveCfg = Release|Any CPU {FC0E9BCE-2848-45DC-AE20-FB7E862A199E}.Release|Any CPU.Build.0 = Release|Any CPU + {064158B8-C0A0-4CE5-8D6A-77FE657788FE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {064158B8-C0A0-4CE5-8D6A-77FE657788FE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {064158B8-C0A0-4CE5-8D6A-77FE657788FE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {064158B8-C0A0-4CE5-8D6A-77FE657788FE}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/samples/chat/Chat.csproj b/src/samples/chat/Chat.csproj index bc2d5894..a1390c7d 100644 --- a/src/samples/chat/Chat.csproj +++ b/src/samples/chat/Chat.csproj @@ -11,7 +11,7 @@ - + diff --git a/src/samples/perf-benchmarks/PerfBenchmarks.csproj b/src/samples/perf-benchmarks/PerfBenchmarks.csproj index 3d7f2978..fefae512 100644 --- a/src/samples/perf-benchmarks/PerfBenchmarks.csproj +++ b/src/samples/perf-benchmarks/PerfBenchmarks.csproj @@ -10,7 +10,7 @@ - + diff --git a/src/samples/perf-benchmarks/PerfProtocol.cs b/src/samples/perf-benchmarks/PerfProtocol.cs index faa01da9..eee59ba5 100644 --- a/src/samples/perf-benchmarks/PerfProtocol.cs +++ b/src/samples/perf-benchmarks/PerfProtocol.cs @@ -7,7 +7,6 @@ namespace DataTransferBenchmark; - // TODO: Align with perf protocol public class PerfProtocol : IProtocol { @@ -47,7 +46,6 @@ public async Task DialAsync(IChannel downChannel, IChannelFactory upChannelFacto } }); - long bytesRead = 0; while (!downChannel.Token.IsCancellationRequested) { diff --git a/src/samples/pubsub-chat/Program.cs b/src/samples/pubsub-chat/Program.cs index 4439865d..51987414 100644 --- a/src/samples/pubsub-chat/Program.cs +++ b/src/samples/pubsub-chat/Program.cs @@ -35,22 +35,20 @@ ILocalPeer peer = peerFactory.Create(optionalFixedIdentity, addr); - PubsubRouter router = serviceProvider.GetService()!; - ITopic topic = router.Subscribe("chat-room:awesome-chat-room"); - -_ = router.RunAsync(peer, new MDnsDiscoveryProtocol(serviceProvider.GetService()), token: ts.Token); - - -topic.OnMessage += ((byte[] msg) => +topic.OnMessage += (byte[] msg) => { ChatMessage? chatMessage = JsonSerializer.Deserialize(Encoding.UTF8.GetString(msg)); if (chatMessage is not null) { Console.WriteLine("{0}: {1}", chatMessage.SenderNick, chatMessage.Message); } -}); +}; + +_ = router.RunAsync(peer, new MDnsDiscoveryProtocol(serviceProvider.GetService()), token: ts.Token); + + string peerId = peer.Address.At(Nethermind.Libp2p.Core.Enums.Multiaddr.P2p)!;