Example #1
0
 /**
  * Adds the node reference in the resources as a friend to the node this plugin is loaded.
  *
  * @return the corresponding PeerAdditionReturnCode indicating whether the bridge was added
  *     successfully as a friend
  */
 private PeerAdditionReturnCodes addFriendBridge() {
   SimpleFieldSet bridgeNodeFS;
   try {
     bridgeNodeFS = nodeRefHelper.getBridgeNodeRefFS();
   } catch (IOException e) {
     Logger.error(this, "IO Exception while parsing bridge reference resource file");
     return PeerAdditionReturnCodes.INTERNAL_ERROR;
   }
   PeerNode pn;
   try {
     pn = node.createNewDarknetNode(bridgeNodeFS, FRIEND_TRUST.HIGH, FRIEND_VISIBILITY.NO);
     ((DarknetPeerNode) pn).setPrivateDarknetCommentNote("Master Bridge");
   } catch (FSParseException e) {
     return PeerAdditionReturnCodes.CANT_PARSE;
   } catch (PeerParseException e) {
     return PeerAdditionReturnCodes.CANT_PARSE;
   } catch (ReferenceSignatureVerificationException e) {
     return PeerAdditionReturnCodes.INVALID_SIGNATURE;
   } catch (Throwable t) {
     Logger.error(this, "Internal error adding reference :" + t.getMessage(), t);
     return PeerAdditionReturnCodes.INTERNAL_ERROR;
   }
   if (Arrays.equals(pn.getPubKeyHash(), node.getDarknetPubKeyHash())) {
     Logger.warning(this, "The bridge  node reference file belongs to this node.");
     return PeerAdditionReturnCodes.TRY_TO_ADD_SELF;
   }
   if (!node.addPeerConnection(pn)) {
     return PeerAdditionReturnCodes.ALREADY_IN_REFERENCE;
   }
   return PeerAdditionReturnCodes.OK;
 }
Example #2
0
  public static void main(String[] args)
      throws FSParseException, PeerParseException, InvalidThresholdException, NodeInitException,
          ReferenceSignatureVerificationException {
    // Logger.setupStdoutLogging(LogLevel.NORMAL,
    // "freenet.node.CPUAdjustingSwapRequestInterval:minor"
    // /*"freenet.node.LocationManager:debug,freenet.node.FNPPacketManager:normal,freenet.io.comm.MessageCore:debug"*/);
    System.out.println("SecretPing (CRAM) test using real nodes:");
    System.out.println();
    String wd = "realNodeSecretPingTest";
    new File(wd).mkdir();
    // NOTE: globalTestInit returns in ignored random source
    NodeStarter.globalTestInit(
        wd,
        false,
        LogLevel.ERROR,
        "freenet.node.Location:normal,freenet.node.simulator.RealNodeSecretPingTest:normal,freenet.node.NetworkIDManager:normal",
        true);

    DummyRandomSource random = new DummyRandomSource();
    // DiffieHellman.init(random);
    Node[] nodes = new Node[NUMBER_OF_NODES];
    Logger.normal(RealNodeRoutingTest.class, "Creating nodes...");
    Executor executor = new PooledExecutor();

    // Allow secret pings, but don't automatically send them (this is the test for them!)
    freenet.node.NetworkIDManager.disableSecretPings = false;
    freenet.node.NetworkIDManager.disableSecretPinger = true;

    for (int i = 0; i < NUMBER_OF_NODES; i++) {
      nodes[i] =
          NodeStarter.createTestNode(
              DARKNET_PORT_BASE + i,
              0,
              wd,
              true,
              MAX_HTL,
              0 /* no dropped packets */,
              random,
              executor,
              500 * NUMBER_OF_NODES,
              storeSize,
              true,
              true,
              false,
              false,
              false,
              true,
              true,
              0,
              true,
              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);
    Logger.normal(RealNodeRoutingTest.class, "Added small-world links");

    for (int i = 0; i < NUMBER_OF_NODES; i++) nodes[i].start(false);

    // Now sit back and watch the fireworks!
    int cycleNumber = 0;
    RunningAverage avg2 = new BootstrappingDecayingRunningAverage(0.0, 0.0, 1.0, 100, null);
    while (true) {
      cycleNumber++;

      try {
        Thread.sleep(2000);
      } catch (InterruptedException e) {
        // Ignore
      }

      Node source = nodes[random.nextInt(NUMBER_OF_NODES)];
      PeerNode verify = source.peers.getRandomPeer();
      PeerNode pathway = source.peers.getRandomPeer(verify);

      Logger.error(
          source,
          "verify ("
              + getPortNumber(verify)
              + ") through: "
              + getPortNumber(pathway)
              + "; so far "
              + avg2.currentValue());

      long uid = random.nextLong();
      long secret = random.nextLong();

      if (verify == null) {
        Logger.error(source, "verify peernode is null");
        continue;
      }

      if (pathway == null) {
        Logger.error(source, "pathway peernode is null");
        continue;
      }

      try {
        // Send the FNPStoreSecret message to the 'verify' node
        verify.sendSync(DMT.createFNPStoreSecret(uid, secret), null, false);

        if (!getAck(source, verify, uid)) {
          Logger.error(source, "did not get storesecret ack for " + uid);
          avg2.report(0.0);
          continue;
        }

        // Send the request for the secret through the 'pathway' node.
        pathway.sendSync(
            DMT.createFNPSecretPing(
                uid, verify.getLocation(), PING_HTL, DAWN_HTL, 0, verify.getIdentity()),
            null,
            false);

        long result = getSecretPingResponse(source, pathway, uid);
        if (result != secret) {
          Logger.error(source, "not matched: " + secret + " != " + result);
          avg2.report(0.0);
        } else {
          Logger.error(source, "match: " + secret);
          avg2.report(1.0);
        }
      } catch (NotConnectedException e) {
        Logger.error(source, "what?", e);
        avg2.report(0.0);
      } catch (DisconnectedException e) {
        Logger.error(source, "huh?", e);
        avg2.report(0.0);
      } catch (SyncSendWaitedTooLongException e) {
        Logger.error(source, "eh?", e);
        avg2.report(0.0);
      }
    }
  }
Example #3
0
 static String getPortNumber(PeerNode p) {
   if (p == null || p.getPeer() == null) return "null";
   return Integer.toString(p.getPeer().getPort());
 }