public void addNode(NodeInfo n) { if( n != null ) { byNumber.put(n.getNumber(), n); byName.put(n.getName(), n); } }
public void removeNode(NodeInfo nodeInfo) { byNumber.remove(nodeInfo.getNumber()); byName.remove(nodeInfo.getName()); } }
@Override public void addNode(NodeInfo nodeInfo) { try (PooledDb db = dbPool.db()) { String sqlText = "insert into config(http_client_port,http_server_port,udp_server_port, node_number, node_name, public_host,host,public_key) values(?,?,?,?,?,?,?,?);"; try ( PreparedStatement statement = db.statementReturningKeys(sqlText) ) { statement.setInt(1, nodeInfo.getClientAddress().getPort()); statement.setInt(2, nodeInfo.getServerAddress().getPort()); statement.setInt(3, nodeInfo.getNodeAddress().getPort()); statement.setInt(4, nodeInfo.getNumber()); statement.setString(5, nodeInfo.getName()); statement.setString(6, nodeInfo.getPublicHost()); statement.setString(7, nodeInfo.getClientAddress().getHostName()); statement.setBytes(8, nodeInfo.getPublicKey().pack()); db.updateWithStatement(statement); } catch (Exception e) { e.printStackTrace(); throw e; } } catch (SQLException se) { se.printStackTrace(); throw new Failure("add node failed:" + se); } catch (Exception e) { e.printStackTrace(); } }
statement.setInt(3, nodeInfo.getNodeAddress().getPort()); statement.setInt(4, nodeInfo.getNumber()); statement.setString(5, nodeInfo.getName()); statement.setString(6, nodeInfo.getPublicHost()); statement.setString(7, nodeInfo.getClientAddress().getHostName());
public void obtainNotification(CallbackNotification notification) { node.report(DatagramAdapter.VerboseLevel.DETAILED, "Notify callback ", notification.getId().toBase64String(), " type ", notification.getType().name(), " from node ", notification.getFrom().getName()); if (notification.getType() == CallbackNotification.CallbackNotificationType.COMPLETED) { if (checkCallbackSignature(notification.getSignature())) complete(); } else if (notification.getType() == CallbackNotification.CallbackNotificationType.NOT_RESPONDING) { addNodeToSended(notification.getFrom().getNumber()); checkForComplete(); } }
private Contract createNetConfigContract(Contract contract, List<NodeInfo> netConfig, Collection<PrivateKey> currentConfigKeys) throws IOException { contract = contract.createRevision(); ListRole listRole = new ListRole("owner"); for(NodeInfo ni: netConfig) { SimpleRole role = new SimpleRole(ni.getName()); contract.registerRole(role); role.addKeyRecord(new KeyRecord(ni.getPublicKey())); listRole.addRole(role); } listRole.setQuorum(netConfig.size()-1); contract.registerRole(listRole); contract.getStateData().set("net_config",netConfig); List<KeyRecord> creatorKeys = new ArrayList<>(); for(PrivateKey key : currentConfigKeys) { creatorKeys.add(new KeyRecord(key.getPublicKey())); contract.addSignerKey(key); } contract.setCreator(creatorKeys); contract.seal(); return contract; }
private Contract createNetConfigContract(List<NodeInfo> netConfig,PrivateKey issuerKey) throws IOException { Contract contract = new Contract(); contract.setIssuerKeys(issuerKey.getPublicKey()); contract.registerRole(new RoleLink("creator", "issuer")); ListRole listRole = new ListRole("owner"); for(NodeInfo ni: netConfig) { SimpleRole role = new SimpleRole(ni.getName()); contract.registerRole(role); role.addKeyRecord(new KeyRecord(ni.getPublicKey())); listRole.addRole(role); } listRole.setQuorum(netConfig.size()-1); contract.registerRole(listRole); RoleLink ownerLink = new RoleLink("ownerlink","owner"); ChangeOwnerPermission changeOwnerPermission = new ChangeOwnerPermission(ownerLink); HashMap<String,Object> fieldsMap = new HashMap<>(); fieldsMap.put("net_config",null); Binder modifyDataParams = Binder.of("fields",fieldsMap); ModifyDataPermission modifyDataPermission = new ModifyDataPermission(ownerLink,modifyDataParams); contract.addPermission(changeOwnerPermission); contract.addPermission(modifyDataPermission); contract.setExpiresAt(ZonedDateTime.now().plusYears(40)); contract.getStateData().set("net_config",netConfig); contract.addSignerKey(issuerKey); contract.seal(); return contract; }