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 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> <version>2.3.2</version>
<configuration> <configuration>
<showDeprecation>true</showDeprecation> <showDeprecation>true</showDeprecation>
<source>1.5</source> <source>1.7</source>
<target>1.5</target> <target>1.7</target>
</configuration> </configuration>
</plugin> </plugin>

View File

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

View File

@ -146,7 +146,6 @@ public final class ApiConnectionImpl extends ApiConnection {
private void open(String host, int port, boolean secure) throws ApiConnectionException { private void open(String host, int port, boolean secure) throws ApiConnectionException {
try { try {
InetAddress ia = InetAddress.getByName(host); InetAddress ia = InetAddress.getByName(host);
if (ia.isReachable(1000)) {
if (secure) { if (secure) {
sock = openSSLSocket(ia, port); sock = openSSLSocket(ia, port);
} else { } else {
@ -161,9 +160,6 @@ public final class ApiConnectionImpl extends ApiConnection {
processor = new Processor(); processor = new Processor();
processor.setDaemon(true); processor.setDaemon(true);
processor.start(); processor.start();
} else {
throw new ApiConnectionException(String.format("Host '%s' port %d is uncreachable", host, port));
}
} catch (UnknownHostException ex) { } catch (UnknownHostException ex) {
connected = false; connected = false;
throw new ApiConnectionException(String.format("Unknown host '%s'", host), ex); 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 // 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 // caused by a "SSL peer shut down incorrectly" error
for (String s : ssl.getSupportedCipherSuites()) { 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[]{})); ssl.setEnabledCipherSuites(cs.toArray(new String[]{}));
return ssl; return ssl;