PAN-2577 - missing p2p info when queried live (#1310)

It turns out we don't have the p2p host and port at RPC initialization.
To fix this change to query hosts and ports at method invocaiton time
instead of whent he constructor is called.
Signed-off-by: Adrian Sutton <adrian.sutton@consensys.net>
pull/2/head
Danno Ferrin 6 years ago committed by GitHub
parent 20b0c420ff
commit b184320826
  1. 44
      ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/NetServices.java

@ -24,15 +24,30 @@ import com.google.common.collect.ImmutableMap;
public class NetServices implements JsonRpcMethod {
private final ImmutableMap<String, ImmutableMap<String, String>> services;
private final JsonRpcConfiguration jsonRpcConfiguration;
private final WebSocketConfiguration webSocketConfiguration;
private final P2PNetwork p2pNetwork;
private final MetricsConfiguration metricsConfiguration;
public NetServices(
final JsonRpcConfiguration jsonRpcConfiguration,
final WebSocketConfiguration webSocketConfiguration,
final P2PNetwork p2pNetwork,
final MetricsConfiguration metricsConfiguration) {
this.jsonRpcConfiguration = jsonRpcConfiguration;
this.webSocketConfiguration = webSocketConfiguration;
this.p2pNetwork = p2pNetwork;
this.metricsConfiguration = metricsConfiguration;
}
ImmutableMap.Builder<String, ImmutableMap<String, String>> servicesMapBuilder =
@Override
public String getName() {
return "net_services";
}
@Override
public JsonRpcResponse response(final JsonRpcRequest req) {
final ImmutableMap.Builder<String, ImmutableMap<String, String>> servicesMapBuilder =
ImmutableMap.builder();
if (jsonRpcConfiguration.isEnabled()) {
@ -47,15 +62,12 @@ public class NetServices implements JsonRpcMethod {
webSocketConfiguration.getHost(), webSocketConfiguration.getPort()));
}
if (p2pNetwork.isP2pEnabled()) {
if (p2pNetwork.isP2pEnabled()) {
p2pNetwork
.getLocalEnode()
.ifPresent(
enode -> {
p2pNetwork
.getLocalEnode()
.ifPresent(
enode ->
servicesMapBuilder.put(
"p2p", createServiceDetailsMap(enode.getIp(), enode.getListeningPort()));
});
}
"p2p", createServiceDetailsMap(enode.getIp(), enode.getListeningPort())));
}
if (metricsConfiguration.isEnabled()) {
servicesMapBuilder.put(
@ -63,17 +75,7 @@ public class NetServices implements JsonRpcMethod {
createServiceDetailsMap(metricsConfiguration.getHost(), metricsConfiguration.getPort()));
}
services = servicesMapBuilder.build();
}
@Override
public String getName() {
return "net_services";
}
@Override
public JsonRpcResponse response(final JsonRpcRequest req) {
return new JsonRpcSuccessResponse(req.getId(), services);
return new JsonRpcSuccessResponse(req.getId(), servicesMapBuilder.build());
}
private ImmutableMap<String, String> createServiceDetailsMap(final String host, final int port) {

Loading…
Cancel
Save