Examples of FreenetInetAddress


Examples of freenet.io.comm.FreenetInetAddress

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

Examples of freenet.io.comm.FreenetInetAddress

    }
   
    config.register("bindTo", "0.0.0.0", sortOrder++, true, true, "Node.bindTo", "Node.bindToLong", new NodeBindtoCallback());
   
    try {
      bindTo = new FreenetInetAddress(config.getString("bindTo"), false);
     
    } catch (UnknownHostException e) {
      throw new NodeInitException(NodeInitException.EXIT_COULD_NOT_BIND_USM, "Invalid bindTo: "+config.getString("bindTo"));
    }
   
View Full Code Here

Examples of freenet.io.comm.FreenetInetAddress

  /**
   * Combine the NodeIPDetector's output with any per-port information we may have to get a definitive
   * (for that port/NodeCrypto) list of IP addresses (still without port numbers).
   */
  FreenetInetAddress[] detectPrimaryIPAddress() {
    FreenetInetAddress addr = crypto.getBindTo();
    if(addr.isRealInternetAddress(false, true, false)) {
      // Binding to a real internet address => don't want us to use the others, most likely
      // he is on a multi-homed box where only one IP can be used for Freenet.
      return new FreenetInetAddress[] { addr };
    }
    return ipDetector.detectPrimaryIPAddress(!crypto.config.includeLocalAddressesInNoderefs);
View Full Code Here

Examples of freenet.io.comm.FreenetInetAddress

    assert(detectedAddrs != null);
    synchronized(this) {
      hasDetectedIAD = true;
    }
    for(InetAddress detectedAddr: detectedAddrs) {
      FreenetInetAddress addr = new FreenetInetAddress(detectedAddr);
      if(!addresses.contains(addr)) {
        Logger.normal(this, "Detected IP address: "+addr);
        addresses.add(addr);
        if(addr.isRealInternetAddress(false, false, false))
          addedValidIP = true;
      }
    }
   
    if((pluginDetectedIPs != null) && (pluginDetectedIPs.length > 0)) {
      for(DetectedIP pluginDetectedIP: pluginDetectedIPs) {
        InetAddress addr = pluginDetectedIP.publicAddress;
        if(addr == null) continue;
        FreenetInetAddress a = new FreenetInetAddress(addr);
        if(!addresses.contains(a)) {
          Logger.normal(this, "Plugin detected IP address: "+a);
          addresses.add(a);
          if(a.isRealInternetAddress(false, false, false))
            addedValidIP = true;
        }
      }
    }
   
    boolean hadAddedValidIP = addedValidIP;
   
    int confidence = 0;
   
    // Try to pick it up from our connections
    if(node.peers != null) {
      PeerNode[] peerList = node.peers.myPeers();
      HashMap<FreenetInetAddress,Integer> countsByPeer = new HashMap<FreenetInetAddress,Integer>();
      // FIXME use a standard mutable int object, we have one somewhere
      for(PeerNode pn: peerList) {
        if(!pn.isConnected()) {
          if(logDEBUG) Logger.minor(this, "Not connected");
          continue;
        }
        if(!pn.isRealConnection()) {
          // Only let seed server connections through.
          // 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;
        }
        if(logMINOR)
          Logger.minor(this, "Peer "+pn.getPeer()+" thinks we are "+addr);
        if(countsByPeer.containsKey(addr)) {
          countsByPeer.put(addr, countsByPeer.get(addr) + 1);
        } else {
          countsByPeer.put(addr, 1);
        }
      }
      if(countsByPeer.size() == 1) {
                Entry<FreenetInetAddress, Integer> countByPeer = countsByPeer.entrySet().iterator().next();
        FreenetInetAddress addr = countByPeer.getKey();
        confidence = countByPeer.getValue();
        Logger.minor(this, "Everyone agrees we are "+addr);
        if(!addresses.contains(addr)) {
          if(addr.isRealInternetAddress(false, false, false))
            addedValidIP = true;
          addresses.add(addr);
        }
      } else if(countsByPeer.size() > 1) {
        // Take two most popular addresses.
        FreenetInetAddress best = null;
        FreenetInetAddress secondBest = null;
        int bestPopularity = 0;
        int secondBestPopularity = 0;
        for(Map.Entry<FreenetInetAddress,Integer> entry : countsByPeer.entrySet()) {
          FreenetInetAddress cur = entry.getKey();
          int curPop = entry.getValue();
          Logger.minor(this, "Detected peer: "+cur+" popularity "+curPop);
          if(curPop >= bestPopularity) {
            secondBestPopularity = bestPopularity;
            bestPopularity = curPop;
View Full Code Here

Examples of freenet.io.comm.FreenetInetAddress

          overrideIPAddress = null;
          lastIPAddress = null;
          redetectAddress();
          return;
        }
        FreenetInetAddress addr;
        try {
          addr = new FreenetInetAddress(val, false, true);
        } catch (HostnameSyntaxException e) {
          throw new InvalidConfigValueException(l10n("unknownHostErrorInIPOverride", "error", "hostname or IP address syntax error"));
        } catch (UnknownHostException e) {
          throw new InvalidConfigValueException(l10n("unknownHostErrorInIPOverride", "error", e.getMessage()));
        }
        // Compare as IPs.
        if(addr.equals(overrideIPAddress)) return;
        overrideIPAddressString = val;
        overrideIPAddress = addr;
        lastIPAddress = null;
        synchronized(this) {
          hasValidAddressOverride = true;
        }
        if(!hadValidAddressOverride) {
          onGetValidAddressOverride();
        }
        redetectAddress();
      }
    });
   
    hasValidAddressOverride = true;
    overrideIPAddressString = nodeConfig.getString("ipAddressOverride");
    if(overrideIPAddressString.length() == 0)
      overrideIPAddress = null;
    else {
      try {
        overrideIPAddress = new FreenetInetAddress(overrideIPAddressString, false, true);
      } catch (HostnameSyntaxException e) {
        synchronized(this) {
          hasValidAddressOverride = false;
        }
        String msg = "Invalid IP override syntax: "+overrideIPAddressString+" in config: "+e.getMessage();
        Logger.error(this, msg);
        System.err.println(msg+" but starting up anyway, ignoring the configured IP override");
        overrideIPAddress = null;
      } catch (UnknownHostException e) {
        // **FIXME** This never happens for this reason with current FreenetInetAddress(String, boolean, boolean) code; perhaps it needs review?
        String msg = "Unknown host: "+overrideIPAddressString+" in config: "+e.getMessage();
        Logger.error(this, msg);
        System.err.println(msg+" but starting up anyway with no IP override");
        overrideIPAddress = null;
      }
    }
   
    // Temporary IP address hint
   
    nodeConfig.register("tempIPAddressHint", "", sortOrder++, true, false, "NodeIPDectector.tempAddressHint", "NodeIPDectector.tempAddressHintLong", new StringCallback() {

      @Override
      public String get() {
        return "";
      }
     
      @Override
      public void set(String val) throws InvalidConfigValueException {
        if(val.length() == 0) {
          return;
        }
        if(overrideIPAddress != null) return;
        try {
          oldIPAddress = new FreenetInetAddress(val, false);
        } catch (UnknownHostException e) {
          throw new InvalidConfigValueException("Unknown host: "+e.getMessage());
        }
        redetectAddress();
      }
    });
   
    String ipHintString = nodeConfig.getString("tempIPAddressHint");
    if(ipHintString.length() > 0) {
      try {
        oldIPAddress = new FreenetInetAddress(ipHintString, false);
      } catch (UnknownHostException e) {
        String msg = "Unknown host: "+ipHintString+" in config: "+e.getMessage();
        Logger.error(this, msg);
        System.err.println(msg);
        oldIPAddress = null;
View Full Code Here

Examples of freenet.io.comm.FreenetInetAddress

      if(pn.isDisabled()) continue;
      if(pn.matchesPeerAndPort(peer))
        return pn;
    }
    // Try a match by IP address if we can't match exactly by IP:port.
    FreenetInetAddress addr = peer.getFreenetAddress();
    for(PeerNode pn : peerList) {
      if(pn.isDisabled()) continue;
      if(pn.matchesIP(addr, false))
        return pn;
    }
View Full Code Here

Examples of freenet.io.comm.FreenetInetAddress

      if(pn.isDisabled()) continue;
      if(pn.matchesPeerAndPort(peer) && pn.getOutgoingMangler() == mangler)
        return pn;
    }
    // Try a match by IP address if we can't match exactly by IP:port.
    FreenetInetAddress addr = peer.getFreenetAddress();
    for(PeerNode pn : peerList) {
      if(pn.isDisabled()) continue;
      if(pn.matchesIP(addr, false) && pn.getOutgoingMangler() == mangler)
        return pn;
    }
View Full Code Here

Examples of freenet.io.comm.FreenetInetAddress

      localhostAddress = InetAddress.getByName("127.0.0.1");
    } catch (UnknownHostException e3) {
      // Does not do a reverse lookup, so this is impossible
      throw new Error(e3);
    }
    fLocalhostAddress = new FreenetInetAddress(localhostAddress);

    this.securityLevels = new SecurityLevels(this, config);

    // Location of master key
    nodeConfig.register("masterKeyFile", "master.keys", sortOrder++, true, true, "Node.masterKeyFile", "Node.masterKeyFileLong",
View Full Code Here

Examples of freenet.io.comm.FreenetInetAddress

   */
  @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

Examples of freenet.io.comm.FreenetInetAddress

      boolean any = false;
      Peer[] handshakeIPs = nodeToAddNow.getHandshakeIPs();
      if(handshakeIPs != null) {
        for(Peer p : handshakeIPs) {
          if(p == null) continue;
          FreenetInetAddress addr = p.getFreenetAddress();
          if(addr == null) continue;
          InetAddress a = addr.getAddress(false);
          if(a == null) continue;
          if(a.isAnyLocalAddress() || a.isLinkLocalAddress() || IPUtil.isSiteLocalAddress(a)) continue;
          any = true;
          if(crypto.allowConnection(nodeToAddNow, addr))
            okay = true;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.