summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristoph Schulthess2017-03-27 18:16:22 +0200
committerChristoph Schulthess2017-03-27 18:16:22 +0200
commit6d28b78bd3d3820bf5e0944b22bffe2f97c16084 (patch)
treec6ab70c3922fd063e2b1dd3379fb902c874f5a65
parentnew relay task (diff)
downloadtmlite-bwlp-6d28b78bd3d3820bf5e0944b22bffe2f97c16084.tar.gz
tmlite-bwlp-6d28b78bd3d3820bf5e0944b22bffe2f97c16084.tar.xz
tmlite-bwlp-6d28b78bd3d3820bf5e0944b22bffe2f97c16084.zip
renaming and comments (jipi)
-rw-r--r--src/main/java/org/openslx/taskmanager/tasks/RemoteDebug.java (renamed from src/main/java/org/openslx/taskmanager/tasks/DirectedRelay.java)56
1 files changed, 55 insertions, 1 deletions
diff --git a/src/main/java/org/openslx/taskmanager/tasks/DirectedRelay.java b/src/main/java/org/openslx/taskmanager/tasks/RemoteDebug.java
index 7bf470d..4a684e8 100644
--- a/src/main/java/org/openslx/taskmanager/tasks/DirectedRelay.java
+++ b/src/main/java/org/openslx/taskmanager/tasks/RemoteDebug.java
@@ -19,7 +19,11 @@ import org.openslx.taskmanager.api.AbstractTask;
import com.google.gson.annotations.Expose;
-public class DirectedRelay extends AbstractTask
+/**
+ * @author Christoph Schulthess
+ *
+ */
+public class RemoteDebug extends AbstractTask
{
protected Output status = new Output();
@@ -29,6 +33,9 @@ public class DirectedRelay extends AbstractTask
@Expose
public int port;
+ /**
+ * Run debug task
+ */
@Override
protected boolean execute()
{
@@ -53,6 +60,11 @@ public class DirectedRelay extends AbstractTask
return true;
}
+ /**
+ * @param SSLSocket dbgSock
+ * @throws IOException
+ * Connect SSLSocket dbgSock to debug server at ip:port specified by the JSON object
+ */
protected void connectToDbg ( SSLSocket dbgSock ) throws IOException {
InetSocketAddress addr = new InetSocketAddress( ip, port );
dbgSock.connect( addr );
@@ -60,12 +72,21 @@ public class DirectedRelay extends AbstractTask
status.setDbgAddr( addr );
}
+ /**
+ * @param SSLServerSocket srvSock
+ * @throws IOException
+ * Bind SSLServerSocket srvSock to local port and update status object accordingly.
+ */
protected void bindToPort ( SSLServerSocket srvSock ) throws IOException {
srvSock.bind( null );
status.setListenPort( srvSock.getLocalPort() );
status.addMessage( "INFO: Listening on localhost:" + status.getListenPort() + "." );
}
+ /**
+ * @return SSLContext
+ * Get all-trusting SSLContext via the trustAll() method
+ */
protected SSLContext getSSLContext() {
SSLContext ctx = null;
try {
@@ -77,6 +98,11 @@ public class DirectedRelay extends AbstractTask
return ctx;
}
+ /**
+ * @param dbgSock - SSLSocket connected to debug server
+ * @param poolSock - SSLSocket retrieved via srvSock.accept()
+ * Create and start the two necessary relays. Join them, so that proper postcondition is enforced.
+ */
private void relay( SSLSocket dbgSock, SSLSocket poolSock ) {
Relay toDbg = new Relay( poolSock, dbgSock, status );
Relay toPool = new Relay( dbgSock, poolSock, status );
@@ -93,6 +119,11 @@ public class DirectedRelay extends AbstractTask
}
}
+ /**
+ * @return SSLContext
+ * @throws Exception
+ * Create all-trusting X509 certificate manager to disable verification in the bwlp-environment.
+ */
protected SSLContext trustAll () throws Exception
{
TrustManager[] trustAllMgr = new TrustManager[] { new X509TrustManager() {
@@ -108,18 +139,32 @@ public class DirectedRelay extends AbstractTask
return ctx;
}
+ /**
+ * @param ctx - SSLContext
+ * @return SSLServerSocket
+ * @throws IOException
+ */
private SSLServerSocket getSrvSock( SSLContext ctx ) throws IOException
{
SSLServerSocketFactory sssf = ctx.getServerSocketFactory();
return ( SSLServerSocket ) sssf.createServerSocket();
}
+ /**
+ * @param ctx - SSLContext
+ * @return SSLSocket
+ * @throws IOException
+ */
private SSLSocket getDbgSock( SSLContext ctx ) throws IOException
{
SSLSocketFactory ssf = ctx.getSocketFactory();
return ( SSLSocket ) ssf.createSocket();
}
+
+ /**
+ * Set status class for this object and push a first message to it.
+ */
@Override
protected boolean initTask()
{
@@ -128,6 +173,11 @@ public class DirectedRelay extends AbstractTask
return true;
}
+
+ /**
+ * Status class that holds information about the current debug task.
+ * Most important is probably the listen port which is sent to the client to connect its VNC server in reverse mode.
+ */
public static class Output
{
@@ -151,6 +201,10 @@ public class DirectedRelay extends AbstractTask
}
}
+ /**
+ * Generic relay class to write data from one socket to another.
+ * For a working debug task, you need two of these - one for each direction.
+ */
private class Relay extends Thread
{
boolean active = true;