Author: toad
Date: 2006-05-11 17:59:40 +0000 (Thu, 11 May 2006)
New Revision: 8662
Modified:
trunk/freenet/src/freenet/io/comm/Peer.java
trunk/freenet/src/freenet/node/Node.java
trunk/freenet/src/freenet/node/Version.java
Log:
691: Update ARK when IP address changes.
Modified: trunk/freenet/src/freenet/io/comm/Peer.java
===================================================================
--- trunk/freenet/src/freenet/io/comm/Peer.java 2006-05-11 17:49:31 UTC (rev
8661)
+++ trunk/freenet/src/freenet/io/comm/Peer.java 2006-05-11 17:59:40 UTC (rev
8662)
@@ -131,6 +131,31 @@
return true;
}
+ public boolean strictEquals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (!(o instanceof Peer)) {
+ return false;
+ }
+
+ final Peer peer = (Peer) o;
+
+ if (_port != peer._port) {
+ return false;
+ }
+ if (this._address != null) {
+
if(!getHostName(_address).equals(getHostName(peer._address))) {
+ return false;
+ }
+ } else {
+ if (!hostname.equals(peer.hostname)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
public InetAddress getAddress() {
if (_address != null) {
return _address;
Modified: trunk/freenet/src/freenet/node/Node.java
===================================================================
--- trunk/freenet/src/freenet/node/Node.java 2006-05-11 17:49:31 UTC (rev
8661)
+++ trunk/freenet/src/freenet/node/Node.java 2006-05-11 17:59:40 UTC (rev
8662)
@@ -120,9 +120,13 @@
private ClientPutter inserter;
private boolean shouldInsert;
+ private Peer lastInsertedAddress;
public void update() {
Logger.minor(this, "update()");
+ Peer p = new Peer(Node.this.getPrimaryIPAddress(),
Node.this.portNumber);
+ if(p.strictEquals(lastInsertedAddress)) return;
+ Logger.minor(this, "Inserting ARK because "+p+" !=
"+lastInsertedAddress);
synchronized(this) {
if(inserter != null) {
// Already inserting.
@@ -168,6 +172,15 @@
try {
inserter.start();
+ if(fs.get("physical.udp") == null)
+ lastInsertedAddress = null;
+ else {
+ try {
+ lastInsertedAddress = new
Peer(fs.get("physical.udp"));
+ } catch (PeerParseException e1) {
+ Logger.error(this, "Error
parsing own ref: "+e1+" : "+fs.get("physical.udp"), e1);
+ }
+ }
} catch (InserterException e) {
onFailure(e, inserter);
}
@@ -192,6 +205,7 @@
public void onFailure(InserterException e, BaseClientPutter
state) {
Logger.minor(this, "ARK insert failed: "+e);
+ lastInsertedAddress = null;
// :(
// Better try again
try {
@@ -217,6 +231,8 @@
}
public void onConnectedPeer() {
+ Peer p = new Peer(Node.this.getPrimaryIPAddress(),
Node.this.portNumber);
+ if(p.equals(lastInsertedAddress)) return;
synchronized(this) {
if(!shouldInsert) return;
if(inserter != null) {
@@ -785,16 +801,19 @@
// Set to null
overrideIPAddress = null;
lastIPAddress = null;
+ shouldInsertARK();
return;
}
InetAddress addr;
try {
addr = InetAddress.getByName(val);
+ shouldInsertARK();
} catch (UnknownHostException e) {
throw new
InvalidConfigValueException("Unknown host: "+e.getMessage());
}
overrideIPAddress = addr;
lastIPAddress = null;
+ shouldInsertARK();
}
});
@@ -1764,6 +1783,7 @@
InetAddress addr = ipDetector.getAddress();
if(addr != null) {
lastIPAddress = addr;
+ shouldInsertARK();
return addr;
}
// Try to pick it up from our connections
@@ -1787,6 +1807,7 @@
if(countsByPeer.size() == 0) return null;
Iterator it = countsByPeer.keySet().iterator();
if(countsByPeer.size() == 1) {
+ shouldInsertARK();
return (InetAddress) it.next();
}
// Pick most popular address
@@ -1812,6 +1833,7 @@
else {
this.alerts.unregister(primaryIPUndetectedAlert);
}
+ shouldInsertARK();
return lastIPAddress;
}
Modified: trunk/freenet/src/freenet/node/Version.java
===================================================================
--- trunk/freenet/src/freenet/node/Version.java 2006-05-11 17:49:31 UTC (rev
8661)
+++ trunk/freenet/src/freenet/node/Version.java 2006-05-11 17:59:40 UTC (rev
8662)
@@ -20,7 +20,7 @@
public static final String protocolVersion = "1.0";
/** The build number of the current revision */
- private static final int buildNumber = 690;
+ private static final int buildNumber = 691;
/** Oldest build of Fred we will talk to */
private static final int lastGoodBuild = 591;
@@ -49,6 +49,7 @@
public static final String cvsRevision = "@custom@";
private static boolean logDEBUG =
Logger.shouldLog(Logger.DEBUG,Version.class);
+
/**
* @return the node's version designators as an array
*/