Package freenet.io.comm

Examples of freenet.io.comm.Peer


        else {
          try {
            String[] all = fs.getAll("physical.udp");
            Peer[] peers = new Peer[all.length];
            for(int i=0;i<all.length;i++)
              peers[i] = new Peer(all[i], false);
            lastInsertedPeers = peers;
          } catch (PeerParseException e1) {
            Logger.error(this, "Error parsing own " + darknetOpennetString + " ref: "+e1+" : "+fs.get("physical.udp"), e1);
          } catch (UnknownHostException e1) {
            Logger.error(this, "Error parsing own " + darknetOpennetString + " ref: "+e1+" : "+fs.get("physical.udp"), e1);
View Full Code Here


      } catch (NotConnectedException e) {
        if(logMINOR) Logger.minor(this, "Lost connection replying to "+m);
      }
      return true;
    } else if(spec == DMT.FNPDetectedIPAddress) {
      Peer p = (Peer) m.getObject(DMT.EXTERNAL_ADDRESS);
      source.setRemoteDetectedPeer(p);
      node.ipDetector.redetectAddress();
      return true;
    } else if(spec == DMT.FNPTime) {
      return handleTime(m, source);
View Full Code Here

   * However, if ignoreSourcePort is set, we will search for a similar address with a different port
   * number in the node reference.
   */
  @Override
  public synchronized Peer getPeer(){
    Peer detectedPeer = super.getPeer();
    if(ignoreSourcePort) {
      FreenetInetAddress addr = detectedPeer == null ? null : detectedPeer.getFreenetAddress();
      int port = detectedPeer == null ? -1 : detectedPeer.getPort();
      if(nominalPeer == null) return detectedPeer;
      for(Peer p : nominalPeer) {
        if(p.getPort() != port && p.getFreenetAddress().equals(addr)) {
          return p;
        }
View Full Code Here

   * Report peer success as boolean
   */
  private boolean disablePeer(String nodeIdentifier) {
    for(DarknetPeerNode pn: n.peers.getDarknetPeers())
    {
      Peer peer = pn.getPeer();
      String nodeIpAndPort = "";
      if(peer != null) {
        nodeIpAndPort = peer.toString();
      }
      String name = pn.myName;
      String identity = pn.getIdentityString();
      if(identity.equals(nodeIdentifier) || nodeIpAndPort.equals(nodeIdentifier) || name.equals(nodeIdentifier)) {
        pn.disablePeer();
View Full Code Here

   * Report peer success as boolean
   */
  private boolean enablePeer(String nodeIdentifier) {
    for(DarknetPeerNode pn: n.peers.getDarknetPeers())
    {
      Peer peer = pn.getPeer();
      String nodeIpAndPort = "";
      if(peer != null) {
        nodeIpAndPort = peer.toString();
      }
      String name = pn.myName;
      String identity = pn.getIdentityString();
      if(identity.equals(nodeIdentifier) || nodeIpAndPort.equals(nodeIdentifier) || name.equals(nodeIdentifier)) {
        pn.enablePeer();
View Full Code Here

     * Report peer existence as boolean
     */
    private boolean havePeer(String nodeIdentifier) {
      for(DarknetPeerNode pn: n.peers.getDarknetPeers())
      {
        Peer peer = pn.getPeer();
        String nodeIpAndPort = "";
        if(peer != null) {
          nodeIpAndPort = peer.toString();
        }
        String name = pn.myName;
        String identity = pn.getIdentityString();
        if(identity.equals(nodeIdentifier) || nodeIpAndPort.equals(nodeIdentifier) || name.equals(nodeIdentifier))
        {
View Full Code Here

     */
    private boolean removePeer(String nodeIdentifier) {
      System.out.println("Removing peer from node for: "+nodeIdentifier);
      for(DarknetPeerNode pn: n.peers.getDarknetPeers())
      {
        Peer peer = pn.getPeer();
        String nodeIpAndPort = "";
        if(peer != null) {
            nodeIpAndPort = peer.toString();
        }
        String name = pn.myName;
        String identity = pn.getIdentityString();
        if(identity.equals(nodeIdentifier) || nodeIpAndPort.equals(nodeIdentifier) || name.equals(nodeIdentifier))
        {
View Full Code Here

    } else if (type.equals(Buffer.class)) {
      return new Buffer(dis);
    } else if (type.equals(ShortBuffer.class)) {
        return new ShortBuffer(dis);
    } else if (type.equals(Peer.class)) {
      return new Peer(dis);
    } else if (type.equals(BitArray.class)) {
      return new BitArray(dis, MAX_BITARRAY_SIZE);
    } else if (type.equals(NodeCHK.class)) {
      // Use Key.read(...) rather than NodeCHK-specific method because write(...) writes the TYPE field.
      return Key.read(dis);
View Full Code Here

      String physical[] = fs.getAll("physical.udp");
      if(physical == null) {
        // Leave it empty
      } else {
        for(String phys: physical) {
          Peer p;
          try {
            p = new Peer(phys, true, true);
          } catch(HostnameSyntaxException e) {
            if(fromLocal)
              Logger.error(this, "Invalid hostname or IP Address syntax error while parsing peer reference in local peers list: " + phys);
            System.err.println("Invalid hostname or IP Address syntax error while parsing peer reference: " + phys);
            continue;
          } catch (PeerParseException e) {
            if(fromLocal)
              Logger.error(this, "Invalid hostname or IP Address syntax error while parsing peer reference in local peers list: " + phys);
            System.err.println("Invalid hostname or IP Address syntax error while parsing peer reference: " + phys);
            continue;
          } catch (UnknownHostException e) {
            if(fromLocal)
              Logger.error(this, "Invalid hostname or IP Address syntax error while parsing peer reference in local peers list: " + phys);
            System.err.println("Invalid hostname or IP Address syntax error while parsing peer reference: " + phys);
            continue;
          }
          if(!nominalPeer.contains(p))
            nominalPeer.add(p);
        }
      }
    } catch(Exception e1) {
      throw new FSParseException(e1);
    }
    if(nominalPeer.isEmpty()) {
      Logger.normal(this, "No IP addresses found for identity '" + identityAsBase64String + "', possibly at location '" + location + ": " + userToString());
      detectedPeer = null;
    } else {
      detectedPeer = nominalPeer.get(0);
    }
    updateShortToString();

    // Don't create trackers until we have a key
    currentTracker = null;
    previousTracker = null;

    timeLastSentPacket = -1;
    timeLastReceivedPacket = -1;
    timeLastReceivedSwapRequest = -1;
    timeLastRoutable = -1;
    timeAddedOrRestarted = System.currentTimeMillis();

    swapRequestsInterval = new SimpleRunningAverage(50, Node.MIN_INTERVAL_BETWEEN_INCOMING_SWAP_REQUESTS);
    probeRequestsInterval = new SimpleRunningAverage(50, Node.MIN_INTERVAL_BETWEEN_INCOMING_PROBE_REQUESTS);

    messageQueue = new PeerMessageQueue();

    decrementHTLAtMaximum = node.random.nextFloat() < Node.DECREMENT_AT_MAX_PROB;
    decrementHTLAtMinimum = node.random.nextFloat() < Node.DECREMENT_AT_MIN_PROB;

    pingNumber = node.random.nextLong();

    // A SimpleRunningAverage would be a bad choice because it would cause oscillations.
    // So go for a filter.
    pingAverage =
      // Short average otherwise we will reject for a *REALLY* long time after any spike.
      new TimeDecayingRunningAverage(1, SECONDS.toMillis(30), 0, NodePinger.CRAZY_MAX_PING_TIME, node);

    // TDRA for probability of rejection
    pRejected =
      new TimeDecayingRunningAverage(0, MINUTES.toMillis(4), 0.0, 1.0, node);

    // ARK stuff.

    parseARK(fs, true, false);

    // Now for the metadata.
    // The metadata sub-fieldset contains data about the node which is not part of the node reference.
    // It belongs to this node, not to the node being described.
    // Therefore, if we are parsing a remotely supplied ref, ignore it.

    long now = System.currentTimeMillis();
    if(fromLocal) {

      SimpleFieldSet metadata = fs.subset("metadata");

      if(metadata != null) {
       
        location.setPeerLocations(fs.getAll("peersLocation"));
       
        // Don't be tolerant of nonexistant domains; this should be an IP address.
        Peer p;
        try {
          String detectedUDPString = metadata.get("detected.udp");
          p = null;
          if(detectedUDPString != null)
            p = new Peer(detectedUDPString, false);
        } catch(UnknownHostException e) {
          p = null;
          Logger.error(this, "detected.udp = " + metadata.get("detected.udp") + " - " + e, e);
        } catch(PeerParseException e) {
          p = null;
View Full Code Here

  * Do occasional DNS requests, but ignoreHostnames should be true
  * on PeerNode construction
  */
  public void maybeUpdateHandshakeIPs(boolean ignoreHostnames) {
    long now = System.currentTimeMillis();
    Peer localDetectedPeer = null;
    synchronized(this) {
      localDetectedPeer = detectedPeer;
      if((now - lastAttemptedHandshakeIPUpdateTime) < MINUTES.toMillis(5)) {
        //Logger.minor(this, "Looked up recently (localDetectedPeer = "+localDetectedPeer + " : "+((localDetectedPeer == null) ? "" : localDetectedPeer.getAddress(false).toString()));
        return;
      }
      // We want to come back right away for DNS requesting if this is our first time through
      if(!ignoreHostnames)
        lastAttemptedHandshakeIPUpdateTime = now;
    }
    if(logMINOR)
      Logger.minor(this, "Updating handshake IPs for peer '" + shortToString() + "' (" + ignoreHostnames + ')');
    Peer[] myNominalPeer;

    // Don't synchronize while doing lookups which may take a long time!
    synchronized(this) {
      myNominalPeer = nominalPeer.toArray(new Peer[nominalPeer.size()]);
    }

    Peer[] localHandshakeIPs;
    if(myNominalPeer.length == 0) {
      if(localDetectedPeer == null) {
        synchronized(this) {
          handshakeIPs = null;
        }
        if(logMINOR)
          Logger.minor(this, "1: maybeUpdateHandshakeIPs got a result of: " + handshakeIPsToString());
        return;
      }
      localHandshakeIPs = new Peer[]{localDetectedPeer};
      localHandshakeIPs = updateHandshakeIPs(localHandshakeIPs, ignoreHostnames);
      synchronized(this) {
        handshakeIPs = localHandshakeIPs;
      }
      if(logMINOR)
        Logger.minor(this, "2: maybeUpdateHandshakeIPs got a result of: " + handshakeIPsToString());
      return;
    }

    // Hack for two nodes on the same IP that can't talk over inet for routing reasons
    FreenetInetAddress localhost = node.fLocalhostAddress;
    Peer[] nodePeers = outgoingMangler.getPrimaryIPAddress();

    List<Peer> localPeers = null;
    synchronized(this) {
      localPeers = new ArrayList<Peer>(nominalPeer);
    }

    boolean addedLocalhost = false;
    Peer detectedDuplicate = null;
    for(Peer p: myNominalPeer) {
      if(p == null)
        continue;
      if(localDetectedPeer != null) {
        if((p != localDetectedPeer) && p.equals(localDetectedPeer)) {
          // Equal but not the same object; need to update the copy.
          detectedDuplicate = p;
        }
      }
      FreenetInetAddress addr = p.getFreenetAddress();
      if(addr.equals(localhost)) {
        if(addedLocalhost)
          continue;
        addedLocalhost = true;
      }
      for(Peer nodePeer: nodePeers) {
        // REDFLAG - Two lines so we can see which variable is null when it NPEs
        FreenetInetAddress myAddr = nodePeer.getFreenetAddress();
        if(myAddr.equals(addr)) {
          if(!addedLocalhost)
            localPeers.add(new Peer(localhost, p.getPort()));
          addedLocalhost = true;
        }
      }
      if(localPeers.contains(p))
        continue;
      localPeers.add(p);
    }

    localHandshakeIPs = localPeers.toArray(new Peer[localPeers.size()]);
    localHandshakeIPs = updateHandshakeIPs(localHandshakeIPs, ignoreHostnames);
    synchronized(this) {
      handshakeIPs = localHandshakeIPs;
      if((detectedDuplicate != null) && detectedDuplicate.equals(localDetectedPeer))
        localDetectedPeer = detectedPeer = detectedDuplicate;
      updateShortToString();
    }
    if(logMINOR) {
      if(localDetectedPeer != null)
View Full Code Here

TOP

Related Classes of freenet.io.comm.Peer

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.