导航菜单

页面标题

页面副标题

Kaspi.kz v5.85.1 - SocketConnector.java 源代码

正在查看: Kaspi.kz v5.85.1 应用的 SocketConnector.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.neovisionaries.ws.client;

import java.io.IOException;
import java.net.Socket;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;

class SocketConnector {
    private final Address mAddress;
    private final int mConnectionTimeout;
    private final String mHost;
    private final int mPort;
    private final ProxyHandshaker mProxyHandshaker;
    private final SSLSocketFactory mSSLSocketFactory;
    private Socket mSocket;

    SocketConnector(Socket socket, Address address, int i) {
        this(socket, address, i, null, null, null, 0);
    }

    SocketConnector(Socket socket, Address address, int i, ProxyHandshaker proxyHandshaker, SSLSocketFactory sSLSocketFactory, String str, int i2) {
        this.mSocket = socket;
        this.mAddress = address;
        this.mConnectionTimeout = i;
        this.mProxyHandshaker = proxyHandshaker;
        this.mSSLSocketFactory = sSLSocketFactory;
        this.mHost = str;
        this.mPort = i2;
    }

    public Socket getSocket() {
        return this.mSocket;
    }

    public int getConnectionTimeout() {
        return this.mConnectionTimeout;
    }

    public void connect() throws WebSocketException {
        try {
            doConnect();
        } catch (WebSocketException e) {
            try {
                this.mSocket.close();
            } catch (IOException unused) {
            }
            throw e;
        }
    }

    private void doConnect() throws WebSocketException {
        boolean z = this.mProxyHandshaker != null;
        try {
            this.mSocket.connect(this.mAddress.toInetSocketAddress(), this.mConnectionTimeout);
            if (z) {
                handshake();
            }
        } catch (IOException e) {
            throw new WebSocketException(WebSocketError.SOCKET_CONNECT_ERROR, String.format("Failed to connect to %s'%s': %s", z ? "the proxy " : "", this.mAddress, e.getMessage()), e);
        }
    }

    private void handshake() throws WebSocketException {
        try {
            this.mProxyHandshaker.perform();
            SSLSocketFactory sSLSocketFactory = this.mSSLSocketFactory;
            if (sSLSocketFactory == null) {
                return;
            }
            try {
                Socket createSocket = sSLSocketFactory.createSocket(this.mSocket, this.mHost, this.mPort, true);
                this.mSocket = createSocket;
                try {
                    ((SSLSocket) createSocket).startHandshake();
                } catch (IOException e) {
                    throw new WebSocketException(WebSocketError.SSL_HANDSHAKE_ERROR, String.format("SSL handshake with the WebSocket endpoint (%s) failed: %s", this.mAddress, e.getMessage()), e);
                }
            } catch (IOException e2) {
                throw new WebSocketException(WebSocketError.SOCKET_OVERLAY_ERROR, "Failed to overlay an existing socket: " + e2.getMessage(), e2);
            }
        } catch (IOException e3) {
            throw new WebSocketException(WebSocketError.PROXY_HANDSHAKE_ERROR, String.format("Handshake with the proxy server (%s) failed: %s", this.mAddress, e3.getMessage()), e3);
        }
    }

    void closeSilently() {
        try {
            this.mSocket.close();
        } catch (Throwable unused) {
        }
    }
}