Author: toad
Date: 2008-04-19 16:14:38 +0000 (Sat, 19 Apr 2008)
New Revision: 19422
Modified:
trunk/freenet/src/freenet/l10n/freenet.l10n.en.properties
trunk/freenet/src/freenet/node/IPDetectorPluginManager.java
Log:
Separate UserAlert for port forwarding.
I haven't separated the old one yet.
Modified: trunk/freenet/src/freenet/l10n/freenet.l10n.en.properties
===================================================================
--- trunk/freenet/src/freenet/l10n/freenet.l10n.en.properties 2008-04-19
15:45:29 UTC (rev 19421)
+++ trunk/freenet/src/freenet/l10n/freenet.l10n.en.properties 2008-04-19
16:14:38 UTC (rev 19422)
@@ -479,6 +479,11 @@
IPDetectorPluginManager.suggestForwardTwoPortsWithLink= You may want to
${link}forward the ports${/link} (UDP port numbers ${port1} and ${port2})
manually (or you may already have done so, Freenet cannot easily detect this).
IPDetectorPluginManager.symmetric=Your internet connection appears to be
behind a symmetric NAT or firewall. You will probably only be able to connect
to users directly connected to the internet or behind restricted cone NATs.
IPDetectorPluginManager.symmetricTitle=Symmetric firewall detected
+IPDetectorPluginManager.forwardPortShort=Connection problems: Please forward
UDP port ${port}.
+IPDetectorPluginManager.forwardTwoPortsShort=Connection problems: Please
forward UDP ports ${port1} and ${port2}.
+IPDetectorPluginManager.forwardPort=Your node appears to be behind some sort
of NAT (see the connectivity page for details). You should forward UDP (not
TCP) port ${port} if possible to improve connectivity. It is possible you have
already done this; it takes a while for Freenet to detect a port forward. See
${link}here${/link} for some more information.
+IPDetectorPluginManager.forwardTwoPorts=Your node appears to be behind some
sort of NAT (see the connectivity page for details). You should forward UDP
(not TCP) ports ${port1} and ${port2} if possible to improve connectivity. It
is possible you have already done this; it takes a while for Freenet to detect
a port forward. See ${link}here${/link} for some more information.
+IPDetectorPluginManager.portForwardHelpURL=http://wiki.freenetproject.org/FirewallAndRouterIssues
IPUndetectedUserAlert.detecting=Freenet is currently attempting to detect your
external IP address. If this takes more than a few minutes there is something
wrong...
IPUndetectedUserAlert.detectingShort=Freenet is currently attempting to detect
your external IP address.
IPUndetectedUserAlert.detectingWithConfigLink=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
${link}configuration parameter${/link}.
Modified: trunk/freenet/src/freenet/node/IPDetectorPluginManager.java
===================================================================
--- trunk/freenet/src/freenet/node/IPDetectorPluginManager.java 2008-04-19
15:45:29 UTC (rev 19421)
+++ trunk/freenet/src/freenet/node/IPDetectorPluginManager.java 2008-04-19
16:14:38 UTC (rev 19422)
@@ -22,6 +22,7 @@
import freenet.pluginmanager.FredPlugin;
import freenet.pluginmanager.FredPluginIPDetector;
import freenet.pluginmanager.FredPluginPortForward;
+import freenet.support.HTMLEncoder;
import freenet.support.HTMLNode;
import freenet.support.Logger;
import freenet.support.OOMHandler;
@@ -33,6 +34,118 @@
*/
public class IPDetectorPluginManager implements ForwardPortCallback {
+ public class PortForwardAlert implements UserAlert {
+
+ private int[] portsNotForwarded;
+
+ private short maxPriorityShown;
+ private int maxPortsLength;
+
+ private boolean valid;
+
+ public String anchor() {
+ return "port-forward:"+super.hashCode();
+ }
+
+ public String dismissButtonText() {
+ return L10n.getString("UserAlert.hide");
+ }
+
+ public HTMLNode getHTMLText() {
+ HTMLNode div = new HTMLNode("div");
+ String url =
HTMLEncoder.encode(l10n("portForwardHelpURL"));
+ if(portsNotForwarded.length == 1) {
+ L10n.addL10nSubstitution(div,
"IPDetectorPluginManager.forwardPortShort",
+ new String[] { "port", "link",
"/link" },
+ new String[] {
Integer.toString(portsNotForwarded[0]), "<a href=\""+url+"\">", "</a>" });
+ } else if(portsNotForwarded.length == 2) {
+ L10n.addL10nSubstitution(div,
"IPDetectorPluginManager.forwardTwoPortsShort",
+ new String[] { "port1",
"port2", "link", "/link" },
+ new String[] {
Integer.toString(portsNotForwarded[0]), Integer.toString(portsNotForwarded[1]),
"<a href=\""+url+"\">", "</a>" });
+ } else {
+ Logger.error(this, "Unknown number of ports to
forward: "+portsNotForwarded.length);
+ }
+ return div;
+ }
+
+ public short getPriorityClass() {
+ return innerGetPriorityClass();
+ }
+
+ public short innerGetPriorityClass() {
+ if(connectionType == DetectedIP.SYMMETRIC_NAT ||
connectionType == DetectedIP.SYMMETRIC_UDP_FIREWALL)
+ // Only able to connect to directly connected /
full cone nodes.
+ return UserAlert.ERROR;
+ else return UserAlert.MINOR;
+ }
+
+ public String getShortText() {
+ if(portsNotForwarded.length == 1) {
+ return l10n("forwardPortShort", "port",
Integer.toString(portsNotForwarded[0]));
+ } else if(portsNotForwarded.length == 2) {
+ return l10n("forwardTwoPortsShort", new
String[] { "port1", "port2" },
+ new String[] {
Integer.toString(portsNotForwarded[0]), Integer.toString(portsNotForwarded[1])
});
+ } else {
+ Logger.error(this, "Unknown number of ports to
forward: "+portsNotForwarded.length);
+ return "";
+ }
+ }
+
+ public String getText() {
+ String url = l10n("portForwardHelpURL");
+ if(portsNotForwarded.length == 1) {
+ return l10n("forwardPort", new String[] {
"port", "link", "/link" },
+ new String[] {
Integer.toString(portsNotForwarded[0]), "", " ("+url+")" });
+ } else if(portsNotForwarded.length == 2) {
+ return l10n("forwardTwoPorts", new String[] {
"port1", "port2", "link", "/link" },
+ new String[] {
Integer.toString(portsNotForwarded[0]), Integer.toString(portsNotForwarded[1]),
"", " ("+url+")" });
+ } else {
+ Logger.error(this, "Unknown number of ports to
forward: "+portsNotForwarded.length);
+ return "";
+ }
+ }
+
+ public String getTitle() {
+ return getShortText();
+ }
+
+ public Object getUserIdentifier() {
+ return IPDetectorPluginManager.this;
+ }
+
+ public boolean isValid() {
+ portsNotForwarded = getUDPPortsNotForwarded();
+ if(portsNotForwarded.length > maxPortsLength) {
+ valid = true;
+ maxPortsLength = portsNotForwarded.length;
+ }
+ short prio = innerGetPriorityClass();
+ if(prio < maxPriorityShown) {
+ valid = true;
+ maxPriorityShown = prio;
+ }
+ if(portsNotForwarded.length == 0) return false;
+ return valid;
+ }
+
+ public void isValid(boolean validity) {
+ valid = validity;
+ }
+
+ public void onDismiss() {
+ valid = false;
+ }
+
+ public boolean shouldUnregisterOnDismiss() {
+ return false;
+ }
+
+ public boolean userCanDismiss() {
+ return true;
+ }
+
+ }
+
public class MyUserAlert extends AbstractUserAlert {
final boolean suggestPortForward;
@@ -117,6 +230,7 @@
private final MyUserAlert restrictedAlert;
private short connectionType;
private ProxyUserAlert proxyAlert;
+ private final PortForwardAlert portForwardAlert;
private boolean started;
IPDetectorPluginManager(Node node, NodeIPDetector detector) {
@@ -134,6 +248,7 @@
true, UserAlert.WARNING, false);
restrictedAlert = new MyUserAlert(l10n("restrictedTitle"),
l10n("restricted"),
false, UserAlert.MINOR, false);
+ portForwardAlert = new PortForwardAlert();
}
/**
@@ -177,6 +292,7 @@
void start() {
// Cannot be initialized until UserAlertManager has been
created.
proxyAlert = new ProxyUserAlert(node.clientCore.alerts);
+ node.clientCore.alerts.register(portForwardAlert);
started = true;
tryMaybeRun();
}