public ClientNetwork(String nodeUrl, PrivateKey privateKey, BasicHttpClientSession session) throws IOException { client = new Client(nodeUrl, privateKey, session); if (client == null) throw new IOException("failed to connect to to the universa network"); reporter.verbose("Read Universa network configuration: " + client.size() + " nodes"); reporter.message("Network version: " + client.getVersion()); }
private static void finish() { finish(reporter.getErrors().size()); }
static public BasicHttpClientSession getSession(int nodeNumber) throws IOException { if (session == null) { String keyFileName = prefs.get("session_" + nodeNumber, null); if (keyFileName != null) { reporter.verbose("Loading session from " + keyFileName); try { session = BasicHttpClientSession.reconstructSession(Boss.unpack(Do.read(keyFileName))); } catch(FileNotFoundException e) { // it is ok - session is not reconstructed } catch (Exception e) { reporter.warning("can't read session file: " + keyFileName); e.printStackTrace(); } } else { reporter.verbose("No session found at the prefs "); } } return session; }
public ClientNetwork(BasicHttpClientSession session, boolean delayedStart) throws IOException { for (int i = 1; i < 10; i++) { try { client = new Client("http://node-" + Do.randomIntInRange(1, 10) + "-com.universa.io:8080", CLIMain.getPrivateKey(), session, delayedStart); break; } catch (IOException e) { reporter.warning("failed to read network from node " + i); } } if (client == null) throw new IOException("failed to connect to to the universa network"); reporter.verbose("Read Universa network configuration: " + client.size() + " nodes"); reporter.message("Network version: " + client.getVersion()); }
public void verbose(String text) { if (verboseMode) message(text); }
reporter.message("The capsule is not sealed properly:"); contract.getErrors().forEach(e -> reporter.error(e.getError().toString(), e.getObjectName(), e.getMessage())); if (reporter.isVerboseMode()) { reporter.error(Errors.BAD_REVOKE.name(), r.getId().toString(), "revocation not allowed"); } catch (Exception clientError) { clientError.printStackTrace(); reporter.newLine();
es.submit(() -> { final String url = nodes.get(nodeNumber).url; reporter.verbose("Checking node " + url); for (int i = 0; i < 5; i++) { try { if (client.ping(nodeNumber)) { okNodes.getAndIncrement(); reporter.verbose("Got an answer from " + url); return; reporter.message("retry #" + (i+1) + " on connection failure: " + url); Thread.sleep(200); } catch (InterruptedException e) { reporter.error(Errors.NOT_READY.name(), url, "failed to connect"); }) ); f.get(4, TimeUnit.SECONDS); } catch (TimeoutException e) { reporter.verbose("node test is timed out"); f.cancel(true); } catch (Exception e) { int n = okNodes.get(); if (n >= client.size() * 0.12) reporter.message("Universa network is active, " + n + " node(s) are reachable"); else reporter.error("NOT_READY", "network", "Universa network is temporarily inaccessible, reachable nodes: " + n);
reporter.warning("errors from " + c.getNodeNumber() + ": " + r.errors); break; }); if (consensus[0] != null) reporter.message("State consensus found:" + consensus[0]); else { reporter.warning("no consensus found " + states.size()); .forEach(kv -> { List<ItemResult> itemResults = kv.getValue(); reporter.message("" + kv.getKey() + ": " + itemResults.size() + ": " + itemResults.stream() .map(x -> x.meta.getStringOrThrow("url"))
/** * Check bytes is contract. And if bytes is, check contract for errors. Print errors if found. * * @param data - data to check. * * @return true if bytes is Contract and Contract is valid. */ private static Boolean checkBytesIsValidContract(byte[] data) { try { Contract contract = new Contract(data); if (!contract.isOk()) { reporter.message("The capsule is not sealed"); contract.getErrors().forEach(e -> reporter.error(e.getError().toString(), e.getObjectName(), e.getMessage())); } checkContract(contract); } catch (RuntimeException e) { addError(Errors.BAD_VALUE.name(), "byte[] data", e.getMessage()); return false; } catch (Quantiser.QuantiserException e) { addError("QUANTIZER_COST_LIMIT", "", e.toString()); } catch (IOException e) { addError(Errors.BAD_VALUE.name(), "byte[] data", e.getMessage()); return false; } return true; }
Config.forceInit(Parcel.class); reporter.clear(); reporter.setQuiet(true); } else { reporter.setQuiet(false); usage("No options: " + e.getMessage()); } catch (Finished e) { if (reporter.isQuiet()) System.out.println(reporter.reportJson()); if(!options.has("no-exit")) { System.exit(e.getStatus());
/** * Outputs newline on the console only (does nothing in quiet more). */ public void newLine() { console("\n"); }
private static void addError(String code, String object, String message) { reporter.error(code, object, message); }
@Test public void checkTheNetwork() throws Exception { Reporter r = callMain("--network", "--verbose"); assertThat(r.getMessage(-1) + r.getMessage(-2) + r.getMessage(-3) + r.getMessage(-4) + r.getMessage(-5), matches("3 node")); }
@Test public void checkNetwork() throws Exception { ClientNetwork n = new ClientNetwork(null); assertEquals(36, n.size()); ConsoleInterceptor.copyOut(() -> { int active = n.checkNetworkState(new Reporter()); assertEquals(36, active); }); } }
String keyFileName = prefs.get("privateKeyFile", null); if (keyFileName != null) { reporter.verbose("Loading private key from " + keyFileName); try { privateKey = new PrivateKey(Do.read(keyFileName)); } catch (IOException e) { reporter.warning("can't read privte Key file: " + keyFileName); reporter.warning("\nUser private key is not set, generating new one."); reporter.message("new private key has been generated"); privateKey = new PrivateKey(2048); reporter.verbose("creating new keys directory: " + keysDir.toString()); final Set<PosixFilePermission> perms = PosixFilePermissions.fromString("rwx------"); final FileAttribute<Set<PosixFilePermission>> ownerOnly = PosixFilePermissions.asFileAttribute(perms);
public void warning(String msg) { message(msg); }
public ClientNetwork(String nodeUrl, BasicHttpClientSession session, boolean delayedStart) throws IOException { client = new Client(nodeUrl, CLIMain.getPrivateKey(), session, delayedStart); if (client == null) throw new IOException("failed to connect to to the universa network"); reporter.verbose("Read Universa network configuration: " + client.size() + " nodes"); reporter.message("Network version: " + client.getVersion()); }
private static void report(String message) { reporter.message(message); }
private static void checkSj(Contract contract, Permission sj) { Binder params = sj.getParams(); String fieldName = "state.data." + params.getStringOrThrow("field_name"); reporter.verbose("splitjoins permission fond on field '" + fieldName + "'"); StringBuilder outcome = new StringBuilder(); List<Decimal> values = new ArrayList<>(); reporter.verbose("operation is: "+ outcome.toString()); Decimal saldo = values.stream().reduce(Decimal.ZERO, (a, b) -> a.add(b)); if( saldo.compareTo(Decimal.ZERO) == 0 ) reporter.verbose("Saldo looks good (zero)"); else reporter.warning("Saldo is not zero: "+saldo);
private static Reporter callMain(String... args) throws Exception { output = ConsoleInterceptor.copyOut(() -> { String[] argsNew = new String[args.length+1]; for(int i =0; i< args.length;i++) { argsNew[i] = args[i]; } argsNew[args.length] = "--no-exit"; CLIMain.main(argsNew); errors = CLIMain.getReporter().getErrors(); }); return CLIMain.getReporter(); }