use of im.actor.runtime.mtproto.ConnectionEndpoint in project actor-platform by actorapp.
the class Endpoints method parse.
@Override
public void parse(BserValues values) throws IOException {
List<byte[]> endpointsRepeatedBytes = values.getRepeatedBytes(1);
endpoints = new ConnectionEndpoint[endpointsRepeatedBytes.size()];
for (int i = 0; i < endpoints.length; i++) {
endpoints[i] = ConnectionEndpoint.fromBytes(endpointsRepeatedBytes.get(i));
}
List<byte[]> trustedKeysRepeatedBytes = values.getRepeatedBytes(2);
trustedKeys = new TrustedKey[trustedKeysRepeatedBytes.size()];
for (int i = 0; i < trustedKeys.length; i++) {
trustedKeys[i] = TrustedKey.fromBytes(trustedKeysRepeatedBytes.get(i));
}
}
use of im.actor.runtime.mtproto.ConnectionEndpoint in project actor-platform by actorapp.
the class AsyncTcpConnection method doConnect.
@Override
public void doConnect() {
connectExecutor.submit((Runnable) () -> {
try {
ConnectionEndpoint endpoint1 = getEndpoint();
if (endpoint1.getKnownIp() != null) {
try {
Log.d(TAG, "Trying to connect to " + endpoint1.getHost() + " with Known IP " + endpoint1.getKnownIp());
Socket socket1 = new Socket();
socket1.setKeepAlive(false);
socket1.setTcpNoDelay(true);
socket1.connect(new InetSocketAddress(endpoint1.getKnownIp(), endpoint1.getPort()), ManagedConnection.CONNECTION_TIMEOUT);
if (endpoint1.getType() == ConnectionEndpoint.TYPE_TCP_TLS) {
SSLSocketFactory socketFactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
socket1 = socketFactory.createSocket(socket1, endpoint1.getHost(), endpoint1.getPort(), true);
}
socket1.getInputStream();
socket1.getOutputStream();
Log.d(TAG, "Connection successful");
onSocketCreated(socket1);
return;
} catch (Throwable e) {
e.printStackTrace();
}
}
Log.d(TAG, "Trying to connect to " + endpoint1.getHost());
Socket socket1 = new Socket();
socket1.setKeepAlive(false);
socket1.setTcpNoDelay(true);
socket1.connect(new InetSocketAddress(endpoint1.getHost(), endpoint1.getPort()), ManagedConnection.CONNECTION_TIMEOUT);
if (endpoint1.getType() == ConnectionEndpoint.TYPE_TCP_TLS) {
SSLSocketFactory socketFactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
socket1 = socketFactory.createSocket(socket1, endpoint1.getHost(), endpoint1.getPort(), true);
}
socket1.getInputStream();
socket1.getOutputStream();
onSocketCreated(socket1);
} catch (Throwable e) {
e.printStackTrace();
crashConnection();
}
});
}
Aggregations