Package freenet.crypt

Examples of freenet.crypt.DummyRandomSource


        testRestart("password");
    }
   
    private void testRestart(String password) throws MasterKeysWrongPasswordException, MasterKeysFileSizeException, IOException {
        File keysFile = new File(base, "test.master.keys");
        DummyRandomSource random = new DummyRandomSource(77391);
        MasterKeys original = MasterKeys.read(keysFile, random, password);
        byte[] clientCacheMasterKey = original.clientCacheMasterKey;
        DatabaseKey dkey = original.createDatabaseKey(random);
        MasterSecret tempfileMasterSecret = original.getPersistentMasterSecret();
        MasterKeys restored = MasterKeys.read(keysFile, random, password);
View Full Code Here


        testChangePassword("password", "new password");
    }
   
    private void testChangePassword(String oldPassword, String newPassword) throws MasterKeysWrongPasswordException, MasterKeysFileSizeException, IOException {
        File keysFile = new File(base, "test.master.keys");
        DummyRandomSource random = new DummyRandomSource(77391);
        MasterKeys original = MasterKeys.read(keysFile, random, oldPassword);
        byte[] clientCacheMasterKey = original.clientCacheMasterKey;
        DatabaseKey dkey = original.createDatabaseKey(random);
        MasterSecret tempfileMasterSecret = original.getPersistentMasterSecret();
        // Change password.
View Full Code Here

        //NodeStarter.globalTestInit(name, false, LogLevel.ERROR, "freenet.node.Location:MINOR,freenet.io.comm:MINOR,freenet.node.NodeDispatcher:MINOR,freenet.node.simulator:MINOR,freenet.node.PeerManager:MINOR,freenet.node.RequestSender:MINOR");
        //NodeStarter.globalTestInit(name, false, LogLevel.ERROR, "freenet.node.FNP:MINOR,freenet.node.Packet:MINOR,freenet.io.comm:MINOR,freenet.node.PeerNode:MINOR,freenet.node.DarknetPeerNode:MINOR");
        NodeStarter.globalTestInit(name, false, LogLevel.ERROR, "", true);
        System.out.println("Insert/retrieve test");
        System.out.println();
        DummyRandomSource random = new DummyRandomSource(3142);
        DummyRandomSource topologyRandom = new DummyRandomSource(3143);
        //DiffieHellman.init(random);
        Node[] nodes = new Node[NUMBER_OF_NODES];
        Logger.normal(RealNodeRoutingTest.class, "Creating nodes...");
        Executor executor = new PooledExecutor();
        for(int i=0;i<NUMBER_OF_NODES;i++) {
            nodes[i] =
              NodeStarter.createTestNode(DARKNET_PORT_BASE+i, 0, name, DISABLE_PROBABILISTIC_HTLS, MAX_HTL, 20 /* 5% */, random, executor, 500*NUMBER_OF_NODES, 256*1024, true, ENABLE_SWAPPING, false, ENABLE_ULPRS, ENABLE_PER_NODE_FAILURE_TABLES, ENABLE_SWAP_QUEUEING, ENABLE_PACKET_COALESCING, BWLIMIT, ENABLE_FOAF, false, true, USE_SLASHDOT_CACHE, null);
            Logger.normal(RealNodeRoutingTest.class, "Created node "+i);
        }
       
        // Now link them up
        makeKleinbergNetwork(nodes, START_WITH_IDEAL_LOCATIONS, DEGREE, FORCE_NEIGHBOUR_CONNECTIONS, topologyRandom);

        Logger.normal(RealNodeRoutingTest.class, "Added random links");
       
        for(int i=0;i<NUMBER_OF_NODES;i++) {
            nodes[i].start(false);
            System.err.println("Started node "+i+"/"+nodes.length);
        }
       
        waitForAllConnected(nodes);
       
        waitForPingAverage(0.5, nodes, new DummyRandomSource(3143), MAX_PINGS, 1000);
       
        random = new DummyRandomSource(3144);
       
        System.out.println();
        System.out.println("Ping average > 95%, lets do some inserts/requests");
        System.out.println();
       
View Full Code Here

          System.err.println("Mass delete failed, test may not be accurate.");
          System.exit(EXIT_CANNOT_DELETE_OLD_DATA);
        }
        wd.mkdir();
       
        DummyRandomSource random = new DummyRandomSource();
       
        //NOTE: globalTestInit returns in ignored random source
        //NodeStarter.globalTestInit(testName, false, LogLevel.ERROR, "freenet.node.Location:normal,freenet.node.simulator.RealNodeRoutingTest:normal,freenet.node.NodeDispatcher:NORMAL" /*,freenet.node.FailureTable:MINOR,freenet.node.Node:MINOR,freenet.node.Request:MINOR,freenet.io.comm.MessageCore:MINOR" "freenet.store:minor,freenet.node.LocationManager:debug,freenet.node.FNPPacketManager:normal,freenet.io.comm.MessageCore:debug"*/);
        // Uncomment as appropriate.
        // For testing high-level stuff (requests/ULPRs/FT bugs)
        NodeStarter.globalTestInit(testName, false, LogLevel.ERROR, "freenet.node.Location:normal,freenet.node.simulator.RealNodeRoutingTest:normal,freenet.node.NodeDispatcher:NORMAL,freenet.node.FailureTable:MINOR,freenet.node.Node:MINOR,freenet.node.Request:MINOR,freenet.io.comm.MessageCore:MINOR,freenet.node.PeerNode:MINOR,freenet.node.DarknetPeerNode:MINOR,freenet.io.xfer.PacketThrottle:MINOR,freenet.node.PeerManager:MINOR,freenet.client.async:MINOR", true);
        // For testing low-level stuff (connection bugs)
        //NodeStarter.globalTestInit(testName, false, LogLevel.ERROR, "freenet.node.Location:normal,freenet.node.simulator.RealNodeRoutingTest:normal,freenet.node.Node:MINOR,freenet.io.comm.MessageCore:MINOR,freenet.node.PeerNode:MINOR,freenet.node.DarknetPeerNode:MINOR,freenet.node.FNP:MINOR,freenet.io.xfer.PacketThrottle:MINOR,freenet.node.PeerManager:MINOR", true);
        Node[] nodes = new Node[NUMBER_OF_NODES];
        Logger.normal(RealNodeRoutingTest.class, "Creating nodes...");
        Executor executor = new PooledExecutor();
        for(int i=0;i<NUMBER_OF_NODES;i++) {
            nodes[i] =
              NodeStarter.createTestNode(DARKNET_PORT_BASE+i, 0, testName, true, MAX_HTL, 20 /* 5% */, random, executor, 500*NUMBER_OF_NODES, 1024*1024, true, ENABLE_SWAPPING, false, ENABLE_ULPRS, ENABLE_PER_NODE_FAILURE_TABLES, true, true, 0, ENABLE_FOAF, false, true, false, null);
            Logger.normal(RealNodeRoutingTest.class, "Created node "+i);
        }
        SimpleFieldSet refs[] = new SimpleFieldSet[NUMBER_OF_NODES];
        for(int i=0;i<NUMBER_OF_NODES;i++)
            refs[i] = nodes[i].exportDarknetPublicFieldSet();
        Logger.normal(RealNodeRoutingTest.class, "Created "+NUMBER_OF_NODES+" nodes");
        // Now link them up
        // Connect the set
        for(int i=0;i<NUMBER_OF_NODES;i++) {
            int next = (i+1) % NUMBER_OF_NODES;
            int prev = (i+NUMBER_OF_NODES-1)%NUMBER_OF_NODES;
            nodes[i].connect(nodes[next], trust, visibility);
            nodes[i].connect(nodes[prev], trust, visibility);
        }
        Logger.normal(RealNodeRoutingTest.class, "Connected nodes");
        // Now add some random links
        for(int i=0;i<NUMBER_OF_NODES*5;i++) {
            if(i % NUMBER_OF_NODES == 0)
                Logger.normal(RealNodeRoutingTest.class, String.valueOf(i));
            int length = (int)Math.pow(NUMBER_OF_NODES, random.nextDouble());
            int nodeA = random.nextInt(NUMBER_OF_NODES);
            int nodeB = (nodeA+length)%NUMBER_OF_NODES;
            //System.out.println(""+nodeA+" -> "+nodeB);
            Node a = nodes[nodeA];
            Node b = nodes[nodeB];
            a.connect(b, trust, visibility);
            b.connect(a, trust, visibility);
        }
       
        Logger.normal(RealNodeRoutingTest.class, "Added random links");
       
    for(Node node: nodes)
            node.start(false);
       
        int successfulTests = 0;
       
        long totalPropagationTime = 0;
       
        for(int totalCount=0;totalCount<NUMBER_OF_TESTS;totalCount++) {
       
        final boolean isSSK;
        isSSK = (totalCount & 0x1) == 1;
        //isSSK = true;
       
        // Now create a key.
       
        byte[] buf = new byte[32];
        random.nextBytes(buf);
        String keyName = HexUtil.bytesToHex(buf);
       
        FreenetURI testKey;
        ClientKey insertKey;
        ClientKey fetchKey;
View Full Code Here

    }
    wd.mkdir();
    //NOTE: globalTestInit returns in ignored random source
    NodeStarter.globalTestInit(dir, false, LogLevel.ERROR, "", true);
    // Make the network reproducible so we can easily compare different routing options by specifying a seed.
    DummyRandomSource random = new DummyRandomSource(3142);
    //DiffieHellman.init(random);
    Node[] nodes = new Node[NUMBER_OF_NODES];
    Logger.normal(RealNodeRoutingTest.class, "Creating nodes...");
    Executor executor = new PooledExecutor();
    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);
    }
    Logger.normal(RealNodeRoutingTest.class, "Created " + NUMBER_OF_NODES + " nodes");
    // Now link them up
    makeKleinbergNetwork(nodes, START_WITH_IDEAL_LOCATIONS, DEGREE, FORCE_NEIGHBOUR_CONNECTIONS, random);

    Logger.normal(RealNodeRoutingTest.class, "Added random links");

    for(int i = 0; i < NUMBER_OF_NODES; i++) {
      System.err.println("Starting node " + i);
      nodes[i].start(false);
    }

    waitForAllConnected(nodes);

    // Make the choice of nodes to ping to and from deterministic too.
    // There is timing noise because of all the nodes, but the network
    // and the choice of nodes to start and finish are deterministic, so
    // the overall result should be more or less deterministic.
    waitForPingAverage(0.98, nodes, new DummyRandomSource(3143), MAX_PINGS, 5000);
    System.exit(0);
  }
View Full Code Here

      System.err.println("Unabled to create test directory \"" + dir + "\".");
      return;
    }
    NodeStarter.globalTestInit(dir, false, LogLevel.ERROR, "", true);
    // Make the network reproducible so we can easily compare different routing options by specifying a seed.
    DummyRandomSource random = new DummyRandomSource(3142);
    Node[] nodes = new Node[NUMBER_OF_NODES];
    Logger.normal(RealNodeProbeTest.class, "Creating nodes...");
    Executor executor = new PooledExecutor();
    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, 256*1024, true, ENABLE_SWAPPING, false, false, false, ENABLE_SWAP_QUEUEING, true, OUTPUT_BANDWIDTH_LIMIT, ENABLE_FOAF, false, true, false, null, i == 0);
      Logger.normal(RealNodeProbeTest.class, "Created node " + i);
    }
    Logger.normal(RealNodeProbeTest.class, "Created " + NUMBER_OF_NODES + " nodes");
    // Now link them up
    makeKleinbergNetwork(nodes, START_WITH_IDEAL_LOCATIONS, DEGREE, FORCE_NEIGHBOUR_CONNECTIONS, random);

    Logger.normal(RealNodeProbeTest.class, "Added random links");

    for(int i = 0; i < NUMBER_OF_NODES; i++) {
      System.err.println("Starting node " + i);
      nodes[i].start(false);
    }

        System.out.println();
        System.out.println("Ping average > 95%, lets do some inserts/requests");
        System.out.println();
       
        if(DO_INSERT_TEST) {
         
            waitForPingAverage(0.5, nodes, new DummyRandomSource(3143), MAX_PINGS, 1000);
           
            RealNodeRequestInsertTest tester = new RealNodeRequestInsertTest(nodes, random, 10);
           
            waitForAllConnected(nodes);
           
            while(true) {
              try {
                waitForAllConnected(nodes);
                int status = tester.insertRequestTest();
                if(status == -1) continue;
                System.out.println("Insert test completed with status "+status);
                break;
              } catch (Throwable t) {
                Logger.error(RealNodeRequestInsertTest.class, "Caught "+t, t);
              }
            }
        }

    final NumberFormat nf = NumberFormat.getInstance();
    Listener print = new Listener() {
      @Override
      public void onError(Error error, Byte code, boolean local) {
        System.out.print("Probe error: " + error.name());
        if (local) System.out.print(" (local)");
        System.out.println(code == null ? "" : " (" + code + ")");
      }

      @Override
      public void onRefused() {
        System.out.println("Probe refused.");
      }

      @Override
      public void onOutputBandwidth(float outputBandwidth) {
        System.out.println("Probe got bandwidth limit " + nf.format(outputBandwidth) +
          " KiB per second.");
      }

      @Override
      public void onBuild(int build) {
        System.out.println("Probe got build " + build + ".");
      }

      @Override
      public void onIdentifier(long identifier, byte uptimePercentage) {
        System.out.println("Probe got identifier " + identifier + " with uptime percentage " + uptimePercentage + ".");
      }

      @Override
      public void onLinkLengths(float[] linkLengths) {
        System.out.print("Probe got link lengths: { ");
        for (Float length : linkLengths) System.out.print(length + " ");
        System.out.println("}.");
      }

      @Override
      public void onLocation(float location) {
        System.out.println("Probe got location " + location + ".");
      }

      @Override
      public void onStoreSize(float storeSize) {
        System.out.println("Probe got store size " + nf.format(storeSize) + " GiB.");
      }

      @Override
      public void onUptime(float uptimePercentage) {
        System.out.print("Probe got uptime " + nf.format(uptimePercentage) + "%.");
      }

      @Override
      public void onRejectStats(byte[] stats) {
        System.out.println("Probe got reject stats:");
        System.out.println("CHK request: "+stats[0]);
        System.out.println("SSK request: "+stats[1]);
        System.out.println("CHK insert: "+stats[2]);
        System.out.println("SSK insert: "+stats[3]);
      }

      @Override
      public void onOverallBulkOutputCapacity(
          byte bandwidthClassForCapacityUsage, float outputBulkCapacityUsed) {
        System.out.println("Probe got output capacity "+nf.format(outputBulkCapacityUsed)+
            "% (bandwidth class "+bandwidthClassForCapacityUsage+")");
      }
    };

    final Type types[] = {
      Type.BANDWIDTH,
      Type.BUILD,
      Type.IDENTIFIER,
      Type.LINK_LENGTHS,
      Type.LOCATION,
      Type.STORE_SIZE,
      Type.UPTIME_48H,
      Type.UPTIME_7D,
      Type.REJECT_STATS,
      Type.OVERALL_BULK_OUTPUT_CAPACITY_USAGE
    };

    int index = 0;
    byte htl = Probe.MAX_HTL;
    BufferedReader r;
    Console console = System.console();
    if(console != null)
      r = new BufferedReader(console.reader());
    else
      r = new BufferedReader(new InputStreamReader(System.in)); // Use the system locale here.
    while (true) {
      System.err.println("Sending probes from node " + index + " with HTL " + htl + ".");
      System.err.println("0) BANDWIDTH");
      System.err.println("1) BUILD");
      System.err.println("2) IDENTIFIER");
      System.err.println("3) LINK_LENGTHS");
      System.err.println("4) LOCATION");
      System.err.println("5) STORE_SIZE");
      System.err.println("6) UPTIME 48-hour");
      System.err.println("7) UPTIME 7-day");
      System.err.println("8) REJECT_STATS");
      System.err.println("9) OVERALL_BULK_OUTPUT_CAPACITY_USAGE");
      System.err.println("10) Pick another node");
      System.err.println("11) Pick another HTL");
      System.err.println("12) Pick current node's refusals");
     
      System.err.println("Anything else to exit.");
      System.err.println("Select: ");
      try {
        int selection = Integer.parseInt(r.readLine());
        if (selection == types.length) {
          System.err.print("Enter new node index ([0-" + (NUMBER_OF_NODES - 1) + "]):");
          index = Integer.valueOf(r.readLine());
        }
        else if (selection == types.length+1) {
          System.err.print("Enter new HTL: ");
          htl = Byte.valueOf(r.readLine());
        } else if (selection == types.length+2) {
          SubConfig nodeConfig = nodes[index].config.get("node");
          String[] options = { "probeBandwidth", "probeBuild", "probeIdentifier", "probeLinkLengths", "probeLinkLengths", "probeUptime" };
          for (String option : options) {
            System.err.print(option + ": ");
            nodeConfig.set(option, Boolean.valueOf(r.readLine()));
          }
        } else nodes[index].startProbe(htl, random.nextLong(), types[selection], print);
      } catch (Exception e) {
        //If a non-number is entered or one outside the bounds.
        System.out.print(e.toString());
        e.printStackTrace();
        //Return isn't enough to exit: the nodes are still in the background.
View Full Code Here

        //NodeStarter.globalTestInit(name, false, LogLevel.ERROR, "freenet.node.Location:MINOR,freenet.io.comm:MINOR,freenet.node.NodeDispatcher:MINOR,freenet.node.simulator:MINOR,freenet.node.PeerManager:MINOR,freenet.node.RequestSender:MINOR");
        //NodeStarter.globalTestInit(name, false, LogLevel.ERROR, "freenet.node.FNP:MINOR,freenet.node.Packet:MINOR,freenet.io.comm:MINOR,freenet.node.PeerNode:MINOR,freenet.node.DarknetPeerNode:MINOR");
        NodeStarter.globalTestInit(name, false, LogLevel.ERROR, "", true);
        System.out.println("Busy network test (inserts/retrieves in quantity/stress test)");
        System.out.println();
        DummyRandomSource random = new DummyRandomSource();
        //DiffieHellman.init(random);
        Node[] nodes = new Node[NUMBER_OF_NODES];
        Logger.normal(RealNodeRoutingTest.class, "Creating nodes...");
        Executor executor = new PooledExecutor();
        for(int i=0;i<NUMBER_OF_NODES;i++) {
            nodes[i] =
              NodeStarter.createTestNode(DARKNET_PORT_BASE+i, 0, name, false, MAX_HTL, 20 /* 5% */, random, executor, 500*NUMBER_OF_NODES, (CHKBlock.DATA_LENGTH+CHKBlock.TOTAL_HEADERS_LENGTH)*100, true, ENABLE_SWAPPING, false, ENABLE_ULPRS, ENABLE_PER_NODE_FAILURE_TABLES, ENABLE_SWAP_QUEUEING, ENABLE_PACKET_COALESCING, 8000, ENABLE_FOAF, false, true, false, null);
            Logger.normal(RealNodeRoutingTest.class, "Created node "+i);
        }

        // Now link them up
        makeKleinbergNetwork(nodes, START_WITH_IDEAL_LOCATIONS, DEGREE, FORCE_NEIGHBOUR_CONNECTIONS, random);

        Logger.normal(RealNodeRoutingTest.class, "Added random links");

        for(int i=0;i<NUMBER_OF_NODES;i++) {
            nodes[i].start(false);
            System.err.println("Started node "+i+"/"+nodes.length);
        }

        waitForAllConnected(nodes);

        waitForPingAverage(0.95, nodes, random, MAX_PINGS, 1000);

        System.out.println();
        System.out.println("Ping average > 95%, lets do some inserts/requests");
        System.out.println();

        HighLevelSimpleClient[] clients = new HighLevelSimpleClient[nodes.length];
        for(int i=0;i<clients.length;i++) {
          clients[i] = nodes[i].clientCore.makeClient(RequestStarter.IMMEDIATE_SPLITFILE_PRIORITY_CLASS, false, false);
        }

        // Insert 100 keys into random nodes

        ClientCHK[] keys = new ClientCHK[INSERT_KEYS];

        String baseString = System.currentTimeMillis() + " ";
        for(int i=0;i<INSERT_KEYS;i++) {
          System.err.println("Inserting "+i+" of "+INSERT_KEYS);
            int node1 = random.nextInt(NUMBER_OF_NODES);
            Node randomNode = nodes[node1];
            String dataString = baseString + i;
            byte[] data = dataString.getBytes("UTF-8");
            ClientCHKBlock b;
            b = ClientCHKBlock.encode(data, false, false, (short)-1, 0, COMPRESSOR_TYPE.DEFAULT_COMPRESSORDESCRIPTOR, false);
View Full Code Here

    GetPubkey pubkeyCache = new SimpleGetPubkey(pk);
    SSKStore store = new SSKStore(pubkeyCache);
    SaltedHashFreenetStore<SSKBlock> saltStore = SaltedHashFreenetStore.construct(f, "testCachingFreenetStoreSSK", store, weakPRNG, 20, true, SemiOrderedShutdownHook.get(), true, true, ticker, null);
    CachingFreenetStore<SSKBlock> cachingStore = new CachingFreenetStore<SSKBlock>(store, cachingFreenetStoreMaxSize, cachingFreenetStorePeriod, saltStore, ticker);
    cachingStore.start(null, true);
    RandomSource random = new DummyRandomSource(12345);

    for(int i=0;i<5;i++) {
      String test = "test" + i;
      ClientSSKBlock block = encodeBlockSSK(test, random);
      SSKBlock sskBlock = (SSKBlock) block.getBlock();
View Full Code Here

    GetPubkey pubkeyCache = new SimpleGetPubkey(pk);
    SSKStore store = new SSKStore(pubkeyCache);
    SaltedHashFreenetStore<SSKBlock> saltStore = SaltedHashFreenetStore.construct(f, "testCachingFreenetStoreOnCloseSSK", store, weakPRNG, 10, false, SemiOrderedShutdownHook.get(), true, true, ticker, null);
    CachingFreenetStore<SSKBlock> cachingStore = new CachingFreenetStore<SSKBlock>(store, cachingFreenetStoreMaxSize, cachingFreenetStorePeriod, saltStore, ticker);
    cachingStore.start(null, true);
    RandomSource random = new DummyRandomSource(12345);
   
    List<ClientSSKBlock> sskBlocks = new ArrayList<ClientSSKBlock>();
    List<String> tests = new ArrayList<String>();

    for(int i=0;i<5;i++) {
View Full Code Here

    GetPubkey pubkeyCache = new SimpleGetPubkey(pk);
    SSKStore store = new SSKStore(pubkeyCache);
    SaltedHashFreenetStore<SSKBlock> saltStore = SaltedHashFreenetStore.construct(f, "testCachingFreenetStoreOnCloseSSK", store, weakPRNG, 10, false, SemiOrderedShutdownHook.get(), true, true, ticker, null);
    CachingFreenetStore<SSKBlock> cachingStore = new CachingFreenetStore<SSKBlock>(store, cachingFreenetStoreMaxSize, cachingFreenetStorePeriod, saltStore, ticker);
    cachingStore.start(null, true);
    RandomSource random = new DummyRandomSource(12345);
   
    List<ClientSSKBlock> sskBlocks = new ArrayList<ClientSSKBlock>();
    List<String> tests = new ArrayList<String>();

    for(int i=0;i<5;i++) {
View Full Code Here

TOP

Related Classes of freenet.crypt.DummyRandomSource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.