public void execute() { try { LOG.info("Starting Ethereum main loop ... "); networkRunner.start(); if (networkRunner.getNetwork().isP2pEnabled()) { pantheonController.getSynchronizer().start(); } jsonRpc.ifPresent(service -> service.start().join()); websocketRpc.ifPresent(service -> service.start().join()); metrics.ifPresent(service -> service.start().join()); LOG.info("Ethereum main loop is up."); writePantheonPortsToFile(); networkRunner.awaitStop(); } catch (final InterruptedException e) { LOG.debug("Interrupted, exiting", e); Thread.currentThread().interrupt(); } catch (final Exception ex) { LOG.error("Exception in main loop:", ex); throw new IllegalStateException(ex); } }
@Override public void close() throws Exception { networkRunner.stop(); networkRunner.awaitStop(); exec.shutdown(); try { jsonRpc.ifPresent(service -> service.stop().join()); websocketRpc.ifPresent(service -> service.stop().join()); metrics.ifPresent(service -> service.stop().join()); } finally { try { exec.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS); } finally { try { vertx.close(); } finally { pantheonController.close(); } } } }
NetworkRunner.builder() .subProtocols(EthProtocol.get()) .protocolManagers(singletonList(ethProtocolManager)) .metricsSystem(new NoOpMetricsSystem()) .build(); network = networkRunner.getNetwork(); this.port = network.getLocalPeerInfo().getPort(); network.subscribeDisconnect( transactionPool = TransactionPoolFactory.createTransactionPool(protocolSchedule, protocolContext, ethContext); networkRunner.start();
NetworkRunner.builder() .protocolManagers(protocolManagers) .subProtocols(subProtocols) protocolSchedule, pantheonController, networkRunner.getNetwork(), synchronizer, transactionPool, protocolSchedule, pantheonController, networkRunner.getNetwork(), synchronizer, transactionPool,
public int getP2pUdpPort() { return networkRunner.getNetwork().getDiscoverySocketAddress().getPort(); }
public int getP2pTcpPort() { return networkRunner.getNetwork().getLocalPeerInfo().getPort(); } }
private void writePantheonPortsToFile() { final Properties properties = new Properties(); if (networkRunner.getNetwork().isListening()) { properties.setProperty("discovery", String.valueOf(getP2pUdpPort())); properties.setProperty("p2p", String.valueOf(getP2pTcpPort())); } if (getJsonRpcPort().isPresent()) { properties.setProperty("json-rpc", String.valueOf(getJsonRpcPort().get())); } if (getWebsocketPort().isPresent()) { properties.setProperty("ws-rpc", String.valueOf(getWebsocketPort().get())); } if (getMetricsPort().isPresent()) { properties.setProperty("metrics", String.valueOf(getMetricsPort().get())); } final File portsFile = new File(dataDir.toFile(), "pantheon.ports"); portsFile.deleteOnExit(); try (final FileOutputStream fileOutputStream = new FileOutputStream(portsFile)) { properties.store( fileOutputStream, "This file contains the ports used by the running instance of Pantheon. This file will be deleted after the node is shutdown."); } catch (final Exception e) { LOG.warn("Error writing ports file", e); } }