node = new Node(config, myInfo, ledger, network, nodeKey); cache = node.getCache(); parcelCache = node.getParcelCache(); envCache = node.getEnvCache();
@SuppressWarnings("deprecation") //outdated method. will be replaced with new one soon private void checkForNetConfig(Contract contract) { if (contract.getIssuer().getKeys().stream().anyMatch(key -> config.getNetworkReconfigKeyAddress().isMatchingKey(key))) { if(contract.getParent() == null) return; if(contract.getRevoking().size() == 0 || !contract.getRevoking().get(0).getId().equals(contract.getParent())) return; Contract parent = contract.getRevoking().get(0); if(!checkContractCorrespondsToConfig(parent,network.allNodes())) { return; } if(!checkIfContractContainsNetConfig(contract)) { return; } List<NodeInfo> networkNodes = network.allNodes(); List contractNodes = (List)DefaultBiMapper.getInstance().deserializeObject(contract.getStateData().get("net_config")); contractNodes.stream().forEach(nodeInfo -> { if(!networkNodes.contains(nodeInfo)) { addNode((NodeInfo) nodeInfo); } networkNodes.remove(nodeInfo); }); networkNodes.stream().forEach( nodeInfo -> removeNode(nodeInfo)); } }
private Binder getContract(Binder params, Session session) throws IOException { checkNode(session, true); Binder res = new Binder(); if (!node.getConfig().isPermanetMode()) return res; HashId origin = (HashId) params.get("origin"); int limit = params.getInt("limit", 100); if (limit > node.getConfig().getQueryContractsLimit()) limit = node.getConfig().getQueryContractsLimit(); if (limit < 1) limit = 1; Object keeping = node.getLedger().getKeepingByOrigin(origin, limit); if (keeping == null) return res; if (keeping instanceof byte[]) res.put("packedContract", keeping); else if (keeping instanceof List) res.put("contractIds", keeping); return res; }
node.registerParcel(parcel); n.waitParcel(parcel.getId(), 15000); ItemResult itemResult = n.waitItem(stepaCoins.getId(), 15000); ItemState itemState1 = node.waitItem(parcel.getPaymentContract().getRevoking().get(0).getId(), 15000).state; ItemState itemState2 = node.getLedger().getRecord(parcel.getPaymentContract().getRevoking().get(0).getId()).getState();
@Test(timeout = 15000) public void resyncOther() throws Exception { Contract c = new Contract(TestKeys.privateKey(0)); c.seal(); addToAllLedgers(c, ItemState.PENDING_POSITIVE); node.getLedger().getRecord(c.getId()).destroy(); assertEquals(ItemState.UNDEFINED, node.checkItem(c.getId()).state); node.resync(c.getId()); assertEquals(ItemState.PENDING, node.checkItem(c.getId()).state); assertEquals(ItemState.UNDEFINED, node.waitItem(c.getId(), 12000).state); }
private Binder getBody(Binder params, Session session) throws IOException { checkNode(session, true); Binder res = new Binder(); if (!node.getConfig().isPermanetMode()) return res; HashId itemId = (HashId) params.get("itemId"); byte[] body = node.getLedger().getKeepingItem(itemId); if (body != null) { res.put("packedContract", body); return res; } node.resync(itemId); ItemResult itemResult = node.checkItem(itemId); if (itemResult == ItemResult.UNDEFINED) return res; Approvable item = node.getKeepingItemFromNetwork(itemId); if (item == null) return res; if ((item instanceof Contract) && (item.getId().equals(itemId)) && (HashId.of(((Contract) item).getLastSealedBinary()).equals(itemId))) { StateRecord record = node.getLedger().getRecord(itemId); node.getLedger().putKeepingItem(record, item); body = ((Contract) item).getPackedTransaction(); res.put("packedContract", body); } return res; }
Set<Long> envs = testSpace.node.node.getLedger().getSubscriptionEnviromentIds(simpleContract.getOrigin()); if(envs.size() > 0) { for(Long envId : envs) { NImmutableEnvironment environment = testSpace.node.node.getLedger().getEnvironment(envId); for (ContractSubscription foundCss : environment.subscriptions()) { System.out.println("expected: " + calculateExpires); envs = networkNode.node.getLedger().getSubscriptionEnviromentIds(simpleContract.getOrigin()); if(envs.size() > 0) { for(Long envId : envs) { NImmutableEnvironment environment = networkNode.node.getLedger().getEnvironment(envId); for (ContractSubscription foundCss : environment.subscriptions()) { System.out.println("expected: " + calculateExpires); absentNodeNumbers.add(testSpace.nodes.get(1).node.getNumber()); testSpace.nodes.get(1).shutdown(); testSpace.nodes.remove(1); envs = networkNode.node.getLedger().getSubscriptionEnviromentIds(simpleContract.getOrigin()); if(envs.size() > 0) { for(Long envId : envs) { NImmutableEnvironment environment = networkNode.node.getLedger().getEnvironment(envId); for (ContractSubscription foundCss : environment.subscriptions()) { System.out.println("expected: " + calculateExpires.minusSeconds(seconds * 2)); int absentNodeNumber = testSpace.nodes.get(absentNode).node.getNumber(); testSpace.nodes.get(absentNode).shutdown(); testSpace.nodes.remove(absentNode);
private Binder queryNameContract(Binder params, Session session) throws IOException { checkNode(session, true); Binder b = new Binder(); String nameContract = params.getStringOrThrow("name"); NNameRecord nr = node.getLedger().getNameRecord(nameContract); if (nr != null) { NImmutableEnvironment env = node.getLedger().getEnvironment(nr.getEnvironmentId()); if (env != null) { byte[] packedContract = env.getContract().getPackedTransaction(); b.put("packedContract", packedContract); } } return b; }
@Override public ItemResult getItemState(NodeInfo nodeInfo, HashId id) throws IOException { return nodes.get(nodeInfo).checkItem(id); }
data = node.getLedger().getContractInStorage(id); if ((data == null) && node.getConfig().isPermanetMode()) data = node.getLedger().getKeepingItem(id); NImmutableEnvironment nie = node.getLedger().getEnvironment(id); result.putAll( "version", Main.NODE_VERSION, "number", node.getNumber(), "nodes", nodes );
mm.get(i).node.addNode(main.myInfo); mm.get(i).node.removeNode(main.myInfo);
private void checkNode(Session session, boolean checkKeyLimit) throws CommandFailedException { // checking node if (node == null) { throw new CommandFailedException(Errors.NOT_READY, "", "please call again after a while"); } if(node.isSanitating()) { //WHILE NODE IS SANITATING IT COMMUNICATES WITH THE OTHER NODES ONLY if(netConfig.toList().stream().anyMatch(nodeInfo -> nodeInfo.getPublicKey().equals(session.getPublicKey()))) return; throw new CommandFailedException(Errors.NOT_READY, "", "please call again after a while"); } // checking key limit if (checkKeyLimit) if (!node.checkKeyLimit(session.getPublicKey())) throw new CommandFailedException(Errors.COMMAND_FAILED, "", "exceeded the limit of requests for key per minute, please call again after a while"); }
private Binder getStats(Binder params, Session session) throws CommandFailedException { checkNode(session, true); if (config == null || node == null || !( config.getNetworkAdminKeyAddress().isMatchingKey(session.getPublicKey()) || node.getNodeKey().equals(session.getPublicKey()) || config.getKeysWhiteList().contains(session.getPublicKey()) || config.getAddressesWhiteList().stream().anyMatch(addr -> addr.isMatchingKey(session.getPublicKey())) )) { System.out.println("command needs admin key"); return Binder.of( "itemResult", itemResultOfError(Errors.BAD_CLIENT_KEY,"getStats", "command needs admin key")); } return node.provideStats(params.getInt("showDays",null)); }
node_s = new Node(config_s, myInfo, ledger_s, network_s, getNodeKey(0)); ((TestSingleNetwork)network_s).addNode(myInfo, node_s);
setUp(); while (node.isSanitating()) { System.out.println("Node sanitating " + node.getRecordsToSanitate().size()); Thread.sleep(2000);
@Override public NImmutableEnvironment getEnvironment(HashId itemId, NodeInfo nodeInfo, Duration maxTimeout) throws InterruptedException { Node node = nodes.get(nodeInfo); return node.getEnvCache().get(itemId); }
private TestSpace prepareTestSpace(PrivateKey key) throws Exception { TestSpace testSpace = new TestSpace(); testSpace.nodes = new ArrayList<>(); for (int i = 0; i < 4; i++) testSpace.nodes.add(createMain("node" + (i + 1), "", false)); testSpace.node = testSpace.nodes.get(0); assertEquals("http://localhost:8080", testSpace.node.myInfo.internalUrlString()); assertEquals("http://localhost:8080", testSpace.node.myInfo.publicUrlString()); testSpace.myKey = key; testSpace.client = new Client(testSpace.myKey, testSpace.node.myInfo, null); testSpace.clients = new ArrayList(); for (int i = 0; i < 4; i++) testSpace.clients.add(new Client(testSpace.myKey, testSpace.nodes.get(i).myInfo, null)); for (Main m : testSpace.nodes) { while (m.node.isSanitating()) Thread.sleep(100); } return testSpace; }