Skip to content

Commit

Permalink
Add Inbound field to admin_peers rpc call response (#7443)
Browse files Browse the repository at this point in the history
  • Loading branch information
obasekiosa authored Nov 29, 2024
1 parent 14406f3 commit 8fed53f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/Nethermind/Nethermind.JsonRpc.Test/Modules/AdminModuleTests.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<JsonRpcSuccessResponse>(serialized);
var peerInfoList = ((JsonElement)response.Result!).Deserialize<List<PeerInfo>>(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()
{
Expand Down
6 changes: 5 additions & 1 deletion src/Nethermind/Nethermind.JsonRpc/Modules/Admin/PeerInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public class PeerInfo
public string EthDetails { get; set; }
public string LastSignal { get; set; }

public bool Inbound { get; set; }

public PeerInfo()
{
}
Expand All @@ -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);

}
}
}
Expand Down

0 comments on commit 8fed53f

Please sign in to comment.