summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/thrift/ThriftManager.java
diff options
context:
space:
mode:
Diffstat (limited to 'dozentenmodul/src/main/java/thrift/ThriftManager.java')
-rw-r--r--dozentenmodul/src/main/java/thrift/ThriftManager.java28
1 files changed, 28 insertions, 0 deletions
diff --git a/dozentenmodul/src/main/java/thrift/ThriftManager.java b/dozentenmodul/src/main/java/thrift/ThriftManager.java
index 716c4439..cc085ecd 100644
--- a/dozentenmodul/src/main/java/thrift/ThriftManager.java
+++ b/dozentenmodul/src/main/java/thrift/ThriftManager.java
@@ -1,5 +1,8 @@
package thrift;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
import org.apache.log4j.Logger;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.protocol.TProtocol;
@@ -44,6 +47,15 @@ public class ThriftManager {
private static final int SATELLITE_TIMEOUT = 10000;
/**
+ * IP Validation Regex
+ */
+ private static final String IP_VALID_PATTERN =
+ "^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." +
+ "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." +
+ "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." +
+ "([01]?\\d\\d?|2[0-4]\\d|25[0-5])$";
+
+ /**
* Protected constructor to avoid external instantiation
*/
protected ThriftManager() {
@@ -106,6 +118,7 @@ public class ThriftManager {
final TProtocol protocol = new TBinaryProtocol(transport);
// now we are ready to create the client, according to ClientType!
_satClient.set(new Server.Client(protocol));
+ LOGGER.info("Satellite '" + SATELLITE_IP + "' reachable. Client initialised.");
}
return true;
}
@@ -119,7 +132,22 @@ public class ThriftManager {
LOGGER.error("Given IP for satellite is empty.");
return false;
}
+ // validate
+ Matcher matcher = Pattern.compile(IP_VALID_PATTERN).matcher(ip);
+ if (!matcher.matches()) {
+ LOGGER.error("Given form of IP is invalid: " + ip);
+ return false;
+ }
+ // finally set it
SATELLITE_IP = ip;
+
+ // last check: try to connect
+ if (!init(ClientType.SATELLITE, SATELLITE_IP, SATELLITE_PORT, SATELLITE_TIMEOUT)) {
+ // init failed
+ LOGGER.error("Could not initialise new client to satellite: " + SATELLITE_IP);
+ return false;
+ }
+ // TODO final last: get version from server
return true;
}
/**