@Test public void copyTest() { Config config = new Config(); PrivateKey randomKey = new PrivateKey(4096); config.getKeysWhiteList().add(randomKey.getPublicKey()); config.getAddressesWhiteList().add(new KeyAddress(randomKey.getPublicKey(), 0, true)); Config copyConfig = config.copy(); assertEquals(config.getKeysWhiteList(), copyConfig.getKeysWhiteList()); assertEquals(config.getMaxDiskCacheAge(), copyConfig.getMaxDiskCacheAge()); assertEquals(config.getStatsIntervalSmall(), copyConfig.getStatsIntervalSmall()); assertEquals(config.getStatsIntervalBig(), copyConfig.getStatsIntervalBig()); assertEquals(config.getExpriedNamesCleanupInterval(), copyConfig.getExpriedNamesCleanupInterval()); assertEquals(config.getExpriedStorageCleanupInterval(), copyConfig.getExpriedStorageCleanupInterval()); assertEquals(config.getHoldDuration(), copyConfig.getHoldDuration()); assertEquals(config.getDeclinedItemExpiration(), copyConfig.getDeclinedItemExpiration()); assertEquals(config.getAddressesWhiteList(), copyConfig.getAddressesWhiteList()); assertEquals(config.getPositiveConsensus(), copyConfig.getPositiveConsensus()); assertEquals(config.getResyncBreakConsensus(), copyConfig.getResyncBreakConsensus()); assertEquals(config.getMaxItemCreationAge(), copyConfig.getMaxItemCreationAge()); assertEquals(config.getRevokedItemExpiration(), copyConfig.getRevokedItemExpiration()); assertEquals(config.getMaxElectionsTime(), copyConfig.getMaxElectionsTime()); assertEquals(config.getMaxConsensusReceivedCheckTime(), copyConfig.getMaxConsensusReceivedCheckTime()); assertEquals(config.getMaxResyncTime(), copyConfig.getMaxResyncTime()); assertEquals(config.getMaxCacheAge(), copyConfig.getMaxCacheAge()); assertEquals(config.getMaxNameCacheAge(), copyConfig.getMaxNameCacheAge()); assertEquals(config.getMaxGetItemTime(), copyConfig.getMaxGetItemTime()); assertEquals(config.getGetItemRetryCount(), copyConfig.getGetItemRetryCount());
@BeforeClass public static void beforeClass() throws Exception { nodeConfig = new Config(); nodeConfig.addTransactionUnitsIssuerKeyData(new KeyAddress("Zau3tT8YtDkj3UDBSznrWHAjbhhU4SXsfQLWDFsv5vw24TLn6s")); }
private void pulseStartCleanup() { lowPrioExecutorService.scheduleAtFixedRate(() -> ledger.cleanup(config.isPermanetMode()),1,config.getMaxDiskCacheAge().getSeconds(),TimeUnit.SECONDS); lowPrioExecutorService.scheduleAtFixedRate(() -> ledger.removeExpiredStoragesAndSubscriptionsCascade(),config.getExpriedStorageCleanupInterval().getSeconds(),config.getExpriedStorageCleanupInterval().getSeconds(),TimeUnit.SECONDS); lowPrioExecutorService.scheduleAtFixedRate(() -> ledger.clearExpiredNameRecords(config.getHoldDuration()),config.getExpriedNamesCleanupInterval().getSeconds(),config.getExpriedNamesCleanupInterval().getSeconds(),TimeUnit.SECONDS); }
/** * Save callback record to ledger for possible synchronization. * * @param id is callback identifier * @param environmentId is environment identifier * @param config is node configuration * @param networkNodesCount is count of nodes in Universa network * @param ledger is node ledger */ public static void addCallbackRecordToLedger(HashId id, long environmentId, Config config, int networkNodesCount, Ledger ledger) { ZonedDateTime now = ZonedDateTime.now(); ZonedDateTime expiresAt = now.plus(config.getFollowerCallbackExpiration()).plusSeconds(config.getFollowerCallbackDelay().getSeconds() * (networkNodesCount + 3)); ZonedDateTime storedUntil = now.plus(config.getFollowerCallbackStateStoreTime()); ledger.addFollowerCallback(id, environmentId, expiresAt, storedUntil); }
config.getNetworkAdminKeyAddress().isMatchingKey(key) || getNodeKey().equals(key) || config.getKeysWhiteList().contains(key) || config.getAddressesWhiteList().stream().anyMatch(addr -> addr.isMatchingKey(key))) return true; if (requests >= config.getLimitRequestsForKeyPerMinute()) return false;
private static void initTestSet(int posCons, int negCons) throws Exception { config_s = new Config(); config_s.setPositiveConsensus(posCons); config_s.setNegativeConsensus(negCons); config_s.setResyncBreakConsensus(1); config_s.addTransactionUnitsIssuerKeyData(new KeyAddress("Zau3tT8YtDkj3UDBSznrWHAjbhhU4SXsfQLWDFsv5vw24TLn6s")); config_s.setPermanetMode(false);
private Binder resyncItem(Binder params, Session session) throws CommandFailedException { checkNode(session, true); KeyAddress tmpAddress = null; try { tmpAddress = new KeyAddress("JKEgDs9CoCCymD9TgmjG8UBLxuJwT5GZ3PaZyG6o2DQVGRQPjXHCG8JouC8eZw5Nd1w9krCS"); } catch (KeyAddress.IllegalAddressException e) { e.printStackTrace(); } if (config.limitFreeRegistrations()) if(!( tmpAddress.isMatchingKey(session.getPublicKey()) || config.getNetworkAdminKeyAddress().isMatchingKey(session.getPublicKey()) || config.getKeysWhiteList().contains(session.getPublicKey()) || config.getAddressesWhiteList().stream().anyMatch(addr -> addr.isMatchingKey(session.getPublicKey())) )) { System.out.println("approve ERROR: command needs client key from whitelist"); return Binder.of( "itemResult", itemResultOfError(Errors.BAD_CLIENT_KEY,"resyncItem", "command needs client key from whitelist")); } try { Binder result = Binder.of("itemResult", node.checkItem((HashId) params.get("itemId"))); node.resync((HashId) params.get("itemId")); return result; } catch (Exception e) { System.out.println("getState ERROR: " + e.getMessage()); return Binder.of( "itemResult", itemResultOfError(Errors.COMMAND_FAILED,"resyncItem", e.getMessage())); } }
normalClients.add(new Client("http://node-"+(i+1)+"-pro.universa.io:8080",new PrivateKey(2048),null)); config = new Config(); config.setConsensusConfigUpdater((config, n) -> { resyncBreak += 1; config.setPositiveConsensus(positive); config.setNegativeConsensus(negative); config.setResyncBreakConsensus(resyncBreak); }); config.updateConsensusConfig(NODES_COUNT);
static Main createMain(String name,boolean nolog) throws InterruptedException { String path = new File("src/test_node_config_v2/"+name).getAbsolutePath(); System.out.println(path); String[] args = new String[]{"--test", "--config", path, nolog ? "--nolog" : ""}; Main main = new Main(args); try { main.config.addTransactionUnitsIssuerKeyData(new KeyAddress("Zau3tT8YtDkj3UDBSznrWHAjbhhU4SXsfQLWDFsv5vw24TLn6s")); } catch (KeyAddress.IllegalAddressException e) { e.printStackTrace(); } try { //main.config.getKeysWhiteList().add(CLIMain.getPrivateKey().getPublicKey()); main.config.getAddressesWhiteList().add(new KeyAddress(CLIMain.getPrivateKey().getPublicKey(), 0, true)); } catch (IOException e) { e.printStackTrace(); } //main.config.getKeysWhiteList().add(main.config.getUIssuerKey()); main.waitReady(); return main; }
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)); }
private Binder startApproval(final Binder params, Session session) throws IOException, Quantiser.QuantiserException { if (config == null || config.limitFreeRegistrations()) if(config == null || ( !config.getKeysWhiteList().contains(session.getPublicKey()) && !config.getAddressesWhiteList().stream().anyMatch(addr -> addr.isMatchingKey(session.getPublicKey())))) { System.out.println("startApproval ERROR: session key shoild be in the white list"); return Binder.of( "itemResult", itemResultOfError(Errors.BAD_CLIENT_KEY,"startApproval", "command needs client key from whitelist")); } int n = asyncStarts.incrementAndGet(); AtomicInteger k = new AtomicInteger(); params.getListOrThrow("packedItems").forEach((item) -> es.execute(() -> { try { checkNode(session); System.out.println("Request to start registration #"+n+":"+k.incrementAndGet()); node.registerItem(Contract.fromPackedTransaction(((Bytes)item).toArray())); } catch (Exception e) { e.printStackTrace(); } }) ); //TODO: return ItemResult return new Binder(); }
x.config.getKeysWhiteList().clear(); x.config.getAddressesWhiteList().clear(); }); mm.forEach(x -> x.config.getAddressesWhiteList().add(new KeyAddress(newPrivateKey.getPublicKey(), 0, true)));
@Test public void addWhiteListAddressTest() { Config config = new Config(); PrivateKey randomKey = new PrivateKey(4096); KeyAddress keyAddr = new KeyAddress(randomKey.getPublicKey(), 0, true); config.getAddressesWhiteList().add(keyAddr); assertTrue(config.getAddressesWhiteList().contains(keyAddr)); } }
@Override public Collection<PublicKey> getAdditionalKeysToSignWith(String extendedType) { Set<PublicKey> set = new HashSet<>(); if(extendedType.equals(NSmartContract.SmartContractType.UNS1)) { set.add(config.getAuthorizedNameServiceCenterKey()); } return set; } };
int uptime = b.getIntOrThrow("uptime"); testSpace.nodes.get(0).config.setStatsIntervalSmall(Duration.ofSeconds(4)); testSpace.nodes.get(0).config.setStatsIntervalBig(Duration.ofSeconds(60)); testSpace.nodes.get(0).config.getAddressesWhiteList().add(new KeyAddress(issuerKey.getPublicKey(), 0, true));
@Test public void addWhiteListKeyTest() { Config config = new Config(); PrivateKey randomKey = new PrivateKey(4096); config.getKeysWhiteList().add(randomKey.getPublicKey()); assertTrue(config.getKeysWhiteList().contains(randomKey.getPublicKey())); }
expiresAt = ZonedDateTime.now().plus(config.getFollowerCallbackExpiration()); skipNodes = nodeDigests.size() - nodeDigests.subSet(callbackDigest, myDigest).size() - 1; delay += skipNodes * config.getFollowerCallbackDelay().toMillis(); if (allNodes.size() % 2 == 1) delay += config.getFollowerCallbackDelay().toMillis() / 3;
ZonedDateTime expiration = ZonedDateTime.now() .plus(newState == ItemState.REVOKED ? config.getRevokedItemExpiration() : config.getDeclinedItemExpiration()); record.setExpiresAt(expiration); try {
@Before public void beforeScriptEngineTest() throws Exception { // add U issuer test key configForProvider.addTransactionUnitsIssuerKeyData(new KeyAddress("Zau3tT8YtDkj3UDBSznrWHAjbhhU4SXsfQLWDFsv5vw24TLn6s")); }