OK, unified format version here then. Btw greg, I haven't managed to apply
your routing patch. The problem seems to be related to the file
CPAlgoRoutingTable.java.bak that is mentioned on the second line of the
patch.
/N
Index: freenet/node/IPAddressDetector.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/node/IPAddressDetector.java,v
retrieving revision 1.9
diff -u -r1.9 IPAddressDetector.java
--- freenet/node/IPAddressDetector.java 16 Apr 2003 22:59:09 -0000 1.9
+++ freenet/node/IPAddressDetector.java 30 May 2003 07:32:52 -0000
@@ -18,8 +18,9 @@
*/
class IPAddressDetector implements Checkpointed {
-
+ private String preferedAddressString = null;
public IPAddressDetector() {
+
}
@@ -41,25 +42,53 @@
InetAddress[] lastAddressList = null;
long lastDetectedTime = -1;
- public InetAddress getAddress() {
- return getAddress(0);
+ /**
+ * 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);
}
+ /**
+ * 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);
+ }
+
/**
* Get the IP address
+ * @param preferedAddress An address that for some reason is prefered above
others. Might be null
+ * @return Detected ip address
*/
- public InetAddress getAddress(long recheckTime) {
- if(lastInetAddress == null ||
- System.currentTimeMillis() >
- (lastDetectedTime + recheckTime))
- checkpoint();
- return lastInetAddress;
+ public InetAddress getAddress(long recheckTime,String preferedAddress) {
+ if(lastInetAddress == null ||
+ System.currentTimeMillis() >
+ (lastDetectedTime + recheckTime))
+ checkpoint(preferedAddress);
+ return lastInetAddress;
}
+ /**
+ * Get the IP address
+ * @return Detected ip address
+ */
+ public InetAddress getAddress(long recheckTime) {
+ return getAddress(recheckTime,null);
+ }
+
+ public void checkpoint() {
+ checkpoint(null);
+ }
+
/**
* Execute a checkpoint - detect our internet IP address and log it
+ * @param preferedAddress An address that for some reason is prefered above
others. Might be null
*/
- public synchronized void checkpoint() {
+ protected synchronized void checkpoint(String preferedAddress) {
boolean logDEBUG = Core.logger.shouldLog(Logger.DEBUG);
Vector addrs = new Vector();
boolean old = false;
@@ -76,6 +105,7 @@
addrs.add(oldDetect());
old = true;
}
+
if(!old) {
while(interfaces.hasMoreElements()) {
java.net.NetworkInterface iface =
@@ -85,6 +115,7 @@
iface.getDisplayName(), Core.logger.DEBUG);
Enumeration ee = iface.getInetAddresses();
while(ee.hasMoreElements()) {
+
InetAddress addr = (InetAddress)(ee.nextElement());
addrs.add(addr);
if(logDEBUG)
@@ -98,7 +129,7 @@
Logger.DEBUG);
}
InetAddress oldAddress = lastInetAddress;
- onGetAddresses(addrs);
+ onGetAddresses(addrs,preferedAddress);
lastDetectedTime = System.currentTimeMillis();
if(oldAddress != null && !lastInetAddress.equals(oldAddress)) {
Core.logger.log(this, "Public IP Address changed from "+
@@ -142,32 +173,47 @@
/** Do something with the list of detected IP addresses
* @param v Vector of InetAddresses
+ * @param preferedAddress An address that for some reason is prefered above
others. Might be null
*/
- protected void onGetAddresses(Vector v) {
+ protected void onGetAddresses(Vector v,String preferedAddress) {
if(Core.logger.shouldLog(Logger.DEBUG))
Core.logger.log(this, "onGetAddresses("+v.size()+" addresses)",
Logger.DEBUG);
+ InetAddress lastValidDetectedInetAddress = null;
if(v.size() == 0) {
Core.logger.log(this, "No addresses found!", Core.logger.ERROR);
- lastInetAddress = null;
+ lastValidDetectedInetAddress = null;
} else {
+ InetAddress preferedInetAddress = null;
+
+ try {
+ preferedInetAddress = InetAddress.getByName(preferedAddress);
+ } catch (UnknownHostException e) {
+
+ }
+
InetAddress[] a = new InetAddress[v.size()];
for(int x=0;x<v.size();x++) {
- InetAddress addr = (InetAddress)(v.elementAt(x));
- if(addr != null) {
- if(Core.logger.shouldLog(Core.logger.DEBUG))
- Core.logger.log(this, "Address "+x+": "+addr,
- Core.logger.DEBUG);
- if(isInternetAddress(addr)) {
- if(Core.logger.shouldLog(Core.logger.DEBUG))
- Core.logger.log(this, "Setting default address to "+
- addr.getHostAddress(),
- Core.logger.DEBUG);
- lastInetAddress = addr; // FIXME: add support for multihoming
- }
- }
+ lastValidDetectedInetAddress = (InetAddress)(v.elementAt(x));
+ if(lastValidDetectedInetAddress != null) {
+ if(Core.logger.shouldLog(Core.logger.DEBUG))
+ Core.logger.log(this, "Address "+x+":
"+lastValidDetectedInetAddress,
+ Core.logger.DEBUG);
+ if(isInternetAddress(lastValidDetectedInetAddress)) {
+ if(Core.logger.shouldLog(Core.logger.DEBUG))
+ Core.logger.log(this, "Setting default address to "+
+ lastValidDetectedInetAddress.getHostAddress(),
+ Core.logger.DEBUG);
+
+ if(preferedInetAddress != null &&
lastValidDetectedInetAddress.equals(preferedInetAddress)) //Prefer continuing using
the specified address if it is still available to us
+ break;
+
if(lastValidDetectedInetAddress.equals(lastInetAddress))
//Prefer continuing using the current address if it is still available to us
+ break;
+ }
+ }
}
}
+ lastInetAddress = lastValidDetectedInetAddress; // FIXME: add support for
multihoming
}
protected boolean isInternetAddress(InetAddress addr) {
Index: freenet/node/Main.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/node/Main.java,v
retrieving revision 1.211
diff -u -r1.211 Main.java
--- freenet/node/Main.java 21 May 2003 18:06:37 -0000 1.211
+++ freenet/node/Main.java 30 May 2003 07:32:56 -0000
@@ -52,7 +52,7 @@
public static Params params = null;
static byte[] cipherKey = null;
static byte[] baseIV = null;
- static String oldAddress = null;
+ static String oldTCPAddressAndPort = null; //Contains the address of the node in
a a.b.c.d:port or hostname:port style
static BlockCipher cipher;
static Authentity privateKey;
static long ARKversion;
@@ -346,7 +346,12 @@
// get the node's physical addresses
Address[] addr;
try {
- addr = getAddresses(th, params, ipDetector.getAddress());
+ String preferedAddress = null;
+ int colon = oldTCPAddressAndPort.indexOf(':');
+ if (colon != -1) {
+ preferedAddress
=oldTCPAddressAndPort.substring(0, colon);
+ }
+ addr = getAddresses(th, params,
ipDetector.getAddress(preferedAddress));
}
catch (BadAddressException e) {
Node.badAddress = true;
@@ -365,7 +370,7 @@
myRef = Node.makeNodeRef(privateKey, addr, sh, ph,
ARKversion, ARKcrypt);
- Core.logger.log(Main.class, "Old address: "+oldAddress,
+ Core.logger.log(Main.class, "Old address: "+oldTCPAddressAndPort,
Core.logger.DEBUG);
tcpAddress a = getTcpAddress();
Core.logger.log(Main.class,
@@ -373,7 +378,7 @@
Core.logger.DEBUG);
if (a != null &&
- !(a.toString().equals(oldAddress))) {
+ !(a.toString().equals(oldTCPAddressAndPort))) {
Core.logger.log(Main.class,
"Address has changed since last run",
Core.logger.MINOR);
@@ -2141,9 +2146,11 @@
}
FieldSet phys = fs.getSet("physical");
if(phys != null)
- oldAddress = phys.get("tcp");
+ oldTCPAddressAndPort = phys.get("tcp");
+
+
Core.logger.log(Main.class, "Got oldAddress: "+
- oldAddress==null?"(null)":oldAddress,
+
oldTCPAddressAndPort==null?"(null)":oldTCPAddressAndPort,
Core.logger.DEBUG);
FieldSet ark = fs.getSet("ARK");
String s = ark==null ? null : ark.get("revision");
@@ -2208,8 +2215,8 @@
finally {
if(in != null) in.close();
}
- if(oldAddress != null) {
- Core.logger.log(Main.class, "Old address was "+oldAddress,
+ if(oldTCPAddressAndPort != null) {
+ Core.logger.log(Main.class, "Old address was "+oldTCPAddressAndPort,
Core.logger.DEBUG);
}
} catch (FileNotFoundException e) {