[or-cvs] r11651: introduced template configurations for nodes, fixed a deadlo (in puppetor/trunk/src/de/uniba/wiai/lspi/puppetor: . examples impl)

kloesing at seul.org kloesing at seul.org
Wed Sep 26 12:14:42 UTC 2007


Author: kloesing
Date: 2007-09-26 08:14:42 -0400 (Wed, 26 Sep 2007)
New Revision: 11651

Modified:
   puppetor/trunk/src/de/uniba/wiai/lspi/puppetor/Network.java
   puppetor/trunk/src/de/uniba/wiai/lspi/puppetor/examples/AccessingPublicWebServerOverTor.java
   puppetor/trunk/src/de/uniba/wiai/lspi/puppetor/impl/EventManagerImpl.java
   puppetor/trunk/src/de/uniba/wiai/lspi/puppetor/impl/NetworkImpl.java
   puppetor/trunk/src/de/uniba/wiai/lspi/puppetor/impl/ProxyNodeImpl.java
Log:
introduced template configurations for nodes, fixed a deadlock

Modified: puppetor/trunk/src/de/uniba/wiai/lspi/puppetor/Network.java
===================================================================
--- puppetor/trunk/src/de/uniba/wiai/lspi/puppetor/Network.java	2007-09-26 09:46:45 UTC (rev 11650)
+++ puppetor/trunk/src/de/uniba/wiai/lspi/puppetor/Network.java	2007-09-26 12:14:42 UTC (rev 11651)
@@ -793,4 +793,20 @@
 	 */
 	public abstract void mergeNetworks(Network remoteNetwork)
 			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.
+	 * 
+	 * @param nodeClass
+	 *            The class of nodes of which future instances will have the
+	 *            given configuration string.
+	 * @param templateConfigurationString
+	 *            The configuration string.
+	 * @throws RemoteException
+	 *             Thrown if an error occurs when accessed remotely.
+	 */
+	public abstract void addTemplateConfiguration(
+			Class<? extends ProxyNode> nodeClass,
+			String templateConfigurationString) throws RemoteException;
 }

Modified: puppetor/trunk/src/de/uniba/wiai/lspi/puppetor/examples/AccessingPublicWebServerOverTor.java
===================================================================
--- puppetor/trunk/src/de/uniba/wiai/lspi/puppetor/examples/AccessingPublicWebServerOverTor.java	2007-09-26 09:46:45 UTC (rev 11650)
+++ puppetor/trunk/src/de/uniba/wiai/lspi/puppetor/examples/AccessingPublicWebServerOverTor.java	2007-09-26 12:14:42 UTC (rev 11651)
@@ -40,6 +40,7 @@
 import de.uniba.wiai.lspi.puppetor.EventType;
 import de.uniba.wiai.lspi.puppetor.Network;
 import de.uniba.wiai.lspi.puppetor.NetworkFactory;
+import de.uniba.wiai.lspi.puppetor.ProxyNode;
 import de.uniba.wiai.lspi.puppetor.TorProcessException;
 
 /**
@@ -68,10 +69,13 @@
 		// network to initialize a test case.
 		Network network = NetworkFactory.createNetwork("example1");
 
-		// create a single proxy node with name "proxy", control port 7001,
-		// and SOCKS port 7002
-		network.createProxy("proxy", 7001, 7002);
+		// configure firewall restrictions for all newly created nodes
+		network.addTemplateConfiguration(ProxyNode.class,
+				"ReachableAddresses accept *:80, accept *:443, reject *:*");
 
+		// create a single proxy node with name "proxy"
+		ProxyNode proxy = network.createProxy("proxy");
+
 		// write configuration of proxy node
 		network.writeConfigurations();
 
@@ -93,7 +97,7 @@
 
 		// create client application
 		ClientApplication client = network.createClient("client",
-				"www.google.com", 80, 7002);
+				"www.google.com", 80, proxy.getSocksPort());
 
 		// create event listener to listen for client application events
 		EventListener clientEventListener = new EventListener() {

Modified: puppetor/trunk/src/de/uniba/wiai/lspi/puppetor/impl/EventManagerImpl.java
===================================================================
--- puppetor/trunk/src/de/uniba/wiai/lspi/puppetor/impl/EventManagerImpl.java	2007-09-26 09:46:45 UTC (rev 11650)
+++ puppetor/trunk/src/de/uniba/wiai/lspi/puppetor/impl/EventManagerImpl.java	2007-09-26 12:14:42 UTC (rev 11651)
@@ -465,14 +465,12 @@
 	 * @param event
 	 *            The event type.
 	 */
-	synchronized void observeEvent(Event event) {
+	private synchronized void observeEvent(Event event) {
 
-		String source = event.getSource();
-
 		// log entering
-		this.logger.entering(this.getClass().getName(), "observeEvent",
-				new Object[] { source, event });
+		this.logger.entering(this.getClass().getName(), "observeEvent", event);
 
+		String source = event.getSource();
 		this.logger.log(Level.FINE, "Observed event " + event + " from source "
 				+ source + "!");
 

Modified: puppetor/trunk/src/de/uniba/wiai/lspi/puppetor/impl/NetworkImpl.java
===================================================================
--- puppetor/trunk/src/de/uniba/wiai/lspi/puppetor/impl/NetworkImpl.java	2007-09-26 09:46:45 UTC (rev 11650)
+++ puppetor/trunk/src/de/uniba/wiai/lspi/puppetor/impl/NetworkImpl.java	2007-09-26 12:14:42 UTC (rev 11651)
@@ -259,7 +259,7 @@
 	 * work only with interface types to assure that all operations could also
 	 * be performed by the application itself.
 	 */
-	private Map<String, ProxyNode> nodes = new HashMap<String, ProxyNode>();
+	private Map<String, ProxyNode> nodes;
 
 	/**
 	 * Determines if the given <code>name</code> is unique in this network.
@@ -288,6 +288,12 @@
 	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/.
 	 * 
@@ -368,6 +374,10 @@
 		// this.logFile = new File(this.workingDir.getAbsolutePath()
 		// + "\\events.log");
 
+		// 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);
 
@@ -557,6 +567,10 @@
 		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);
 		
@@ -639,6 +653,10 @@
 		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);
 
@@ -686,6 +704,10 @@
 		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);
 
@@ -1371,4 +1393,32 @@
 		// log exiting
 		logger.exiting(this.getClass().getName(), "hupRouters");
 	}
+
+	public void addTemplateConfiguration(Class<? extends ProxyNode> nodeClass,
+			String templateConfigurationString) {
+		if (!this.templateConfigurations.containsKey(nodeClass)) {
+			this.templateConfigurations.put(nodeClass, new ArrayList<String>());
+		}
+		this.templateConfigurations.get(nodeClass).add(
+				templateConfigurationString);
+	}
+
+	/**
+	 * 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));
+			}
+		}
+	}
 }

Modified: puppetor/trunk/src/de/uniba/wiai/lspi/puppetor/impl/ProxyNodeImpl.java
===================================================================
--- puppetor/trunk/src/de/uniba/wiai/lspi/puppetor/impl/ProxyNodeImpl.java	2007-09-26 09:46:45 UTC (rev 11650)
+++ puppetor/trunk/src/de/uniba/wiai/lspi/puppetor/impl/ProxyNodeImpl.java	2007-09-26 12:14:42 UTC (rev 11651)
@@ -755,8 +755,7 @@
 				String line = null;
 				try {
 					while ((line = br.readLine()) != null) {
-						eventManager.observeUnparsedEvent(ProxyNodeImpl.this
-								.getNodeName(), line);
+						eventManager.observeUnparsedEvent(nodeName, line);
 					}
 				} catch (IOException e) {
 



More information about the tor-commits mailing list