Skip to content

Commit

Permalink
Rollback ms change(caused a bug); fix identify proto; publish protobu…
Browse files Browse the repository at this point in the history
…f gen with version equal to protobuf; add color to chat sample
  • Loading branch information
flcl42 committed Sep 10, 2024
1 parent dc5c440 commit c0f3b71
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 11 deletions.
13 changes: 12 additions & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,25 @@ jobs:
dotnet test Libp2p.Protocols.Pubsub.Tests ${{ env.PACK_OPTS }}
dotnet test Libp2p.Protocols.Quic.Tests ${{ env.PACK_OPTS }}
- name: Publish protobuf generator
continue-on-error: true
working-directory: ${{ env.WORKING_DIR }}
env:
PACK_OPTS: -c ${{ env.BUILD_CONFIG }} --no-build
run: |
dotnet pack Libp2p.Generators.Protobuf ${{ env.PACK_OPTS }}
dotnet nuget push **/*.nupkg \
-k ${{ github.event.inputs.feed == 'Production' && secrets.NUGET_API_KEY || secrets.NUGETTEST_API_KEY }} \
-s ${{ github.event.inputs.feed == 'Production' && 'https://api.nuget.org/v3/index.json' || 'https://apiint.nugettest.org/v3/index.json' }}
- name: Publish
working-directory: ${{ env.WORKING_DIR }}
env:
PACK_OPTS: -c ${{ env.BUILD_CONFIG }} --no-build -p:Version=${{ github.event.inputs.version }}
run: |
dotnet pack Libp2p ${{ env.PACK_OPTS }}
dotnet pack Libp2p.Core ${{ env.PACK_OPTS }}
dotnet pack Libp2p.Generators.Protobuf ${{ env.PACK_OPTS }}
dotnet pack Libp2p.Protocols.Identify ${{ env.PACK_OPTS }}
dotnet pack Libp2p.Protocols.IpTcp ${{ env.PACK_OPTS }}
dotnet pack Libp2p.Protocols.MDns ${{ env.PACK_OPTS }}
Expand Down
16 changes: 14 additions & 2 deletions src/libp2p/Libp2p.Protocols.Identify/IdentifyProtocol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
using Nethermind.Libp2p.Core;
using Microsoft.Extensions.Logging;
using Nethermind.Libp2p.Core.Dto;
using Multiformats.Address;
using Multiformats.Address.Protocols;
using Multiformats.Address.Net;

namespace Nethermind.Libp2p.Protocols;

Expand Down Expand Up @@ -57,14 +59,24 @@ public async Task ListenAsync(IChannel channel, IChannelFactory? channelFactory,
ProtocolVersion = _protocolVersion,
AgentVersion = _agentVersion,
PublicKey = context.LocalPeer.Identity.PublicKey.ToByteString(),
ListenAddrs = { ByteString.CopyFrom(context.LocalEndpoint.Get<IP>().ToBytes()) },
ObservedAddr = ByteString.CopyFrom(context.RemoteEndpoint.Get<IP>().ToBytes()),
ListenAddrs = { ByteString.CopyFrom(ToEndpoint(context.LocalEndpoint).ToBytes()) },
ObservedAddr = ByteString.CopyFrom(ToEndpoint(context.RemoteEndpoint).ToBytes()),
Protocols = { _peerFactoryBuilder.AppLayerProtocols.Select(p => p.Id) }
};

byte[] ar = new byte[identify.CalculateSize()];
identify.WriteTo(ar);

await channel.WriteSizeAndDataAsync(ar);
_logger?.LogDebug("Sent peer info {identify}", identify);
}

private static Multiaddress ToEndpoint(Multiaddress addr) => new()
{
Protocols =
{
addr.Has<IP4>() ? addr.Get<IP4>() : addr.Get<IP6>(),
addr.Has<TCP>() ? addr.Get<TCP>() : addr.Get<UDP>()
}
};
}
11 changes: 4 additions & 7 deletions src/libp2p/Libp2p.Protocols.Multistream/MultistreamProtocol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,11 @@ public async Task DialAsync(IChannel channel, IChannelFactory? channelFactory,

context.SpecificProtocolRequest = null;
await channel.WriteLineAsync(selected.Id);

_ = channel.ReadLineAsync().ContinueWith(async t =>
string response = await channel.ReadLineAsync();
if (await DialProtocol(selected) != true)
{
if (t.Result != selected.Id)
{
await channel.CloseAsync();
}
});
return;
}
}
else
{
Expand Down
7 changes: 6 additions & 1 deletion src/samples/chat/ChatProtocol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
internal class ChatProtocol : SymmetricProtocol, IProtocol
{
private static readonly ConsoleReader Reader = new();
private readonly ConsoleColor defautConsoleColor = Console.ForegroundColor;

public string Id => "/chat/1.0.0";

protected override async Task ConnectAsync(IChannel channel, IChannelFactory? channelFactory,
Expand All @@ -19,7 +21,10 @@ protected override async Task ConnectAsync(IChannel channel, IChannelFactory? ch
for (; ; )
{
ReadOnlySequence<byte> read = await channel.ReadAsync(0, ReadBlockingMode.WaitAny).OrThrow();
Console.Write(Encoding.UTF8.GetString(read).Replace("\n\n", "\n> "));
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("{0}", Encoding.UTF8.GetString(read).Replace("\r", "").Replace("\n\n", ""));
Console.ForegroundColor = defautConsoleColor;
Console.Write("> ");
}
});
for (; ; )
Expand Down

0 comments on commit c0f3b71

Please sign in to comment.