Add 'inbound' field to admin_peers JSON-RPC Call (#7461)

* Add 'inbound' field to admin_peers JSON-RPC Call

Signed-off-by: 7suyash7 <suyashnyn1@gmail.com>

* added changelog entry

Signed-off-by: Sally MacFarlane <macfarla.github@gmail.com>

---------

Signed-off-by: 7suyash7 <suyashnyn1@gmail.com>
Signed-off-by: Sally MacFarlane <macfarla.github@gmail.com>
Co-authored-by: Sally MacFarlane <macfarla.github@gmail.com>
pull/7473/head
Suyash Nayan 3 months ago committed by GitHub
parent cca2f7554a
commit b2b55a54fb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 1
      CHANGELOG.md
  2. 10
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/NetworkResult.java
  3. 6
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/PeerResult.java
  4. 15
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/NetworkResultTest.java

@ -18,6 +18,7 @@
- Added support for tracing private transactions using `priv_traceTransaction` API. [#6161](https://github.com/hyperledger/besu/pull/6161) - Added support for tracing private transactions using `priv_traceTransaction` API. [#6161](https://github.com/hyperledger/besu/pull/6161)
- Wrap WorldUpdater into EVMWorldupdater [#7434](https://github.com/hyperledger/besu/pull/7434) - Wrap WorldUpdater into EVMWorldupdater [#7434](https://github.com/hyperledger/besu/pull/7434)
- Bump besu-native to 0.9.4 [#7456](https://github.com/hyperledger/besu/pull/7456) - Bump besu-native to 0.9.4 [#7456](https://github.com/hyperledger/besu/pull/7456)
- Add 'inbound' field to admin_peers JSON-RPC Call [#7461](https://github.com/hyperledger/besu/pull/7461)
### Bug fixes ### Bug fixes

@ -24,10 +24,13 @@ public class NetworkResult {
private final String localAddress; private final String localAddress;
private final String remoteAddress; private final String remoteAddress;
private final boolean inbound;
public NetworkResult(final SocketAddress localAddress, final SocketAddress remoteAddress) { public NetworkResult(
final SocketAddress localAddress, final SocketAddress remoteAddress, final boolean inbound) {
this.localAddress = removeTrailingSlash(localAddress.toString()); this.localAddress = removeTrailingSlash(localAddress.toString());
this.remoteAddress = removeTrailingSlash(remoteAddress.toString()); this.remoteAddress = removeTrailingSlash(remoteAddress.toString());
this.inbound = inbound;
} }
@JsonGetter(value = "localAddress") @JsonGetter(value = "localAddress")
@ -40,6 +43,11 @@ public class NetworkResult {
return remoteAddress; return remoteAddress;
} }
@JsonGetter(value = "inbound")
public boolean isInbound() {
return inbound;
}
private String removeTrailingSlash(final String address) { private String removeTrailingSlash(final String address) {
if (address != null && address.startsWith("/")) { if (address != null && address.startsWith("/")) {
return address.substring(1); return address.substring(1);

@ -45,7 +45,11 @@ public interface PeerResult {
.map(Capability::toString) .map(Capability::toString)
.map(TextNode::new) .map(TextNode::new)
.collect(Collectors.toList())) .collect(Collectors.toList()))
.network(new NetworkResult(connection.getLocalAddress(), connection.getRemoteAddress())) .network(
new NetworkResult(
connection.getLocalAddress(),
connection.getRemoteAddress(),
connection.inboundInitiated()))
.port(Quantity.create(peerInfo.getPort())) .port(Quantity.create(peerInfo.getPort()))
.id(peerInfo.getNodeId().toString()) .id(peerInfo.getNodeId().toString())
.protocols(Map.of(peer.getProtocolName(), ProtocolsResult.fromEthPeer(peer))) .protocols(Map.of(peer.getProtocolName(), ProtocolsResult.fromEthPeer(peer)))

@ -26,9 +26,22 @@ public class NetworkResultTest {
@Test @Test
public void localAndRemoteAddressShouldNotStartWithForwardSlash() { public void localAndRemoteAddressShouldNotStartWithForwardSlash() {
final SocketAddress socketAddress = new InetSocketAddress("1.2.3.4", 7890); final SocketAddress socketAddress = new InetSocketAddress("1.2.3.4", 7890);
final NetworkResult networkResult = new NetworkResult(socketAddress, socketAddress); final NetworkResult networkResult = new NetworkResult(socketAddress, socketAddress, true);
assertThat(networkResult.getLocalAddress()).isEqualTo("1.2.3.4:7890"); assertThat(networkResult.getLocalAddress()).isEqualTo("1.2.3.4:7890");
assertThat(networkResult.getRemoteAddress()).isEqualTo("1.2.3.4:7890"); assertThat(networkResult.getRemoteAddress()).isEqualTo("1.2.3.4:7890");
assertThat(networkResult.isInbound()).isTrue();
}
@Test
public void inboundFieldShouldReflectConnectionDirection() {
final SocketAddress localAddress = new InetSocketAddress("192.168.0.1", 30303);
final SocketAddress remoteAddress = new InetSocketAddress("10.0.0.1", 30303);
final NetworkResult inboundConnection = new NetworkResult(localAddress, remoteAddress, true);
assertThat(inboundConnection.isInbound()).isTrue();
final NetworkResult outboundConnection = new NetworkResult(localAddress, remoteAddress, false);
assertThat(outboundConnection.isInbound()).isFalse();
} }
} }

Loading…
Cancel
Save