private final void onReceived(byte[] packedNotifications) { try { if (consumer != null) { List<Notification> nn = unpack(packedNotifications); for (Notification n : nn) { if( n == null ) report(getLabel(), "bad notification skipped", DatagramAdapter.VerboseLevel.BASE); else { logNotification(n,null); consumer.accept(n); } } } } catch (IOException e) { report(getLabel(), "ignoring notification, " + e, DatagramAdapter.VerboseLevel.BASE); } }
@Override public void deliver(NodeInfo toNode, Notification notification) { try { byte[] data = packNotifications(myInfo, Do.listOf(notification)); logNotification(notification,toNode); if(adapter != null) { adapter.send(toNode, data); } else { report(getLabel(), "UDPAdapter is null"); } } catch (InterruptedException e) { report(getLabel(), "Expected interrupted exception"); } catch (Exception e) { report(getLabel(), "deliver exception: " + e.getMessage()); e.printStackTrace(); } }
/** * Set verbose level via {@link UDPAdapter} */ public void restartUDPAdapter() { try { network.restartUDPAdapter(); } catch (IOException e) { e.printStackTrace(); } }
report(getLabel(), "notification TO null"); return; report(getLabel(), "notification FROM null"); return; report(getLabel(), () -> concatReportMessage( from.getNumber(), "->", DatagramAdapter.VerboseLevel.DETAILED); } else if(notification instanceof ItemNotification) { report(getLabel(), () -> concatReportMessage( from.getNumber(), "->", DatagramAdapter.VerboseLevel.DETAILED); } else { report(getLabel(), () -> concatReportMessage("unknown notification ",notification.getClass().getName()));
NodeInfo from = getInfo(number); if (from == null) throw new IOException(myInfo.getNumber()+": unknown node number: " + number); } catch (Exception e) { report(getLabel(), "failed to unpack notification: " + e, DatagramAdapter.VerboseLevel.BASE); throw new IOException("failed to unpack notifications", e);
public void report(String label, String message) { report(label, message, DatagramAdapter.VerboseLevel.DETAILED); }
}); network = new NetworkV2(netConfig, myInfo, nodeKey); node = new Node(config, myInfo, ledger, network, nodeKey); cache = node.getCache();
assertEquals (DatagramAdapter.VerboseLevel.NOTHING, main.network.getVerboseLevel()); assertEquals (DatagramAdapter.VerboseLevel.NOTHING, main.node.getVerboseLevel()); ItemResult itemResult2 = client.getState(parcel2.getPayloadContract().getId()); assertEquals (DatagramAdapter.VerboseLevel.BASE, main.network.getVerboseLevel()); assertEquals (DatagramAdapter.VerboseLevel.BASE, main.node.getVerboseLevel()); ItemResult itemResult3 = client.getState(parcel3.getPayloadContract().getId()); assertEquals (DatagramAdapter.VerboseLevel.NOTHING, main.network.getVerboseLevel()); assertEquals (DatagramAdapter.VerboseLevel.NOTHING, main.node.getVerboseLevel());
assertEquals (DatagramAdapter.VerboseLevel.NOTHING, main.network.getUDPVerboseLevel()); ItemResult itemResult2 = client.getState(parcel2.getPayloadContract().getId()); assertEquals (DatagramAdapter.VerboseLevel.BASE, main.network.getUDPVerboseLevel()); ItemResult itemResult4 = client.getState(parcel4.getPayloadContract().getId()); assertEquals (DatagramAdapter.VerboseLevel.DETAILED, main.network.getUDPVerboseLevel()); ItemResult itemResult3 = client.getState(parcel3.getPayloadContract().getId()); assertEquals (DatagramAdapter.VerboseLevel.NOTHING, main.network.getUDPVerboseLevel());
@Override public NImmutableEnvironment getEnvironment(HashId itemId, NodeInfo nodeInfo, Duration maxTimeout) throws InterruptedException { try { System.out.println("getEnvironment " + itemId.toBase64String()); // URL url = new URL("http://localhost:8080/contracts/" + itemId.toBase64String()); URL url = new URL(nodeInfo.publicUrlString() + "/environments/" + itemId.toBase64String()); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestProperty("User-Agent", "Universa JAVA API Client"); connection.setRequestProperty("Connection", "close"); connection.setRequestMethod("GET"); if (200 != connection.getResponseCode()) return null; byte[] data = Do.read(connection.getInputStream()); return Boss.load(data); } catch (Exception e) { report(getLabel(), "download failure. from: " + nodeInfo.getNumber() + " by: " + myInfo.getNumber() +" reason: " + e, DatagramAdapter.VerboseLevel.BASE); e.printStackTrace(); return null; } }
public void report(String label, Callable<String> message) { report(label, message, DatagramAdapter.VerboseLevel.DETAILED); }
@Override public Parcel getParcel(HashId itemId, NodeInfo nodeInfo, Duration maxTimeout) throws InterruptedException { try { // URL url = new URL("http://localhost:8080/contracts/" + itemId.toBase64String()); URL url = new URL(nodeInfo.publicUrlString() + "/parcels/" + itemId.toBase64String()); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestProperty("User-Agent", "Universa JAVA API Client"); connection.setRequestProperty("Connection", "close"); connection.setRequestMethod("GET"); if (200 != connection.getResponseCode()) return null; byte[] data = Do.read(connection.getInputStream()); Parcel parcel = Parcel.unpack(data); // tp.trace(); // Contract c = Contract.fromPackedTransaction(data); return parcel; } catch (Exception e) { report(getLabel(), "download failure. from: " + nodeInfo.getNumber() + " by: " + myInfo.getNumber() +" reason: " + e); return null; } }
@Override public Approvable getItem(HashId itemId, NodeInfo nodeInfo, Duration maxTimeout) throws InterruptedException { try { // URL url = new URL("http://localhost:8080/contracts/" + itemId.toBase64String()); URL url = new URL(nodeInfo.publicUrlString() + "/contracts/" + itemId.toBase64String()); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestProperty("User-Agent", "Universa JAVA API Client"); connection.setRequestProperty("Connection", "close"); connection.setRequestMethod("GET"); if (200 != connection.getResponseCode()) return null; byte[] data = Do.read(connection.getInputStream()); TransactionPack tp = TransactionPack.unpack(data, true); // tp.trace(); // Contract c = Contract.fromPackedTransaction(data); return tp.getContract(); } catch (Exception e) { report(getLabel(), "download failure. from: " + nodeInfo.getNumber() + " by: " + myInfo.getNumber() +" reason: " + e, DatagramAdapter.VerboseLevel.BASE); e.printStackTrace(); return null; } }