void addEndpoint(String path, SimpleEndpoint sep) { addEndpoint(path, (params, result) -> { result.putAll(sep.execute(params)); }); }
void addEndpoint(String path, SimpleEndpoint sep) { addEndpoint(path, (params, result) -> { result.putAll(sep.execute(params)); }); }
/** * Get session of http client connected to node with given number * * @param i number of the node to return session with * @return session */ public BasicHttpClientSession getSession(int i) throws IllegalStateException, IOException { return getClient(i).httpClient.getSession(); }
/** * Register packed binary contract and wait for the consensus. * * @param packedContract * @param millisToWait wait for the consensus as long as specified time, <= 0 means no wait (returns some pending * state from registering). * @return last item status returned by the network * @throws ClientError */ public ItemResult register(byte[] packedContract, long millisToWait) throws ClientError { return client.register(packedContract, millisToWait); }
/** * We have received {@link PacketTypes#KEY_REQ_PART1} packet. Waiting for part2 or continue if it has got already. * @param packet received {@link Packet} */ private void onReceiveKeyReqPart1(Packet packet) { report(logLabel, ()->"received key_req_part1 from " + packet.senderNodeId + " (packetId="+packet.packetId+")", VerboseLevel.BASE); SessionReader sessionReader = getOrCreateSessionReaderCandidate(packet.senderNodeId); if (sessionReader != null) { sessionReader.protectFromDuples(packet.packetId, ()->{ sessionReader.removeHandshakePacketsFromRetransmitMap(); sessionReader.handshake_keyReqPart1 = packet.payload; onReceiveKeyReq(sessionReader); }); } }
/** * Get extended statistics of the node including by-day payments in "U". Accessible to node owners (with node {@link PrivateKey} as session key) and network admins * @return dictionary containing uptime, ledger size, and number of contracts approved for a minute, hour and since restart. it also contains by-day payments information * @param showPaymentsDays the number of days to provide payments volume for * @throws ClientError */ public Binder getStats(Integer showPaymentsDays) throws ClientError { return protect(() -> httpClient.command("getStats","showDays",showPaymentsDays)); }
protected final <T> T protect(Executor<T> e) throws ClientError { try { return e.execute(); } catch (Exception ex) { //ex.printStackTrace(); throw new ClientError(ex); } }
/** * We have received {@link PacketTypes#SESSION_ACK} packet. * Need to stop retransmitting of any handshake packets. * @param packet received {@link Packet} */ private void onReceiveSessionAck(Packet packet) { report(logLabel, ()->"received session_ack from " + packet.senderNodeId, VerboseLevel.BASE); SessionReader sessionReader = getSessionReader(packet.senderNodeId); if (sessionReader != null) { sessionReader.removeHandshakePacketsFromRetransmitMap(); } } }
/** * Execude custom command on the node * @param name name of the command * @param params parameters of the command * @return execution result */ public Binder command(String name, Object... params) throws IOException { return httpClient.command(name, params); }
/** * Start http client (used with constructor passing delayedStart = true) * @param session set to null or to the reconstructed instance * @throws IOException */ public void start(BasicHttpClientSession session) throws IOException { httpClient.start(clientPrivateKey, nodePublicKey, session); }
public void setNeworkVerboseLevel(int level) { if(network instanceof NetworkV2) { ((NetworkV2)network).setVerboseLevel(level); } }
/** * Restart http client * @throws IOException */ public void restart() throws IOException { httpClient.restart(); }
/** * Get number of node cliet connection is established with * @return number of node */ public int getNodeNumber() { return httpClient.getNodeNumber(); } /**
public RetransmitItem(Packet packet, byte[] sourcePayload) { this.packet = packet; this.sourcePayload = sourcePayload; this.retransmitCounter = 0; this.receiverNodeId = packet.receiverNodeId; this.packetId = packet.packetId; this.type = packet.type; updateNextRetransmitTime(); } public void updateNextRetransmitTime() {
/** * Get session of http client * * @return session */ public BasicHttpClientSession getSession() throws IllegalStateException { return httpClient.getSession(); }
/** * Register contract on the network without payment. May require special client key / network configuration * @param packed {@link com.icodici.universa.contract.TransactionPack} binary * @return result of registration * @throws ClientError */ public ItemResult register(byte[] packed) throws ClientError { return register(packed, 0); }
/** * We have received {@link PacketTypes#KEY_REQ_PART2} packet. Waiting for part1 or continue if it has got already. * @param packet received {@link Packet} */ private void onReceiveKeyReqPart2(Packet packet) { report(logLabel, ()->"received key_req_part2 from " + packet.senderNodeId + " (packetId="+packet.packetId+")", VerboseLevel.BASE); SessionReader sessionReader = getOrCreateSessionReaderCandidate(packet.senderNodeId); if (sessionReader != null) { sessionReader.protectFromDuples(packet.packetId, ()->{ sessionReader.removeHandshakePacketsFromRetransmitMap(); sessionReader.handshake_keyReqPart2 = packet.payload; onReceiveKeyReq(sessionReader); }); } }
/** * Look for the name assosiated with a given address * @param address to look for * @return {@link Binder} containing name, description and url associated with address or null * @throws ClientError */ public Binder queryNameRecord(String address) throws ClientError { return protect(() -> { Binder result = httpClient.command("queryNameRecord", "address", address); return result; }); }
/** * Get current network rate for operating FOLLOWER1 contracts * @return {@link Binder} containing origins-days per U rate and callback price in U * @throws ClientError */ public Binder followerGetRate() throws ClientError { return protect(() -> { Binder result = httpClient.command("followerGetRate"); return result; }); }