Package freenet.node

Examples of freenet.node.Node


        int next = (i+1) % nodes.length;
        connect(nodes[i], nodes[next]);
      }
    }
    for (int i=0; i<nodes.length; i++) {
      Node a = nodes[i];
      // Normalise the probabilities
      double norm = 0.0;
      for (int j=0; j<nodes.length; j++) {
        Node b = nodes[j];
        if (a.getLocation() == b.getLocation()) continue;
        norm += 1.0 / distance (a, b);
      }
      // Create degree/2 outgoing connections
      for (int k=0; k<nodes.length; k++) {
        Node b = nodes[k];
        if (a.getLocation() == b.getLocation()) continue;
        double p = 1.0 / distance (a, b) / norm;
        for (int n = 0; n < degree / 2; n++) {
          if (random.nextFloat() < p) {
            connect(a, b);
            break;
View Full Code Here


        try {
          Thread.sleep(sleepTime);
        } catch(InterruptedException e1) {
        }
        try {
          Node randomNode = nodes[random.nextInt(nodes.length)];
          Node randomNode2 = randomNode;
          while(randomNode2 == randomNode) {
            randomNode2 = nodes[random.nextInt(nodes.length)];
          }
          double loc2 = randomNode2.getLocation();
          Logger.normal(RealNodeRoutingTest.class, "Pinging " + randomNode2.getDarknetPortNumber() + " @ " + loc2 + " from " + randomNode.getDarknetPortNumber() + " @ " + randomNode.getLocation());
         
          int hopsTaken = randomNode.routedPing(loc2, randomNode2.getDarknetPubKeyHash());
          pings++;
          if(hopsTaken < 0) {
            failures++;
            avg.report(0.0);
            avg2.report(0.0);
            double ratio = (double) successes / ((double) (failures + successes));
            System.err.println("Routed ping " + pings + " FAILED from " + randomNode.getDarknetPortNumber() + " to " + randomNode2.getDarknetPortNumber() + " (long:" + ratio + ", short:" + avg.currentValue() + ", vague:" + avg2.currentValue() + ')');
          } else {
            totalHopsTaken += hopsTaken;
            successes++;
            avg.report(1.0);
            avg2.report(1.0);
            double ratio = (double) successes / ((double) (failures + successes));
            System.err.println("Routed ping " + pings + " success: " + hopsTaken + ' ' + randomNode.getDarknetPortNumber() + " to " + randomNode2.getDarknetPortNumber() + " (long:" + ratio + ", short:" + avg.currentValue() + ", vague:" + avg2.currentValue() + ')');
          }
        } catch(Throwable t) {
          Logger.error(RealNodeRoutingTest.class, "Caught " + t, t);
        }
      }
View Full Code Here

   
  };

  public void createFproxy() {
    NodeClientCore core = this.core;
    Node node = core.node;
    synchronized(this) {
      if(haveCalledFProxy) return;
      haveCalledFProxy = true;
    }
   
View Full Code Here

                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)
View Full Code Here

   * @throws IOException
   * @throws NodeInitException
   * @throws InterruptedException
   */
  public static void main(String[] args) throws InvalidThresholdException, IOException, NodeInitException, InterruptedException {
    Node secondNode = null;
    try {
    String ipOverride = null;
    if(args.length > 0)
      ipOverride = args[0];
        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);
        MersenneTwister fastRandom = new MersenneTwister(seed);
        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 secondInnerDir = new File(dir, Integer.toString(DARKNET_PORT));
        secondInnerDir.mkdir();
        FileInputStream fis = new FileInputStream(seednodes);
        FileUtil.writeTo(fis, new File(secondInnerDir, "seednodes.fref"));
        fis.close();

        // Create the test data
        System.out.println("Creating test data.");
        File dataFile = File.createTempFile("testdata", ".tmp", dir);
        OutputStream os = new FileOutputStream(dataFile);
        byte[] buf = new byte[4096];
        for(long written = 0; written < TEST_SIZE;) {
          fastRandom.nextBytes(buf);
          int toWrite = (int) Math.min(TEST_SIZE - written, buf.length);
          os.write(buf, 0, toWrite);
          written += toWrite;
        }
        os.close();

        // Insert it to the established node.
        System.out.println("Inserting test data to an established node.");
        FreenetURI uri = insertData(dataFile);

        // Bootstrap a second node.
        secondInnerDir.mkdir();
        fis = new FileInputStream(seednodes);
        FileUtil.writeTo(fis, new File(secondInnerDir, "seednodes.fref"));
        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);

    if (!TestUtil.waitForNodes(secondNode)) {
      secondNode.park();
      System.exit(EXIT_FAILED_TARGET);
    }

        // Fetch the data
        long startFetchTime = System.currentTimeMillis();
        HighLevelSimpleClient 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.out.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(secondNode != null)
            secondNode.park();
        } catch (Throwable t1) {}
        System.exit(EXIT_THREW_SOMETHING);
      }
  }
View Full Code Here

    public static void main(String[] args) throws FSParseException, PeerParseException, InterruptedException, ReferenceSignatureVerificationException, NodeInitException, InvalidThresholdException {
        RandomSource random = NodeStarter.globalTestInit("pingtest", false, LogLevel.ERROR, "", true);
        // Create 2 nodes
        Executor executor = new PooledExecutor();
        Node node1 = NodeStarter.createTestNode(DARKNET_PORT1, 0, "pingtest", true, Node.DEFAULT_MAX_HTL, 0, random, executor, 1000, 65536, true, false, false, false, false, false, true, 0, false, false, true, false, null);
        Node node2 = NodeStarter.createTestNode(DARKNET_PORT2, 0, "pingtest", true, Node.DEFAULT_MAX_HTL, 0, random, executor, 1000, 65536, true, false, false, false, false, false, true, 0, false, false, true, false, null);
        // Connect
        node1.connect(node2, trust, visibility);
        node2.connect(node1, trust, visibility);
        // No swapping
        node1.start(true);
        node2.start(true);
        // Ping
        PeerNode pn = node1.getPeerNodes()[0];
        int pingID = 0;
        Thread.sleep(20000);
        //node1.usm.setDropProbability(4);
View Full Code Here

        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);
            CHKBlock block = b.getBlock();
View Full Code Here

    }
  }

  @Override
  public long checkRecentlyFailed(Key key, boolean realTime) {
    Node node = sched.getNode();
    return node.clientCore.checkRecentlyFailed(key, realTime);
  }
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.