Author: Jogy
Date: 2006-05-24 21:53:50 +0000 (Wed, 24 May 2006)
New Revision: 8858
Added:
trunk/freenet/src/freenet/node/useralerts/
trunk/freenet/src/freenet/node/useralerts/BuildOldAgeUserAlert.java
trunk/freenet/src/freenet/node/useralerts/IPUndetectedUserAlert.java
trunk/freenet/src/freenet/node/useralerts/MeaningfulNodeNameUserAlert.java
trunk/freenet/src/freenet/node/useralerts/PeerManagerUserAlert.java
trunk/freenet/src/freenet/node/useralerts/RevocationKeyFoundUserAlert.java
trunk/freenet/src/freenet/node/useralerts/UpdatedVersionAvailableUserAlert.java
trunk/freenet/src/freenet/node/useralerts/UserAlert.java
trunk/freenet/src/freenet/node/useralerts/UserAlertManager.java
Removed:
trunk/freenet/src/freenet/node/BuildOldAgeUserAlert.java
trunk/freenet/src/freenet/node/IPUndetectedUserAlert.java
trunk/freenet/src/freenet/node/MeaningfulNodeNameUserAlert.java
trunk/freenet/src/freenet/node/PeerManagerUserAlert.java
trunk/freenet/src/freenet/node/UserAlert.java
trunk/freenet/src/freenet/node/UserAlertManager.java
trunk/freenet/src/freenet/node/updater/RevocationKeyFoundUserAlert.java
trunk/freenet/src/freenet/node/updater/UpdatedVersionAvailableUserAlert.java
Modified:
trunk/freenet/src/freenet/clients/http/WelcomeToadlet.java
trunk/freenet/src/freenet/node/Node.java
trunk/freenet/src/freenet/node/PeerManager.java
trunk/freenet/src/freenet/node/updater/NodeUpdater.java
Log:
Cleanup: Move all UserAlters into a separate package freenet.node.useralerts
(and extract the subclass in PeerManager....)
nextgen: be sure to update as this affects some classes of the node updater!!
Modified: trunk/freenet/src/freenet/clients/http/WelcomeToadlet.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/WelcomeToadlet.java 2006-05-24
21:46:27 UTC (rev 8857)
+++ trunk/freenet/src/freenet/clients/http/WelcomeToadlet.java 2006-05-24
21:53:50 UTC (rev 8858)
@@ -14,8 +14,8 @@
import freenet.keys.FreenetURI;
import freenet.node.Node;
import freenet.node.NodeStarter;
-import freenet.node.UserAlert;
import freenet.node.Version;
+import freenet.node.useralerts.UserAlert;
import freenet.support.Bucket;
import freenet.support.HTMLEncoder;
import freenet.support.Logger;
Deleted: trunk/freenet/src/freenet/node/BuildOldAgeUserAlert.java
===================================================================
--- trunk/freenet/src/freenet/node/BuildOldAgeUserAlert.java 2006-05-24
21:46:27 UTC (rev 8857)
+++ trunk/freenet/src/freenet/node/BuildOldAgeUserAlert.java 2006-05-24
21:53:50 UTC (rev 8858)
@@ -1,39 +0,0 @@
-package freenet.node;
-
-public class BuildOldAgeUserAlert implements UserAlert {
- private boolean isValid=true;
- int lastGoodVersion = 0;
-
- public boolean userCanDismiss() {
- return false;
- }
-
- public String getTitle() {
- return "Build too old";
- }
-
- public String getText() {
- if(lastGoodVersion == 0)
- throw new IllegalArgumentException("Not valid");
- String s;
- s = "This node's software is older than the oldest version
(Build #"+lastGoodVersion+") allowed by the newest peers we " +
- "try to connect to. Please update your node as
soon as possible as you will not be " +
- "able to connect to peers labeled \"TOO NEW\"
until you do. " +
- "(Freenet may leave your node in the dust of
the past if you don't upgrade.)";
- return s;
- }
-
- public short getPriorityClass() {
- return UserAlert.ERROR;
- }
-
- public boolean isValid() {
- if(lastGoodVersion == 0)
- return false;
- return isValid;
- }
-
- public void isValid(boolean b){
- if(userCanDismiss()) isValid=b;
- }
-}
Deleted: trunk/freenet/src/freenet/node/IPUndetectedUserAlert.java
===================================================================
--- trunk/freenet/src/freenet/node/IPUndetectedUserAlert.java 2006-05-24
21:46:27 UTC (rev 8857)
+++ trunk/freenet/src/freenet/node/IPUndetectedUserAlert.java 2006-05-24
21:53:50 UTC (rev 8858)
@@ -1,33 +0,0 @@
-package freenet.node;
-
-public class IPUndetectedUserAlert implements UserAlert {
- boolean isValid=true;
-
- public boolean userCanDismiss() {
- return true;
- }
-
- public String getTitle() {
- return "Unknown external address";
- }
-
- 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.";
- }
-
- public short getPriorityClass() {
- return UserAlert.ERROR;
- }
-
- public boolean isValid() {
- return isValid;
- }
-
- public void isValid(boolean validity){
- if(userCanDismiss()) isValid=validity;
- }
-}
Deleted: trunk/freenet/src/freenet/node/MeaningfulNodeNameUserAlert.java
===================================================================
--- trunk/freenet/src/freenet/node/MeaningfulNodeNameUserAlert.java
2006-05-24 21:46:27 UTC (rev 8857)
+++ trunk/freenet/src/freenet/node/MeaningfulNodeNameUserAlert.java
2006-05-24 21:53:50 UTC (rev 8858)
@@ -1,33 +0,0 @@
-package freenet.node;
-
-public class MeaningfulNodeNameUserAlert implements UserAlert {
- private boolean isValid=true;
-
- public boolean userCanDismiss() {
- return true;
- }
-
- public String getTitle() {
- return "Your node name isn't defined";
- }
-
- public String getText() {
- return "It seems that your node's name isn't defined. Setting "+
- "up a node name doesn't affect your anonymity in any way but "+
- "is useful for your peers to know who you are in case they have
"+
- "to reach you. You can change the node's name at the
Configuration page. "+
- "Putting your e-mail address there is generally speaking a good
idea.";
- }
-
- public short getPriorityClass() {
- return UserAlert.WARNING;
- }
-
- public boolean isValid() {
- return isValid;
- }
-
- public void isValid(boolean b){
- if(userCanDismiss()) isValid=b;
- }
-}
Modified: trunk/freenet/src/freenet/node/Node.java
===================================================================
--- trunk/freenet/src/freenet/node/Node.java 2006-05-24 21:46:27 UTC (rev
8857)
+++ trunk/freenet/src/freenet/node/Node.java 2006-05-24 21:53:50 UTC (rev
8858)
@@ -87,6 +87,10 @@
import freenet.keys.SSKBlock;
import freenet.keys.SSKVerifyException;
import freenet.node.fcp.FCPServer;
+import freenet.node.useralerts.BuildOldAgeUserAlert;
+import freenet.node.useralerts.IPUndetectedUserAlert;
+import freenet.node.useralerts.MeaningfulNodeNameUserAlert;
+import freenet.node.useralerts.UserAlertManager;
import freenet.node.updater.NodeUpdater;
import freenet.pluginmanager.PluginManager;
import freenet.store.BerkeleyDBFreenetStore;
Modified: trunk/freenet/src/freenet/node/PeerManager.java
===================================================================
--- trunk/freenet/src/freenet/node/PeerManager.java 2006-05-24 21:46:27 UTC
(rev 8857)
+++ trunk/freenet/src/freenet/node/PeerManager.java 2006-05-24 21:53:50 UTC
(rev 8858)
@@ -18,6 +18,7 @@
import freenet.io.comm.NotConnectedException;
import freenet.io.comm.Peer;
import freenet.io.comm.PeerParseException;
+import freenet.node.useralerts.PeerManagerUserAlert;
import freenet.support.Logger;
import freenet.support.SimpleFieldSet;
Deleted: trunk/freenet/src/freenet/node/PeerManagerUserAlert.java
===================================================================
--- trunk/freenet/src/freenet/node/PeerManagerUserAlert.java 2006-05-24
21:46:27 UTC (rev 8857)
+++ trunk/freenet/src/freenet/node/PeerManagerUserAlert.java 2006-05-24
21:53:50 UTC (rev 8858)
@@ -1,70 +0,0 @@
-package freenet.node;
-
-public class PeerManagerUserAlert implements UserAlert {
-
- final Node n;
- int conns;
- int peers;
- boolean isValid=true;
-
- PeerManagerUserAlert(Node n) {
- this.n = n;
- }
-
- public boolean userCanDismiss() {
- return false;
- }
-
- public String getTitle() {
- if(peers == 0)
- return "No peers found";
- if(conns == 0)
- return "No open connections";
- if(conns == 1)
- return "Only 1 open connection";
- if(conns == 2)
- return "Only 2 open connections";
- else throw new IllegalArgumentException("Not valid");
- }
-
- public String getText() {
- String s;
- if(peers == 0) {
- s = "This node has no peers to connect to, therefore it will
not " +
- "be able to function normally. Ideally you
should connect to peers run by people you know " +
- "(if you are paranoid, then people you trust;
if not, then at least people you've talked to)";
- String end = " log on to irc.freenode.net channel #freenet-refs
and ask around for somebody to connect to";
- if(n.testnetEnabled)
- s += ", but since this is a testnet node, we suggest
that you " + end + ".";
- else
- s += ". You could " + end + ", but remember that you
are vulnerable to " +
- "those you are directly connected to.
(This is especially true in this early alpha of Freenet 0.7...)";
- } else if(conns == 0) {
- s = "This node has not been able to connect to any
other nodes so far; it will not be able to function normally. " +
- "Hopefully some of your peers will connect soon; if
not, try to get some more peers.";
- } else if(conns == 1) {
- s = "This node only has one connection. Performance
will be impaired, and you have no anonymity nor even plausible deniability if
that one person is malicious. " +
- "Your node is attached to the network like a 'leaf' and
does not contribute to the network's health." +
- "Try to get at least 3 connected peers at any given
time.";
- } else if(conns == 2) {
- s = "This node has only two connections. Performance
and security will not be very good, and your node is not doing any routing for
other nodes. " +
- "Your node is embedded like a 'chain' in the network
and does not contribute to the network's health." +
- "Try to get at least 3 connected peers at any given
time.";
- } else throw new IllegalArgumentException("Not valid");
- return s;
- }
-
- public short getPriorityClass() {
- if(peers == 0 || conns == 0)
- return UserAlert.CRITICAL_ERROR;
- return UserAlert.ERROR;
- }
-
- public boolean isValid() {
- return (peers == 0 || conns <= 2)&&isValid;
- }
-
- public void isValid(boolean b){
- if(userCanDismiss()) isValid=b;
- }
-}
Deleted: trunk/freenet/src/freenet/node/UserAlert.java
===================================================================
--- trunk/freenet/src/freenet/node/UserAlert.java 2006-05-24 21:46:27 UTC
(rev 8857)
+++ trunk/freenet/src/freenet/node/UserAlert.java 2006-05-24 21:53:50 UTC
(rev 8858)
@@ -1,42 +0,0 @@
-package freenet.node;
-
-public interface UserAlert {
-
- /**
- * Can the user dismiss the alert?
- * If not, it persists until it is unregistered.
- */
- public boolean userCanDismiss();
-
- /**
- * Title of alert (must be short!).
- */
- public String getTitle();
-
- /**
- * Content of alert (plain text).
- */
- public String getText();
-
- /**
- * Priority class
- */
- public short getPriorityClass();
-
- /**
- * Is the alert valid right now? Suggested use is to synchronize on the
- * alert, then check this, then get the data.
- */
- public boolean isValid();
-
- public void isValid(boolean validity);
-
- /** An error which prevents normal operation */
- public final static short CRITICAL_ERROR = 0;
- /** An error which prevents normal operation but might be temporary */
- public final static short ERROR = 1;
- /** An error; limited anonymity due to not enough connections, for
example */
- public final static short WARNING = 2;
- /** Something minor */
- public final static short MINOR = 3;
-}
Deleted: trunk/freenet/src/freenet/node/UserAlertManager.java
===================================================================
--- trunk/freenet/src/freenet/node/UserAlertManager.java 2006-05-24
21:46:27 UTC (rev 8857)
+++ trunk/freenet/src/freenet/node/UserAlertManager.java 2006-05-24
21:53:50 UTC (rev 8858)
@@ -1,80 +0,0 @@
-package freenet.node;
-
-import java.util.Arrays;
-import java.util.Comparator;
-import java.util.HashSet;
-
-/**
- * Collection of UserAlert's.
- */
-public class UserAlertManager implements Comparator {
-
- final HashSet alerts;
-
- UserAlertManager() {
- alerts = new HashSet();
- }
-
- public synchronized void register(UserAlert alert) {
- alerts.add(alert);
- }
-
- public synchronized void unregister(UserAlert alert) {
- alerts.remove(alert);
- }
-
- public UserAlert[] getAlerts() {
- UserAlert[] a = (UserAlert[]) alerts.toArray(new
UserAlert[alerts.size()]);
- Arrays.sort(a, this);
- return a;
- }
-
- public int compare(Object arg0, Object arg1) {
- UserAlert a0 = (UserAlert)arg0;
- UserAlert a1 = (UserAlert)arg1;
- if(a0 == a1) return 0;
- short p0 = a0.getPriorityClass();
- short p1 = a1.getPriorityClass();
- if(p0 < p1) return -1;
- if(p0 > p1) return 1;
- return 0;
- }
-
- /**
- * Write the alerts as HTML to a StringBuffer
- */
- public void toHtml(StringBuffer buf) {
- synchronized(alerts){
- UserAlert[] a = getAlerts();
- for(int i=0;i<a.length;i++) {
- UserAlert alert = a[i];
- if(!alert.isValid()) continue;
-
- short level = a[i].getPriorityClass();
- if(level <= UserAlert.CRITICAL_ERROR)
- buf.append("<div class=\"infobox
infobox-error\">\n");
- else if(level <= UserAlert.ERROR)
- buf.append("<div class=\"infobox
infobox-alert\">\n");
- else if(level <= UserAlert.WARNING)
- buf.append("<div class=\"infobox
infobox-warning\">\n");
- else if(level <= UserAlert.MINOR)
- buf.append("<div class=\"infobox
infobox-information\">\n");
- //
- buf.append("<div class=\"infobox-header\">\n");
- buf.append(a[i].getTitle());
- buf.append("</div>\n");
- //
- buf.append("<div class=\"infobox-content\">\n");
- buf.append(a[i].getText());
- //
- if(a[i].userCanDismiss())
- buf.append("<form method=\"post\"
action=\".\"><input type=\"hidden\" name=\"disable\" value=\""+
- a[i].hashCode()+"\"
/><input type=\"submit\" value=\"Hide\" /></form>");
- //
- buf.append("</div>\n");
- buf.append("</div>\n");
- }
- }
- }
-
-}
Modified: trunk/freenet/src/freenet/node/updater/NodeUpdater.java
===================================================================
--- trunk/freenet/src/freenet/node/updater/NodeUpdater.java 2006-05-24
21:46:27 UTC (rev 8857)
+++ trunk/freenet/src/freenet/node/updater/NodeUpdater.java 2006-05-24
21:53:50 UTC (rev 8858)
@@ -20,6 +20,8 @@
import freenet.node.Node;
import freenet.node.RequestStarter;
import freenet.node.Version;
+import freenet.node.useralerts.RevocationKeyFoundUserAlert;
+import freenet.node.useralerts.UpdatedVersionAvailableUserAlert;
import freenet.support.ArrayBucket;
import freenet.support.Logger;
Deleted: trunk/freenet/src/freenet/node/updater/RevocationKeyFoundUserAlert.java
===================================================================
--- trunk/freenet/src/freenet/node/updater/RevocationKeyFoundUserAlert.java
2006-05-24 21:46:27 UTC (rev 8857)
+++ trunk/freenet/src/freenet/node/updater/RevocationKeyFoundUserAlert.java
2006-05-24 21:53:50 UTC (rev 8858)
@@ -1,41 +0,0 @@
-package freenet.node.updater;
-
-import freenet.node.UserAlert;
-
-public class RevocationKeyFoundUserAlert implements UserAlert {
- private final String msg;
-
- RevocationKeyFoundUserAlert(String msg){
- this.msg=msg;
- }
-
- public boolean userCanDismiss() {
- return false;
- }
-
- public String getTitle() {
- return "The private key of the project has been compromized!";
- }
-
- public String getText() {
- //TODO: reformulate : maybe put the GPG key fingerprint of
"trusted devs"
- return "Your node has found the auto-updater's revocation key
on the network. "+
- "It means that our auto-updating system is likely to
have been COMPROMIZED! "+
- "Consequently, it has been disabled on your node to
prevent \"bad things\" to "+
- "be installed. We strongly advise you to check the
project's website for updates. "+
- "Please take care of verifying that the website hasn't
been spoofed either. "+
- "The revocation message is the following : "+msg;
- }
-
- public short getPriorityClass() {
- return UserAlert.CRITICAL_ERROR;
- }
-
- public boolean isValid() {
- return true;
- }
-
- public void isValid(boolean b){
- // We ignore it : it's ALWAYS valid !
- }
-}
\ No newline at end of file
Deleted:
trunk/freenet/src/freenet/node/updater/UpdatedVersionAvailableUserAlert.java
===================================================================
---
trunk/freenet/src/freenet/node/updater/UpdatedVersionAvailableUserAlert.java
2006-05-24 21:46:27 UTC (rev 8857)
+++
trunk/freenet/src/freenet/node/updater/UpdatedVersionAvailableUserAlert.java
2006-05-24 21:53:50 UTC (rev 8858)
@@ -1,42 +0,0 @@
-package freenet.node.updater;
-
-import freenet.node.UserAlert;
-
-public class UpdatedVersionAvailableUserAlert implements UserAlert {
- private boolean isValid;
- private int version;
-
- UpdatedVersionAvailableUserAlert(int version){
- this.version=version;
- isValid=false;
- }
-
- public synchronized void set(int v){
- version = v;
- }
-
- public boolean userCanDismiss() {
- return false;
- }
-
- public String getTitle() {
- return "A new stable version of Freenet is available";
- }
-
- public String getText() {
- return "It seems that your node isn't running the latest
version of the software. "+
- "Updating to "+version+" is advised.";
- }
-
- public short getPriorityClass() {
- return UserAlert.MINOR;
- }
-
- public boolean isValid() {
- return isValid;
- }
-
- public void isValid(boolean b){
- isValid=b;
- }
-}
\ No newline at end of file
Added: trunk/freenet/src/freenet/node/useralerts/BuildOldAgeUserAlert.java
===================================================================
--- trunk/freenet/src/freenet/node/useralerts/BuildOldAgeUserAlert.java
2006-05-24 21:46:27 UTC (rev 8857)
+++ trunk/freenet/src/freenet/node/useralerts/BuildOldAgeUserAlert.java
2006-05-24 21:53:50 UTC (rev 8858)
@@ -0,0 +1,39 @@
+package freenet.node.useralerts;
+
+public class BuildOldAgeUserAlert implements UserAlert {
+ private boolean isValid=true;
+ public int lastGoodVersion = 0;
+
+ public boolean userCanDismiss() {
+ return false;
+ }
+
+ public String getTitle() {
+ return "Build too old";
+ }
+
+ public String getText() {
+ if(lastGoodVersion == 0)
+ throw new IllegalArgumentException("Not valid");
+ String s;
+ s = "This node's software is older than the oldest version
(Build #"+lastGoodVersion+") allowed by the newest peers we " +
+ "try to connect to. Please update your node as
soon as possible as you will not be " +
+ "able to connect to peers labeled \"TOO NEW\"
until you do. " +
+ "(Freenet may leave your node in the dust of
the past if you don't upgrade.)";
+ return s;
+ }
+
+ public short getPriorityClass() {
+ return UserAlert.ERROR;
+ }
+
+ public boolean isValid() {
+ if(lastGoodVersion == 0)
+ return false;
+ return isValid;
+ }
+
+ public void isValid(boolean b){
+ if(userCanDismiss()) isValid=b;
+ }
+}
Added: trunk/freenet/src/freenet/node/useralerts/IPUndetectedUserAlert.java
===================================================================
--- trunk/freenet/src/freenet/node/useralerts/IPUndetectedUserAlert.java
2006-05-24 21:46:27 UTC (rev 8857)
+++ trunk/freenet/src/freenet/node/useralerts/IPUndetectedUserAlert.java
2006-05-24 21:53:50 UTC (rev 8858)
@@ -0,0 +1,33 @@
+package freenet.node.useralerts;
+
+public class IPUndetectedUserAlert implements UserAlert {
+ boolean isValid=true;
+
+ public boolean userCanDismiss() {
+ return true;
+ }
+
+ public String getTitle() {
+ return "Unknown external address";
+ }
+
+ 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.";
+ }
+
+ public short getPriorityClass() {
+ return UserAlert.ERROR;
+ }
+
+ public boolean isValid() {
+ return isValid;
+ }
+
+ public void isValid(boolean validity){
+ if(userCanDismiss()) isValid=validity;
+ }
+}
Added:
trunk/freenet/src/freenet/node/useralerts/MeaningfulNodeNameUserAlert.java
===================================================================
--- trunk/freenet/src/freenet/node/useralerts/MeaningfulNodeNameUserAlert.java
2006-05-24 21:46:27 UTC (rev 8857)
+++ trunk/freenet/src/freenet/node/useralerts/MeaningfulNodeNameUserAlert.java
2006-05-24 21:53:50 UTC (rev 8858)
@@ -0,0 +1,34 @@
+package freenet.node.useralerts;
+
+public class MeaningfulNodeNameUserAlert implements UserAlert {
+ private boolean isValid=true;
+
+ public boolean userCanDismiss() {
+ return true;
+ }
+
+ public String getTitle() {
+ return "Your node name isn't defined";
+ }
+
+ public String getText() {
+ return "It seems that your node's name isn't defined. Setting "
+
+ "up a node name doesn't affect your anonymity in any way but " +
+ "is useful for your peers to know who you are in case they have
" +
+ "to reach you. You can change the node's name at the
Configuration page. " +
+ "Putting your e-mail address or IRC nickname there is generally
speaking " +
+ "a good idea and helps your friends to identify your node.";
+ }
+
+ public short getPriorityClass() {
+ return UserAlert.WARNING;
+ }
+
+ public boolean isValid() {
+ return isValid;
+ }
+
+ public void isValid(boolean b){
+ if(userCanDismiss()) isValid=b;
+ }
+}
Added: trunk/freenet/src/freenet/node/useralerts/PeerManagerUserAlert.java
===================================================================
--- trunk/freenet/src/freenet/node/useralerts/PeerManagerUserAlert.java
2006-05-24 21:46:27 UTC (rev 8857)
+++ trunk/freenet/src/freenet/node/useralerts/PeerManagerUserAlert.java
2006-05-24 21:53:50 UTC (rev 8858)
@@ -0,0 +1,72 @@
+package freenet.node.useralerts;
+
+import freenet.node.Node;
+
+public class PeerManagerUserAlert implements UserAlert {
+
+ final Node n;
+ public int conns;
+ public int peers;
+ boolean isValid=true;
+
+ public PeerManagerUserAlert(Node n) {
+ this.n = n;
+ }
+
+ public boolean userCanDismiss() {
+ return false;
+ }
+
+ public String getTitle() {
+ if(peers == 0)
+ return "No peers found";
+ if(conns == 0)
+ return "No open connections";
+ if(conns == 1)
+ return "Only 1 open connection";
+ if(conns == 2)
+ return "Only 2 open connections";
+ else throw new IllegalArgumentException("Not valid");
+ }
+
+ public String getText() {
+ String s;
+ if(peers == 0) {
+ s = "This node has no peers to connect to, therefore it will
not " +
+ "be able to function normally. Ideally you
should connect to peers run by people you know " +
+ "(if you are paranoid, then people you trust;
if not, then at least people you've talked to)";
+ String end = " log on to irc.freenode.net channel #freenet-refs
and ask around for somebody to connect to";
+ if(n.isTestnetEnabled())
+ s += ", but since this is a testnet node, we suggest
that you " + end + ".";
+ else
+ s += ". You could " + end + ", but remember that you
are vulnerable to " +
+ "those you are directly connected to.
(This is especially true in this early alpha of Freenet 0.7...)";
+ } else if(conns == 0) {
+ s = "This node has not been able to connect to any
other nodes so far; it will not be able to function normally. " +
+ "Hopefully some of your peers will connect soon; if
not, try to get some more peers.";
+ } else if(conns == 1) {
+ s = "This node only has one connection. Performance
will be impaired, and you have no anonymity nor even plausible deniability if
that one person is malicious. " +
+ "Your node is attached to the network like a 'leaf' and
does not contribute to the network's health." +
+ "Try to get at least 3 connected peers at any given
time.";
+ } else if(conns == 2) {
+ s = "This node has only two connections. Performance
and security will not be very good, and your node is not doing any routing for
other nodes. " +
+ "Your node is embedded like a 'chain' in the network
and does not contribute to the network's health." +
+ "Try to get at least 3 connected peers at any given
time.";
+ } else throw new IllegalArgumentException("Not valid");
+ return s;
+ }
+
+ public short getPriorityClass() {
+ if(peers == 0 || conns == 0)
+ return UserAlert.CRITICAL_ERROR;
+ return UserAlert.ERROR;
+ }
+
+ public boolean isValid() {
+ return (peers == 0 || conns <= 2)&&isValid;
+ }
+
+ public void isValid(boolean b){
+ if(userCanDismiss()) isValid=b;
+ }
+}
Added:
trunk/freenet/src/freenet/node/useralerts/RevocationKeyFoundUserAlert.java
===================================================================
--- trunk/freenet/src/freenet/node/useralerts/RevocationKeyFoundUserAlert.java
2006-05-24 21:46:27 UTC (rev 8857)
+++ trunk/freenet/src/freenet/node/useralerts/RevocationKeyFoundUserAlert.java
2006-05-24 21:53:50 UTC (rev 8858)
@@ -0,0 +1,39 @@
+package freenet.node.useralerts;
+
+public class RevocationKeyFoundUserAlert implements UserAlert {
+ private final String msg;
+
+ public RevocationKeyFoundUserAlert(String msg){
+ this.msg=msg;
+ }
+
+ public boolean userCanDismiss() {
+ return false;
+ }
+
+ public String getTitle() {
+ return "The private key of the project has been compromized!";
+ }
+
+ public String getText() {
+ //TODO: reformulate : maybe put the GPG key fingerprint of
"trusted devs"
+ return "Your node has found the auto-updater's revocation key
on the network. "+
+ "It means that our auto-updating system is likely to
have been COMPROMIZED! "+
+ "Consequently, it has been disabled on your node to
prevent \"bad things\" to "+
+ "be installed. We strongly advise you to check the
project's website for updates. "+
+ "Please take care of verifying that the website hasn't
been spoofed either. "+
+ "The revocation message is the following : "+msg;
+ }
+
+ public short getPriorityClass() {
+ return UserAlert.CRITICAL_ERROR;
+ }
+
+ public boolean isValid() {
+ return true;
+ }
+
+ public void isValid(boolean b){
+ // We ignore it : it's ALWAYS valid !
+ }
+}
Added:
trunk/freenet/src/freenet/node/useralerts/UpdatedVersionAvailableUserAlert.java
===================================================================
---
trunk/freenet/src/freenet/node/useralerts/UpdatedVersionAvailableUserAlert.java
2006-05-24 21:46:27 UTC (rev 8857)
+++
trunk/freenet/src/freenet/node/useralerts/UpdatedVersionAvailableUserAlert.java
2006-05-24 21:53:50 UTC (rev 8858)
@@ -0,0 +1,42 @@
+package freenet.node.useralerts;
+
+import freenet.node.Node;
+
+public class UpdatedVersionAvailableUserAlert implements UserAlert {
+ private boolean isValid;
+ private int version;
+
+ public UpdatedVersionAvailableUserAlert(int version){
+ this.version=version;
+ isValid=false;
+ }
+
+ public synchronized void set(int v){
+ version = v;
+ }
+
+ public boolean userCanDismiss() {
+ return false;
+ }
+
+ public String getTitle() {
+ return "A new stable version of Freenet is available";
+ }
+
+ public String getText() {
+ return "It seems that your node isn't running the latest
version of the software. "+
+ "Updating to "+version+" is advised.";
+ }
+
+ public short getPriorityClass() {
+ return UserAlert.MINOR;
+ }
+
+ public boolean isValid() {
+ return isValid;
+ }
+
+ public void isValid(boolean b){
+ isValid=b;
+ }
+}
Added: trunk/freenet/src/freenet/node/useralerts/UserAlert.java
===================================================================
--- trunk/freenet/src/freenet/node/useralerts/UserAlert.java 2006-05-24
21:46:27 UTC (rev 8857)
+++ trunk/freenet/src/freenet/node/useralerts/UserAlert.java 2006-05-24
21:53:50 UTC (rev 8858)
@@ -0,0 +1,42 @@
+package freenet.node.useralerts;
+
+public interface UserAlert {
+
+ /**
+ * Can the user dismiss the alert?
+ * If not, it persists until it is unregistered.
+ */
+ public boolean userCanDismiss();
+
+ /**
+ * Title of alert (must be short!).
+ */
+ public String getTitle();
+
+ /**
+ * Content of alert (plain text).
+ */
+ public String getText();
+
+ /**
+ * Priority class
+ */
+ public short getPriorityClass();
+
+ /**
+ * Is the alert valid right now? Suggested use is to synchronize on the
+ * alert, then check this, then get the data.
+ */
+ public boolean isValid();
+
+ public void isValid(boolean validity);
+
+ /** An error which prevents normal operation */
+ public final static short CRITICAL_ERROR = 0;
+ /** An error which prevents normal operation but might be temporary */
+ public final static short ERROR = 1;
+ /** An error; limited anonymity due to not enough connections, for
example */
+ public final static short WARNING = 2;
+ /** Something minor */
+ public final static short MINOR = 3;
+}
Added: trunk/freenet/src/freenet/node/useralerts/UserAlertManager.java
===================================================================
--- trunk/freenet/src/freenet/node/useralerts/UserAlertManager.java
2006-05-24 21:46:27 UTC (rev 8857)
+++ trunk/freenet/src/freenet/node/useralerts/UserAlertManager.java
2006-05-24 21:53:50 UTC (rev 8858)
@@ -0,0 +1,80 @@
+package freenet.node.useralerts;
+
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.HashSet;
+
+/**
+ * Collection of UserAlert's.
+ */
+public class UserAlertManager implements Comparator {
+
+ final HashSet alerts;
+
+ public UserAlertManager() {
+ alerts = new HashSet();
+ }
+
+ public synchronized void register(UserAlert alert) {
+ alerts.add(alert);
+ }
+
+ public synchronized void unregister(UserAlert alert) {
+ alerts.remove(alert);
+ }
+
+ public UserAlert[] getAlerts() {
+ UserAlert[] a = (UserAlert[]) alerts.toArray(new
UserAlert[alerts.size()]);
+ Arrays.sort(a, this);
+ return a;
+ }
+
+ public int compare(Object arg0, Object arg1) {
+ UserAlert a0 = (UserAlert)arg0;
+ UserAlert a1 = (UserAlert)arg1;
+ if(a0 == a1) return 0;
+ short p0 = a0.getPriorityClass();
+ short p1 = a1.getPriorityClass();
+ if(p0 < p1) return -1;
+ if(p0 > p1) return 1;
+ return 0;
+ }
+
+ /**
+ * Write the alerts as HTML to a StringBuffer
+ */
+ public void toHtml(StringBuffer buf) {
+ synchronized(alerts){
+ UserAlert[] a = getAlerts();
+ for(int i=0;i<a.length;i++) {
+ UserAlert alert = a[i];
+ if(!alert.isValid()) continue;
+
+ short level = a[i].getPriorityClass();
+ if(level <= UserAlert.CRITICAL_ERROR)
+ buf.append("<div class=\"infobox
infobox-error\">\n");
+ else if(level <= UserAlert.ERROR)
+ buf.append("<div class=\"infobox
infobox-alert\">\n");
+ else if(level <= UserAlert.WARNING)
+ buf.append("<div class=\"infobox
infobox-warning\">\n");
+ else if(level <= UserAlert.MINOR)
+ buf.append("<div class=\"infobox
infobox-information\">\n");
+ //
+ buf.append("<div class=\"infobox-header\">\n");
+ buf.append(a[i].getTitle());
+ buf.append("</div>\n");
+ //
+ buf.append("<div class=\"infobox-content\">\n");
+ buf.append(a[i].getText());
+ //
+ if(a[i].userCanDismiss())
+ buf.append("<form method=\"post\"
action=\".\"><input type=\"hidden\" name=\"disable\" value=\""+
+ a[i].hashCode()+"\"
/><input type=\"submit\" value=\"Hide\" /></form>");
+ //
+ buf.append("</div>\n");
+ buf.append("</div>\n");
+ }
+ }
+ }
+
+}