Author: toad
Date: 2006-02-03 01:52:31 +0000 (Fri, 03 Feb 2006)
New Revision: 7995
Modified:
trunk/freenet/src/freenet/node/Node.java
trunk/freenet/src/freenet/node/PeerNode.java
trunk/freenet/src/freenet/node/Version.java
Log:
431:
Try localhost (as well as the open IP) if two nodes are on the same IP.
They might not be able to talk to one another over the internet proper.
For bishop.
Note that there may be security issues here; we should for example check
incoming untrusted references for our IP as well as localhost.
Modified: trunk/freenet/src/freenet/node/Node.java
===================================================================
--- trunk/freenet/src/freenet/node/Node.java 2006-02-03 01:34:42 UTC (rev
7994)
+++ trunk/freenet/src/freenet/node/Node.java 2006-02-03 01:52:31 UTC (rev
7995)
@@ -17,6 +17,7 @@
import java.io.OutputStreamWriter;
import java.net.InetAddress;
import java.net.SocketException;
+import java.net.UnknownHostException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
@@ -205,6 +206,9 @@
static final long MAX_ARCHIVED_FILE_SIZE = 1024*1024; // arbitrary... FIXME
static final int MAX_CACHED_ELEMENTS = 1024; // equally arbitrary! FIXME
hopefully we can cache many of these though
+ // Helpers
+ public final InetAddress localhostAddress;
+
/**
* Read all storable settings (identity etc) from the node file.
* @param filename The name of the file to read from.
@@ -369,6 +373,12 @@
testnetHandler = null;
statusUploader = null;
}
+ try {
+ localhostAddress = InetAddress.getByName("127.0.0.1");
+ } catch (UnknownHostException e3) {
+ // Does not do a reverse lookup, so this is impossible
+ throw new Error(e3);
+ }
portNumber = port;
startupTime = System.currentTimeMillis();
recentlyCompletedIDs = new LRUQueue();
@@ -935,7 +945,7 @@
* detection properly with NetworkInterface, and we should use
* third parties if available and UP&P if available.
*/
- private InetAddress getPrimaryIPAddress() {
+ InetAddress getPrimaryIPAddress() {
if(overrideIPAddress != null) {
Logger.minor(this, "Returning overridden address:
"+overrideIPAddress);
return overrideIPAddress;
@@ -1341,7 +1351,7 @@
final LRUQueue recentlyCompletedIDs;
static final int MAX_RECENTLY_COMPLETED_IDS = 10*1000;
-
+
/**
* Has a request completed with this ID recently?
*/
Modified: trunk/freenet/src/freenet/node/PeerNode.java
===================================================================
--- trunk/freenet/src/freenet/node/PeerNode.java 2006-02-03 01:34:42 UTC
(rev 7994)
+++ trunk/freenet/src/freenet/node/PeerNode.java 2006-02-03 01:52:31 UTC
(rev 7995)
@@ -6,6 +6,7 @@
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
+import java.net.InetAddress;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
@@ -314,8 +315,20 @@
for(int i=1;i<nominalPeer.size()+1;i++)
p[i]=(Peer) nominalPeer.get(i);
}else{
- return (Peer[]) nominalPeer.toArray(new
Peer[nominalPeer.size()]);
+ p = (Peer[]) nominalPeer.toArray(new Peer[nominalPeer.size()]);
}
+ // Hack for two nodes on the same IP that can't talk over inet for
routing reasons
+ InetAddress localhost = node.localhostAddress;
+ InetAddress nodeIP = node.getPrimaryIPAddress();
+ if(nodeIP.equals(localhost)) return p;
+ InetAddress peerIP = detectedPeer.getAddress();
+ if(peerIP.equals(localhost)) return p;
+ if(nodeIP.equals(peerIP)) {
+ Peer[] newPeers = new Peer[p.length+1];
+ System.arraycopy(p, 0, newPeers, 0, p.length);
+ newPeers[newPeers.length-1] = new Peer(node.localhostAddress,
detectedPeer.getPort());
+ p = newPeers;
+ }
return p;
}
Modified: trunk/freenet/src/freenet/node/Version.java
===================================================================
--- trunk/freenet/src/freenet/node/Version.java 2006-02-03 01:34:42 UTC (rev
7994)
+++ trunk/freenet/src/freenet/node/Version.java 2006-02-03 01:52:31 UTC (rev
7995)
@@ -20,7 +20,7 @@
public static final String protocolVersion = "1.0";
/** The build number of the current revision */
- private static final int buildNumber = 430;
+ private static final int buildNumber = 431;
/** Oldest build of Fred we will talk to */
private static final int lastGoodBuild = 403;