private void usage(String text) { log("usafe called"); boolean error = false; PrintStream out = System.out; if (text != null) { out = System.err; error = true; } out.println("\n" + NAME_STRING); if (text != null) out.println("ERROR: " + text + "\n"); try { parser.printHelpOn(out); } catch (IOException e) { e.printStackTrace(); } if (options != null && !options.has("test")) System.exit(100); } }
private void loadNetConfig() throws IOException { netConfig = new NetConfig(configRoot + "/config/nodes"); log("Network configuration is loaded from " + configRoot + ", " + netConfig.size() + " nodes."); }
/** * Request the shutdown and wait until the node stops. */ public void shutdown() { try { if (hookThread != null) Runtime.getRuntime().removeShutdownHook(hookThread); // network.close(); ledger.close(); log("shutting down"); network.shutdown(); clientHTTPServer.shutdown(); } catch (Exception e) { } synchronized (parser) { parser.notifyAll(); } try { logger.close(); } catch (Exception e) { e.printStackTrace(); } }
private void startClientHttpServer() throws Exception { log("prepare to start client HTTP server on " + myInfo.getClientAddress().getPort()); clientHTTPServer = new ClientHTTPServer(nodeKey, myInfo.getClientAddress().getPort(), logger); clientHTTPServer.setCache(cache); clientHTTPServer.setParcelCache(parcelCache); clientHTTPServer.setNetConfig(netConfig); // node = new Node() }
private void loadNodeConfig() throws IOException, SQLException { Yaml yaml = new Yaml(); configRoot = (String) options.valueOf("config"); nodeKey = null; Binder settings = Binder.of(yaml.load(new FileInputStream(configRoot + "/config/config.yaml"))); log("node settings: " + settings); String nodeKeyFileName = configRoot + "/tmp/" + settings.getStringOrThrow("node_name") + ".private.unikey"; log(nodeKeyFileName); nodeKey = new PrivateKey(Do.read(nodeKeyFileName)); myInfo = new NodeInfo(nodeKey.getPublicKey(), settings.getIntOrThrow("node_number"), settings.getStringOrThrow("node_name"), (String) settings.getListOrThrow("ip").get(0), settings.getStringOrThrow("public_host"), settings.getIntOrThrow("udp_server_port"), settings.getIntOrThrow("http_client_port"), settings.getIntOrThrow("http_server_port") ); config.setIsFreeRegistrationsAllowedFromYaml(settings.getBoolean("allow_free_registrations", false)); config.setPermanetMode(settings.getBoolean("permanet_mode", false)); ledger = new PostgresLedger(settings.getStringOrThrow("database")); log("ledger constructed"); log("key loaded: " + nodeKey.info()); log("node local URL: " + myInfo.publicUrlString()); log("node info: " + myInfo.toBinder()); }
log(NAME_STRING); } else if(options.has("database")) { ledger = new PostgresLedger((String) options.valueOf("database")); log("ledger constructed"); Object[] result = ledger.loadConfig(); myInfo = (NodeInfo) result[0]; log("key loaded: " + nodeKey.info()); log("node local URL: " + myInfo.publicUrlString()); log("node info: " + myInfo.toBinder()); log("--------------- step 3 --------------------"); log("Starting the client HTTP server..."); startClientHttpServer(); log("--------------- step 4 --------------------"); log("Starting the Universa node service..."); startNode(); log("all initialization is done -----------------------------------"); startAndWaitEnd(); } catch (OptionException e) { } catch (InterruptedException e) { e.printStackTrace(); log("interrupted exception, leaving"); System.err.println("interrupted exception, leaving"); } catch (Exception e) {
resyncBreak += 1; log(myInfo.getNumber() + ": Network consensus is set to (negative/positive/resyncBreak): " + negative + " / " + positive + " / " + resyncBreak); config.setPositiveConsensus(positive); config.setNegativeConsensus(negative);