Author: nextgens
Date: 2007-04-12 18:38:21 +0000 (Thu, 12 Apr 2007)
New Revision: 12615
Modified:
trunk/freenet/src/freenet/node/fcp/FCPConnectionHandler.java
trunk/freenet/src/freenet/node/fcp/FCPServer.java
Log:
Add two config settings related to testDDA
Modified: trunk/freenet/src/freenet/node/fcp/FCPConnectionHandler.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/FCPConnectionHandler.java
2007-04-12 18:07:52 UTC (rev 12614)
+++ trunk/freenet/src/freenet/node/fcp/FCPConnectionHandler.java
2007-04-12 18:38:21 UTC (rev 12615)
@@ -62,8 +62,6 @@
private final HashMap checkedDirectories = new HashMap();
// DDACheckJobs in flight
private final HashMap inTestDirectories = new HashMap();
- private static final boolean ASSUME_DOWNLOAD_DDA_IS_ALLOWED = false;
- private static final boolean ASSUME_UPLOAD_DDA_IS_ALLOWED = false;
public FCPConnectionHandler(Socket s, FCPServer server) {
this.sock = s;
@@ -304,9 +302,9 @@
}
if(writeRequest)
- return (da == null ? ASSUME_UPLOAD_DDA_IS_ALLOWED :
da.canWrite);
+ return (da == null ?
server.isDownloadDDAAlwaysAllowed() : da.canWrite);
else
- return (da == null ? ASSUME_DOWNLOAD_DDA_IS_ALLOWED :
da.canRead);
+ return (da == null ? server.isUploadDDAAlwaysAllowed()
: da.canRead);
}
/**
Modified: trunk/freenet/src/freenet/node/fcp/FCPServer.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/FCPServer.java 2007-04-12 18:07:52 UTC
(rev 12614)
+++ trunk/freenet/src/freenet/node/fcp/FCPServer.java 2007-04-12 18:38:21 UTC
(rev 12615)
@@ -77,6 +77,8 @@
public static final int QUEUE_MAX_RETRIES = -1;
public static final long QUEUE_MAX_DATA_SIZE = Long.MAX_VALUE;
private boolean canStartPersister = false;
+ private boolean assumeDownloadDDAIsAllowed;
+ private boolean assumeUploadDDAIsAllowed;
private void startPersister() {
Thread t = new Thread(persister = new FCPServerPersister(),
"FCP request persistence handler");
@@ -89,7 +91,7 @@
persister = null;
}
- public FCPServer(String ipToBindTo, String allowedHosts, String
allowedHostsFullAccess, int port, Node node, NodeClientCore core, boolean
persistentDownloadsEnabled, String persistentDownloadsDir, long
persistenceInterval, boolean isEnabled) throws IOException,
InvalidConfigValueException {
+ public FCPServer(String ipToBindTo, String allowedHosts, String
allowedHostsFullAccess, int port, Node node, NodeClientCore core, boolean
persistentDownloadsEnabled, String persistentDownloadsDir, long
persistenceInterval, boolean isEnabled, boolean assumeDDADownloadAllowed,
boolean assumeDDAUploadAllowed) throws IOException, InvalidConfigValueException
{
this.bindTo = ipToBindTo;
this.allowedHostsFullAccess = new
AllowedHosts(allowedHostsFullAccess);
this.persistenceInterval = persistenceInterval;
@@ -99,6 +101,8 @@
setPersistentDownloadsFile(new File(persistentDownloadsDir));
this.node = node;
this.core = core;
+ this.assumeDownloadDDAIsAllowed = assumeDDADownloadAllowed;
+ this.assumeUploadDDAIsAllowed = assumeDDAUploadAllowed;
clientsByName = new WeakHashMap();
// This one is only used to get the default settings.
Individual FCP conns
@@ -323,45 +327,80 @@
}
}
+ static class AssumeDDADownloadIsAllowedCallback implements
BooleanCallback{
+ FCPServer server;
+
+ public boolean get() {
+ return server.assumeDownloadDDAIsAllowed;
+ }
+
+ public void set(boolean val) throws InvalidConfigValueException
{
+ if(val == get()) return;
+ server.assumeDownloadDDAIsAllowed = val;
+ }
+ }
+
+ static class AssumeDDAUploadIsAllowedCallback implements
BooleanCallback{
+ FCPServer server;
+
+ public boolean get() {
+ return server.assumeUploadDDAIsAllowed;
+ }
+
+ public void set(boolean val) throws InvalidConfigValueException
{
+ if(val == get()) return;
+ server.assumeUploadDDAIsAllowed = val;
+ }
+ }
+
+
public static FCPServer maybeCreate(Node node, NodeClientCore core,
Config config) throws IOException, InvalidConfigValueException {
SubConfig fcpConfig = new SubConfig("fcp", config);
- fcpConfig.register("enabled", true, 2, true, false, "Is FCP
server enabled ?", "Is FCP server enabled ?", new FCPEnabledCallback(core));
+ short sortOrder = 0;
+ fcpConfig.register("enabled", true, sortOrder++, true, false,
"Is FCP server enabled ?", "Is FCP server enabled ?", new
FCPEnabledCallback(core));
fcpConfig.register("port", FCPServer.DEFAULT_FCP_PORT /*
anagram of 1984, and 1000 up from old number */,
2, true, true, "FCP port number", "FCP port
number", new FCPPortNumberCallback(core));
- fcpConfig.register("bindTo", "127.0.0.1", 2, false, true, "IP
address to bind to", "IP address to bind the FCP server to", new
FCPBindtoCallback(core));
- fcpConfig.register("allowedHosts", "127.0.0.1,0:0:0:0:0:0:0:1",
2, false, true, "Allowed hosts (read the warning!)",
+ fcpConfig.register("bindTo", "127.0.0.1", sortOrder++, false,
true, "IP address to bind to", "IP address to bind the FCP server to", new
FCPBindtoCallback(core));
+ fcpConfig.register("allowedHosts", "127.0.0.1,0:0:0:0:0:0:0:1",
sortOrder++, false, true, "Allowed hosts (read the warning!)",
"IP addresses that are allowed to connect to
the FCP server. " +
"May be a comma-separated list of single IPs
and CIDR masked IPs like 192.168.0.0/24. "+
"WARNING! Anyone who has access to FCP can
upload any file the node has access to, or download files to disk " +
"(but the node will try not to overwrite
existing files).", new FCPAllowedHostsCallback(core));
- fcpConfig.register("allowedHostsFullAccess",
"127.0.0.1,0:0:0:0:0:0:0:1", 2, false, true, "Hosts allowed full access",
+ fcpConfig.register("allowedHostsFullAccess",
"127.0.0.1,0:0:0:0:0:0:0:1", sortOrder++, false, true, "Hosts allowed full
access",
"IP addresses which are allowed full access to
the node. Clients on these IPs may restart the node, reconfigure it, etc. " +
"Note that ALL clients are allowed to do direct
disk I/O!", new FCPAllowedHostsFullAccessCallback(core));
PersistentDownloadsEnabledCallback cb1;
PersistentDownloadsFileCallback cb2;
PersistentDownloadsIntervalCallback cb3;
- fcpConfig.register("persistentDownloadsEnabled", true, 3, true,
true, "Enable persistent downloads?", "Whether to enable Persistence=forever
for FCP requests. Meaning whether to support requests which persist over node
restarts; they must be written to disk and this may constitute a security risk
for some people.",
+ fcpConfig.register("persistentDownloadsEnabled", true,
sortOrder++, true, true, "Enable persistent downloads?", "Whether to enable
Persistence=forever for FCP requests. Meaning whether to support requests which
persist over node restarts; they must be written to disk and this may
constitute a security risk for some people.",
cb1 = new PersistentDownloadsEnabledCallback());
boolean persistentDownloadsEnabled =
fcpConfig.getBoolean("persistentDownloadsEnabled");
- fcpConfig.register("persistentDownloadsFile", "downloads.dat",
4, true, false, "Filename to store persistent downloads in", "Filename to store
details of persistent downloads to",
+ fcpConfig.register("persistentDownloadsFile", "downloads.dat",
sortOrder++, true, false, "Filename to store persistent downloads in",
"Filename to store details of persistent downloads to",
cb2 = new PersistentDownloadsFileCallback());
String persistentDownloadsDir =
fcpConfig.getString("persistentDownloadsFile");
- fcpConfig.register("persistentDownloadsInterval", (5*60*1000),
5, true, false, "Interval between writing persistent downloads to disk",
"Interval between writing persistent downloads to disk",
+ fcpConfig.register("persistentDownloadsInterval", (5*60*1000),
sortOrder++, true, false, "Interval between writing persistent downloads to
disk", "Interval between writing persistent downloads to disk",
cb3 = new
PersistentDownloadsIntervalCallback());
long persistentDownloadsInterval =
fcpConfig.getLong("persistentDownloadsInterval");
+ AssumeDDADownloadIsAllowedCallback cb4;
+ AssumeDDAUploadIsAllowedCallback cb5;
+ fcpConfig.register("assumeDownloadDDAIsAllowed", true,
sortOrder++, true, false, "Assume that download DDA is allowed ?", "Assume that
download DDA is allowed ? if false, you have to issue a TestDDARequest before
making any DDA access.", cb4 = new AssumeDDADownloadIsAllowedCallback());
+ fcpConfig.register("assumeUploadDDAIsAllowed", true,
sortOrder++, true, false, "Assume that upload DDA is allowed ?", "Assume that
upload DDA is allowed ? if false, you have to issue a TestDDARequest before
making any DDA access.", cb5 = new AssumeDDAUploadIsAllowedCallback());
+
FCPServer fcp;
- fcp = new FCPServer(fcpConfig.getString("bindTo"),
fcpConfig.getString("allowedHosts"),
fcpConfig.getString("allowedHostsFullAccess"), fcpConfig.getInt("port"), node,
core, persistentDownloadsEnabled, persistentDownloadsDir,
persistentDownloadsInterval, fcpConfig.getBoolean("enabled"));
+ fcp = new FCPServer(fcpConfig.getString("bindTo"),
fcpConfig.getString("allowedHosts"),
fcpConfig.getString("allowedHostsFullAccess"), fcpConfig.getInt("port"), node,
core, persistentDownloadsEnabled, persistentDownloadsDir,
persistentDownloadsInterval, fcpConfig.getBoolean("enabled"),
fcpConfig.getBoolean("assumeDownloadDDAIsAllowed"),
fcpConfig.getBoolean("assumeUploadDDAIsAllowed"));
core.setFCPServer(fcp);
if(fcp != null) {
cb1.server = fcp;
cb2.server = fcp;
cb3.server = fcp;
+ cb4.server = fcp;
+ cb5.server = fcp;
}
if(fcp != null)
@@ -776,5 +815,13 @@
public FCPClient getGlobalClient() {
return globalClient;
}
+
+ protected boolean isDownloadDDAAlwaysAllowed() {
+ return assumeDownloadDDAIsAllowed;
+ }
+
+ protected boolean isUploadDDAAlwaysAllowed() {
+ return assumeUploadDDAIsAllowed;
+ }
}