Search in sources :

Example 1 with ConnectionEndpoint

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));
    }
}
Also used : ConnectionEndpoint(im.actor.runtime.mtproto.ConnectionEndpoint)

Example 2 with ConnectionEndpoint

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();
        }
    });
}
Also used : ConnectionEndpoint(im.actor.runtime.mtproto.ConnectionEndpoint) InetSocketAddress(java.net.InetSocketAddress) SSLSocketFactory(javax.net.ssl.SSLSocketFactory) Socket(java.net.Socket)

Aggregations

ConnectionEndpoint (im.actor.runtime.mtproto.ConnectionEndpoint)2 InetSocketAddress (java.net.InetSocketAddress)1 Socket (java.net.Socket)1 SSLSocketFactory (javax.net.ssl.SSLSocketFactory)1