/** * @deprecated Use {@link #createTestNode(TestNodeParameters)} instead */ @Deprecated public static Node createTestNode(int port, int opennetPort, String testName, boolean disableProbabilisticHTLs, short maxHTL, int dropProb, RandomSource random, Executor executor, int threadLimit, long storeSize, boolean ramStore, boolean enableSwapping, boolean enableARKs, boolean enableULPRs, boolean enablePerNodeFailureTables, boolean enableSwapQueueing, boolean enablePacketCoalescing, int outputBandwidthLimit, boolean enableFOAF, boolean connectToSeednodes, boolean longPingTimes, boolean useSlashdotCache, String ipAddressOverride) throws NodeInitException { return createTestNode(port, opennetPort, testName, disableProbabilisticHTLs, maxHTL, dropProb, random, executor, threadLimit, storeSize, ramStore, enableSwapping, enableARKs, enableULPRs, enablePerNodeFailureTables, enableSwapQueueing, enablePacketCoalescing, outputBandwidthLimit, enableFOAF, connectToSeednodes, longPingTimes, useSlashdotCache, ipAddressOverride, false); }
/** * @see #globalTestInit(File, boolean, LogLevel, String, boolean, RandomSource) * @deprecated Instead use {@link #globalTestInit(File, boolean, LogLevel, String, boolean, * RandomSource)}. */ @Deprecated public static RandomSource globalTestInit(String testName, boolean enablePlug, LogLevel logThreshold, String details, boolean noDNS) throws InvalidThresholdException { return globalTestInit(new File(testName), enablePlug, logThreshold, details, noDNS, null); }
public static void start_osgi(String[] args) { nodestarter_osgi = new NodeStarter(); nodestarter_osgi.start(args); }
File dir = new File("bootstrap-test"); FileUtil.removeAll(dir); RandomSource random = NodeStarter.globalTestInit(dir.getPath(), false, LogLevel.ERROR, "", false); File seednodes = new File("seednodes.fref"); if(!seednodes.exists() || seednodes.length() == 0 || !seednodes.canRead()) { node = NodeStarter.createTestNode(DARKNET_PORT, OPENNET_PORT, "bootstrap-test", false, Node.DEFAULT_MAX_HTL, 0, random, executor, 1000, 5*1024*1024, true, true, true, true, true, true, true, 12*1024, false, true, false, false, ipOverride);
this.secureRandom = NodeStarter.getGlobalSecureRandom(); isPRNGReady = true; toadlets.getStartupToadlet().setIsPRNGReady(); long memoryLimit = NodeStarter.getMemoryLimitBytes();
long maxMemory = NodeStarter.getMemoryLimitMB(); if (maxMemory < 0) defaultRamBucketPoolSize = 10; long overallMemoryLimit = NodeStarter.getMemoryLimitBytes(); if (overallMemoryLimit > 512 * 1024 * 1024) {
long memoryLimit = NodeStarter.getMemoryLimitMB(); if(!NodeStarter.isTestingVM()) {
@Override public void run() { node.getNodeStarter().restart(); } }, 1);
/** Get the memory limit in MB. Return -1 if we don't know, -2 for unlimited. */ public static long getMemoryLimitMB() { long limit = getMemoryLimitBytes(); if(limit <= 0) return limit; if(limit == Long.MAX_VALUE) return -2; limit /= (1024 * 1024); if(limit > Integer.MAX_VALUE) return -1; // Seems unlikely. FIXME 2TB limit! return limit; }
/** * Generates a random byte[] of a specified length * @param length How long the byte[] should be * @return The randomly generated byte[] */ private static byte[] genRandomBytes(int length){ byte[] randBytes = new byte[length]; NodeStarter.getGlobalSecureRandom().nextBytes(randBytes); return randBytes; }
/** * Read the config file from the arguments. * Then create a node. * Anything that needs static init should ideally be in here. * @param args */ public static void main(String[] args) throws IOException { NodeStarter.main(args); }
public static void main(String[] args) { // Immediately try entering background mode. This way also class // loading will be subject to reduced priority. ProcessPriority.enterBackgroundMode(); // Start the application. If the JVM was launched from the native // Wrapper then the application will wait for the native Wrapper to // call the application's start method. Otherwise the start method // will be called immediately. WrapperManager.start(new NodeStarter(), args); }
int newMemoryLimit = memoryLimit + extraMemoryMB; if(NodeStarter.isSomething32bits() && newMemoryLimit > 1408) { Logger.error(UpdateDeployContext.class, "We've detected a 32bit JVM so we're refusing to set maxmemory to "+newMemoryLimit); newMemoryLimit = 1408;
File dir = new File("bootstrap-pull-test"); FileUtil.removeAll(dir); RandomSource random = NodeStarter.globalTestInit(dir.getPath(), false, LogLevel.ERROR, "", false); byte[] seed = new byte[64]; random.nextBytes(seed); fis.close(); PooledExecutor executor = new PooledExecutor(); secondNode = NodeStarter.createTestNode(DARKNET_PORT, OPENNET_PORT, dir.getPath(), false, Node.DEFAULT_MAX_HTL, 0, random, executor, 1000, 5*1024*1024, true, true, true, true, true, true, true, 12*1024, false, true, false, false, ipOverride); secondNode.start(true);
/** Restart the node. Does not return. */ private void restart(UpdateDeployContext ctx) { if (logMINOR) Logger.minor(this, "Restarting..."); node.getNodeStarter().restart(); try { Thread.sleep(MINUTES.toMillis(5)); } catch (InterruptedException e) { // Break } // in case it's still restarting System.err .println("Failed to restart. Exiting, please restart the node."); System.exit(NodeInitException.EXIT_RESTART_FAILED); }
private long maxDatastoreSize() { long maxMemory = NodeStarter.getMemoryLimitBytes(); if(maxMemory == Long.MAX_VALUE) return 1024*1024*1024; // Treat as don't know. if(maxMemory < 128*1024*1024) return 1024*1024*1024; // 1GB default if don't know or very small memory. // Don't use the first 100MB for slot filters. long available = maxMemory - 100*1024*1024; // Don't use more than 50% of available memory for slot filters. available = available / 2; // Slot filters are 4 bytes per slot. long slots = available / 4; // There are 3 types of keys. We want the number of { SSK, CHK, pubkey } i.e. the number of slots in each store. slots /= 3; // We return the total size, so we don't need to worry about cache vs store or even client cache. // One key of all 3 types combined uses Node.sizePerKey bytes on disk. So we get a size. return slots * Node.sizePerKey; }
@Override public OutputStream getOutputStreamUnbuffered() throws IOException { synchronized(this) { if(readOnly) throw new IOException("Read only"); } OutputStream os = underlying.getOutputStreamUnbuffered(); return AEADOutputStream.createAES(os, key, NodeStarter.getGlobalSecureRandom()); }
NodeStarter.globalTestInit(dir, false, LogLevel.ERROR, "", true); for(int i = 0; i < NUMBER_OF_NODES; i++) { System.err.println("Creating node " + i); nodes[i] = NodeStarter.createTestNode(DARKNET_PORT_BASE + i, 0, dir, true, MAX_HTL, 0 /* no dropped packets */, random, executor, 500 * NUMBER_OF_NODES, 65536, true, ENABLE_SWAPPING, false, false, false, ENABLE_SWAP_QUEUEING, true, 0, ENABLE_FOAF, false, true, false, null); Logger.normal(RealNodeRoutingTest.class, "Created node " + i);
/** * TODO FIXME: Someone who understands all the parameters please add sane defaults. */ public static final class TestNodeParameters { /** The UDP port number. Each test node must have a different port number. */ public int port; /** The UDP opennet port number. Each test node must have a different port number. */ public int opennetPort; /** The directory where the test node will put all its data. <br> * Will be created automatically if it does not exist.<br> * {@link NodeStarter#createTestNode(TestNodeParameters)} will NOT fail if this exists. * You should make sure on your own to delete this before and after tests to ensure * a clean state. Notice that JUnit provides a mechanism for automatic creation * and deletion of test directories (TemporaryFolder).<br> * Notice that a subdirectory with the name being the port number of the node will be * created there, and all data of the node will be put into it. So you can and should use * the same baseDirectory when calling {@link NodeStarter#globalTestInit(File, boolean, * LogLevel, String, boolean, RandomSource)} (which you have to do once for each Java VM): * Each one will start with a fresh empty subdirectory for as long as each of them uses a * unique port number. */ public File baseDirectory = new File("freenet-test-node-" + UUID.randomUUID().toString()); public boolean disableProbabilisticHTLs; public short maxHTL; public int dropProb; public RandomSource random; public Executor executor; public int threadLimit = 500; public long storeSize; public boolean ramStore; public boolean enableSwapping;
w.write(sb.toString()); w.flush(); n.getNodeStarter().restart(); } else if(uline.startsWith("QUIT") && (core.directTMCI == this)) { StringBuilder sb = new StringBuilder();