Skip to content

Commit

Permalink
p2p logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Marchhill committed Nov 6, 2024
1 parent 8de524c commit 80ddd25
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Nethermind.Network.Discovery;

internal class NethermindLoggerFactory(ILogManager logManager, bool lowerLogLevel = false) : ILoggerFactory
public class NethermindLoggerFactory(ILogManager logManager, bool lowerLogLevel = false) : ILoggerFactory
{
public Microsoft.Extensions.Logging.ILogger CreateLogger(string categoryName)
{
Expand Down
4 changes: 4 additions & 0 deletions src/Nethermind/Nethermind.Shutter/Config/IShutterConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ public interface IShutterConfig : IConfig
DefaultValue = "60000", HiddenFromDocs = true)]
uint DisconnectionLogInterval { get; set; }

[ConfigItem(Description = "Whether to output libp2p logs.",
DefaultValue = "false", HiddenFromDocs = true)]
bool P2PLogsEnabled { get; set; }

public void Validate(out Multiaddress[] bootnodeP2PAddresses)
{
if (Validator && ValidatorInfoFile is null)
Expand Down
1 change: 1 addition & 0 deletions src/Nethermind/Nethermind.Shutter/Config/ShutterConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ public class ShutterConfig : IShutterConfig
public ushort MaxKeyDelay { get; set; } = 1666;
public uint DisconnectionLogTimeout { get; set; } = 1200000;
public uint DisconnectionLogInterval { get; set; } = 60000;
public bool P2PLogsEnabled { get; set; } = false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
<ProjectReference Include="..\Nethermind.Specs\Nethermind.Specs.csproj" />
<ProjectReference Include="..\Nethermind.Serialization.Ssz\Nethermind.Serialization.Ssz.csproj" />
<ProjectReference Include="..\Nethermind.Merkleization\Nethermind.Merkleization.csproj" />
<ProjectReference Include="..\Nethermind.Network.Discovery\Nethermind.Network.Discovery.csproj" />
</ItemGroup>

</Project>
32 changes: 20 additions & 12 deletions src/Nethermind/Nethermind.Shutter/ShutterP2P.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Nethermind.Libp2p.Protocols.Pubsub;
using Nethermind.Libp2p.Stack;
using Nethermind.Libp2p.Protocols;
using Nethermind.Network.Discovery;
using System;
using System.Threading.Tasks;
using System.Threading;
Expand All @@ -19,6 +20,7 @@
using System.IO.Abstractions;
using Nethermind.KeyStore.Config;
using System.Net;
using Microsoft.Extensions.Logging;

namespace Nethermind.Shutter;

Expand All @@ -45,7 +47,8 @@ public ShutterP2P(IShutterConfig shutterConfig, ILogManager logManager, IFileSys
_cfg = shutterConfig;
DisconnectionLogTimeout = TimeSpan.FromMilliseconds(_cfg.DisconnectionLogTimeout);
DisconnectionLogInterval = TimeSpan.FromMilliseconds(_cfg.DisconnectionLogInterval);
_serviceProvider = new ServiceCollection()

IServiceCollection serviceCollection = new ServiceCollection()
.AddLibp2p(builder => builder)
.AddSingleton(new IdentifyProtocolSettings
{
Expand All @@ -63,17 +66,22 @@ public ShutterP2P(IShutterConfig shutterConfig, ILogManager logManager, IFileSys
})
.AddSingleton<PubsubRouter>()
.AddSingleton<PeerStore>()
.AddSingleton(sp => sp.GetService<IPeerFactoryBuilder>()!.Build())
//.AddSingleton<ILoggerFactory>(new NethermindLoggerFactory(logManager))
// .AddLogging(builder =>
// builder.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace)
// .AddSimpleConsole(l =>
// {
// l.SingleLine = true;
// l.TimestampFormat = "[HH:mm:ss.FFF]";
// })
// )
.BuildServiceProvider();
.AddSingleton(sp => sp.GetService<IPeerFactoryBuilder>()!.Build());

if (_cfg.P2PLogsEnabled)
{
serviceCollection
.AddSingleton<ILoggerFactory>(new NethermindLoggerFactory(logManager))
.AddLogging(builder =>
builder.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace)
.AddSimpleConsole(l =>
{
l.SingleLine = true;
l.TimestampFormat = "[HH:mm:ss.FFF]";
})
);
}
_serviceProvider = serviceCollection.BuildServiceProvider();

IPeerFactory peerFactory = _serviceProvider!.GetService<IPeerFactory>()!;

Expand Down

0 comments on commit 80ddd25

Please sign in to comment.