Package freenet.node

Examples of freenet.node.Node


    return name;
  }

  @Override
  public short getPriorityClass() {
    Node node = updater.node;
    if(node.updateIsUrgent())
      return UserAlert.CRITICAL_ERROR;
    if(updater.inFinalCheck() || updater.canUpdateNow() || !updater.isArmed())
      return UserAlert.ERROR;
    else
      return UserAlert.MINOR;
View Full Code Here


        } catch (InterruptedException e1) {
        }
        String dataString = baseString + requestNumber;
        // Pick random node to insert to
        int node1 = random.nextInt(NUMBER_OF_NODES);
        Node randomNode = nodes[node1];
        //Logger.error(RealNodeRequestInsertTest.class,"Inserting: \""+dataString+"\" to "+node1);
       
        //boolean isSSK = requestNumber % 2 == 1;
        boolean isSSK = true;
       
        FreenetURI testKey;
        ClientKey insertKey;
        ClientKey fetchKey;
        ClientKeyBlock block;
       
      byte[] buf = dataString.getBytes("UTF-8");
        if(isSSK) {
          testKey = new FreenetURI("KSK", dataString);
         
          insertKey = InsertableClientSSK.create(testKey);
          fetchKey = ClientKSK.create(testKey);
         
          block = ((InsertableClientSSK)insertKey).encode(new ArrayBucket(buf), false, false, (short)-1, buf.length, random, COMPRESSOR_TYPE.DEFAULT_COMPRESSORDESCRIPTOR, false);
        } else {
          block = ClientCHKBlock.encode(buf, false, false, (short)-1, buf.length, COMPRESSOR_TYPE.DEFAULT_COMPRESSORDESCRIPTOR, false);
          insertKey = fetchKey = block.getClientKey();
          testKey = insertKey.getURI();
        }
       
        System.err.println();
        System.err.println("Created random test key "+testKey+" = "+fetchKey.getNodeKey(false));
        System.err.println();
       
        byte[] data = dataString.getBytes("UTF-8");
        Logger.minor(RealNodeRequestInsertTest.class, "Decoded: "+new String(block.memoryDecode(), "UTF-8"));
        Logger.normal(RealNodeRequestInsertTest.class,"Insert Key: "+insertKey.getURI());
        Logger.normal(RealNodeRequestInsertTest.class,"Fetch Key: "+fetchKey.getURI());
    try {
      insertAttempts++;
      randomNode.clientCore.realPut(block.getBlock(), false, FORK_ON_CACHEABLE, false, false, REAL_TIME_FLAG);
      Logger.error(RealNodeRequestInsertTest.class, "Inserted to "+node1);
    } catch (freenet.node.LowLevelPutException putEx) {
      Logger.error(RealNodeRequestInsertTest.class, "Insert failed: "+ putEx);
      System.err.println("Insert failed: "+ putEx);
      return EXIT_INSERT_FAILED;
    }
        // Pick random node to request from
        int node2;
        do {
            node2 = random.nextInt(NUMBER_OF_NODES);
        } while(node2 == node1);
        Node fetchNode = nodes[node2];
        try {
          block = fetchNode.clientCore.realGetKey(fetchKey, false, false, false, REAL_TIME_FLAG);
        } catch (LowLevelGetException e) {
          block = null;
        }
View Full Code Here

    System.out.println("Version:" + Version.buildNumber());
    csvLine.add(String.valueOf(Version.buildNumber()));

    int exitCode = 0;
    Node node = null;
    Node node2 = null;
    try {
      final File dir = new File("longterm-push-pull-test-" + uid);
      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()) {
        System.err.println("Unable to read seednodes.fref, it doesn't exist, or is empty");
        System.exit(EXIT_NO_SEEDNODES);
      }

      final File innerDir = new File(dir, Integer.toString(DARKNET_PORT1));
      innerDir.mkdir();
      FileInputStream fis = new FileInputStream(seednodes);
      FileUtil.writeTo(fis, new File(innerDir, "seednodes.fref"));
      fis.close();

      // Create one node
      node = NodeStarter.createTestNode(DARKNET_PORT1, OPENNET_PORT1, dir.getPath(), false, Node.DEFAULT_MAX_HTL,
              0, random, new PooledExecutor(), 1000, 4 * 1024 * 1024, true, true, true, true, true, true, true,
              12 * 1024, true, true, false, false, null);
      Logger.getChain().setThreshold(LogLevel.ERROR);

      // Start it
      node.start(true);
      long t1 = System.currentTimeMillis();
      if (!TestUtil.waitForNodes(node)) {
        exitCode = EXIT_FAILED_TARGET;
        return;
      }
       
      long t2 = System.currentTimeMillis();
      System.out.println("SEED-TIME:" + (t2 - t1));
      csvLine.add(String.valueOf(t2 - t1));

      // Push one block only.
     
      RandomAccessBucket data = randomData(node);
      HighLevelSimpleClient client = node.clientCore.makeClient((short) 0, false, false);
      FreenetURI uri = new FreenetURI("KSK@" + uid + "-" + dateFormat.format(today.getTime()));
      System.out.println("PUSHING " + uri);
     
      try {
        InsertBlock block = new InsertBlock(data, new ClientMetadata(), uri);
        t1 = System.currentTimeMillis();
        client.insert(block, false, null);
        t2 = System.currentTimeMillis();
       
        System.out.println("PUSH-TIME-" + ":" + (t2 - t1));
        csvLine.add(String.valueOf(t2 - t1));
      } catch (InsertException e) {
        e.printStackTrace();
        csvLine.add("N/A");
      }

      data.free();

      node.park();

      // Node 2
      File innerDir2 = new File(dir, Integer.toString(DARKNET_PORT2));
      innerDir2.mkdir();
      fis = new FileInputStream(seednodes);
      FileUtil.writeTo(fis, new File(innerDir2, "seednodes.fref"));
      fis.close();
      node2 = NodeStarter.createTestNode(DARKNET_PORT2, OPENNET_PORT2, dir.getPath(), false,
              Node.DEFAULT_MAX_HTL, 0, random, new PooledExecutor(), 1000, 5 * 1024 * 1024, true, true, true,
              true, true, true, true, 12 * 1024, false, true, false, false, null);
      node2.start(true);

      t1 = System.currentTimeMillis();
      if (!TestUtil.waitForNodes(node2)) {
        exitCode = EXIT_FAILED_TARGET;
        return;
      }
      t2 = System.currentTimeMillis();
      System.out.println("SEED-TIME:" + (t2 - t1));
      csvLine.add(String.valueOf(t2 - t1));

      // PULL N+1 BLOCKS
      for (int i = 0; i <= MAX_N; i++) {
        client = node2.clientCore.makeClient((short) 0, false, false);
        Calendar targetDate = (Calendar) today.clone();
        targetDate.add(Calendar.DAY_OF_MONTH, -((1 << i) - 1));

        uri = new FreenetURI("KSK@" + uid + "-" + dateFormat.format(targetDate.getTime()));
        System.out.println("PULLING " + uri);

        try {
          t1 = System.currentTimeMillis();
          client.fetch(uri);
          t2 = System.currentTimeMillis();

          System.out.println("PULL-TIME-" + i + ":" + (t2 - t1));
          csvLine.add(String.valueOf(t2 - t1));
        } catch (FetchException e) {
          if (e.getMode() != FetchExceptionMode.ALL_DATA_NOT_FOUND
                  && e.getMode() != FetchExceptionMode.DATA_NOT_FOUND)
            e.printStackTrace();
          csvLine.add(FetchException.getShortMessage(e.getMode()));
        }
      }
    } catch (Throwable t) {
      t.printStackTrace();
      exitCode = EXIT_THREW_SOMETHING;
    } finally {
      try {
        if (node != null)
          node.park();
      } catch (Throwable t1) {
      }
      try {
        if (node2 != null)
          node2.park();
      } catch (Throwable t1) {
      }

      File file = new File(uid + ".csv");
      writeToStatusLog(file, csvLine);
View Full Code Here

    System.out.println("Version:" + Version.buildNumber());
    csvLine.add(String.valueOf(Version.buildNumber()));

    int exitCode = 0;
    Node node = null;
    Node node2 = null;
    try {
      final File dir = new File("longterm-push-pull-test-" + uid);
      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()) {
        System.err.println("Unable to read seednodes.fref, it doesn't exist, or is empty");
        System.exit(EXIT_NO_SEEDNODES);
      }

      final File innerDir = new File(dir, Integer.toString(DARKNET_PORT1));
      innerDir.mkdir();
      FileInputStream fis = new FileInputStream(seednodes);
      FileUtil.writeTo(fis, new File(innerDir, "seednodes.fref"));
      fis.close();

      // Create one node
      node = NodeStarter.createTestNode(DARKNET_PORT1, OPENNET_PORT1, dir.getPath(), false, Node.DEFAULT_MAX_HTL,
              0, random, new PooledExecutor(), 1000, 4 * 1024 * 1024, true, true, true, true, true, true, true,
              12 * 1024, true, true, false, false, null);
      Logger.getChain().setThreshold(LogLevel.ERROR);

      // Start it
      node.start(true);
      long t1 = System.currentTimeMillis();
      if (!TestUtil.waitForNodes(node)) {
        exitCode = EXIT_FAILED_TARGET;
        return;
      }
       
      long t2 = System.currentTimeMillis();
      System.out.println("SEED-TIME:" + (t2 - t1));
      csvLine.add(String.valueOf(t2 - t1));

      // PUSH N+1 BLOCKS
      for (int i = 0; i <= MAX_N; i++) {
          RandomAccessBucket data = randomData(node);
        HighLevelSimpleClient client = node.clientCore.makeClient((short) 0, false, false);
        FreenetURI uri = new FreenetURI("KSK@" + uid + "-" + dateFormat.format(today.getTime()) + "-" + i);
        System.out.println("PUSHING " + uri);
        client.addEventHook(new ClientEventListener() {

          @Override
          public void receive(ClientEvent ce, ClientContext context) {
            System.out.println(ce.getDescription());
          }
         
        });

        try {
          InsertBlock block = new InsertBlock(data, new ClientMetadata(), uri);
          t1 = System.currentTimeMillis();
          client.insert(block, false, null);
          t2 = System.currentTimeMillis();

          System.out.println("PUSH-TIME-" + i + ":" + (t2 - t1));
          csvLine.add(String.valueOf(t2 - t1));
        } catch (InsertException e) {
          e.printStackTrace();
          csvLine.add("N/A");
        }

        data.free();
      }

      node.park();

      // Node 2
      File innerDir2 = new File(dir, Integer.toString(DARKNET_PORT2));
      innerDir2.mkdir();
      fis = new FileInputStream(seednodes);
      FileUtil.writeTo(fis, new File(innerDir2, "seednodes.fref"));
      fis.close();
      node2 = NodeStarter.createTestNode(DARKNET_PORT2, OPENNET_PORT2, dir.getPath(), false,
              Node.DEFAULT_MAX_HTL, 0, random, new PooledExecutor(), 1000, 5 * 1024 * 1024, true, true, true,
              true, true, true, true, 12 * 1024, false, true, false, false, null);
      node2.start(true);

      t1 = System.currentTimeMillis();
      if (!TestUtil.waitForNodes(node2)) {
        exitCode = EXIT_FAILED_TARGET;
        return;
      }
      t2 = System.currentTimeMillis();
      System.out.println("SEED-TIME:" + (t2 - t1));
      csvLine.add(String.valueOf(t2 - t1));

      // PULL N+1 BLOCKS
      for (int i = 0; i <= MAX_N; i++) {
        HighLevelSimpleClient client = node2.clientCore.makeClient((short) 0, false, false);
        Calendar targetDate = (Calendar) today.clone();
        targetDate.add(Calendar.DAY_OF_MONTH, -((1 << i) - 1));

        FreenetURI uri = new FreenetURI("KSK@" + uid + "-" + dateFormat.format(targetDate.getTime()) + "-" + i);
        System.out.println("PULLING " + uri);

        try {
          t1 = System.currentTimeMillis();
          client.fetch(uri);
          t2 = System.currentTimeMillis();

          System.out.println("PULL-TIME-" + i + ":" + (t2 - t1));
          csvLine.add(String.valueOf(t2 - t1));
        } catch (FetchException e) {
          if (e.getMode() != FetchExceptionMode.ALL_DATA_NOT_FOUND
                  && e.getMode() != FetchExceptionMode.DATA_NOT_FOUND)
            e.printStackTrace();
          csvLine.add(FetchException.getShortMessage(e.getMode()));
        }
      }
    } catch (Throwable t) {
      t.printStackTrace();
      exitCode = EXIT_THREW_SOMETHING;
    } finally {
      try {
        if (node != null)
          node.park();
      } catch (Throwable t1) {
      }
      try {
        if (node2 != null)
          node2.park();
      } catch (Throwable t1) {
      }

      File file = new File(uid + ".csv");
      writeToStatusLog(file, csvLine);
View Full Code Here

    System.out.println("Version:" + Version.buildNumber());
    csvLine.add(String.valueOf(Version.buildNumber()));

    int exitCode = 0;
    Node node = null;
    Node node2 = null;
    FileInputStream fis = null;
    File file = new File("mhk-test-"+uid + ".csv");
    long t1, t2;

    HighLevelSimpleClient client = null;
   
    try {
     
      // INSERT STUFF
     
      final File dir = new File("longterm-mhk-test-" + uid);
      if(!dumpOnly) {
      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()) {
        System.err.println("Unable to read seednodes.fref, it doesn't exist, or is empty");
        System.exit(EXIT_NO_SEEDNODES);
      }

      final File innerDir = new File(dir, Integer.toString(DARKNET_PORT1));
      innerDir.mkdir();
      fis = new FileInputStream(seednodes);
      FileUtil.writeTo(fis, new File(innerDir, "seednodes.fref"));
      fis.close();

      // Create one node
      node = NodeStarter.createTestNode(DARKNET_PORT1, OPENNET_PORT1, dir.getPath(), false, Node.DEFAULT_MAX_HTL,
              0, random, new PooledExecutor(), 1000, 4 * 1024 * 1024, true, true, true, true, true, true, true,
              12 * 1024, true, true, false, false, null);
      Logger.getChain().setThreshold(LogLevel.ERROR);

      // Start it
      node.start(true);
      t1 = System.currentTimeMillis();
      if (!TestUtil.waitForNodes(node)) {
        exitCode = EXIT_FAILED_TARGET;
        return;
      }
       
      t2 = System.currentTimeMillis();
      System.out.println("SEED-TIME:" + (t2 - t1));
      csvLine.add(String.valueOf(t2 - t1));

      // Create four CHKs
     
      RandomAccessBucket single = randomData(node);
      RandomAccessBucket[] mhks = new RandomAccessBucket[3];
     
      for(int i=0;i<mhks.length;i++) mhks[i] = randomData(node);
     
      client = node.clientCore.makeClient((short) 0, false, false);

      System.err.println("Inserting single block 3 times");
     
      InsertBlock block = new InsertBlock(single, new ClientMetadata(), FreenetURI.EMPTY_CHK_URI);
     
      FreenetURI uri = null;
     
      int successes = 0;
     
      for(int i=0;i<3;i++) {
        System.err.println("Inserting single block, try #"+i);
        try {
          t1 = System.currentTimeMillis();
          FreenetURI thisURI = client.insert(block, false, null);
          if(uri != null && !thisURI.equals(uri)) {
            System.err.println("URI "+i+" is "+thisURI+" but previous is "+uri);
            System.exit(EXIT_DIFFERENT_URI);
          }
          uri = thisURI;
          t2 = System.currentTimeMillis();
         
          System.out.println("PUSH-TIME-" + i + ":" + (t2 - t1)+" for "+uri+" for single block");
          csvLine.add(String.valueOf(t2 - t1));
          csvLine.add(uri.toASCIIString());
          successes++;
        } catch (InsertException e) {
          e.printStackTrace();
          csvLine.add(InsertException.getShortMessage(e.getMode()));
          csvLine.add("N/A");
          System.out.println("INSERT FAILED: "+e+" for insert "+i+" for single block");
        }
      }
     
      if(successes == 3)
        System.err.println("All inserts succeeded for single block: "+successes);
      else if(successes != 0)
        System.err.println("Some inserts succeeded for single block: "+successes);
      else
        System.err.println("NO INSERTS SUCCEEDED FOR SINGLE BLOCK: "+successes);
     
      uri = null;
     
      // Insert 3 blocks
     
      for(int i=0;i<3;i++) {
        System.err.println("Inserting MHK #"+i);
        uri = null;
        block = new InsertBlock(mhks[i], new ClientMetadata(), FreenetURI.EMPTY_CHK_URI);
        try {
          t1 = System.currentTimeMillis();
          FreenetURI thisURI = client.insert(block, false, null);
          uri = thisURI;
          t2 = System.currentTimeMillis();
         
          System.out.println("PUSH-TIME-" + i + ":" + (t2 - t1)+" for "+uri+" for MHK #"+i);
          csvLine.add(String.valueOf(t2 - t1));
          csvLine.add(uri.toASCIIString());
          successes++;
        } catch (InsertException e) {
          e.printStackTrace();
          csvLine.add(InsertException.getShortMessage(e.getMode()));
          csvLine.add("N/A");
          System.out.println("INSERT FAILED: "+e+" for MHK #"+i);
        }
      }
     
      if(successes == 3)
        System.err.println("All inserts succeeded for MHK: "+successes);
      else if(successes != 0)
        System.err.println("Some inserts succeeded for MHK: "+successes);
      else
        System.err.println("NO INSERTS SUCCEEDED FOR MHK: "+successes);
     
      uri = null;
      }
     
      // PARSE FILE AND FETCH OLD STUFF IF APPROPRIATE
     
      boolean match = false;
     
      FreenetURI singleURI = null;
      FreenetURI[] mhkURIs = new FreenetURI[3];
      fis = new FileInputStream(file);
      BufferedReader br = new BufferedReader(new InputStreamReader(fis, ENCODING));
      String line = null;
      int linesTooShort = 0, linesBroken = 0, linesNoNumber = 0, linesNoURL = 0, linesNoFetch = 0;
      int total = 0, singleKeysSucceeded = 0, mhkSucceeded = 0;
      int totalSingleKeyFetches = 0, totalSingleKeySuccesses = 0;
      while((line = br.readLine()) != null) {
       
        singleURI = null;
        for(int i=0;i<mhkURIs.length;i++) mhkURIs[i] = null;
        //System.out.println("LINE: "+line);
        String[] split = line.split("!");
        Date date = dateFormat.parse(split[0]);
        GregorianCalendar calendar = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
        calendar.setTime(date);
        System.out.println("Date: "+dateFormat.format(calendar.getTime()));
        GregorianCalendar target = (GregorianCalendar) today.clone();
        target.set(Calendar.HOUR_OF_DAY, 0);
        target.set(Calendar.MINUTE, 0);
        target.set(Calendar.MILLISECOND, 0);
        target.set(Calendar.SECOND, 0);
        target.add(Calendar.DAY_OF_MONTH, -DELTA);
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.getTime();
        target.getTime();
        try {
          if(split.length < 3) {
            linesTooShort++;
            continue;
          }
          int seedTime = Integer.parseInt(split[2]);
          System.out.println("Seed time: "+seedTime);
         
          int token = 3;
          if(split.length < 4) {
            linesTooShort++;
            continue;
          }
         
          for(int i=0;i<3;i++) {
            int insertTime = Integer.parseInt(split[token]);
            System.out.println("Single key insert "+i+" : "+insertTime);
            token++;
            FreenetURI thisURI = new FreenetURI(split[token]);
            if(singleURI == null)
              singleURI = thisURI;
            else {
              if(!singleURI.equals(thisURI)) {
                System.err.println("URI is not the same for all 3 inserts: was "+singleURI+" but "+i+" is "+thisURI);
                linesBroken++;
                continue;
              }
            }
            token++;
          }
          System.out.println("Single key URI: "+singleURI);
         
          for(int i=0;i<3;i++) {
            int insertTime = Integer.parseInt(split[token]);
            token++;
            mhkURIs[i] = new FreenetURI(split[token]);
            token++;
            System.out.println("MHK #"+i+" URI: "+mhkURIs[i]+" insert time "+insertTime);
          }
         
        } catch (NumberFormatException e) {
          System.err.println("Failed to parse row: "+e);
          linesNoNumber++;
          continue;
        } catch (MalformedURLException e) {
          System.err.println("Failed to parse row: "+e);
          linesNoURL++;
          continue;
        }
        if(Math.abs(target.getTimeInMillis() - calendar.getTimeInMillis()) < HOURS.toMillis(12)) {
          System.out.println("Found row for target date "+dateFormat.format(target.getTime())+" : "+dateFormat.format(calendar.getTime()));
          System.out.println("Version: "+split[1]);
          match = true;
          break;
        } else if(split.length > 3+6+6) {
          int token = 3 + 6 + 6;
          int singleKeyFetchTime = -1;
          boolean singleKeySuccess = false;
          for(int i=0;i<3;i++) {
            // Fetched 3 times
            if(!singleKeySuccess) {
              try {
                singleKeyFetchTime = Integer.parseInt(split[token]);
                singleKeySuccess = true;
                System.out.println("Fetched single key on try "+i+" on "+date+" in "+singleKeyFetchTime+"ms");
              } catch (NumberFormatException e) {
                System.out.println("Failed fetch single key on "+date+" try "+i+" : "+split[token]);
                singleKeyFetchTime = -1;
              }
            } // Else will be empty.
            token++;
          }
          boolean mhkSuccess = false;
          for(int i=0;i<3;i++) {
            totalSingleKeyFetches++;
            int mhkFetchTime = -1;
            try {
              mhkFetchTime = Integer.parseInt(split[token]);
              mhkSuccess = true;
              totalSingleKeySuccesses++;
              System.out.println("Fetched MHK #"+i+" on "+date+" in "+mhkFetchTime+"ms");
            } catch (NumberFormatException e) {
              System.out.println("Failed fetch MHK #"+i+" on "+date+" : "+split[token]);
            }
            token++;
          }
          total++;
          if(singleKeySuccess)
            singleKeysSucceeded++;
          if(mhkSuccess)
            mhkSucceeded++;
        } else linesNoFetch++;
      }
      System.out.println("Lines where insert failed or no fetch: too short: "+linesTooShort+" broken: "+linesBroken+" no number: "+linesNoNumber+" no url: "+linesNoURL+" no fetch "+linesNoFetch);
      System.out.println("Total attempts where insert succeeded and fetch executed: "+total);
      System.out.println("Single keys succeeded: "+singleKeysSucceeded);
      System.out.println("MHKs succeeded: "+mhkSucceeded);
      System.out.println("Single key individual fetches: "+totalSingleKeyFetches);
      System.out.println("Single key individual fetches succeeded: "+totalSingleKeySuccesses);
      System.out.println("Success rate for individual keys (from MHK inserts): "+((double)totalSingleKeySuccesses)/((double)totalSingleKeyFetches));
      System.out.println("Success rate for the single key triple inserted: "+((double)singleKeysSucceeded)/((double)total));
      System.out.println("Success rate for the MHK (success = any of the 3 different keys worked): "+((double)mhkSucceeded)/((double)total));
      fis.close();
      fis = null;
     
      // FETCH STUFF
     
     
      if((!dumpOnly) && match) {
       
        // FETCH SINGLE URI
       
        // Fetch the first one 3 times, since the MHK is 3 fetches also.
        // Technically this is 9 fetches because we multiply by 3 fetches per high-level fetch by default.
       
        boolean fetched = false;
        for(int i=0;i<3;i++) {
          if(fetched) {
            csvLine.add("");
            continue;
          }
          try {
            t1 = System.currentTimeMillis();
            client.fetch(singleURI);
            t2 = System.currentTimeMillis();
           
            System.out.println("PULL-TIME FOR SINGLE URI:" + (t2 - t1));
            csvLine.add(String.valueOf(t2 - t1));
            fetched = true;
          } catch (FetchException e) {
            if (e.getMode() != FetchExceptionMode.ALL_DATA_NOT_FOUND
                && e.getMode() != FetchExceptionMode.DATA_NOT_FOUND)
              e.printStackTrace();
            csvLine.add(FetchException.getShortMessage(e.getMode()));
            System.err.println("FAILED PULL FOR SINGLE URI: "+e);
          }
        }
       
        for(int i=0;i<mhkURIs.length;i++) {
          try {
            t1 = System.currentTimeMillis();
            client.fetch(mhkURIs[i]);
            t2 = System.currentTimeMillis();
           
            System.out.println("PULL-TIME FOR MHK #"+i+":" + (t2 - t1));
            csvLine.add(String.valueOf(t2 - t1));
          } catch (FetchException e) {
            if (e.getMode() != FetchExceptionMode.ALL_DATA_NOT_FOUND
                && e.getMode() != FetchExceptionMode.DATA_NOT_FOUND)
              e.printStackTrace();
            csvLine.add(FetchException.getShortMessage(e.getMode()));
            System.err.println("FAILED PULL FOR MHK #"+i+": "+e);
          }
        }
      }
     
    } catch (Throwable t) {
      t.printStackTrace();
      exitCode = EXIT_THREW_SOMETHING;
    } finally {
      try {
        if (node != null)
          node.park();
      } catch (Throwable tt) {
      }
      try {
        if (node2 != null)
          node2.park();
      } catch (Throwable tt) {
      }
      Closer.close(fis);

      if(!dumpOnly) {
View Full Code Here

  public static int OPENNET_PORT1 = 5003;
  public static int DARKNET_PORT2 = 5004;
  public static int OPENNET_PORT2 = 5005;
 
  public static void main(String[] args) throws InvalidThresholdException, IOException, NodeInitException, InterruptedException {
    Node node = null;
    Node secondNode = null;
    try {
    String ipOverride = null;
    if(args.length > 0)
      ipOverride = args[0];
        File dir = new File("bootstrap-push-pull-test");
        FileUtil.removeAll(dir);
        RandomSource random = NodeStarter.globalTestInit(dir.getPath(), false, LogLevel.NORMAL, ""/*"freenet.node:MINOR,freenet.client:MINOR"*/, false);
        File seednodes = new File("seednodes.fref");
        if(!seednodes.exists() || seednodes.length() == 0 || !seednodes.canRead()) {
          System.err.println("Unable to read seednodes.fref, it doesn't exist, or is empty");
          System.exit(EXIT_NO_SEEDNODES);
        }
        File innerDir = new File(dir, Integer.toString(DARKNET_PORT1));
        innerDir.mkdir();
        FileInputStream fis = new FileInputStream(seednodes);
        FileUtil.writeTo(fis, new File(innerDir, "seednodes.fref"));
        fis.close();
        // Create one node
        Executor executor = new PooledExecutor();
        node = NodeStarter.createTestNode(DARKNET_PORT1, OPENNET_PORT1, 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);
        //NodeCrypto.DISABLE_GROUP_STRIP = true;
      //Logger.setupStdoutLogging(LogLevel.MINOR, "freenet:NORMAL,freenet.node.NodeDispatcher:MINOR,freenet.node.FNPPacketMangler:MINOR");
      Logger.getChain().setThreshold(LogLevel.ERROR); // kill logging
      // Start it
        node.start(true);
    if (!TestUtil.waitForNodes(node)) {
      node.park();
      System.exit(EXIT_FAILED_TARGET);
    }
        System.err.println("Creating test data: "+TEST_SIZE+" bytes.");
        RandomAccessBucket data = node.clientCore.tempBucketFactory.makeBucket(TEST_SIZE);
        OutputStream os = data.getOutputStream();
    try {
        byte[] buf = new byte[4096];
        for(long written = 0; written < TEST_SIZE;) {
          node.fastWeakRandom.nextBytes(buf);
          int toWrite = (int) Math.min(TEST_SIZE - written, buf.length);
          os.write(buf, 0, toWrite);
          written += toWrite;
        }
    } finally {
        os.close();
    }
        System.err.println("Inserting test data.");
        HighLevelSimpleClient client = node.clientCore.makeClient((short)0, false, false);
        InsertBlock block = new InsertBlock(data, new ClientMetadata(), FreenetURI.EMPTY_CHK_URI);
        long startInsertTime = System.currentTimeMillis();
        FreenetURI uri;
        try {
      uri = client.insert(block, false, null);
    } catch (InsertException e) {
      System.err.println("INSERT FAILED: "+e);
      e.printStackTrace();
      System.exit(EXIT_INSERT_FAILED);
      return;
    }
        long endInsertTime = System.currentTimeMillis();
        System.err.println("RESULT: Insert took "+(endInsertTime-startInsertTime)+"ms ("+TimeUtil.formatTime(endInsertTime-startInsertTime)+") to "+uri+" .");
        node.park();
   
        // Bootstrap a second node.
        File secondInnerDir = new File(dir, Integer.toString(DARKNET_PORT2));
        secondInnerDir.mkdir();
        fis = new FileInputStream(seednodes);
        FileUtil.writeTo(fis, new File(secondInnerDir, "seednodes.fref"));
        fis.close();
        executor = new PooledExecutor();
        secondNode = NodeStarter.createTestNode(DARKNET_PORT2, OPENNET_PORT2, 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);
    if (!TestUtil.waitForNodes(secondNode)) {
      secondNode.park();
      System.exit(EXIT_FAILED_TARGET);
    }
       
        // Fetch the data
        long startFetchTime = System.currentTimeMillis();
        client = secondNode.clientCore.makeClient((short)0, false, false);
        try {
      client.fetch(uri);
    } catch (FetchException e) {
      System.err.println("FETCH FAILED: "+e);
      e.printStackTrace();
      System.exit(EXIT_FETCH_FAILED);
      return;
    }
    long endFetchTime = System.currentTimeMillis();
    System.err.println("RESULT: Fetch took "+(endFetchTime-startFetchTime)+"ms ("+TimeUtil.formatTime(endFetchTime-startFetchTime)+") of "+uri+" .");
    secondNode.park();
    System.exit(0);
      } catch (Throwable t) {
        System.err.println("CAUGHT: "+t);
        t.printStackTrace();
        try {
          if(node != null)
            node.park();
        } catch (Throwable t1) {}
        try {
          if(secondNode != null)
            secondNode.park();
        } catch (Throwable t1) {}

        System.exit(EXIT_THREW_SOMETHING);
      }
  }
View Full Code Here

    System.out.println("Version:" + Version.buildNumber());
    csvLine.add(String.valueOf(Version.buildNumber()));

    int exitCode = 0;
    Node node = null;
    Node node2 = null;
    FileInputStream fis = null;
    File file = new File("many-single-blocks-test-"+uid + ".csv");
    long t1, t2;
   
    try {
     
      // INSERT STUFF
     
      final File dir = new File("longterm-mhk-test-" + uid);
      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()) {
        System.err.println("Unable to read seednodes.fref, it doesn't exist, or is empty");
        System.exit(EXIT_NO_SEEDNODES);
      }

      final File innerDir = new File(dir, Integer.toString(DARKNET_PORT1));
      innerDir.mkdir();
      fis = new FileInputStream(seednodes);
      FileUtil.writeTo(fis, new File(innerDir, "seednodes.fref"));
      fis.close();

      // Create one node
      node = NodeStarter.createTestNode(DARKNET_PORT1, OPENNET_PORT1, dir.getPath(), false, Node.DEFAULT_MAX_HTL,
              0, random, new PooledExecutor(), 1000, 4 * 1024 * 1024, true, true, true, true, true, true, true,
              12 * 1024, true, true, false, false, null);
      Logger.getChain().setThreshold(LogLevel.ERROR);

      // Start it
      node.start(true);
      t1 = System.currentTimeMillis();
      if (!TestUtil.waitForNodes(node)) {
        exitCode = EXIT_FAILED_TARGET;
        return;
      }
       
      t2 = System.currentTimeMillis();
      System.out.println("SEED-TIME:" + (t2 - t1));
      csvLine.add(String.valueOf(t2 - t1));

      HighLevelSimpleClient client = node.clientCore.makeClient((short) 0, false, false);

      int successes = 0;
     
      long startInsertsTime = System.currentTimeMillis();
     
      InsertBatch batch = new InsertBatch(client);
     
      // Inserts are sloooooow so do them in parallel.
     
      for(int i=0;i<INSERTED_BLOCKS;i++) {
       
        System.err.println("Inserting block "+i);
       
        RandomAccessBucket single = randomData(node);
       
        InsertBlock block = new InsertBlock(single, new ClientMetadata(), FreenetURI.EMPTY_CHK_URI);
       
        batch.startInsert(block);
       
      }
     
      batch.waitUntilFinished();
      FreenetURI[] uris = batch.getURIs();
      long[] times = batch.getTimes();
      InsertException[] errors = batch.getErrors();
     
      for(int i=0;i<INSERTED_BLOCKS;i++) {
        if(uris[i] != null) {
          csvLine.add(String.valueOf(times[i]));
          csvLine.add(uris[i].toASCIIString());
          System.out.println("Pushed block "+i+" : "+uris[i]+" in "+times[i]);
          successes++;
        } else {
          csvLine.add(InsertException.getShortMessage(errors[i].getMode()));
          csvLine.add("N/A");
          System.out.println("Failed to push block "+i+" : "+errors[i]);
        }
      }
     
      long endInsertsTime = System.currentTimeMillis();
     
      System.err.println("Succeeded inserts: "+successes+" of "+INSERTED_BLOCKS+" in "+(endInsertsTime-startInsertsTime)+"ms");
     
      FetchContext fctx = client.getFetchContext();
      fctx.maxNonSplitfileRetries = 0;
      fctx.maxSplitfileBlockRetries = 0;
      RequestClient requestContext = new RequestClient() {

        @Override
        public boolean persistent() {
          return false;
        }

        @Override
        public boolean realTimeFlag() {
          return false;
        }
       
      };
     
      // PARSE FILE AND FETCH OLD STUFF IF APPROPRIATE
     
      FreenetURI[] mhkURIs = new FreenetURI[3];
      fis = new FileInputStream(file);
      BufferedReader br = new BufferedReader(new InputStreamReader(fis, ENCODING));
      String line = null;
      GregorianCalendar target = (GregorianCalendar) today.clone();
      target.set(Calendar.HOUR_OF_DAY, 0);
      target.set(Calendar.MINUTE, 0);
      target.set(Calendar.MILLISECOND, 0);
      target.set(Calendar.SECOND, 0);
      GregorianCalendar[] targets = new GregorianCalendar[MAX_N+1];
      for(int i=0;i<targets.length;i++) {
        targets[i] = ((GregorianCalendar)target.clone());
        targets[i].add(Calendar.DAY_OF_MONTH, -((1<<i)-1));
        targets[i].getTime();
      }
      int[] totalFetchesByDelta = new int[MAX_N+1];
      int[] totalSuccessfulFetchesByDelta = new int[MAX_N+1];
      long[] totalFetchTimeByDelta = new long[MAX_N+1];
     
loopOverLines:
      while((line = br.readLine()) != null) {
       
        for(int i=0;i<mhkURIs.length;i++) mhkURIs[i] = null;
        //System.out.println("LINE: "+line);
        String[] split = line.split("!");
        Date date = dateFormat.parse(split[0]);
        GregorianCalendar calendar = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
        calendar.setTime(date);
        System.out.println("Date: "+dateFormat.format(calendar.getTime()));
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.getTime();
        FreenetURI[] insertedURIs = new FreenetURI[INSERTED_BLOCKS];
        int[] insertTimes = new int[INSERTED_BLOCKS];
        if(split.length < 3) continue;
        int seedTime = Integer.parseInt(split[2]);
        System.out.println("Seed time: "+seedTime);
        if(split.length < 4) continue;
       
        int token = 3;
       
        if(split.length < token + INSERTED_BLOCKS * 2) continue;
     
        for(int i=0;i<INSERTED_BLOCKS;i++) {
          try {
            insertTimes[i] = Integer.parseInt(split[token]);
          } catch (NumberFormatException e) {
            insertTimes[i] = -1;
          }
          token++;
          try {
            insertedURIs[i] = new FreenetURI(split[token]);
          } catch (MalformedURLException e) {
            insertedURIs[i] = null;
          }
          token++;
          System.out.println("Key insert "+i+" : "+insertedURIs[i]+" in "+insertTimes[i]);
        }
        for(int i=0;i<targets.length;i++) {
          if(Math.abs(targets[i].getTimeInMillis() - calendar.getTimeInMillis()) < HOURS.toMillis(12)) {
            System.out.println("Found row for target date "+((1<<i)-1)+" days ago.");
            System.out.println("Version: "+split[1]);
            csvLine.add(Integer.toString(i));
            int pulled = 0;
            int inserted = 0;
            for(int j=0;j<INSERTED_BLOCKS;j++) {
              if(insertedURIs[j] == null) {
                csvLine.add("INSERT FAILED");
                continue;
              }
              inserted++;
              try {
                t1 = System.currentTimeMillis();
                FetchWaiter fw = new FetchWaiter(requestContext);
                client.fetch(insertedURIs[j], 32768, fw, fctx);
                fw.waitForCompletion();
                t2 = System.currentTimeMillis();
               
                System.out.println("PULL-TIME FOR BLOCK "+j+": " + (t2 - t1));
                csvLine.add(String.valueOf(t2 - t1));
                pulled++;
              } catch (FetchException e) {
                if (e.getMode() != FetchExceptionMode.ALL_DATA_NOT_FOUND
                    && e.getMode() != FetchExceptionMode.DATA_NOT_FOUND)
                  e.printStackTrace();
                csvLine.add(FetchException.getShortMessage(e.getMode()));
                System.err.println("FAILED PULL FOR BLOCK "+j+": "+e);
              }
            }
            System.out.println("Pulled "+pulled+" blocks of "+inserted+" from "+((1<<i)-1)+" days ago.");
          }
        }
       
        while(split.length > token + INSERTED_BLOCKS) {
          int delta;
          try {
            delta = Integer.parseInt(split[token]);
          } catch (NumberFormatException e) {
            System.err.println("Unable to parse token "+token+" = \""+token+"\"");
            System.err.println("This is supposed to be a delta");
            System.err.println("Skipping the rest of the line for date "+dateFormat.format(calendar.getTime()));
            continue loopOverLines;
          }
          System.out.println("Delta: "+((1<<delta)-1)+" days");
          token++;
          int totalFetchTime = 0;
          int totalSuccesses = 0;
          int totalFetches = 0;
          for(int i=0;i<INSERTED_BLOCKS;i++) {
            if(split[token].equals(""))
              continue;
            int mhkFetchTime = -1;
            totalFetches++;
            try {
              mhkFetchTime = Integer.parseInt(split[token]);
              System.out.println("Fetched block #"+i+" on "+date+" in "+mhkFetchTime+"ms");
              totalSuccesses++;
              totalFetchTime += mhkFetchTime;
            } catch (NumberFormatException e) {
              System.out.println("Failed block #"+i+" on "+date+" : "+split[token]);
            }
            token++;
          }
          totalFetchesByDelta[delta] += totalFetches;
          totalSuccessfulFetchesByDelta[delta] += totalSuccesses;
          totalFetchTimeByDelta[delta] += totalFetchTime;
          System.err.println("Succeeded: "+totalSuccesses+" of "+totalFetches+" average "+((double)totalFetchTime)/((double)totalSuccesses)+"ms for delta "+delta+" on "+dateFormat.format(date));
        }
      }
     
      System.out.println();
      System.out.println();
     
      for(int i=0;i<MAX_N+1;i++) {
        System.out.println("DELTA: "+i+" days: Total fetches: "+totalFetchesByDelta[i]+" total successes "+totalSuccessfulFetchesByDelta[i]+" = "+((totalSuccessfulFetchesByDelta[i]*100.0)/totalFetchesByDelta[i])+"% in "+(totalFetchTimeByDelta[i]*1.0)/totalSuccessfulFetchesByDelta[i]+"ms");
      }
     
      fis.close();
      fis = null;
     
    } catch (Throwable t) {
      t.printStackTrace();
      exitCode = EXIT_THREW_SOMETHING;
    } finally {
      try {
        if (node != null)
          node.park();
      } catch (Throwable tt) {
      }
      try {
        if (node2 != null)
          node2.park();
      } catch (Throwable tt) {
      }
      Closer.close(fis);
      writeToStatusLog(file, csvLine);

View Full Code Here

    System.out.println("Version:" + Version.buildNumber());
    csvLine.add(String.valueOf(Version.buildNumber()));

    int exitCode = 0;
    Node node = null;
    Node node2 = null;
    try {
      final File dir = new File("longterm-push-pull-test-" + uid);
      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()) {
        System.err.println("Unable to read seednodes.fref, it doesn't exist, or is empty");
        System.exit(EXIT_NO_SEEDNODES);
      }

      final File innerDir = new File(dir, Integer.toString(DARKNET_PORT1));
      innerDir.mkdir();
      FileInputStream fis = new FileInputStream(seednodes);
      FileUtil.writeTo(fis, new File(innerDir, "seednodes.fref"));
      fis.close();

      // Create one node
      node = NodeStarter.createTestNode(DARKNET_PORT1, OPENNET_PORT1, dir.getPath(), false, Node.DEFAULT_MAX_HTL,
              0, random, new PooledExecutor(), 1000, 4 * 1024 * 1024, true, true, true, true, true, true, true,
              12 * 1024, true, true, false, false, null);
      Logger.getChain().setThreshold(LogLevel.ERROR);

      // Start it
      node.start(true);
      long t1 = System.currentTimeMillis();
      if (!TestUtil.waitForNodes(node)) {
        exitCode = EXIT_FAILED_TARGET;
        return;
      }
       
      long t2 = System.currentTimeMillis();
      System.out.println("SEED-TIME:" + (t2 - t1));
      csvLine.add(String.valueOf(t2 - t1));
     
      FreenetURI todaysInsert = null;

      // PUSH N+1 BLOCKS
      for (int i = 0; i <= MAX_N; i++) {
          RandomAccessBucket data = randomData(node);
        HighLevelSimpleClient client = node.clientCore.makeClient((short) 0, false, false);
        System.out.println("PUSHING " + i);

        try {
          InsertBlock block = new InsertBlock(data, new ClientMetadata(), FreenetURI.EMPTY_CHK_URI);
          t1 = System.currentTimeMillis();
          FreenetURI uri = client.insert(block, false, null);
          if(i == 0) todaysInsert = uri;
          t2 = System.currentTimeMillis();

          System.out.println("PUSH-TIME-" + i + ":" + (t2 - t1)+" for "+uri);
          csvLine.add(String.valueOf(t2 - t1));
          csvLine.add(uri.toASCIIString());
        } catch (InsertException e) {
          e.printStackTrace();
          csvLine.add("N/A");
          csvLine.add("N/A");
        }

        data.free();
      }

      node.park();

      // Node 2
      File innerDir2 = new File(dir, Integer.toString(DARKNET_PORT2));
      innerDir2.mkdir();
      fis = new FileInputStream(seednodes);
      FileUtil.writeTo(fis, new File(innerDir2, "seednodes.fref"));
      fis.close();
      node2 = NodeStarter.createTestNode(DARKNET_PORT2, OPENNET_PORT2, dir.getPath(), false,
              Node.DEFAULT_MAX_HTL, 0, random, new PooledExecutor(), 1000, 5 * 1024 * 1024, true, true, true,
              true, true, true, true, 12 * 1024, false, true, false, false, null);
      node2.start(true);

      t1 = System.currentTimeMillis();
      if (!TestUtil.waitForNodes(node2)) {
        exitCode = EXIT_FAILED_TARGET;
        return;
      }
      t2 = System.currentTimeMillis();
      System.out.println("SEED-TIME:" + (t2 - t1));
      csvLine.add(String.valueOf(t2 - t1));

      // PULL N+1 BLOCKS
      for (int i = 0; i <= MAX_N; i++) {
        HighLevelSimpleClient client = node2.clientCore.makeClient((short) 0, false, false);
        Calendar targetDate = (Calendar) today.clone();
        targetDate.add(Calendar.DAY_OF_MONTH, -((1 << i) - 1));

        FreenetURI uri = null;
       
        if(i == 0) uri = todaysInsert;
        else {
          uri = getHistoricURI(uid, i, targetDate);
        }
       
        if(uri == null) {
          System.out.println("SKIPPING PULL FOR "+i);
          continue;
        }
       
        System.out.println("PULLING " + uri);

        try {
          t1 = System.currentTimeMillis();
          client.fetch(uri);
          t2 = System.currentTimeMillis();

          System.out.println("PULL-TIME-" + i + ":" + (t2 - t1));
          csvLine.add(String.valueOf(t2 - t1));
        } catch (FetchException e) {
          if (e.getMode() != FetchExceptionMode.ALL_DATA_NOT_FOUND
                  && e.getMode() != FetchExceptionMode.DATA_NOT_FOUND)
            e.printStackTrace();
          csvLine.add(FetchException.getShortMessage(e.getMode()));
        }
      }
    } catch (Throwable t) {
      t.printStackTrace();
      exitCode = EXIT_THREW_SOMETHING;
    } finally {
      try {
        if (node != null)
          node.park();
      } catch (Throwable t1) {
      }
      try {
        if (node2 != null)
          node2.park();
      } catch (Throwable t1) {
      }

      File file = new File(uid + ".csv");
      writeToStatusLog(file, csvLine);
View Full Code Here

  static final int DARKNET_PORT = RealNodeULPRTest.DARKNET_PORT_END;
  static final int OPENNET_PORT = DARKNET_PORT+1;

    public static void main(String[] args) throws FSParseException, IOException, OpennetDisabledException, PeerParseException, InterruptedException, ReferenceSignatureVerificationException, NodeInitException, InvalidThresholdException {
      Node node = null;
      try {
      if(args.length == 1)
        STATUS_DIR = new File(args[0]);
        RandomSource random = NodeStarter.globalTestInit("seednode-pingtest", false, LogLevel.ERROR, "", false);
        // Create one node
        Executor executor = new PooledExecutor();
  node = NodeStarter.createTestNode(DARKNET_PORT, OPENNET_PORT, "seednode-pingtest", false, Node.DEFAULT_MAX_HTL, 0, random, executor, 1000, 5*1024*1024, true, false, false, false, false, false, false, 0, false, false, false, false, null);
  // Connect & ping
  List<SeedServerTestPeerNode> seedNodes = new ArrayList<SeedServerTestPeerNode>();
  List<SimpleFieldSet> seedNodesAsSFS = Announcer.readSeednodes(new File("/tmp/", Announcer.SEEDNODES_FILENAME));
  int numberOfNodesInTheFile = 0;
  for(SimpleFieldSet sfs : seedNodesAsSFS) {
    numberOfNodesInTheFile++;
    SeedServerTestPeerNode seednode = node.createNewSeedServerTestPeerNode(sfs);
    try {
      node.connectToSeednode(seednode);
      seedNodes.add(seednode);
    } catch (Exception fse) {
      System.err.println("ERROR adding "+seednode.toString()+ " "+fse.getMessage());
    }
  }
  // Start it
        node.start(true);
  //Logger.setupStdoutLogging(LogLevel.MINOR, "freenet:NORMAL,freenet.node.NodeDispatcher:MINOR,freenet.node.FNPPacketMangler:MINOR");
  Logger.getChain().setThreshold(LogLevel.ERROR); // kill logging
  Thread.sleep(SECONDS.toMillis(2));
  if(seedNodes.size() != numberOfNodesInTheFile)
        System.out.println("ERROR ADDING SOME OF THE SEEDNODES!!");
  System.out.println("Let some time for the "+ seedNodes.size() +" nodes to connect...");
  Thread.sleep(SECONDS.toMillis(8));

  int pingID = 0;
  long deadline = System.currentTimeMillis() + MINUTES.toMillis(2);
  while(System.currentTimeMillis() < deadline) {
    int countConnectedSeednodes = 0;
    for(SeedServerPeerNode seednode : node.peers.getConnectedSeedServerPeersVector(null)) {
      try {
        double pingTime = seednode.averagePingTime();
        int uptime = seednode.getUptime();
        long timeDelta = seednode.getClockDelta();
        if(seednode.isRealConnection())
          continue;
        countConnectedSeednodes++;
        boolean ping = seednode.ping(pingID++);
        if(ping)
          System.out.println(seednode.getIdentityString()+
            " uptime="+uptime+
            " ping="+ping+
            " pingTime="+pingTime+
            " uptime="+seednode.getUptime()+
            " timeDelta="+TimeUtil.formatTime(timeDelta));
        // sanity check
        if(seednode.isRoutable())
          System.out.println(seednode + " is routable!");
      } catch (NotConnectedException e) {
        System.out.println(seednode.getIdentityString() + " is not connected "+seednode.getHandshakeCount());
      }
    }
    Map<FATE, Integer> totals = new EnumMap<FATE, Integer>(SeedServerTestPeerNode.FATE.class);
    for(SeedServerTestPeerNode seednode : seedNodes) {
      FATE fate = seednode.getFate();
      Integer x = totals.get(fate);
      if(x == null)
        totals.put(fate, 1);
      else
        totals.put(fate, x+1);
      System.out.println(seednode.getIdentityString() + " : "+fate+ " : "+seednode.getPeerNodeStatusString());
    }
    System.out.println("TOTALS:");
    for (Entry<FATE, Integer> fateEntry : totals.entrySet()) {
      System.out.println(fateEntry.getKey() + " : " + fateEntry.getValue());
    }
    System.out.println("################## ("+node.peers.countConnectedPeers()+") "+countConnectedSeednodes+'/'+node.peers.countSeednodes());
    Thread.sleep(SECONDS.toMillis(5));
  }
  Map<FATE, Integer> totals = new EnumMap<FATE, Integer>(SeedServerTestPeerNode.FATE.class);
  for(SeedServerTestPeerNode seednode : seedNodes) {
    FATE fate = seednode.getFate();
    Integer x = totals.get(fate);
    if(x == null)
      totals.put(fate, 1);
    else
      totals.put(fate, x+1);
    System.out.println(seednode.getIdentityString() + " : "+fate+ " : "+seednode.getPeerNodeStatusString());
  }
  System.out.println("RESULT:TOTALS:");
  for(FATE fate : totals.keySet()) {
    System.out.println("RESULT:"+fate + " : "+totals.get(fate));
  }
    System.out.println("Completed seednodes scan.");
    // Record statuses.
    System.out.println("FINAL STATUS:");
    long writeTime = System.currentTimeMillis();
    for(SeedServerTestPeerNode peer : seedNodes) {
      String status = writeTime+" : "+peer.getIdentityString()+" : "+peer.getFate();
      System.out.println(status);
      File logFile = new File(STATUS_DIR, peer.getIdentityString());
      FileOutputStream fos = new FileOutputStream(logFile, true);
      OutputStreamWriter osw = new OutputStreamWriter(fos, "UTF-8");
      osw.write(status+"\n");
      osw.close();
      FileInputStream fis = new FileInputStream(logFile);
      InputStreamReader isr = new InputStreamReader(fis, "UTF-8");
      BufferedReader br = new BufferedReader(isr);
      String line;
      int successes = 0;
      int failures = 0;
      long lastSuccess = 0;
      long firstSample = 0;
      long countSince = writeTime - COUNT_SUCCESSES_PERIOD;
      do {
        line = br.readLine();
        if(line == null) break;
        String[] results = line.split(" : ");
        if(results.length != 3) {
          System.err.println("Unable to parse line in "+logFile+" : wrong number of fields : "+results.length+" : "+line);
          continue;
        }
        long time = Long.parseLong(results[0]);
        FATE fate = FATE.valueOf(results[2]);
        if(firstSample == 0) firstSample = time;
        if(fate == FATE.CONNECTED_SUCCESS) {
          if(time >= countSince)
            successes++;
          lastSuccess = time;
        } else {
          if(time >= countSince)
            failures++;
        }
      } while(line != null);
      br.close();
      if(firstSample < countSince && successes == 0)
        System.err.println("RESULT:"+peer.getIdentityString()+" NOT CONNECTED IN LAST WEEK! LAST CONNECTED: "+(lastSuccess > 0 ? TimeUtil.formatTime(writeTime - lastSuccess) : "NEVER"));
      System.out.println(peer.getIdentityString()+" : last success "+(lastSuccess > 0 ? TimeUtil.formatTime(writeTime - lastSuccess) : "NEVER")+" failures in last week: "+failures+" successes in last week: "+successes);
    }
    node.park();
    System.exit(0);
    } catch (Throwable t) {
      System.err.println("CAUGHT: "+t);
      t.printStackTrace();
      try {
        if(node != null)
        node.park();
      } catch (Throwable t1) {}
      System.exit(1);
    }
    }
View Full Code Here

   * @throws NodeInitException
   * @throws InterruptedException
   * @throws IOException
   */
  public static void main(String[] args) throws InvalidThresholdException, NodeInitException, InterruptedException, IOException {
    Node node = null;
    try {
    String ipOverride = null;
    if(args.length > 0)
      ipOverride = args[0];
        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()) {
          System.err.println("Unable to read seednodes.fref, it doesn't exist, or is empty");
          System.exit(EXIT_NO_SEEDNODES);
        }
        File innerDir = new File(dir, Integer.toString(DARKNET_PORT));
        innerDir.mkdir();
        FileInputStream fis = new FileInputStream(seednodes);
        FileUtil.writeTo(fis, new File(innerDir, "seednodes.fref"));
        fis.close();
        // Create one node
        Executor executor = new PooledExecutor();
        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);
        //NodeCrypto.DISABLE_GROUP_STRIP = true;
      //Logger.setupStdoutLogging(LogLevel.MINOR, "freenet:NORMAL,freenet.node.NodeDispatcher:MINOR,freenet.node.FNPPacketMangler:MINOR");
      Logger.getChain().setThreshold(LogLevel.ERROR); // kill logging
      long startTime = System.currentTimeMillis();
      // Start it
        node.start(true);
        // Wait until we have 10 connected nodes...
        int seconds = 0;
    int targetPeers = node.getOpennet().getAnnouncementThreshold();
        while(seconds < 600) {
          Thread.sleep(1000);
          int seeds = node.peers.countSeednodes();
          int seedConns = node.peers.getConnectedSeedServerPeersVector(null).size();
          int opennetPeers = node.peers.countValidPeers();
          int opennetConns = node.peers.countConnectedOpennetPeers();
          System.err.println(""+seconds+" : seeds: "+seeds+", connected: "+seedConns
              +" opennet: peers: "+opennetPeers+", connected: "+opennetConns);
          seconds++;
          if(opennetConns >= targetPeers) {
            long timeTaken = System.currentTimeMillis()-startTime;
            System.out.println("Completed bootstrap ("+targetPeers+" peers) in "+timeTaken+"ms ("+TimeUtil.formatTime(timeTaken)+")");
            node.park();
            System.exit(0);
          }
        }
        System.err.println("Failed to reach target peers count "+targetPeers+" in 5 minutes.");
    node.park();
        System.exit(EXIT_FAILED_TARGET);
      } catch (Throwable t) {
        System.err.println("CAUGHT: "+t);
        t.printStackTrace();
        try {
          if(node != null)
            node.park();
        } catch (Throwable t1) {}
        System.exit(EXIT_THREW_SOMETHING);
      }
  }
View Full Code Here

TOP

Related Classes of freenet.node.Node

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.