[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] r11743: added more methods for manipulating template configurations (in puppetor/trunk/src/de/uniba/wiai/lspi/puppetor: . impl)
Author: kloesing
Date: 2007-10-02 05:33:06 -0400 (Tue, 02 Oct 2007)
New Revision: 11743
Modified:
puppetor/trunk/src/de/uniba/wiai/lspi/puppetor/Network.java
puppetor/trunk/src/de/uniba/wiai/lspi/puppetor/ProxyNode.java
puppetor/trunk/src/de/uniba/wiai/lspi/puppetor/impl/DirectoryNodeImpl.java
puppetor/trunk/src/de/uniba/wiai/lspi/puppetor/impl/NetworkImpl.java
puppetor/trunk/src/de/uniba/wiai/lspi/puppetor/impl/ProxyNodeImpl.java
puppetor/trunk/src/de/uniba/wiai/lspi/puppetor/impl/RouterNodeImpl.java
Log:
added more methods for manipulating template configurations of nodes
Modified: puppetor/trunk/src/de/uniba/wiai/lspi/puppetor/Network.java
===================================================================
--- puppetor/trunk/src/de/uniba/wiai/lspi/puppetor/Network.java 2007-10-02 06:28:15 UTC (rev 11742)
+++ puppetor/trunk/src/de/uniba/wiai/lspi/puppetor/Network.java 2007-10-02 09:33:06 UTC (rev 11743)
@@ -34,6 +34,7 @@
import java.io.File;
import java.rmi.Remote;
import java.rmi.RemoteException;
+import java.util.List;
import java.util.Map;
/**
@@ -720,14 +721,38 @@
public abstract File getWorkingDirectory() throws RemoteException;
/**
+ * Returns all configuration strings of the template of a node class that
+ * will be added to future instances of this node class and its subclasses.
+ * Note that the result only contains those configuration strings that are
+ * added by this node class to possible superclasses and that parameterized
+ * configuration strings, e.g. port configurations, are not included.
+ *
+ * @param nodeClass
+ * The class which will be configured with the returned template
+ * configuration; may not be <code>null</code>.
+ * @return The template configuration for the given node class.
+ * @throws IllegalArgumentException
+ * Thrown if an invalid value is given for the parameter.
+ * @throws RemoteException
+ * Thrown if an error occurs when accessed remotely.
+ */
+ public abstract List<String> getTemplateConfiguration(
+ Class<? extends ProxyNode> nodeClass) throws RemoteException;
+
+ /**
* Adds a configuration string to the template of a node class, so that it
* will be added to future instances of this node class and its subclasses.
*
* @param nodeClass
* The class of nodes of which future instances will have the
- * given configuration string.
+ * given configuration string; may not be <code>null</code>.
* @param templateConfigurationString
- * The configuration string.
+ * The configuration string to add; may neither be
+ * <code>null</code> nor a zero-length string, and must consist
+ * of configuration key and value.
+ * @throws IllegalArgumentException
+ * Thrown if an invalid value is given for either of the
+ * parameters.
* @throws RemoteException
* Thrown if an error occurs when accessed remotely.
*/
@@ -736,6 +761,27 @@
String templateConfigurationString) throws RemoteException;
/**
+ * Removes a configuration string from the template of a node class, so that
+ * it will not be added to future instances of this node class and its
+ * subclasses.
+ *
+ * @param nodeClass
+ * The class of nodes of which future instances will have the
+ * given configuration string; may not be <code>null</code>.
+ * @param templateConfigurationKey
+ * The configuration key to remove; may neither be
+ * <code>null</code> nor a zero-length key.
+ * @throws IllegalArgumentException
+ * Thrown if an invalid value is given for either of the
+ * parameters.
+ * @throws RemoteException
+ * Thrown if an error occurs when accessed remotely.
+ */
+ public abstract void removeTemplateConfiguration(
+ Class<? extends ProxyNode> nodeClass,
+ String templateConfigurationKey) throws RemoteException;
+
+ /**
* Returns the name of this network.
*
* @return The name of this network.
Modified: puppetor/trunk/src/de/uniba/wiai/lspi/puppetor/ProxyNode.java
===================================================================
--- puppetor/trunk/src/de/uniba/wiai/lspi/puppetor/ProxyNode.java 2007-10-02 06:28:15 UTC (rev 11742)
+++ puppetor/trunk/src/de/uniba/wiai/lspi/puppetor/ProxyNode.java 2007-10-02 09:33:06 UTC (rev 11743)
@@ -150,7 +150,7 @@
* @param configurationString
* The configuration string to be added.
* @throws IllegalArgumentException
- * Thrown if the given configurationString is either
+ * Thrown if the given configuration string is either
* <code>null</code>, a zero-length string, or does not
* consist of configuration key and value.
* @throws RemoteException
@@ -209,7 +209,7 @@
* @throws RemoteException
* Thrown if an error occurs when accessed remotely.
*/
- public abstract void deleteConfiguration(String configurationKey)
+ public abstract void removeConfiguration(String configurationKey)
throws RemoteException;
/**
Modified: puppetor/trunk/src/de/uniba/wiai/lspi/puppetor/impl/DirectoryNodeImpl.java
===================================================================
--- puppetor/trunk/src/de/uniba/wiai/lspi/puppetor/impl/DirectoryNodeImpl.java 2007-10-02 06:28:15 UTC (rev 11742)
+++ puppetor/trunk/src/de/uniba/wiai/lspi/puppetor/impl/DirectoryNodeImpl.java 2007-10-02 09:33:06 UTC (rev 11743)
@@ -36,6 +36,8 @@
import java.io.FileWriter;
import java.io.IOException;
import java.rmi.RemoteException;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
@@ -111,29 +113,9 @@
// initialize attribute
this.approvedRouters = new TreeSet<String>();
- // configure this node as an authoritative directory
- this.configuration.add("AuthoritativeDirectory 1");
+ // extend configuration by template configuration of directory nodes
+ this.configuration.addAll(templateConfiguration);
- // TODO make this a little bit more configurable
- this.configuration
- .add("RecommendedVersions 0.2.0.7-alpha,0.2.0.7-alpha-dev");
-
- this.configuration.add("VersioningAuthoritativeDirectory 1");
-
- this.configuration.add("NamingAuthoritativeDirectory 1");
-
- // TODO this requires version 0.2.x, but when using version 0.2.x this
- // is vital for running a private network!!
- this.configuration.add("V2AuthoritativeDirectory 1");
-
- this.configuration.add("V1AuthoritativeDirectory 1");
-
- // TODO this only works since Tor 0.1.2.x!!!
- this.configuration.add("HSAuthoritativeDir 1");
-
- // TODO only in v0.2.x
- // this.configuration.add("HSAuthorityRecordStats 1");
-
// log exiting
this.logger.exiting(this.getClass().getName(), "DirectoryNodeImpl");
}
@@ -234,4 +216,36 @@
// log exiting
this.logger.exiting(this.getClass().getName(), "writeConfiguration");
}
+
+ /**
+ * Template configuration of directory nodes.
+ */
+ static List<String> templateConfiguration;
+
+ static {
+ templateConfiguration = new ArrayList<String>();
+
+ // configure this node as an authoritative directory
+ templateConfiguration.add("AuthoritativeDirectory 1");
+
+ // TODO make this a little bit more configurable
+ templateConfiguration
+ .add("RecommendedVersions 0.2.0.7-alpha,0.2.0.7-alpha-dev");
+
+ templateConfiguration.add("VersioningAuthoritativeDirectory 1");
+
+ templateConfiguration.add("NamingAuthoritativeDirectory 1");
+
+ // TODO this requires version 0.2.x, but when using version 0.2.x this
+ // is vital for running a private network!!
+ templateConfiguration.add("V2AuthoritativeDirectory 1");
+
+ templateConfiguration.add("V1AuthoritativeDirectory 1");
+
+ // TODO this only works since Tor 0.1.2.x!!!
+ templateConfiguration.add("HSAuthoritativeDir 1");
+
+ // TODO only in v0.2.x
+ // templateConfiguration.add("HSAuthorityRecordStats 1");
+ }
}
Modified: puppetor/trunk/src/de/uniba/wiai/lspi/puppetor/impl/NetworkImpl.java
===================================================================
--- puppetor/trunk/src/de/uniba/wiai/lspi/puppetor/impl/NetworkImpl.java 2007-10-02 06:28:15 UTC (rev 11742)
+++ puppetor/trunk/src/de/uniba/wiai/lspi/puppetor/impl/NetworkImpl.java 2007-10-02 09:33:06 UTC (rev 11743)
@@ -181,12 +181,6 @@
private int portCounter = 7000;
/**
- * Map of configuration strings that should be used as template for newly
- * created nodes.
- */
- private Map<Class<? extends ProxyNode>, List<String>> templateConfigurations;
-
- /**
* Creates an initially unpopulated Tor network and creates a new working
* directory for it at test-env/randomTestID/.
*
@@ -269,7 +263,6 @@
// initialize data structures
this.nodes = new HashMap<String, ProxyNode>();
- this.templateConfigurations = new HashMap<Class<? extends ProxyNode>, List<String>>();
// create event manager
this.eventManager = new EventManagerImpl(this.networkName);
@@ -390,10 +383,6 @@
DirectoryNode dir = new DirectoryNodeImpl(this, nodeName, controlPort,
socksPort, orPort, dirPort, serverIpAddress);
- // add configuration strings that have been set as template for new
- // directory nodes
- this.addTemplateConfigurations(dir);
-
// add new directory node to nodes collection
this.nodes.put(nodeName, dir);
@@ -467,10 +456,6 @@
ProxyNode proxy = new ProxyNodeImpl(this, nodeName, controlPort,
socksPort);
- // add configuration strings that have been set as template for new
- // proxy nodes
- this.addTemplateConfigurations(proxy);
-
// add new proxy node to nodes collection
this.nodes.put(nodeName, proxy);
@@ -510,10 +495,6 @@
RouterNode router = new RouterNodeImpl(this, nodeName, controlPort,
socksPort, orPort, dirPort, serverIpAddress);
- // add configuration strings that have been set as template for new
- // router nodes
- this.addTemplateConfigurations(router);
-
// add new router node to nodes collection
this.nodes.put(nodeName, router);
@@ -988,34 +969,121 @@
logger.entering(this.getClass().getName(), "addTemplateConfiguration",
new Object[] { nodeClass, templateConfigurationString });
- // add template string to local map
- if (!this.templateConfigurations.containsKey(nodeClass)) {
- this.templateConfigurations.put(nodeClass, new ArrayList<String>());
+ // check parameters
+ if (nodeClass == null || templateConfigurationString == null
+ || templateConfigurationString.length() < 1
+ || !templateConfigurationString.contains(" ")) {
+ IllegalArgumentException e = new IllegalArgumentException();
+ this.logger.throwing(this.getClass().getName(),
+ "addTemplateConfiguration", e);
+ throw e;
}
- this.templateConfigurations.get(nodeClass).add(
- templateConfigurationString);
+ // add template string to appropriate template configuration
+ if (nodeClass == ProxyNode.class) {
+ ProxyNodeImpl.templateConfiguration
+ .add(templateConfigurationString);
+ } else if (nodeClass == RouterNode.class) {
+ RouterNodeImpl.templateConfiguration
+ .add(templateConfigurationString);
+ } else if (nodeClass == DirectoryNode.class) {
+ DirectoryNodeImpl.templateConfiguration
+ .add(templateConfigurationString);
+ } else {
+ IllegalArgumentException e = new IllegalArgumentException();
+ this.logger.throwing(this.getClass().getName(),
+ "addTemplateConfiguration", e);
+ throw e;
+ }
+
// log exiting
logger.exiting(this.getClass().getName(), "addTemplateConfiguration");
}
- /**
- * Adds all matching template configuration strings to the given node.
- *
- * @param newNode
- * The new node to which the template configuration strings shall
- * be added.
- * @throws RemoteException
- * Thrown if an error occurs when accessed remotely.
- */
- private void addTemplateConfigurations(ProxyNode newNode)
- throws RemoteException {
- for (Class<? extends ProxyNode> nc : this.templateConfigurations
- .keySet()) {
- if (nc.isInstance(newNode)) {
- newNode.addConfigurations(this.templateConfigurations.get(nc));
+ public List<String> getTemplateConfiguration(
+ Class<? extends ProxyNode> nodeClass) {
+
+ // log entering
+ logger.entering(this.getClass().getName(), "getTemplateConfiguration",
+ nodeClass);
+
+ // check parameter
+ if (nodeClass == null) {
+ IllegalArgumentException e = new IllegalArgumentException();
+ this.logger.throwing(this.getClass().getName(),
+ "getTemplateConfiguration", e);
+ throw e;
+ }
+
+ // obtain reference on appropriate template configuration
+ List<String> result = null;
+ if (nodeClass == ProxyNode.class) {
+ result = new ArrayList<String>(ProxyNodeImpl.templateConfiguration);
+ } else if (nodeClass == RouterNode.class) {
+ result = new ArrayList<String>(RouterNodeImpl.templateConfiguration);
+ } else if (nodeClass == DirectoryNode.class) {
+ result = new ArrayList<String>(
+ DirectoryNodeImpl.templateConfiguration);
+ } else {
+ IllegalArgumentException e = new IllegalArgumentException();
+ this.logger.throwing(this.getClass().getName(),
+ "getTemplateConfiguration", e);
+ throw e;
+ }
+
+ // log exiting and return result
+ logger.exiting(this.getClass().getName(), "getTemplateConfiguration",
+ result);
+ return result;
+ }
+
+ public void removeTemplateConfiguration(
+ Class<? extends ProxyNode> nodeClass,
+ String templateConfigurationKey) {
+
+ // log entering
+ logger.entering(this.getClass().getName(),
+ "removeTemplateConfiguration", new Object[] { nodeClass,
+ templateConfigurationKey });
+
+ // check parameters
+ if (nodeClass == null || templateConfigurationKey == null
+ || templateConfigurationKey.length() < 1) {
+ IllegalArgumentException e = new IllegalArgumentException();
+ this.logger.throwing(this.getClass().getName(),
+ "removeTemplateConfiguration", e);
+ throw e;
+ }
+
+ // obtain reference on appropriate template configuration
+ List<String> templateConfig = null;
+ if (nodeClass == ProxyNode.class) {
+ templateConfig = ProxyNodeImpl.templateConfiguration;
+ } else if (nodeClass == RouterNode.class) {
+ templateConfig = RouterNodeImpl.templateConfiguration;
+ } else if (nodeClass == DirectoryNode.class) {
+ templateConfig = DirectoryNodeImpl.templateConfiguration;
+ } else {
+ IllegalArgumentException e = new IllegalArgumentException();
+ this.logger.throwing(this.getClass().getName(),
+ "removeTemplateConfiguration", e);
+ throw e;
+ }
+
+ // iterate over existing template configuration strings and remove all
+ // configuration strings that have the given configuration key
+ for (String currentConfigurationString : templateConfig) {
+ String currentConfigurationKey = currentConfigurationString
+ .substring(0, currentConfigurationString.indexOf(" "));
+ if (currentConfigurationKey.equals(templateConfigurationKey)) {
+ templateConfig.remove(currentConfigurationString);
}
}
+
+ // log exiting
+ logger
+ .exiting(this.getClass().getName(),
+ "removeTemplateConfiguration");
}
public boolean bindAtRmiregistry() throws RemoteException {
Modified: puppetor/trunk/src/de/uniba/wiai/lspi/puppetor/impl/ProxyNodeImpl.java
===================================================================
--- puppetor/trunk/src/de/uniba/wiai/lspi/puppetor/impl/ProxyNodeImpl.java 2007-10-02 06:28:15 UTC (rev 11742)
+++ puppetor/trunk/src/de/uniba/wiai/lspi/puppetor/impl/ProxyNodeImpl.java 2007-10-02 09:33:06 UTC (rev 11743)
@@ -213,34 +213,11 @@
this.configFile = new File(this.workingDir.getAbsolutePath()
+ File.separator + "torrc");
- // initialize configuration with general-purpose configuration entries
- this.configuration = new ArrayList<String>();
- this.configuration.add("DataDirectory .");
- this.configuration.add("SafeLogging 0");
- this.configuration.add("UseEntryGuards 0");
+ // initialize configuration
+ this.configuration = new ArrayList<String>(templateConfiguration);
this.configuration.add("ControlPort " + controlPort);
this.configuration.add("SocksPort " + socksPort);
- this.configuration.add("Log info stdout");
- this.configuration.add("Log info file log");
-
- // TODO do we need this in all nodes or only in directory nodes?!
- this.configuration.add("DirAllowPrivateAddresses 1");
-
- // allow two nodes on the same circuit to be in the same /16 net
- // TODO this depends in private or public network setting!!!
- this.configuration.add("EnforceDistinctSubnets 0");
-
- this.configuration.add("ClientDNSRejectInternalAddresses 0");
-
- // don't rely on node verification, yet... TODO change?
- this.configuration
- .add("AllowInvalidNodes middle,rendezvous,exit,entry,introduction");
-
- // tunnel dir connections
- // this.configuration.add("TunnelDirConns 1");
- // this.configuration.add("PreferTunneledDirConns 1");
-
// initialize state
this.nodeState = NodeState.CONFIGURING;
@@ -336,7 +313,7 @@
this.logger.exiting(this.getClass().getName(), "replaceConfiguration");
}
- public void deleteConfiguration(String configurationKey)
+ public void removeConfiguration(String configurationKey)
throws RemoteException {
// log entering
@@ -768,4 +745,38 @@
public List<String> getConfiguration() {
return new ArrayList<String>(this.configuration);
}
+
+ /**
+ * Template configuration of proxy nodes.
+ */
+ static List<String> templateConfiguration;
+
+ static {
+ templateConfiguration = new ArrayList<String>();
+
+ templateConfiguration.add("DataDirectory .");
+ templateConfiguration.add("SafeLogging 0");
+ templateConfiguration.add("UseEntryGuards 0");
+
+ templateConfiguration.add("Log info stdout");
+ templateConfiguration.add("Log info file log");
+
+ // TODO do we need this in all nodes or only in directory nodes?!
+ templateConfiguration.add("DirAllowPrivateAddresses 1");
+
+ // allow two nodes on the same circuit to be in the same /16 net
+ // TODO this depends in private or public network setting!!!
+ templateConfiguration.add("EnforceDistinctSubnets 0");
+
+ templateConfiguration.add("ClientDNSRejectInternalAddresses 0");
+
+ // don't rely on node verification, yet... TODO change?
+ templateConfiguration
+ .add("AllowInvalidNodes middle,rendezvous,exit,entry,introduction");
+
+ // tunnel dir connections
+ // templateConfiguration.add("TunnelDirConns 1");
+ // templateConfiguration.add("PreferTunneledDirConns 1");
+
+ }
}
Modified: puppetor/trunk/src/de/uniba/wiai/lspi/puppetor/impl/RouterNodeImpl.java
===================================================================
--- puppetor/trunk/src/de/uniba/wiai/lspi/puppetor/impl/RouterNodeImpl.java 2007-10-02 06:28:15 UTC (rev 11742)
+++ puppetor/trunk/src/de/uniba/wiai/lspi/puppetor/impl/RouterNodeImpl.java 2007-10-02 09:33:06 UTC (rev 11743)
@@ -315,10 +315,15 @@
this.dirPort = dirPort;
this.serverIpAddress = serverIpAddress;
+ // extend configuration by template configuration of router nodes
+ this.configuration.addAll(templateConfiguration);
+
+ this.configuration.add("ControlPort " + controlPort);
+ this.configuration.add("SocksPort " + socksPort);
+
// add further configuration to make this node a router node
this.configuration.add("ORPort " + orPort);
this.configuration.add("Nickname " + nodeName);
- this.configuration.add("ContactInfo wont@xxxxxxxxx");
// all routers mirror the directory
this.configuration.add("DirPort " + dirPort);
@@ -334,14 +339,6 @@
// mirroring it)
this.configuration.add("DirListenAddress " + serverIpAddress);
- // allow exit to private network and everything else (node will only
- // be used by other nodes in the private network, so no worry)
- this.configuration.add("ExitPolicyRejectPrivate 0");
- this.configuration.add("ExitPolicy accept *:*");
-
- // bypass testing if we are reachable
- this.configuration.add("AssumeReachable 1");
-
// start a thread to determine the node's fingerprint in the background
this.determineFingerprint();
@@ -408,4 +405,23 @@
// log exiting
this.logger.exiting(this.getClass().getName(), "determineFingerprint");
}
+
+ /**
+ * Template configuration of router nodes.
+ */
+ static List<String> templateConfiguration;
+
+ static {
+ templateConfiguration = new ArrayList<String>();
+
+ templateConfiguration.add("ContactInfo wont@xxxxxxxxx");
+
+ // allow exit to private network and everything else (node will only
+ // be used by other nodes in the private network, so no worry)
+ templateConfiguration.add("ExitPolicyRejectPrivate 0");
+ templateConfiguration.add("ExitPolicy accept *:*");
+
+ // bypass testing if we are reachable
+ templateConfiguration.add("AssumeReachable 1");
+ }
}