> What I really meant with my suggestion was that if fred encounters two or
> more, accrording to whatever filtering scheme used, valid IP addresses
then
> why can't it just have a check to see if one of those addresses are the
one
> currently in use and in that case continue using it. It is simply a matter
> of adding another, possibly very simple, check before making the final
> decision (which very well still might be to use the last encountered valid
> IP) of which of the valid addresses to use.
Attached is a diff which would seem to do just this. When the node starts it
will prefer to continue using any 'old' IP (in this case the old address is
the one from the 'node' file) if it is still available accoring to the same
detection scheme that is currently in place. Same thing happens during
address detection checkpoints later on except that then the 'old' IP will be
the previously detected one.
Tell me if there is something wrong with the diff (or the code), it is the
first one I have ever created. Oh, and another thing, I indented some
sections of the code when I happened to edit in that area.
/N
Index: freenet/node/IPAddressDetector.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/node/IPAddressDetector.java,v
retrieving revision 1.9
diff -r1.9 IPAddressDetector.java
21c21
<
---
> private String preferedAddressString = null;
22a23
>
44,45c45,51
< 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);
47a54,61
> /**
> * 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);
> }
>
49a64,65
> * @param preferedAddress An address that for some reason is prefered above
> others. Might be null
> * @return Detected ip address
51,56c67,72
< 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;
58a75,86
> /**
> * Get the IP address
> * @return Detected ip address
> */
> public InetAddress getAddress(long recheckTime) {
> return getAddress(recheckTime,null);
> }
>
> public void checkpoint() {
> checkpoint(null);
> }
>
60a89
> * @param preferedAddress An address that for some reason is prefered above
> others. Might be null
62c91
< public synchronized void checkpoint() {
---
> protected synchronized void checkpoint(String preferedAddress) {
78a108
>
87a118
>
101c132
< onGetAddresses(addrs);
---
> onGetAddresses(addrs,preferedAddress);
144a176
> * @param preferedAddress An address that for some reason is prefered above
> others. Might be null
146c178
< protected void onGetAddresses(Vector v) {
---
> protected void onGetAddresses(Vector v,String preferedAddress) {
149a182
> InetAddress lastValidDetectedInetAddress = null;
152c185
< lastInetAddress = null;
---
> lastValidDetectedInetAddress = null;
153a187,194
> InetAddress preferedInetAddress = null;
>
> try {
> preferedInetAddress = InetAddress.getByName(preferedAddress);
> } catch (UnknownHostException e) {
>
> }
>
156,168c197,213
< 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;
> }
> }
170a216
> lastInetAddress = lastValidDetectedInetAddress; // FIXME: add support for
> multihoming
Index: freenet/node/Main.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/node/Main.java,v
retrieving revision 1.211
diff -r1.211 Main.java
55c55
< 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
349c349,354
< 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));
368c373
< Core.logger.log(Main.class, "Old address: "+oldAddress,
---
> Core.logger.log(Main.class, "Old address: "+oldTCPAddressAndPort,
376c381
< !(a.toString().equals(oldAddress))) {
---
> !(a.toString().equals(oldTCPAddressAndPort))) {
2144c2149,2151
< oldAddress = phys.get("tcp");
---
> oldTCPAddressAndPort = phys.get("tcp");
>
>
2146c2153
< oldAddress==null?"(null)":oldAddress,
---
>
> oldTCPAddressAndPort==null?"(null)":oldTCPAddressAndPort,
2211,2212c2218,2219
< if(oldAddress != null) {
< Core.logger.log(Main.class, "Old address was "+oldAddress,
---
> if(oldTCPAddressAndPort != null) {
> Core.logger.log(Main.class, "Old address was "+oldTCPAddressAndPort,