Browse Source

Merge branch 'master' of https://github.com/mip-it/hostage.git

qam 10 years ago
parent
commit
7d8ba78c68

+ 22 - 0
src/de/tudarmstadt/informatik/hostage/net/MyServerSocketFactory.java

@@ -13,6 +13,10 @@ import de.tudarmstadt.informatik.hostage.system.PrivilegedPort;
 
 public class MyServerSocketFactory extends ServerSocketFactory {
 
+	/**
+	 * This method creates and returns a ServerSocket. A custom SocketImpl is
+	 * injected into the ServerSocket.
+	 */
 	@Override
 	public ServerSocket createServerSocket(int port) throws IOException {
 		FileDescriptor fd = new PrivilegedPort(port).bindAndGetFD();
@@ -30,12 +34,18 @@ public class MyServerSocketFactory extends ServerSocketFactory {
 		return socket;
 	}
 
+	/**
+	 * Extracts the SocketImpl out of a ServerSocket.
+	 */
 	private SocketImpl getImpl(ServerSocket socket) throws Exception {
 		Field implField = socket.getClass().getDeclaredField("impl");
 		implField.setAccessible(true);
 		return (SocketImpl) implField.get(socket);
 	}
 
+	/**
+	 * Injects a FileDescriptor into a SocketImpl.
+	 */
 	private void injectFD(FileDescriptor fd, SocketImpl impl) throws Exception {
 		Class<?> plainServerSocketImplClazz = impl.getClass();
 		Class<?> plainSocketImplClazz = plainServerSocketImplClazz
@@ -46,6 +56,9 @@ public class MyServerSocketFactory extends ServerSocketFactory {
 		fdField.set(impl, fd);
 	}
 
+	/**
+	 * Injects a SocketImpl into a ServerSocket.
+	 */
 	private void injectImpl(SocketImpl impl, ServerSocket socket)
 			throws Exception {
 		Field implField = socket.getClass().getDeclaredField("impl");
@@ -53,18 +66,27 @@ public class MyServerSocketFactory extends ServerSocketFactory {
 		implField.set(socket, impl);
 	}
 
+	/**
+	 * Sets the isBound Field of a ServerSocket to true.
+	 */
 	private void setBound(ServerSocket socket) throws Exception {
 		Field boundField = socket.getClass().getDeclaredField("isBound");
 		boundField.setAccessible(true);
 		boundField.set(socket, true);
 	}
 
+	/**
+	 * Must override.
+	 */
 	@Override
 	public ServerSocket createServerSocket(int port, int backlog)
 			throws IOException {
 		return createServerSocket(port);
 	}
 
+	/**
+	 * Must override.
+	 */
 	@Override
 	public ServerSocket createServerSocket(int port, int backlog,
 			InetAddress iAddress) throws IOException {

+ 13 - 0
src/de/tudarmstadt/informatik/hostage/system/PrivilegedPort.java

@@ -7,14 +7,23 @@ import android.net.LocalSocket;
 
 public class PrivilegedPort implements Runnable {
 
+	/**
+	 * Path for UDS in abstract namespace.
+	 */
 	private final static String NAME = "hostage";
 
+	/**
+	 * Port to bind.
+	 */
 	private int port;
 
 	public PrivilegedPort(int port) {
 		this.port = port;
 	}
 
+	/**
+	 * Run porthack in separate Thread.
+	 */
 	@Override
 	public void run() {
 		Process p;
@@ -27,6 +36,10 @@ public class PrivilegedPort implements Runnable {
 		}
 	}
 
+	/**
+	 * Start porthack, wait for connection through UDS and receive a file
+	 * descriptor for bound port.
+	 */
 	public FileDescriptor bindAndGetFD() {
 		FileDescriptor fd = null;
 		try {