Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

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

Merged
merged 3 commits into from
Apr 22, 2019
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,30 @@

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()) {
Expand All @@ -47,33 +62,20 @@ public NetServices(
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(
"metrics",
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) {
Expand Down