Package freenet.io.comm

Examples of freenet.io.comm.Peer


  public void receivedPacketFrom(Peer peer) {
    packetTo(peer, false);
  }

  private void packetTo(Peer peer, boolean sent) {
    Peer peer2 = peer.dropHostName();
    if(peer2 == null) {
      Logger.error(this, "Impossible: No host name in AddressTracker.packetTo for "+peer);
      return;
    }
    peer = peer2;
View Full Code Here


  }
 
  public PeerAddressTrackerItem(SimpleFieldSet fs) throws FSParseException {
    super(fs);
    try {
      peer = new Peer(fs.getString("Address"), false);
    } catch (UnknownHostException e) {
      throw (FSParseException)new FSParseException("Unknown domain name in Address: "+e).initCause(e);
    } catch (PeerParseException e) {
      throw new FSParseException(e);
    }
View Full Code Here

  }

  private void sendPacket(byte[] data, Peer replyTo, PeerNode pn) throws LocalAddressException {
    if(pn != null) {
      if(pn.isIgnoreSource()) {
        Peer p = pn.getPeer();
        if(p != null) replyTo = p;
      }
    }
    sock.sendPacket(data, replyTo, pn == null ? crypto.config.alwaysAllowLocalAddresses() : pn.allowLocalAddresses());
    if(pn != null)
View Full Code Here

      negType = negTypes[node.random.nextInt(negTypes.length)];
      Logger.normal(this, "Cannot send handshake to "+pn+" because no common negTypes, choosing random negType of "+negType);
    }
    if(logMINOR) Logger.minor(this, "Possibly sending handshake to "+pn+" negotiation type "+negType);

    Peer peer = pn.getHandshakeIP();
    if(peer == null) {
      pn.couldNotSendHandshake(notRegistered);
      return;
    }
    Peer oldPeer = peer;
    peer = peer.dropHostName();
    if(peer == null) {
      Logger.error(this, "No address for peer "+oldPeer+" so cannot send handshake");
      pn.couldNotSendHandshake(notRegistered);
      return;
View Full Code Here

  public final IncomingLoadSummaryStats incomingLoadStatsBulk;
 
  public final boolean hasFullNoderef;

  PeerNodeStatus(PeerNode peerNode, boolean noHeavy) {
    Peer p = peerNode.getPeer();
    if(p == null) {
      peerAddress = null;
      peerAddressNumerical = null;
      peerAddressBytes = null;
      peerPort = -1;
    } else {
      FreenetInetAddress a = p.getFreenetAddress();
      peerAddress = a.toString();
      InetAddress i = a.getAddress(false);
      if(i != null) {
        peerAddressNumerical = i.getHostAddress();
        peerAddressBytes = i.getAddress();
      } else {
        peerAddressNumerical = null;
        peerAddressBytes = null;
      }
      peerPort = p.getPort();
    }
    this.selectionRate = peerNode.selectionRate();
    this.statusValue = peerNode.getPeerNodeStatus();
    this.statusName = peerNode.getPeerNodeStatusString();
    this.statusCSSName = peerNode.getPeerNodeStatusCSSClassName();
View Full Code Here

  Peer[] detectPrimaryPeers() {
    final boolean logMINOR = NodeIPPortDetector.logMINOR;
    ArrayList<Peer> addresses = new ArrayList<Peer>();
    FreenetInetAddress[] addrs = detectPrimaryIPAddress();
    for(FreenetInetAddress addr: addrs) {
      addresses.add(new Peer(addr, crypto.portNumber));
      if(logMINOR)
        Logger.minor(this, "Adding "+addr);
    }
    // Now try to get the rewritten port number from our peers.
    // Only considering those within this crypto port, this time.
   
    PeerNode[] peerList = crypto.getPeerNodes();
   
    if(peerList != null) {
      HashMap<Peer,Integer> countsByPeer = new HashMap<Peer,Integer>();
      // FIXME use a standard mutable int object, we have one somewhere
      for(PeerNode pn: peerList) {
        Peer p = pn.getRemoteDetectedPeer();
        if((p == null) || p.isNull()) continue;
        // DNSRequester doesn't deal with our own node
        if(!IPUtil.isValidAddress(p.getAddress(true), false)) continue;
        if(logMINOR)
          Logger.minor(this, "Peer "+pn.getPeer()+" thinks we are "+p);
        if(countsByPeer.containsKey(p)) {
          countsByPeer.put(p, countsByPeer.get(p) + 1);
        } else {
          countsByPeer.put(p, 1);
        }
      }
      if(countsByPeer.size() == 1) {
        Iterator<Peer> it = countsByPeer.keySet().iterator();
        Peer p = (it.next());
        Logger.minor(this, "Everyone agrees we are "+p);
        if(!addresses.contains(p)) {
          addresses.add(p);
        }
      } else if(countsByPeer.size() > 1) {
        // Take two most popular addresses.
        Peer best = null;
        Peer secondBest = null;
        int bestPopularity = 0;
        int secondBestPopularity = 0;
        for (Map.Entry<Peer,Integer> entry : countsByPeer.entrySet()) {
          Peer cur = entry.getKey();
          int curPop = entry.getValue();
          Logger.normal(this, "Detected peer: "+cur+" popularity "+curPop);
          if(curPop >= bestPopularity) {
            secondBestPopularity = bestPopularity;
            bestPopularity = curPop;
            secondBest = best;
            best = cur;
          }
        }
        if(best != null) {
          if((bestPopularity > 1) || (addrs.length == 0)) {
             if(!addresses.contains(best)) {
              Logger.normal(this, "Adding best peer "+best+" ("+bestPopularity+ ')');
              addresses.add(best);
            }
            if((secondBest != null) && (secondBestPopularity > 1)) {
              if(!addresses.contains(secondBest)) {
                Logger.normal(this, "Adding second best peer "+secondBest+" ("+secondBest+ ')');
                addresses.add(secondBest);
              }
              if(best.getAddress().equals(secondBest.getAddress()) && bestPopularity == 1) {
                Logger.error(this, "Hrrrm, maybe this is a symmetric NAT? Expect trouble connecting!");
                System.err.println("Hrrrm, maybe this is a symmetric NAT? Expect trouble connecting!");
               
                ipDetector.setMaybeSymmetric();
               
                Peer p = new Peer(best.getFreenetAddress(), crypto.portNumber);
                if(!addresses.contains(p))
                  addresses.add(p);

              }
            }
View Full Code Here

    // Read contents
    String[] udp = fs.getAll("physical.udp");
    if((udp != null) && (udp.length > 0)) {
      for(String u: udp) {
        // Just keep the first one with the correct port number.
        Peer p;
        try {
          p = new Peer(u, false, true);
        } catch (HostnameSyntaxException e) {
          Logger.error(this, "Invalid hostname or IP Address syntax error while loading opennet peer node reference: "+u);
          System.err.println("Invalid hostname or IP Address syntax error while loading opennet peer node reference: "+u);
          continue;
        } catch (PeerParseException e) {
          throw (IOException)new IOException().initCause(e);
        }
        if(p.getPort() == crypto.portNumber) {
          // DNSRequester doesn't deal with our own node
          node.ipDetector.setOldIPAddress(p.getFreenetAddress());
          break;
        }
      }
    }
View Full Code Here

          // We have to trust them anyway.
          if(!(pn instanceof SeedServerPeerNode)) continue;
          if(logMINOR) Logger.minor(this, "Not a real connection and not a seed node: "+pn);
        }
        if(logMINOR) Logger.minor(this, "Maybe a usable connection for IP: "+pn);
        Peer p = pn.getRemoteDetectedPeer();
        if(logMINOR) Logger.minor(this, "Remote detected peer: "+p);
        if(p == null || p.isNull()) continue;
        FreenetInetAddress addr = p.getFreenetAddress();
        if(logMINOR) Logger.minor(this, "Address: "+addr);
        if(addr == null) continue;
        if(!IPUtil.isValidAddress(addr.getAddress(false), false)) {
          if(logMINOR) Logger.minor(this, "Address not valid");
          continue;
View Full Code Here

    // Read contents
    String[] udp = fs.getAll("physical.udp");
    if((udp != null) && (udp.length > 0)) {
      for(String udpAddr : udp) {
        // Just keep the first one with the correct port number.
        Peer p;
        try {
          p = new Peer(udpAddr, false, true);
        } catch (HostnameSyntaxException e) {
          Logger.error(this, "Invalid hostname or IP Address syntax error while parsing our darknet node reference: "+udpAddr);
          System.err.println("Invalid hostname or IP Address syntax error while parsing our darknet node reference: "+udpAddr);
          continue;
        } catch (PeerParseException e) {
          throw (IOException)new IOException().initCause(e);
        }
        if(p.getPort() == getDarknetPortNumber()) {
          // DNSRequester doesn't deal with our own node
          ipDetector.setOldIPAddress(p.getFreenetAddress());
          break;
        }
      }
    }
View Full Code Here

  /**
   * Return a peer of the node given its ip and port, name or identity, as a String
   */
  public PeerNode getPeerNode(String nodeIdentifier) {
    for(PeerNode pn: peers.myPeers()) {
      Peer peer = pn.getPeer();
      String nodeIpAndPort = "";
      if(peer != null) {
        nodeIpAndPort = peer.toString();
      }
      String identity = pn.getIdentityString();
      if(pn instanceof DarknetPeerNode) {
        DarknetPeerNode dpn = (DarknetPeerNode) pn;
        String name = dpn.myName;
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.