Author: toad
Date: 2006-02-21 17:52:44 +0000 (Tue, 21 Feb 2006)
New Revision: 8089
Modified:
trunk/freenet/src/freenet/node/Node.java
trunk/freenet/src/freenet/node/Version.java
trunk/freenet/src/freenet/transport/IPAddressDetector.java
Log:
459: IP detection bugfix, keep old IP if can't find a new one, and dead code
removal.
Modified: trunk/freenet/src/freenet/node/Node.java
===================================================================
--- trunk/freenet/src/freenet/node/Node.java 2006-02-21 17:47:42 UTC (rev
8088)
+++ trunk/freenet/src/freenet/node/Node.java 2006-02-21 17:52:44 UTC (rev
8089)
@@ -283,8 +283,8 @@
if(myOldPeer.getPort() != portNumber)
throw new IllegalArgumentException("Wrong port number "+
myOldPeer.getPort()+" should be
"+portNumber);
+ lastIPAddress = myOldPeer.getAddress();
}
- // FIXME: we ignore the IP for now, and hardcode it to localhost
String identity = fs.get("identity");
if(identity == null)
throw new IOException();
@@ -1342,43 +1342,49 @@
}
Logger.minor(this, "IP address not overridden");
InetAddress addr = ipDetector.getAddress();
- if(addr != null) return addr;
+ if(addr != null) {
+ lastIPAddress = addr;
+ return addr;
+ }
// Try to pick it up from our connections
- if(peers == null) return null;
- PeerNode[] peerList = peers.connectedPeers;
- HashMap countsByPeer = new HashMap();
- // FIXME use a standard mutable int object, we have one
somewhere
- for(int i=0;i<peerList.length;i++) {
- Peer p = peerList[i].getRemoteDetectedPeer();
- if(p == null || p.isNull()) continue;
- InetAddress ip = p.getAddress();
- if(!IPUtil.checkAddress(p.getAddress())) continue;
- if(countsByPeer.containsKey(ip)) {
- Integer count = (Integer) countsByPeer.get(ip);
- Integer newCount = new
Integer(count.intValue()+1);
- countsByPeer.put(ip, newCount);
- } else {
- countsByPeer.put(ip, new Integer(1));
+ if(peers != null) {
+ PeerNode[] peerList = peers.connectedPeers;
+ HashMap countsByPeer = new HashMap();
+ // FIXME use a standard mutable int object, we have one
somewhere
+ for(int i=0;i<peerList.length;i++) {
+ Peer p = peerList[i].getRemoteDetectedPeer();
+ if(p == null || p.isNull()) continue;
+ InetAddress ip = p.getAddress();
+ if(!IPUtil.checkAddress(p.getAddress()))
continue;
+ if(countsByPeer.containsKey(ip)) {
+ Integer count = (Integer)
countsByPeer.get(ip);
+ Integer newCount = new
Integer(count.intValue()+1);
+ countsByPeer.put(ip, newCount);
+ } else {
+ countsByPeer.put(ip, new Integer(1));
+ }
}
- }
- if(countsByPeer.size() == 0) return null;
- Iterator it = countsByPeer.keySet().iterator();
- if(countsByPeer.size() == 1) {
- return (InetAddress) it.next();
- }
- // Pick most popular address
- // FIXME use multi-homing here
- InetAddress best = null;
- int bestPopularity = 0;
- while(it.hasNext()) {
- InetAddress cur = (InetAddress) it.next();
- int curPop = ((Integer)
(countsByPeer.get(best))).intValue();
- if(curPop > bestPopularity) {
- bestPopularity = curPop;
- best = cur;
+ if(countsByPeer.size() == 0) return null;
+ Iterator it = countsByPeer.keySet().iterator();
+ if(countsByPeer.size() == 1) {
+ return (InetAddress) it.next();
}
+ // Pick most popular address
+ // FIXME use multi-homing here
+ InetAddress best = null;
+ int bestPopularity = 0;
+ while(it.hasNext()) {
+ InetAddress cur = (InetAddress) it.next();
+ int curPop = ((Integer)
(countsByPeer.get(best))).intValue();
+ if(curPop > bestPopularity) {
+ bestPopularity = curPop;
+ best = cur;
+ }
+ }
+ lastIPAddress = best;
+ return best;
}
- return best;
+ return lastIPAddress;
}
InetAddress getPrimaryIPAddress() {
Modified: trunk/freenet/src/freenet/node/Version.java
===================================================================
--- trunk/freenet/src/freenet/node/Version.java 2006-02-21 17:47:42 UTC (rev
8088)
+++ trunk/freenet/src/freenet/node/Version.java 2006-02-21 17:52:44 UTC (rev
8089)
@@ -20,7 +20,7 @@
public static final String protocolVersion = "1.0";
/** The build number of the current revision */
- private static final int buildNumber = 458;
+ private static final int buildNumber = 459;
/** Oldest build of Fred we will talk to */
private static final int lastGoodBuild = 403;
Modified: trunk/freenet/src/freenet/transport/IPAddressDetector.java
===================================================================
--- trunk/freenet/src/freenet/transport/IPAddressDetector.java 2006-02-21
17:47:42 UTC (rev 8088)
+++ trunk/freenet/src/freenet/transport/IPAddressDetector.java 2006-02-21
17:52:44 UTC (rev 8089)
@@ -45,22 +45,8 @@
/**
* Fetches the currently detected IP address. If not detected yet a
detection is forced
- * @param preferedAddress An address that for some reason is prefered
above others. Might be null
* @return Detected ip address
*/
- public InetAddress getAddress(String preferedAddress) {
- return getAddress(0, preferedAddress);
- }
-
- public InetAddress getAddress(InetAddress preferredAddress) {
- checkpoint(preferredAddress);
- return lastInetAddress;
- }
-
- /**
- * Fetches the currently detected IP address. If not detected yet a
detection is forced
- * @return Detected ip address
- */
public InetAddress getAddress() {
return getAddress(0, null);
}