Author: toad
Date: 2006-09-01 17:54:51 +0000 (Fri, 01 Sep 2006)
New Revision: 10325
Modified:
trunk/freenet/src/freenet/node/IPDetectorPluginManager.java
trunk/freenet/src/freenet/node/Node.java
trunk/freenet/src/freenet/node/NodeIPDetector.java
trunk/freenet/src/freenet/node/useralerts/IPUndetectedUserAlert.java
Log:
Minor changes to IP address detection:
- Change the no-IP warning while doing the first detection.
- If we have no old IP address, drop the 2 minute delay for STUN; detect
immediately.
- Show the warning even if we have local addresses.
Modified: trunk/freenet/src/freenet/node/IPDetectorPluginManager.java
===================================================================
--- trunk/freenet/src/freenet/node/IPDetectorPluginManager.java 2006-09-01
17:43:22 UTC (rev 10324)
+++ trunk/freenet/src/freenet/node/IPDetectorPluginManager.java 2006-09-01
17:54:51 UTC (rev 10325)
@@ -152,6 +152,10 @@
Peer[] nodeAddrs = detector.getPrimaryIPAddress();
long now = System.currentTimeMillis();
synchronized(this) {
+ if(plugins.length == 0) {
+ detector.hasDetectedPM();
+ return;
+ }
if(runner != null) {
if(logMINOR) Logger.minor(this, "Already
running IP detection plugins");
return;
@@ -263,6 +267,9 @@
if(now - firstTimeUrgent > 2*60*1000)
detect = true;
+ if(!(detector.oldIPAddress != null &&
detector.oldIPAddress.isRealInternetAddress(false, false)))
+ detect = true; // else wait 2
minutes
+
} else {
if(logMINOR) Logger.minor(this, "Not
urgent; conns="+conns.length);
firstTimeUrgent = 0;
@@ -452,6 +459,7 @@
detector.processDetectedIPs(list);
} finally {
runner = null;
+ detector.hasDetectedPM();
}
}
Modified: trunk/freenet/src/freenet/node/Node.java
===================================================================
--- trunk/freenet/src/freenet/node/Node.java 2006-09-01 17:43:22 UTC (rev
10324)
+++ trunk/freenet/src/freenet/node/Node.java 2006-09-01 17:54:51 UTC (rev
10325)
@@ -1348,6 +1348,7 @@
"but this will cause some disruption, and may not be 100%
reliable.";
void start(boolean noSwaps) throws NodeInitException {
+
if(!noSwaps)
lm.startSender(this, this.swapInterval);
nodePinger.start();
@@ -1375,6 +1376,8 @@
// SubConfig pluginManagerConfig = new SubConfig("pluginmanager3",
config);
// pluginManager3 = new
freenet.plugin_new.PluginManager(pluginManagerConfig);
+ ipDetector.start();
+
// Node Updater
try{
nodeUpdater = NodeUpdater.maybeCreate(this, config);
@@ -1392,8 +1395,6 @@
server.register(pproxy, "/plugins/", true);
* */
- ipDetector.start();
-
// Start testnet handler
if(testnetHandler != null)
testnetHandler.start();
Modified: trunk/freenet/src/freenet/node/NodeIPDetector.java
===================================================================
--- trunk/freenet/src/freenet/node/NodeIPDetector.java 2006-09-01 17:43:22 UTC
(rev 10324)
+++ trunk/freenet/src/freenet/node/NodeIPDetector.java 2006-09-01 17:54:51 UTC
(rev 10325)
@@ -50,6 +50,8 @@
private final NodeARKInserter arkPutter;
/** Set when we have grounds to believe that we may be behind a
symmetric NAT. */
boolean maybeSymmetric;
+ private boolean hasDetectedPM;
+ private boolean hasDetectedIAD;
SimpleUserAlert maybeSymmetricAlert;
@@ -58,7 +60,7 @@
this.ticker = node.ps;
ipDetectorManager = new IPDetectorPluginManager(node, this);
ipDetector = new IPAddressDetector(10*1000, this);
- primaryIPUndetectedAlert = new IPUndetectedUserAlert();
+ primaryIPUndetectedAlert = new IPUndetectedUserAlert(this);
arkPutter = new NodeARKInserter(node, this);
}
@@ -69,20 +71,29 @@
* third parties if available and UP&P if available.
*/
Peer[] detectPrimaryIPAddress() {
+ boolean addedValidIP = false;
Logger.minor(this, "Redetecting IPs...");
boolean setMaybeSymmetric = false;
Vector addresses = new Vector();
if(overrideIPAddress != null) {
// If the IP is overridden, the override has to be the
first element.
- addresses.add(new Peer(overrideIPAddress,
node.portNumber));
+ Peer p = new Peer(overrideIPAddress, node.portNumber);
+ addresses.add(p);
+ if(p.getFreenetAddress().isRealInternetAddress(false,
true))
+ addedValidIP = true;
}
InetAddress[] detectedAddrs = ipDetector.getAddress();
+ synchronized(this) {
+ hasDetectedIAD = true;
+ }
if(detectedAddrs != null) {
for(int i=0;i<detectedAddrs.length;i++) {
Peer p = new Peer(detectedAddrs[i],
node.portNumber);
if(!addresses.contains(p)) {
Logger.normal(this, "Detected IP
address: "+p);
addresses.add(p);
+
if(p.getFreenetAddress().isRealInternetAddress(false, false))
+ addedValidIP = true;
}
}
}
@@ -94,6 +105,7 @@
if(!addresses.contains(a)) {
Logger.normal(this, "Plugin detected IP
address: "+a);
addresses.add(a);
+ addedValidIP = true;
}
}
}
@@ -123,7 +135,11 @@
Iterator it = countsByPeer.keySet().iterator();
Peer p = (Peer) (it.next());
Logger.minor(this, "Everyone agrees we are "+p);
- if(!addresses.contains(p)) addresses.add(p);
+ if(!addresses.contains(p)) {
+
if(p.getFreenetAddress().isRealInternetAddress(false, false))
+ addedValidIP = true;
+ addresses.add(p);
+ }
} else if(countsByPeer.size() > 1) {
Iterator it = countsByPeer.keySet().iterator();
// Take two most popular addresses.
@@ -147,11 +163,15 @@
if(!addresses.contains(best)) {
Logger.normal(this,
"Adding best peer "+best+" ("+bestPopularity+")");
addresses.add(best);
+
if(best.getFreenetAddress().isRealInternetAddress(false, false))
+ addedValidIP =
true;
}
if((secondBest != null) &&
(secondBestPopularity > 2)) {
if(!addresses.contains(secondBest)) {
Logger.normal(this, "Adding second best peer "+secondBest+" ("+secondBest+")");
addresses.add(secondBest);
+
if(secondBest.getFreenetAddress().isRealInternetAddress(false, false))
+
addedValidIP = true;
}
if(best.getAddress().equals(secondBest.getAddress()) && bestPopularity == 1) {
Logger.error(this, "Hrrrm, maybe this is a symmetric NAT? Expect trouble
connecting!");
@@ -180,10 +200,10 @@
}
}
if(node.clientCore != null) {
- if (addresses.isEmpty()) {
+ if (addedValidIP) {
+
node.clientCore.alerts.unregister(primaryIPUndetectedAlert);
+ } else {
node.clientCore.alerts.register(primaryIPUndetectedAlert);
- } else {
-
node.clientCore.alerts.unregister(primaryIPUndetectedAlert);
}
}
lastIPAddress = (Peer[]) addresses.toArray(new
Peer[addresses.size()]);
@@ -361,5 +381,15 @@
public void registerIPDetectorPlugin(FredPluginIPDetector detector) {
ipDetectorManager.register(detector);
} // FIXME what about unloading?
+
+ public synchronized boolean isDetecting() {
+ return !(hasDetectedPM && hasDetectedIAD);
+ }
+
+ void hasDetectedPM() {
+ synchronized(this) {
+ hasDetectedPM = true;
+ }
+ }
}
Modified: trunk/freenet/src/freenet/node/useralerts/IPUndetectedUserAlert.java
===================================================================
--- trunk/freenet/src/freenet/node/useralerts/IPUndetectedUserAlert.java
2006-09-01 17:43:22 UTC (rev 10324)
+++ trunk/freenet/src/freenet/node/useralerts/IPUndetectedUserAlert.java
2006-09-01 17:54:51 UTC (rev 10325)
@@ -1,9 +1,16 @@
package freenet.node.useralerts;
+import freenet.node.NodeIPDetector;
import freenet.support.HTMLNode;
public class IPUndetectedUserAlert implements UserAlert {
+
+ public IPUndetectedUserAlert(NodeIPDetector ipm) {
+ this.ipm = ipm;
+ }
+
boolean isValid=true;
+ final NodeIPDetector ipm;
public boolean userCanDismiss() {
return true;
@@ -14,18 +21,25 @@
}
public String getText() {
- return "Freenet was unable to determine your external IP
address " +
- "(or the IP address of your NAT or Firewall). You can
still exchange " +
- "references with other people, however this will only
work if the other " +
- "user is not behind a NAT or Firewall. As soon as you
have connected to " +
- "one other user in this way, Freenet will be able to
determine your " +
- "external IP address. You can determine your current IP
address and tell " +
- "your node with the 'Temporary IP address hint' <a
href=\"/config/\">configuration parameter</a>.";
+ if(ipm.isDetecting())
+ return "Freenet is currently attempting to detect your
external IP address. " +
+ "If this takes more than a few minutes
there is something wrong...";
+ else
+ return "Freenet was unable to determine your external
IP address " +
+ "(or the IP address of your NAT or Firewall).
You can still exchange " +
+ "references with other people, however this
will only work if the other " +
+ "user is not behind a NAT or Firewall. As soon
as you have connected to " +
+ "one other user in this way, Freenet will be
able to determine your " +
+ "external IP address. You can determine your
current IP address and tell " +
+ "your node with the 'Temporary IP address hint'
<a href=\"/config/\">configuration parameter</a>.";
}
public HTMLNode getHTMLText() {
HTMLNode textNode = new HTMLNode("div");
- textNode.addChild("#", "Freenet was unable to determine your
external IP address (or the IP address of your NAT-device or firewall). You can
still exchange references with other people, however this will only work if the
other user is not behind a NAT-device or firewall. As soon as you have
connected to one other user in this way, Freenet will be able to determine your
external IP address. You can determine your current IP address and tell your
node with the \u201cTemporary IP Address Hint\u201d ");
+ if(ipm.isDetecting())
+ textNode.addChild("#", "Freenet is currently attempting
to detect your external IP address. If this takes more than a few minutes there
is something wrong and you can use the Temporary IP Address Hint ");
+ else
+ textNode.addChild("#", "Freenet was unable to determine
your external IP address (or the IP address of your NAT-device or firewall).
You can still exchange references with other people, however this will only
work if the other user is not behind a NAT-device or firewall. As soon as you
have connected to one other user in this way, Freenet will be able to determine
your external IP address. You can determine your current IP address and tell
your node with the \u201cTemporary IP Address Hint\u201d ");
textNode.addChild("a", "href", "/config/", "configuration
parameter");
textNode.addChild("#", ".");
return textNode;