Browse Source

More source code commenting

lp-tu 10 years ago
parent
commit
a595741568
1 changed files with 54 additions and 1 deletions
  1. 54 1
      src/de/tudarmstadt/informatik/hostage/HoneyListener.java

+ 54 - 1
src/de/tudarmstadt/informatik/hostage/HoneyListener.java

@@ -20,11 +20,21 @@ import de.tudarmstadt.informatik.hostage.protocol.Protocol;
 import de.tudarmstadt.informatik.hostage.protocol.SSLProtocol;
 import de.tudarmstadt.informatik.hostage.ui.MainActivity;
 import de.tudarmstadt.informatik.hostage.wrapper.ByteArray;
-
+/**
+ * Protocol listener class:<br>
+ * Creates a Socket on the port of a given protocol and listens for incoming connections.<br>
+ * For each connection creates a Socket and instantiate an {@link AbstractHandler}.
+ * @author Mihai Plasoianu 
+ *
+ */
 public class HoneyListener implements Runnable {
 
 	private ArrayList<AbstractHandler> handlers = new ArrayList<AbstractHandler>();
 
+	/**
+	 * Determines the amount of active handlers.
+	 * @return The number of active handlers.
+	 */
 	public int getHandlerCount() {
 		return handlers.size();
 	}
@@ -42,10 +52,19 @@ public class HoneyListener implements Runnable {
 
 	private boolean running = false;
 
+	/**
+	 * Determines if the service is running.
+	 * @return True if the service is running, else false.
+	 */
 	public boolean isRunning() {
 		return running;
 	}
 
+	/**
+	 * Constructor for the class. Instantiate class variables.
+	 * @param service The Background service that started the listener. 
+	 * @param protocol The Protocol on which the listener is running.
+	 */
 	public HoneyListener(HoneyService service, Protocol protocol) {
 		this.service = service;
 		this.protocol = protocol;
@@ -64,6 +83,9 @@ public class HoneyListener implements Runnable {
 		}
 	}
 
+	/**
+	 * Starts the listener. Creates a server socket runs itself in a new Thread and notifies the background service.
+	 */
 	public void start() {
 		try {
 			server = new MyServerSocketFactory().createServerSocket(protocol
@@ -78,6 +100,9 @@ public class HoneyListener implements Runnable {
 		}
 	}
 
+	/**
+	 * Stops the listener. Closes the server socket, interrupts the Thread its running in and notifies the background service.
+	 */
 	public void stop() {
 		try {
 			server.close();
@@ -91,10 +116,17 @@ public class HoneyListener implements Runnable {
 		}
 	}
 
+	/**
+	 * Determine the name of the protocol the listener is running on.
+	 * @return Name of the protocol
+	 */
 	public String getProtocolName() {
 		return protocol.toString();
 	}
 
+	/**
+	 * Remove all terminated handlers from its internal ArrayList.
+	 */
 	public void refreshHandlers() {
 		for (Iterator<AbstractHandler> iterator = handlers.iterator(); iterator
 				.hasNext();) {
@@ -105,6 +137,9 @@ public class HoneyListener implements Runnable {
 		}
 	}
 
+	/**
+	 * Waits for an incoming connection, accepts it and starts a {@link AbstractHandler}
+	 */
 	private void addHandler() {
 		try {
 			Socket client = server.accept();
@@ -124,6 +159,11 @@ public class HoneyListener implements Runnable {
 		}
 	}
 
+	/**
+	 * Creates a SSLSocket out of the given socket and starts a {@link AbstractHandler}.
+	 * @param client The socket with the accepted connection.
+	 * @throws Exception
+	 */
 	private void startSecureHandler(Socket client) throws Exception {
 		SSLContext sslContext = ((SSLProtocol) protocol).getSSLContext();
 		SSLSocketFactory factory = sslContext.getSocketFactory();
@@ -134,11 +174,24 @@ public class HoneyListener implements Runnable {
 				.newInstance(), sslClient));
 	}
 
+	/**
+	 * Starts a {@link AbstractHandler} with the given socket.
+	 * @param client The socket with the accepted connection.
+	 * @throws Exception
+	 */
 	private void startHandler(Socket client) throws Exception {
 		handlers.add(newInstance(service, this, protocol.getClass()
 				.newInstance(), client));
 	}
 
+	/**
+	 * Creates a new instance of an {@link AbstractHandler}.
+	 * @param service The background service
+	 * @param listener The listener that created the handler
+	 * @param protocol The Protocol the handler will run on
+	 * @param client The Socket the handler uses
+	 * @return A Instance of a {@link AbstractHandler} with the specified parameter.
+	 */
 	private AbstractHandler newInstance(HoneyService service,
 			HoneyListener listener, Protocol protocol, Socket client) {
 		if (protocol.getType().equals(String.class)) {