[PAN-2703] JSON-RPC api net_services should display the actual ports (#1628)

Currently when json-rpc and ws services are configured with a port value of 0, the "net_services" endpoint will display their ports as "0".  A configured port of "0" actually means "choose a random port".  We need to get the actual port that those services are using displayed in the "net_services" JSON-RPC response.
Signed-off-by: Adrian Sutton <adrian.sutton@consensys.net>
pull/2/head
Abdelhamid Bakhta 5 years ago committed by GitHub
parent f5e841c018
commit 8e3a8e1984
  1. 6
      acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/condition/net/ExpectNetServicesReturnsAllServicesAsActive.java
  2. 3
      acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/condition/net/ExpectNetServicesReturnsOnlyJsonRpcActive.java
  3. 6
      ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcHttpService.java
  4. 5
      ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/websocket/WebSocketService.java

@ -44,12 +44,10 @@ public class ExpectNetServicesReturnsAllServicesAsActive implements Condition {
assertThat(InetAddresses.isUriInetAddress(result.get("ws").get("host"))).isTrue(); assertThat(InetAddresses.isUriInetAddress(result.get("ws").get("host"))).isTrue();
final int wsPort = Integer.valueOf(result.get("ws").get("port")); final int wsPort = Integer.valueOf(result.get("ws").get("port"));
// TODO: Port should not be 0-valued. Refer to PAN-2703 assertThat(NetworkUtility.isValidPort(wsPort)).isTrue();
assertThat(NetworkUtility.isValidPort(p2pPort) || wsPort == 0).isTrue();
assertThat(InetAddresses.isUriInetAddress(result.get("jsonrpc").get("host"))).isTrue(); assertThat(InetAddresses.isUriInetAddress(result.get("jsonrpc").get("host"))).isTrue();
final int jsonRpcPort = Integer.valueOf(result.get("jsonrpc").get("port")); final int jsonRpcPort = Integer.valueOf(result.get("jsonrpc").get("port"));
// TODO: Port should not be 0-valued. Refer to PAN-2703 assertThat(NetworkUtility.isValidPort(jsonRpcPort)).isTrue();
assertThat(NetworkUtility.isValidPort(p2pPort) || jsonRpcPort == 0).isTrue();
} }
} }

@ -40,7 +40,6 @@ public class ExpectNetServicesReturnsOnlyJsonRpcActive implements Condition {
assertThat(InetAddresses.isUriInetAddress(result.get("jsonrpc").get("host"))).isTrue(); assertThat(InetAddresses.isUriInetAddress(result.get("jsonrpc").get("host"))).isTrue();
final int jsonrpcPort = Integer.valueOf(result.get("jsonrpc").get("port")); final int jsonrpcPort = Integer.valueOf(result.get("jsonrpc").get("port"));
// TODO: Port should not be 0-valued. Refer to PAN-2703 assertThat(NetworkUtility.isValidPort(jsonrpcPort)).isTrue();
assertThat(NetworkUtility.isValidPort(jsonrpcPort) || jsonrpcPort == 0).isTrue();
} }
} }

@ -203,10 +203,10 @@ public class JsonRpcHttpService {
res -> { res -> {
if (!res.failed()) { if (!res.failed()) {
resultFuture.complete(null); resultFuture.complete(null);
final int actualPort = httpServer.actualPort();
LOG.info( LOG.info(
"JsonRPC service started and listening on {}:{}", "JsonRPC service started and listening on {}:{}", config.getHost(), actualPort);
config.getHost(), config.setPort(actualPort);
httpServer.actualPort());
return; return;
} }
httpServer = null; httpServer = null;

@ -178,11 +178,12 @@ public class WebSocketService {
return res -> { return res -> {
if (res.succeeded()) { if (res.succeeded()) {
final int actualPort = res.result().actualPort();
LOG.info( LOG.info(
"Websocket service started and listening on {}:{}", "Websocket service started and listening on {}:{}",
configuration.getHost(), configuration.getHost(),
res.result().actualPort()); actualPort);
configuration.setPort(actualPort);
resultFuture.complete(null); resultFuture.complete(null);
} else { } else {
resultFuture.completeExceptionally(res.cause()); resultFuture.completeExceptionally(res.cause());

Loading…
Cancel
Save