class EthStatsService {

  public void start() {

    try {

      enodeURL = p2PNetwork.getLocalEnode().orElseThrow();

      vertx
          .createHttpClient(httpClientOptions)
          .webSocket(
              webSocketConnectOptions,
              event -> {
                if (event.succeeded()) {
                  webSocket = event.result();

                  // reconnect if we lose the connection or if an error occurs
                  webSocket.exceptionHandler(ex -> retryConnect());
                  webSocket.closeHandler(handler -> retryConnect());

                  // listen to the messages from the ethstats server in order to validate the
                  // connection
                  webSocket.textMessageHandler(
                      ack -> {
                        EthStatsRequest ethStatsRequest = EthStatsRequest.fromResponse(ack);
                        if (ethStatsRequest.getType().equals(READY)) {
                          LOG.info("Connected to ethstats server");

                          // listen to messages from the ethstats server
                          startListeningEthstatsServer();
                          // send a full report after the connection
                          sendFullReport();
                        } else {
                          LOG.error("Failed to login to ethstats server {}", ack);
                        }
                      });

                  // sending a hello to initiate the connection using the secret
                  sendHello();
                } else {
                  String errorMessage =
                      "Failed to reach the ethstats server " + event.cause().getMessage();
                  if (event.cause() instanceof SSLHandshakeException) {
                    webSocketConnectOptions.setSsl(false);
                    errorMessage += " (trying without ssl)";
                  }
                  LOG.error(errorMessage);
                  retryConnect();
                }
              });
    } catch (Exception e) {
      retryConnect();
    }
  }

  public  EthStatsService(
      final NetstatsUrl netstatsUrl,
      final BlockchainQueries blockchainQueries,
      final EthProtocolManager protocolManager,
      final TransactionPool transactionPool,
      final MiningCoordinator miningCoordinator,
      final SyncState syncState,
      final Vertx vertx,
      final String clientVersion,
      final GenesisConfigOptions genesisConfigOptions,
      final P2PNetwork p2PNetwork);

}