From 8fed53f950769205f8ad1286a6e6c198bfd5b103 Mon Sep 17 00:00:00 2001 From: Osakpolor Obaseki <12957252+obasekiosa@users.noreply.github.com> Date: Fri, 29 Nov 2024 18:33:12 +0100 Subject: [PATCH] Add Inbound field to admin_peers rpc call response (#7443) --- .../Modules/AdminModuleTests.cs | 17 +++++++++++++++++ .../Modules/Admin/PeerInfo.cs | 6 +++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/Nethermind/Nethermind.JsonRpc.Test/Modules/AdminModuleTests.cs b/src/Nethermind/Nethermind.JsonRpc.Test/Modules/AdminModuleTests.cs index 50920da1655..597b3c5e1a9 100644 --- a/src/Nethermind/Nethermind.JsonRpc.Test/Modules/AdminModuleTests.cs +++ b/src/Nethermind/Nethermind.JsonRpc.Test/Modules/AdminModuleTests.cs @@ -1,7 +1,9 @@ // SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited // SPDX-License-Identifier: LGPL-3.0-only +using System; using System.Collections.Concurrent; +using System.Collections.Generic; using System.Text.Json; using System.Threading.Tasks; using FluentAssertions; @@ -63,6 +65,21 @@ public void Setup() _serializer = new EthereumJsonSerializer(); } + [Test] + public async Task Test_peers() + { + string serialized = await RpcTest.TestSerializedRequest(_adminRpcModule, "admin_peers"); + JsonRpcSuccessResponse response = _serializer.Deserialize(serialized); + var peerInfoList = ((JsonElement)response.Result!).Deserialize>(EthereumJsonSerializer.JsonOptions)!; + peerInfoList.Count.Should().Be(1); + PeerInfo peerInfo = peerInfoList[0]; + peerInfo.Host.Should().Be("127.0.0.1"); + peerInfo.Port.Should().Be(30303); + peerInfo.Inbound.Should().BeFalse(); + peerInfo.IsStatic.Should().BeTrue(); + peerInfo.Id.Should().NotBeEmpty(); + } + [Test] public async Task Test_node_info() { diff --git a/src/Nethermind/Nethermind.JsonRpc/Modules/Admin/PeerInfo.cs b/src/Nethermind/Nethermind.JsonRpc/Modules/Admin/PeerInfo.cs index 59d1bb8d962..d7061c06e6e 100644 --- a/src/Nethermind/Nethermind.JsonRpc/Modules/Admin/PeerInfo.cs +++ b/src/Nethermind/Nethermind.JsonRpc/Modules/Admin/PeerInfo.cs @@ -25,6 +25,8 @@ public class PeerInfo public string EthDetails { get; set; } public string LastSignal { get; set; } + public bool Inbound { get; set; } + public PeerInfo() { } @@ -45,12 +47,14 @@ 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; if (includeDetails) { ClientType = peer.Node.ClientType.ToString(); EthDetails = peer.Node.EthDetails; - LastSignal = (peer.InSession ?? peer.OutSession)?.LastPingUtc.ToString(CultureInfo.InvariantCulture); + LastSignal = (peer.InSession ?? peer.OutSession!).LastPingUtc.ToString(CultureInfo.InvariantCulture); + } } }