Fixed to not check for router reachability before connecting
This commit is contained in:
parent
fb0c084f99
commit
044e4e76a0
|
|
@ -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
|
||||||
|
|
||||||
|
|
|
||||||
4
pom.xml
4
pom.xml
|
|
@ -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>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -146,24 +146,20 @@ 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 {
|
|
||||||
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();
|
|
||||||
} else {
|
} 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) {
|
} 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;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue