Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- 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)
- 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,13 @@ public class NetworkResult {

private final String localAddress;
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.remoteAddress = removeTrailingSlash(remoteAddress.toString());
this.inbound = inbound;
}

@JsonGetter(value = "localAddress")
Expand All @@ -40,6 +43,11 @@ public String getRemoteAddress() {
return remoteAddress;
}

@JsonGetter(value = "inbound")
public boolean isInbound() {
return inbound;
}

private String removeTrailingSlash(final String address) {
if (address != null && address.startsWith("/")) {
return address.substring(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ static PeerResult fromEthPeer(final EthPeer peer) {
.map(Capability::toString)
.map(TextNode::new)
.collect(Collectors.toList()))
.network(new NetworkResult(connection.getLocalAddress(), connection.getRemoteAddress()))
.network(
new NetworkResult(
connection.getLocalAddress(),
connection.getRemoteAddress(),
connection.inboundInitiated()))
.port(Quantity.create(peerInfo.getPort()))
.id(peerInfo.getNodeId().toString())
.protocols(Map.of(peer.getProtocolName(), ProtocolsResult.fromEthPeer(peer)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,22 @@ public class NetworkResultTest {
@Test
public void localAndRemoteAddressShouldNotStartWithForwardSlash() {
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.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