Fixed to not check for router reachability before connecting

This commit is contained in:
GideonLeGrange 2014-01-20 14:48:53 +02:00
parent fb0c084f99
commit 044e4e76a0
4 changed files with 21 additions and 22 deletions

View File

@ -130,3 +130,4 @@ Licence
=======
This library is released under the Apache 2.0 licence. See the Licence.md file

View File

@ -34,8 +34,8 @@
<version>2.3.2</version>
<configuration>
<showDeprecation>true</showDeprecation>
<source>1.5</source>
<target>1.5</target>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>

View File

@ -9,7 +9,7 @@ import me.legrange.mikrotik.ApiConnection;
abstract class Example {
protected void connect() throws Exception {
con = ApiConnection.connect(Config.HOST);
con = ApiConnection.connectTLS(Config.HOST);
con.login(Config.USERNAME, Config.PASSWORD);
}

View File

@ -146,24 +146,20 @@ public final class ApiConnectionImpl extends ApiConnection {
private void open(String host, int port, boolean secure) throws ApiConnectionException {
try {
InetAddress ia = InetAddress.getByName(host);
if (ia.isReachable(1000)) {
if (secure) {
sock = openSSLSocket(ia, port);
} else {
sock = new Socket(ia, port);
}
in = new DataInputStream(sock.getInputStream());
out = new DataOutputStream(sock.getOutputStream());
connected = true;
reader = new Reader();
reader.setDaemon(true);
reader.start();
processor = new Processor();
processor.setDaemon(true);
processor.start();
if (secure) {
sock = openSSLSocket(ia, port);
} else {
throw new ApiConnectionException(String.format("Host '%s' port %d is uncreachable", host, port));
sock = new Socket(ia, port);
}
in = new DataInputStream(sock.getInputStream());
out = new DataOutputStream(sock.getOutputStream());
connected = true;
reader = new Reader();
reader.setDaemon(true);
reader.start();
processor = new Processor();
processor.setDaemon(true);
processor.start();
} catch (UnknownHostException ex) {
connected = false;
throw new ApiConnectionException(String.format("Unknown host '%s'", host), ex);
@ -182,7 +178,9 @@ public final class ApiConnectionImpl extends ApiConnection {
// not happy with this code. Without it, SSL throws a "Remote host closed connection during handshake" error
// caused by a "SSL peer shut down incorrectly" error
for (String s : ssl.getSupportedCipherSuites()) {
if (s.startsWith("TLS_DH_anon")) cs.add(s);
if (s.startsWith("TLS_DH_anon")) {
cs.add(s);
}
}
ssl.setEnabledCipherSuites(cs.toArray(new String[]{}));
return ssl;