From cd6e564787dd5cfc11d03469d7035b5d1b60990e Mon Sep 17 00:00:00 2001 From: Osakpolor Obaseki Date: Mon, 16 Sep 2024 10:55:13 +0100 Subject: [PATCH 1/2] Add Inbound field to PeerInfo object --- .../Nethermind.JsonRpc/Modules/Admin/PeerInfo.cs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/Nethermind/Nethermind.JsonRpc/Modules/Admin/PeerInfo.cs b/src/Nethermind/Nethermind.JsonRpc/Modules/Admin/PeerInfo.cs index b567abd394b..c7fc2bbfd55 100644 --- a/src/Nethermind/Nethermind.JsonRpc/Modules/Admin/PeerInfo.cs +++ b/src/Nethermind/Nethermind.JsonRpc/Modules/Admin/PeerInfo.cs @@ -15,7 +15,7 @@ public class PeerInfo public string Host { get; set; } public int Port { get; set; } public string Address { get; set; } - public bool IsBootnode { get; set; } + public bool IsBootnode { get; set; } // change to BootNode (capitalize "N")? public bool IsTrusted { get; set; } public bool IsStatic { get; set; } public string Enode { get; set; } @@ -24,6 +24,8 @@ public class PeerInfo public string EthDetails { get; set; } public string LastSignal { get; set; } + public bool Inbound { get; set; } + public PeerInfo() { } @@ -43,13 +45,13 @@ public PeerInfo(Peer peer, bool includeDetails) IsBootnode = peer.Node.IsBootnode; IsStatic = peer.Node.IsStatic; Enode = peer.Node.ToString(Node.Format.ENode); + Inbound = peer.InSession is not null && peer.InSession.Direction == ConnectionDirection.In; // assumes one of InSession/Outsession is always set.? - if (includeDetails) - { - ClientType = peer.Node.ClientType.ToString(); - EthDetails = peer.Node.EthDetails; - LastSignal = (peer.InSession ?? peer.OutSession)?.LastPingUtc.ToString(CultureInfo.InvariantCulture); - } + if (!includeDetails) return; + + ClientType = peer.Node.ClientType.ToString(); + EthDetails = peer.Node.EthDetails; + LastSignal = (peer.InSession ?? peer.OutSession)?.LastPingUtc.ToString(CultureInfo.InvariantCulture); } } } From a0dff2c00650f20148f6c47874c9c2398f841044 Mon Sep 17 00:00:00 2001 From: Osakpolor Obaseki Date: Tue, 12 Nov 2024 13:06:15 +0100 Subject: [PATCH 2/2] Refactor PeerInfo constructor. --- .../Nethermind.JsonRpc/Modules/Admin/PeerInfo.cs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/Nethermind/Nethermind.JsonRpc/Modules/Admin/PeerInfo.cs b/src/Nethermind/Nethermind.JsonRpc/Modules/Admin/PeerInfo.cs index b659c139c65..7fab3d139f7 100644 --- a/src/Nethermind/Nethermind.JsonRpc/Modules/Admin/PeerInfo.cs +++ b/src/Nethermind/Nethermind.JsonRpc/Modules/Admin/PeerInfo.cs @@ -16,7 +16,7 @@ public class PeerInfo public string Host { get; set; } public int Port { get; set; } public string Address { get; set; } - public bool IsBootnode { get; set; } // change to BootNode (capitalize "N")? + public bool IsBootnode { get; set; } public bool IsTrusted { get; set; } public bool IsStatic { get; set; } public string Enode { get; set; } @@ -41,19 +41,21 @@ public PeerInfo(Peer peer, bool includeDetails) Name = peer.Node.ClientId; Id = peer.Node.Id.Hash.ToString(false); - Host = peer.Node.Host is null ? null : IPAddress.Parse(peer.Node.Host).MapToIPv4().ToString(); + Host = IPAddress.Parse(peer.Node.Host!).MapToIPv4().ToString(); Port = peer.Node.Port; Address = peer.Node.Address.ToString(); IsBootnode = peer.Node.IsBootnode; IsStatic = peer.Node.IsStatic; Enode = peer.Node.ToString(Node.Format.ENode); - Inbound = peer.InSession is not null && peer.InSession.Direction == ConnectionDirection.In; // assumes one of InSession/Outsession is always set.? + Inbound = peer.InSession is not null; - if (!includeDetails) return; + if (includeDetails) + { + ClientType = peer.Node.ClientType.ToString(); + EthDetails = peer.Node.EthDetails; + LastSignal = (peer.InSession ?? peer.OutSession!).LastPingUtc.ToString(CultureInfo.InvariantCulture); - ClientType = peer.Node.ClientType.ToString(); - EthDetails = peer.Node.EthDetails; - LastSignal = (peer.InSession ?? peer.OutSession)?.LastPingUtc.ToString(CultureInfo.InvariantCulture); + } } } }