Add decompiled APK source code (JADX)

- 28,932 files
- Full Java source code
- Smali files
- Resources

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
2026-02-18 14:52:23 -08:00
parent cc210a65ea
commit f9d20bb3fc
26991 changed files with 2541449 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
package okhttp3.internal.connection;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.internal.http.RealInterceptorChain;
/* loaded from: classes5.dex */
public final class ConnectInterceptor implements Interceptor {
public final OkHttpClient client;
public ConnectInterceptor(OkHttpClient okHttpClient) {
this.client = okHttpClient;
}
@Override // okhttp3.Interceptor
public Response intercept(Interceptor.Chain chain) {
RealInterceptorChain realInterceptorChain = (RealInterceptorChain) chain;
Request request = realInterceptorChain.request();
Transmitter transmitter = realInterceptorChain.transmitter();
return realInterceptorChain.proceed(request, transmitter, transmitter.newExchange(chain, !request.method().equals("GET")));
}
}

View File

@@ -0,0 +1,71 @@
package okhttp3.internal.connection;
import java.io.IOException;
import java.io.InterruptedIOException;
import java.net.ProtocolException;
import java.net.UnknownServiceException;
import java.security.cert.CertificateException;
import java.util.Arrays;
import java.util.List;
import javax.net.ssl.SSLException;
import javax.net.ssl.SSLHandshakeException;
import javax.net.ssl.SSLPeerUnverifiedException;
import javax.net.ssl.SSLSocket;
import okhttp3.ConnectionSpec;
import okhttp3.internal.Internal;
/* loaded from: classes5.dex */
public final class ConnectionSpecSelector {
public final List connectionSpecs;
public boolean isFallback;
public boolean isFallbackPossible;
public int nextModeIndex = 0;
public ConnectionSpecSelector(List list) {
this.connectionSpecs = list;
}
public ConnectionSpec configureSecureSocket(SSLSocket sSLSocket) {
ConnectionSpec connectionSpec;
int i = this.nextModeIndex;
int size = this.connectionSpecs.size();
while (true) {
if (i >= size) {
connectionSpec = null;
break;
}
connectionSpec = (ConnectionSpec) this.connectionSpecs.get(i);
if (connectionSpec.isCompatible(sSLSocket)) {
this.nextModeIndex = i + 1;
break;
}
i++;
}
if (connectionSpec == null) {
throw new UnknownServiceException("Unable to find acceptable protocols. isFallback=" + this.isFallback + ", modes=" + this.connectionSpecs + ", supported protocols=" + Arrays.toString(sSLSocket.getEnabledProtocols()));
}
this.isFallbackPossible = isFallbackPossible(sSLSocket);
Internal.instance.apply(connectionSpec, sSLSocket, this.isFallback);
return connectionSpec;
}
public boolean connectionFailed(IOException iOException) {
this.isFallback = true;
if (!this.isFallbackPossible || (iOException instanceof ProtocolException) || (iOException instanceof InterruptedIOException)) {
return false;
}
if (((iOException instanceof SSLHandshakeException) && (iOException.getCause() instanceof CertificateException)) || (iOException instanceof SSLPeerUnverifiedException)) {
return false;
}
return iOException instanceof SSLException;
}
public final boolean isFallbackPossible(SSLSocket sSLSocket) {
for (int i = this.nextModeIndex; i < this.connectionSpecs.size(); i++) {
if (((ConnectionSpec) this.connectionSpecs.get(i)).isCompatible(sSLSocket)) {
return true;
}
}
return false;
}
}

View File

@@ -0,0 +1,289 @@
package okhttp3.internal.connection;
import csdk.gluads.Consts;
import java.io.IOException;
import java.net.ProtocolException;
import okhttp3.Call;
import okhttp3.EventListener;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.ResponseBody;
import okhttp3.internal.Internal;
import okhttp3.internal.http.ExchangeCodec;
import okhttp3.internal.http.RealResponseBody;
import okio.Buffer;
import okio.ForwardingSink;
import okio.ForwardingSource;
import okio.Okio;
import okio.Sink;
import okio.Source;
/* loaded from: classes5.dex */
public final class Exchange {
public final Call call;
public final ExchangeCodec codec;
public boolean duplex;
public final EventListener eventListener;
public final ExchangeFinder finder;
public final Transmitter transmitter;
public boolean isDuplex() {
return this.duplex;
}
public Exchange(Transmitter transmitter, Call call, EventListener eventListener, ExchangeFinder exchangeFinder, ExchangeCodec exchangeCodec) {
this.transmitter = transmitter;
this.call = call;
this.eventListener = eventListener;
this.finder = exchangeFinder;
this.codec = exchangeCodec;
}
public RealConnection connection() {
return this.codec.connection();
}
public void writeRequestHeaders(Request request) {
try {
this.eventListener.requestHeadersStart(this.call);
this.codec.writeRequestHeaders(request);
this.eventListener.requestHeadersEnd(this.call, request);
} catch (IOException e) {
this.eventListener.requestFailed(this.call, e);
trackFailure(e);
throw e;
}
}
public Sink createRequestBody(Request request, boolean z) {
this.duplex = z;
long contentLength = request.body().contentLength();
this.eventListener.requestBodyStart(this.call);
return new RequestBodySink(this.codec.createRequestBody(request, contentLength), contentLength);
}
public void flushRequest() {
try {
this.codec.flushRequest();
} catch (IOException e) {
this.eventListener.requestFailed(this.call, e);
trackFailure(e);
throw e;
}
}
public void finishRequest() {
try {
this.codec.finishRequest();
} catch (IOException e) {
this.eventListener.requestFailed(this.call, e);
trackFailure(e);
throw e;
}
}
public void responseHeadersStart() {
this.eventListener.responseHeadersStart(this.call);
}
public Response.Builder readResponseHeaders(boolean z) {
try {
Response.Builder readResponseHeaders = this.codec.readResponseHeaders(z);
if (readResponseHeaders != null) {
Internal.instance.initExchange(readResponseHeaders, this);
}
return readResponseHeaders;
} catch (IOException e) {
this.eventListener.responseFailed(this.call, e);
trackFailure(e);
throw e;
}
}
public void responseHeadersEnd(Response response) {
this.eventListener.responseHeadersEnd(this.call, response);
}
public ResponseBody openResponseBody(Response response) {
try {
this.eventListener.responseBodyStart(this.call);
String header = response.header("Content-Type");
long reportedContentLength = this.codec.reportedContentLength(response);
return new RealResponseBody(header, reportedContentLength, Okio.buffer(new ResponseBodySource(this.codec.openResponseBodySource(response), reportedContentLength)));
} catch (IOException e) {
this.eventListener.responseFailed(this.call, e);
trackFailure(e);
throw e;
}
}
public void noNewExchangesOnConnection() {
this.codec.connection().noNewExchanges();
}
public void cancel() {
this.codec.cancel();
}
public void detachWithViolence() {
this.codec.cancel();
this.transmitter.exchangeMessageDone(this, true, true, null);
}
public void trackFailure(IOException iOException) {
this.finder.trackFailure();
this.codec.connection().trackFailure(iOException);
}
public IOException bodyComplete(long j, boolean z, boolean z2, IOException iOException) {
if (iOException != null) {
trackFailure(iOException);
}
if (z2) {
if (iOException != null) {
this.eventListener.requestFailed(this.call, iOException);
} else {
this.eventListener.requestBodyEnd(this.call, j);
}
}
if (z) {
if (iOException != null) {
this.eventListener.responseFailed(this.call, iOException);
} else {
this.eventListener.responseBodyEnd(this.call, j);
}
}
return this.transmitter.exchangeMessageDone(this, z2, z, iOException);
}
public void noRequestBody() {
this.transmitter.exchangeMessageDone(this, true, false, null);
}
public final class RequestBodySink extends ForwardingSink {
public long bytesReceived;
public boolean closed;
public boolean completed;
public long contentLength;
public RequestBodySink(Sink sink, long j) {
super(sink);
this.contentLength = j;
}
@Override // okio.ForwardingSink, okio.Sink
public void write(Buffer buffer, long j) {
if (this.closed) {
throw new IllegalStateException(Consts.PLACEMENT_STATUS_CLOSED);
}
long j2 = this.contentLength;
if (j2 != -1 && this.bytesReceived + j > j2) {
throw new ProtocolException("expected " + this.contentLength + " bytes but received " + (this.bytesReceived + j));
}
try {
super.write(buffer, j);
this.bytesReceived += j;
} catch (IOException e) {
throw complete(e);
}
}
@Override // okio.ForwardingSink, okio.Sink, java.io.Flushable
public void flush() {
try {
super.flush();
} catch (IOException e) {
throw complete(e);
}
}
@Override // okio.ForwardingSink, okio.Sink, java.io.Closeable, java.lang.AutoCloseable
public void close() {
if (this.closed) {
return;
}
this.closed = true;
long j = this.contentLength;
if (j != -1 && this.bytesReceived != j) {
throw new ProtocolException("unexpected end of stream");
}
try {
super.close();
complete(null);
} catch (IOException e) {
throw complete(e);
}
}
private IOException complete(IOException iOException) {
if (this.completed) {
return iOException;
}
this.completed = true;
return Exchange.this.bodyComplete(this.bytesReceived, false, true, iOException);
}
}
public final class ResponseBodySource extends ForwardingSource {
public long bytesReceived;
public boolean closed;
public boolean completed;
public final long contentLength;
public ResponseBodySource(Source source, long j) {
super(source);
this.contentLength = j;
if (j == 0) {
complete(null);
}
}
@Override // okio.ForwardingSource, okio.Source
public long read(Buffer buffer, long j) {
if (this.closed) {
throw new IllegalStateException(Consts.PLACEMENT_STATUS_CLOSED);
}
try {
long read = delegate().read(buffer, j);
if (read == -1) {
complete(null);
return -1L;
}
long j2 = this.bytesReceived + read;
long j3 = this.contentLength;
if (j3 != -1 && j2 > j3) {
throw new ProtocolException("expected " + this.contentLength + " bytes but received " + j2);
}
this.bytesReceived = j2;
if (j2 == j3) {
complete(null);
}
return read;
} catch (IOException e) {
throw complete(e);
}
}
@Override // okio.ForwardingSource, okio.Source, java.io.Closeable, java.lang.AutoCloseable
public void close() {
if (this.closed) {
return;
}
this.closed = true;
try {
super.close();
complete(null);
} catch (IOException e) {
throw complete(e);
}
}
public IOException complete(IOException iOException) {
if (this.completed) {
return iOException;
}
this.completed = true;
return Exchange.this.bodyComplete(this.bytesReceived, true, false, iOException);
}
}
}

View File

@@ -0,0 +1,225 @@
package okhttp3.internal.connection;
import java.io.IOException;
import java.net.Socket;
import java.util.List;
import okhttp3.Address;
import okhttp3.Call;
import okhttp3.EventListener;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Route;
import okhttp3.internal.Util;
import okhttp3.internal.connection.RouteSelector;
import okhttp3.internal.http.ExchangeCodec;
/* loaded from: classes5.dex */
public final class ExchangeFinder {
public final Address address;
public final Call call;
public RealConnection connectingConnection;
public final RealConnectionPool connectionPool;
public final EventListener eventListener;
public boolean hasStreamFailure;
public Route nextRouteToTry;
public RouteSelector.Selection routeSelection;
public final RouteSelector routeSelector;
public final Transmitter transmitter;
public RealConnection connectingConnection() {
return this.connectingConnection;
}
public ExchangeFinder(Transmitter transmitter, RealConnectionPool realConnectionPool, Address address, Call call, EventListener eventListener) {
this.transmitter = transmitter;
this.connectionPool = realConnectionPool;
this.address = address;
this.call = call;
this.eventListener = eventListener;
this.routeSelector = new RouteSelector(address, realConnectionPool.routeDatabase, call, eventListener);
}
public ExchangeCodec find(OkHttpClient okHttpClient, Interceptor.Chain chain, boolean z) {
try {
return findHealthyConnection(chain.connectTimeoutMillis(), chain.readTimeoutMillis(), chain.writeTimeoutMillis(), okHttpClient.pingIntervalMillis(), okHttpClient.retryOnConnectionFailure(), z).newCodec(okHttpClient, chain);
} catch (IOException e) {
trackFailure();
throw new RouteException(e);
} catch (RouteException e2) {
trackFailure();
throw e2;
}
}
public final RealConnection findHealthyConnection(int i, int i2, int i3, int i4, boolean z, boolean z2) {
while (true) {
RealConnection findConnection = findConnection(i, i2, i3, i4, z);
synchronized (this.connectionPool) {
try {
if (findConnection.successCount == 0 && !findConnection.isMultiplexed()) {
return findConnection;
}
if (findConnection.isHealthy(z2)) {
return findConnection;
}
findConnection.noNewExchanges();
} catch (Throwable th) {
throw th;
}
}
}
}
public final RealConnection findConnection(int i, int i2, int i3, int i4, boolean z) {
RealConnection realConnection;
Socket socket;
Socket releaseConnectionNoEvents;
RealConnection realConnection2;
boolean z2;
Route route;
boolean z3;
List list;
RouteSelector.Selection selection;
synchronized (this.connectionPool) {
try {
if (this.transmitter.isCanceled()) {
throw new IOException("Canceled");
}
this.hasStreamFailure = false;
Transmitter transmitter = this.transmitter;
realConnection = transmitter.connection;
socket = null;
releaseConnectionNoEvents = (realConnection == null || !realConnection.noNewExchanges) ? null : transmitter.releaseConnectionNoEvents();
Transmitter transmitter2 = this.transmitter;
realConnection2 = transmitter2.connection;
if (realConnection2 != null) {
realConnection = null;
} else {
realConnection2 = null;
}
if (realConnection2 == null) {
if (this.connectionPool.transmitterAcquirePooledConnection(this.address, transmitter2, null, false)) {
realConnection2 = this.transmitter.connection;
route = null;
z2 = true;
} else {
route = this.nextRouteToTry;
if (route != null) {
this.nextRouteToTry = null;
} else if (retryCurrentRoute()) {
route = this.transmitter.connection.route();
}
z2 = false;
}
}
z2 = false;
route = null;
} finally {
}
}
Util.closeQuietly(releaseConnectionNoEvents);
if (realConnection != null) {
this.eventListener.connectionReleased(this.call, realConnection);
}
if (z2) {
this.eventListener.connectionAcquired(this.call, realConnection2);
}
if (realConnection2 != null) {
return realConnection2;
}
if (route != null || ((selection = this.routeSelection) != null && selection.hasNext())) {
z3 = false;
} else {
this.routeSelection = this.routeSelector.next();
z3 = true;
}
synchronized (this.connectionPool) {
try {
if (this.transmitter.isCanceled()) {
throw new IOException("Canceled");
}
if (z3) {
list = this.routeSelection.getAll();
if (this.connectionPool.transmitterAcquirePooledConnection(this.address, this.transmitter, list, false)) {
realConnection2 = this.transmitter.connection;
z2 = true;
}
} else {
list = null;
}
if (!z2) {
if (route == null) {
route = this.routeSelection.next();
}
realConnection2 = new RealConnection(this.connectionPool, route);
this.connectingConnection = realConnection2;
}
} finally {
}
}
if (z2) {
this.eventListener.connectionAcquired(this.call, realConnection2);
return realConnection2;
}
realConnection2.connect(i, i2, i3, i4, z, this.call, this.eventListener);
this.connectionPool.routeDatabase.connected(realConnection2.route());
synchronized (this.connectionPool) {
try {
this.connectingConnection = null;
if (this.connectionPool.transmitterAcquirePooledConnection(this.address, this.transmitter, list, true)) {
realConnection2.noNewExchanges = true;
socket = realConnection2.socket();
realConnection2 = this.transmitter.connection;
this.nextRouteToTry = route;
} else {
this.connectionPool.put(realConnection2);
this.transmitter.acquireConnectionNoEvents(realConnection2);
}
} finally {
}
}
Util.closeQuietly(socket);
this.eventListener.connectionAcquired(this.call, realConnection2);
return realConnection2;
}
public void trackFailure() {
synchronized (this.connectionPool) {
this.hasStreamFailure = true;
}
}
public boolean hasStreamFailure() {
boolean z;
synchronized (this.connectionPool) {
z = this.hasStreamFailure;
}
return z;
}
public boolean hasRouteToTry() {
synchronized (this.connectionPool) {
try {
boolean z = true;
if (this.nextRouteToTry != null) {
return true;
}
if (retryCurrentRoute()) {
this.nextRouteToTry = this.transmitter.connection.route();
return true;
}
RouteSelector.Selection selection = this.routeSelection;
if ((selection == null || !selection.hasNext()) && !this.routeSelector.hasNext()) {
z = false;
}
return z;
} finally {
}
}
}
public final boolean retryCurrentRoute() {
RealConnection realConnection = this.transmitter.connection;
return realConnection != null && realConnection.routeFailureCount == 0 && Util.sameConnection(realConnection.route().address().url(), this.address.url());
}
}

View File

@@ -0,0 +1,433 @@
package okhttp3.internal.connection;
import com.facebook.internal.security.CertificateUtil;
import java.io.IOException;
import java.net.ConnectException;
import java.net.Proxy;
import java.net.Socket;
import java.net.SocketTimeoutException;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import javax.net.ssl.SSLPeerUnverifiedException;
import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocket;
import okhttp3.Address;
import okhttp3.Call;
import okhttp3.CertificatePinner;
import okhttp3.Connection;
import okhttp3.ConnectionSpec;
import okhttp3.EventListener;
import okhttp3.Handshake;
import okhttp3.HttpUrl;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Protocol;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.Route;
import okhttp3.internal.Internal;
import okhttp3.internal.Util;
import okhttp3.internal.Version;
import okhttp3.internal.http.ExchangeCodec;
import okhttp3.internal.http1.Http1ExchangeCodec;
import okhttp3.internal.http2.ConnectionShutdownException;
import okhttp3.internal.http2.ErrorCode;
import okhttp3.internal.http2.Http2Connection;
import okhttp3.internal.http2.Http2ExchangeCodec;
import okhttp3.internal.http2.Http2Stream;
import okhttp3.internal.http2.StreamResetException;
import okhttp3.internal.platform.Platform;
import okhttp3.internal.tls.OkHostnameVerifier;
import okio.BufferedSink;
import okio.BufferedSource;
import okio.Okio;
import okio.Timeout;
import org.apache.http.auth.AUTH;
import org.apache.http.protocol.HTTP;
/* loaded from: classes5.dex */
public final class RealConnection extends Http2Connection.Listener implements Connection {
public final RealConnectionPool connectionPool;
public Handshake handshake;
public Http2Connection http2Connection;
public boolean noNewExchanges;
public Protocol protocol;
public Socket rawSocket;
public int refusedStreamCount;
public final Route route;
public int routeFailureCount;
public BufferedSink sink;
public Socket socket;
public BufferedSource source;
public int successCount;
public int allocationLimit = 1;
public final List transmitters = new ArrayList();
public long idleAtNanos = Long.MAX_VALUE;
public Handshake handshake() {
return this.handshake;
}
public boolean isMultiplexed() {
return this.http2Connection != null;
}
public Route route() {
return this.route;
}
public Socket socket() {
return this.socket;
}
public RealConnection(RealConnectionPool realConnectionPool, Route route) {
this.connectionPool = realConnectionPool;
this.route = route;
}
public void noNewExchanges() {
synchronized (this.connectionPool) {
this.noNewExchanges = true;
}
}
/* JADX WARN: Removed duplicated region for block: B:32:0x00ed */
/* JADX WARN: Removed duplicated region for block: B:43:0x00fd A[ORIG_RETURN, RETURN] */
/* JADX WARN: Removed duplicated region for block: B:47:0x0131 */
/* JADX WARN: Removed duplicated region for block: B:49:0x013c */
/* JADX WARN: Removed duplicated region for block: B:54:0x0144 A[SYNTHETIC] */
/* JADX WARN: Removed duplicated region for block: B:56:0x0137 */
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct add '--show-bad-code' argument
*/
public void connect(int r17, int r18, int r19, int r20, boolean r21, okhttp3.Call r22, okhttp3.EventListener r23) {
/*
Method dump skipped, instructions count: 346
To view this dump add '--comments-level debug' option
*/
throw new UnsupportedOperationException("Method not decompiled: okhttp3.internal.connection.RealConnection.connect(int, int, int, int, boolean, okhttp3.Call, okhttp3.EventListener):void");
}
public final void connectTunnel(int i, int i2, int i3, Call call, EventListener eventListener) {
Request createTunnelRequest = createTunnelRequest();
HttpUrl url = createTunnelRequest.url();
for (int i4 = 0; i4 < 21; i4++) {
connectSocket(i, i2, call, eventListener);
createTunnelRequest = createTunnel(i2, i3, createTunnelRequest, url);
if (createTunnelRequest == null) {
return;
}
Util.closeQuietly(this.rawSocket);
this.rawSocket = null;
this.sink = null;
this.source = null;
eventListener.connectEnd(call, this.route.socketAddress(), this.route.proxy(), null);
}
}
public final void connectSocket(int i, int i2, Call call, EventListener eventListener) {
Socket createSocket;
Proxy proxy = this.route.proxy();
Address address = this.route.address();
if (proxy.type() == Proxy.Type.DIRECT || proxy.type() == Proxy.Type.HTTP) {
createSocket = address.socketFactory().createSocket();
} else {
createSocket = new Socket(proxy);
}
this.rawSocket = createSocket;
eventListener.connectStart(call, this.route.socketAddress(), proxy);
this.rawSocket.setSoTimeout(i2);
try {
Platform.get().connectSocket(this.rawSocket, this.route.socketAddress(), i);
try {
this.source = Okio.buffer(Okio.source(this.rawSocket));
this.sink = Okio.buffer(Okio.sink(this.rawSocket));
} catch (NullPointerException e) {
if ("throw with null exception".equals(e.getMessage())) {
throw new IOException(e);
}
}
} catch (ConnectException e2) {
ConnectException connectException = new ConnectException("Failed to connect to " + this.route.socketAddress());
connectException.initCause(e2);
throw connectException;
}
}
public final void establishProtocol(ConnectionSpecSelector connectionSpecSelector, int i, Call call, EventListener eventListener) {
if (this.route.address().sslSocketFactory() == null) {
List protocols = this.route.address().protocols();
Protocol protocol = Protocol.H2_PRIOR_KNOWLEDGE;
if (protocols.contains(protocol)) {
this.socket = this.rawSocket;
this.protocol = protocol;
startHttp2(i);
return;
} else {
this.socket = this.rawSocket;
this.protocol = Protocol.HTTP_1_1;
return;
}
}
eventListener.secureConnectStart(call);
connectTls(connectionSpecSelector);
eventListener.secureConnectEnd(call, this.handshake);
if (this.protocol == Protocol.HTTP_2) {
startHttp2(i);
}
}
public final void startHttp2(int i) {
this.socket.setSoTimeout(0);
Http2Connection build = new Http2Connection.Builder(true).socket(this.socket, this.route.address().url().host(), this.source, this.sink).listener(this).pingIntervalMillis(i).build();
this.http2Connection = build;
build.start();
}
public final void connectTls(ConnectionSpecSelector connectionSpecSelector) {
SSLSocket sSLSocket;
Protocol protocol;
Address address = this.route.address();
SSLSocket sSLSocket2 = null;
try {
try {
sSLSocket = (SSLSocket) address.sslSocketFactory().createSocket(this.rawSocket, address.url().host(), address.url().port(), true);
} catch (AssertionError e) {
e = e;
}
} catch (Throwable th) {
th = th;
}
try {
ConnectionSpec configureSecureSocket = connectionSpecSelector.configureSecureSocket(sSLSocket);
if (configureSecureSocket.supportsTlsExtensions()) {
Platform.get().configureTlsExtensions(sSLSocket, address.url().host(), address.protocols());
}
sSLSocket.startHandshake();
SSLSession session = sSLSocket.getSession();
Handshake handshake = Handshake.get(session);
if (!address.hostnameVerifier().verify(address.url().host(), session)) {
List peerCertificates = handshake.peerCertificates();
if (!peerCertificates.isEmpty()) {
X509Certificate x509Certificate = (X509Certificate) peerCertificates.get(0);
throw new SSLPeerUnverifiedException("Hostname " + address.url().host() + " not verified:\n certificate: " + CertificatePinner.pin(x509Certificate) + "\n DN: " + x509Certificate.getSubjectDN().getName() + "\n subjectAltNames: " + OkHostnameVerifier.allSubjectAltNames(x509Certificate));
}
throw new SSLPeerUnverifiedException("Hostname " + address.url().host() + " not verified (no certificates)");
}
address.certificatePinner().check(address.url().host(), handshake.peerCertificates());
String selectedProtocol = configureSecureSocket.supportsTlsExtensions() ? Platform.get().getSelectedProtocol(sSLSocket) : null;
this.socket = sSLSocket;
this.source = Okio.buffer(Okio.source(sSLSocket));
this.sink = Okio.buffer(Okio.sink(this.socket));
this.handshake = handshake;
if (selectedProtocol != null) {
protocol = Protocol.get(selectedProtocol);
} else {
protocol = Protocol.HTTP_1_1;
}
this.protocol = protocol;
Platform.get().afterHandshake(sSLSocket);
} catch (AssertionError e2) {
e = e2;
if (!Util.isAndroidGetsocknameError(e)) {
throw e;
}
throw new IOException(e);
} catch (Throwable th2) {
th = th2;
sSLSocket2 = sSLSocket;
if (sSLSocket2 != null) {
Platform.get().afterHandshake(sSLSocket2);
}
Util.closeQuietly((Socket) sSLSocket2);
throw th;
}
}
public final Request createTunnel(int i, int i2, Request request, HttpUrl httpUrl) {
String str = "CONNECT " + Util.hostHeader(httpUrl, true) + " HTTP/1.1";
while (true) {
Http1ExchangeCodec http1ExchangeCodec = new Http1ExchangeCodec(null, null, this.source, this.sink);
TimeUnit timeUnit = TimeUnit.MILLISECONDS;
this.source.timeout().timeout(i, timeUnit);
this.sink.timeout().timeout(i2, timeUnit);
http1ExchangeCodec.writeRequest(request.headers(), str);
http1ExchangeCodec.finishRequest();
Response build = http1ExchangeCodec.readResponseHeaders(false).request(request).build();
http1ExchangeCodec.skipConnectBody(build);
int code = build.code();
if (code == 200) {
if (this.source.getBuffer().exhausted() && this.sink.buffer().exhausted()) {
return null;
}
throw new IOException("TLS tunnel buffered too many bytes!");
}
if (code == 407) {
Request authenticate = this.route.address().proxyAuthenticator().authenticate(this.route, build);
if (authenticate == null) {
throw new IOException("Failed to authenticate with proxy");
}
if ("close".equalsIgnoreCase(build.header(HTTP.CONN_DIRECTIVE))) {
return authenticate;
}
request = authenticate;
} else {
throw new IOException("Unexpected response code for CONNECT: " + build.code());
}
}
}
public final Request createTunnelRequest() {
Request build = new Request.Builder().url(this.route.address().url()).method("CONNECT", null).header(HTTP.TARGET_HOST, Util.hostHeader(this.route.address().url(), true)).header("Proxy-Connection", HTTP.CONN_KEEP_ALIVE).header("User-Agent", Version.userAgent()).build();
Request authenticate = this.route.address().proxyAuthenticator().authenticate(this.route, new Response.Builder().request(build).protocol(Protocol.HTTP_1_1).code(407).message("Preemptive Authenticate").body(Util.EMPTY_RESPONSE).sentRequestAtMillis(-1L).receivedResponseAtMillis(-1L).header(AUTH.PROXY_AUTH, "OkHttp-Preemptive").build());
return authenticate != null ? authenticate : build;
}
public boolean isEligible(Address address, List list) {
if (this.transmitters.size() >= this.allocationLimit || this.noNewExchanges || !Internal.instance.equalsNonHost(this.route.address(), address)) {
return false;
}
if (address.url().host().equals(route().address().url().host())) {
return true;
}
if (this.http2Connection == null || list == null || !routeMatchesAny(list) || address.hostnameVerifier() != OkHostnameVerifier.INSTANCE || !supportsUrl(address.url())) {
return false;
}
try {
address.certificatePinner().check(address.url().host(), handshake().peerCertificates());
return true;
} catch (SSLPeerUnverifiedException unused) {
return false;
}
}
public final boolean routeMatchesAny(List list) {
int size = list.size();
for (int i = 0; i < size; i++) {
Route route = (Route) list.get(i);
Proxy.Type type = route.proxy().type();
Proxy.Type type2 = Proxy.Type.DIRECT;
if (type == type2 && this.route.proxy().type() == type2 && this.route.socketAddress().equals(route.socketAddress())) {
return true;
}
}
return false;
}
public boolean supportsUrl(HttpUrl httpUrl) {
if (httpUrl.port() != this.route.address().url().port()) {
return false;
}
if (httpUrl.host().equals(this.route.address().url().host())) {
return true;
}
return this.handshake != null && OkHostnameVerifier.INSTANCE.verify(httpUrl.host(), (X509Certificate) this.handshake.peerCertificates().get(0));
}
public ExchangeCodec newCodec(OkHttpClient okHttpClient, Interceptor.Chain chain) {
if (this.http2Connection != null) {
return new Http2ExchangeCodec(okHttpClient, this, chain, this.http2Connection);
}
this.socket.setSoTimeout(chain.readTimeoutMillis());
Timeout timeout = this.source.timeout();
long readTimeoutMillis = chain.readTimeoutMillis();
TimeUnit timeUnit = TimeUnit.MILLISECONDS;
timeout.timeout(readTimeoutMillis, timeUnit);
this.sink.timeout().timeout(chain.writeTimeoutMillis(), timeUnit);
return new Http1ExchangeCodec(okHttpClient, this, this.source, this.sink);
}
public void cancel() {
Util.closeQuietly(this.rawSocket);
}
public boolean isHealthy(boolean z) {
if (this.socket.isClosed() || this.socket.isInputShutdown() || this.socket.isOutputShutdown()) {
return false;
}
Http2Connection http2Connection = this.http2Connection;
if (http2Connection != null) {
return http2Connection.isHealthy(System.nanoTime());
}
if (z) {
try {
int soTimeout = this.socket.getSoTimeout();
try {
this.socket.setSoTimeout(1);
return !this.source.exhausted();
} finally {
this.socket.setSoTimeout(soTimeout);
}
} catch (SocketTimeoutException unused) {
} catch (IOException unused2) {
return false;
}
}
return true;
}
@Override // okhttp3.internal.http2.Http2Connection.Listener
public void onStream(Http2Stream http2Stream) {
http2Stream.close(ErrorCode.REFUSED_STREAM, null);
}
@Override // okhttp3.internal.http2.Http2Connection.Listener
public void onSettings(Http2Connection http2Connection) {
synchronized (this.connectionPool) {
this.allocationLimit = http2Connection.maxConcurrentStreams();
}
}
public void trackFailure(IOException iOException) {
synchronized (this.connectionPool) {
try {
if (iOException instanceof StreamResetException) {
ErrorCode errorCode = ((StreamResetException) iOException).errorCode;
if (errorCode == ErrorCode.REFUSED_STREAM) {
int i = this.refusedStreamCount + 1;
this.refusedStreamCount = i;
if (i > 1) {
this.noNewExchanges = true;
this.routeFailureCount++;
}
} else if (errorCode != ErrorCode.CANCEL) {
this.noNewExchanges = true;
this.routeFailureCount++;
}
} else if (!isMultiplexed() || (iOException instanceof ConnectionShutdownException)) {
this.noNewExchanges = true;
if (this.successCount == 0) {
if (iOException != null) {
this.connectionPool.connectFailed(this.route, iOException);
}
this.routeFailureCount++;
}
}
} catch (Throwable th) {
throw th;
}
}
}
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("Connection{");
sb.append(this.route.address().url().host());
sb.append(CertificateUtil.DELIMITER);
sb.append(this.route.address().url().port());
sb.append(", proxy=");
sb.append(this.route.proxy());
sb.append(" hostAddress=");
sb.append(this.route.socketAddress());
sb.append(" cipherSuite=");
Handshake handshake = this.handshake;
sb.append(handshake != null ? handshake.cipherSuite() : "none");
sb.append(" protocol=");
sb.append(this.protocol);
sb.append('}');
return sb.toString();
}
}

View File

@@ -0,0 +1,157 @@
package okhttp3.internal.connection;
import java.io.IOException;
import java.lang.ref.Reference;
import java.net.Proxy;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.List;
import java.util.concurrent.Executor;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import okhttp3.Address;
import okhttp3.Route;
import okhttp3.internal.Util;
import okhttp3.internal.connection.Transmitter;
import okhttp3.internal.platform.Platform;
/* loaded from: classes5.dex */
public final class RealConnectionPool {
public static final Executor executor = new ThreadPoolExecutor(0, Integer.MAX_VALUE, 60, TimeUnit.SECONDS, new SynchronousQueue(), Util.threadFactory("OkHttp ConnectionPool", true));
public boolean cleanupRunning;
public final long keepAliveDurationNs;
public final int maxIdleConnections;
public final Runnable cleanupRunnable = new Runnable() { // from class: okhttp3.internal.connection.RealConnectionPool$$ExternalSyntheticLambda0
@Override // java.lang.Runnable
public final void run() {
RealConnectionPool.this.lambda$new$0();
}
};
public final Deque connections = new ArrayDeque();
public final RouteDatabase routeDatabase = new RouteDatabase();
public final /* synthetic */ void lambda$new$0() {
while (true) {
long cleanup = cleanup(System.nanoTime());
if (cleanup == -1) {
return;
}
if (cleanup > 0) {
long j = cleanup / 1000000;
long j2 = cleanup - (1000000 * j);
synchronized (this) {
try {
wait(j, (int) j2);
} catch (InterruptedException unused) {
}
}
}
}
}
public RealConnectionPool(int i, long j, TimeUnit timeUnit) {
this.maxIdleConnections = i;
this.keepAliveDurationNs = timeUnit.toNanos(j);
if (j > 0) {
return;
}
throw new IllegalArgumentException("keepAliveDuration <= 0: " + j);
}
public boolean transmitterAcquirePooledConnection(Address address, Transmitter transmitter, List list, boolean z) {
for (RealConnection realConnection : this.connections) {
if (!z || realConnection.isMultiplexed()) {
if (realConnection.isEligible(address, list)) {
transmitter.acquireConnectionNoEvents(realConnection);
return true;
}
}
}
return false;
}
public void put(RealConnection realConnection) {
if (!this.cleanupRunning) {
this.cleanupRunning = true;
executor.execute(this.cleanupRunnable);
}
this.connections.add(realConnection);
}
public boolean connectionBecameIdle(RealConnection realConnection) {
if (realConnection.noNewExchanges || this.maxIdleConnections == 0) {
this.connections.remove(realConnection);
return true;
}
notifyAll();
return false;
}
public long cleanup(long j) {
synchronized (this) {
try {
RealConnection realConnection = null;
long j2 = Long.MIN_VALUE;
int i = 0;
int i2 = 0;
for (RealConnection realConnection2 : this.connections) {
if (pruneAndGetAllocationCount(realConnection2, j) > 0) {
i2++;
} else {
i++;
long j3 = j - realConnection2.idleAtNanos;
if (j3 > j2) {
realConnection = realConnection2;
j2 = j3;
}
}
}
long j4 = this.keepAliveDurationNs;
if (j2 < j4 && i <= this.maxIdleConnections) {
if (i > 0) {
return j4 - j2;
}
if (i2 > 0) {
return j4;
}
this.cleanupRunning = false;
return -1L;
}
this.connections.remove(realConnection);
Util.closeQuietly(realConnection.socket());
return 0L;
} catch (Throwable th) {
throw th;
}
}
}
public final int pruneAndGetAllocationCount(RealConnection realConnection, long j) {
List list = realConnection.transmitters;
int i = 0;
while (i < list.size()) {
Reference reference = (Reference) list.get(i);
if (reference.get() != null) {
i++;
} else {
Platform.get().logCloseableLeak("A connection to " + realConnection.route().address().url() + " was leaked. Did you forget to close a response body?", ((Transmitter.TransmitterReference) reference).callStackTrace);
list.remove(i);
realConnection.noNewExchanges = true;
if (list.isEmpty()) {
realConnection.idleAtNanos = j - this.keepAliveDurationNs;
return 0;
}
}
}
return list.size();
}
public void connectFailed(Route route, IOException iOException) {
if (route.proxy().type() != Proxy.Type.DIRECT) {
Address address = route.address();
address.proxySelector().connectFailed(address.url().uri(), route.proxy().address(), iOException);
}
this.routeDatabase.failed(route);
}
}

View File

@@ -0,0 +1,22 @@
package okhttp3.internal.connection;
import java.util.LinkedHashSet;
import java.util.Set;
import okhttp3.Route;
/* loaded from: classes5.dex */
public final class RouteDatabase {
public final Set failedRoutes = new LinkedHashSet();
public synchronized void failed(Route route) {
this.failedRoutes.add(route);
}
public synchronized void connected(Route route) {
this.failedRoutes.remove(route);
}
public synchronized boolean shouldPostpone(Route route) {
return this.failedRoutes.contains(route);
}
}

View File

@@ -0,0 +1,29 @@
package okhttp3.internal.connection;
import java.io.IOException;
import okhttp3.internal.Util;
/* loaded from: classes5.dex */
public final class RouteException extends RuntimeException {
public IOException firstException;
public IOException lastException;
public IOException getFirstConnectException() {
return this.firstException;
}
public IOException getLastConnectException() {
return this.lastException;
}
public RouteException(IOException iOException) {
super(iOException);
this.firstException = iOException;
this.lastException = iOException;
}
public void addConnectException(IOException iOException) {
Util.addSuppressedIfPossible(this.firstException, iOException);
this.lastException = iOException;
}
}

View File

@@ -0,0 +1,166 @@
package okhttp3.internal.connection;
import com.facebook.internal.security.CertificateUtil;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.SocketAddress;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.NoSuchElementException;
import okhttp3.Address;
import okhttp3.Call;
import okhttp3.EventListener;
import okhttp3.HttpUrl;
import okhttp3.Route;
import okhttp3.internal.Util;
/* loaded from: classes5.dex */
public final class RouteSelector {
public final Address address;
public final Call call;
public final EventListener eventListener;
public int nextProxyIndex;
public final RouteDatabase routeDatabase;
public List proxies = Collections.emptyList();
public List inetSocketAddresses = Collections.emptyList();
public final List postponedRoutes = new ArrayList();
public RouteSelector(Address address, RouteDatabase routeDatabase, Call call, EventListener eventListener) {
this.address = address;
this.routeDatabase = routeDatabase;
this.call = call;
this.eventListener = eventListener;
resetNextProxy(address.url(), address.proxy());
}
public boolean hasNext() {
return hasNextProxy() || !this.postponedRoutes.isEmpty();
}
public Selection next() {
if (!hasNext()) {
throw new NoSuchElementException();
}
ArrayList arrayList = new ArrayList();
while (hasNextProxy()) {
Proxy nextProxy = nextProxy();
int size = this.inetSocketAddresses.size();
for (int i = 0; i < size; i++) {
Route route = new Route(this.address, nextProxy, (InetSocketAddress) this.inetSocketAddresses.get(i));
if (this.routeDatabase.shouldPostpone(route)) {
this.postponedRoutes.add(route);
} else {
arrayList.add(route);
}
}
if (!arrayList.isEmpty()) {
break;
}
}
if (arrayList.isEmpty()) {
arrayList.addAll(this.postponedRoutes);
this.postponedRoutes.clear();
}
return new Selection(arrayList);
}
public final void resetNextProxy(HttpUrl httpUrl, Proxy proxy) {
if (proxy != null) {
this.proxies = Collections.singletonList(proxy);
} else {
List<Proxy> select = this.address.proxySelector().select(httpUrl.uri());
this.proxies = (select == null || select.isEmpty()) ? Util.immutableList(Proxy.NO_PROXY) : Util.immutableList(select);
}
this.nextProxyIndex = 0;
}
public final boolean hasNextProxy() {
return this.nextProxyIndex < this.proxies.size();
}
public final Proxy nextProxy() {
if (!hasNextProxy()) {
throw new SocketException("No route to " + this.address.url().host() + "; exhausted proxy configurations: " + this.proxies);
}
List list = this.proxies;
int i = this.nextProxyIndex;
this.nextProxyIndex = i + 1;
Proxy proxy = (Proxy) list.get(i);
resetNextInetSocketAddress(proxy);
return proxy;
}
public final void resetNextInetSocketAddress(Proxy proxy) {
String host;
int port;
this.inetSocketAddresses = new ArrayList();
if (proxy.type() == Proxy.Type.DIRECT || proxy.type() == Proxy.Type.SOCKS) {
host = this.address.url().host();
port = this.address.url().port();
} else {
SocketAddress address = proxy.address();
if (!(address instanceof InetSocketAddress)) {
throw new IllegalArgumentException("Proxy.address() is not an InetSocketAddress: " + address.getClass());
}
InetSocketAddress inetSocketAddress = (InetSocketAddress) address;
host = getHostString(inetSocketAddress);
port = inetSocketAddress.getPort();
}
if (port < 1 || port > 65535) {
throw new SocketException("No route to " + host + CertificateUtil.DELIMITER + port + "; port is out of range");
}
if (proxy.type() == Proxy.Type.SOCKS) {
this.inetSocketAddresses.add(InetSocketAddress.createUnresolved(host, port));
return;
}
this.eventListener.dnsStart(this.call, host);
List lookup = this.address.dns().lookup(host);
if (lookup.isEmpty()) {
throw new UnknownHostException(this.address.dns() + " returned no addresses for " + host);
}
this.eventListener.dnsEnd(this.call, host, lookup);
int size = lookup.size();
for (int i = 0; i < size; i++) {
this.inetSocketAddresses.add(new InetSocketAddress((InetAddress) lookup.get(i), port));
}
}
public static String getHostString(InetSocketAddress inetSocketAddress) {
InetAddress address = inetSocketAddress.getAddress();
if (address == null) {
return inetSocketAddress.getHostName();
}
return address.getHostAddress();
}
public static final class Selection {
public int nextRouteIndex = 0;
public final List routes;
public Selection(List list) {
this.routes = list;
}
public boolean hasNext() {
return this.nextRouteIndex < this.routes.size();
}
public Route next() {
if (!hasNext()) {
throw new NoSuchElementException();
}
List list = this.routes;
int i = this.nextRouteIndex;
this.nextRouteIndex = i + 1;
return (Route) list.get(i);
}
public List getAll() {
return new ArrayList(this.routes);
}
}
}

View File

@@ -0,0 +1,312 @@
package okhttp3.internal.connection;
import java.io.IOException;
import java.io.InterruptedIOException;
import java.lang.ref.Reference;
import java.lang.ref.WeakReference;
import java.net.Socket;
import java.util.concurrent.TimeUnit;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLSocketFactory;
import okhttp3.Address;
import okhttp3.Call;
import okhttp3.CertificatePinner;
import okhttp3.EventListener;
import okhttp3.HttpUrl;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.internal.Internal;
import okhttp3.internal.Util;
import okhttp3.internal.platform.Platform;
import okio.AsyncTimeout;
/* loaded from: classes5.dex */
public final class Transmitter {
public final Call call;
public Object callStackTrace;
public boolean canceled;
public final OkHttpClient client;
public RealConnection connection;
public final RealConnectionPool connectionPool;
public final EventListener eventListener;
public Exchange exchange;
public ExchangeFinder exchangeFinder;
public boolean exchangeRequestDone;
public boolean exchangeResponseDone;
public boolean noMoreExchanges;
public Request request;
public final AsyncTimeout timeout;
public boolean timeoutEarlyExit;
public Transmitter(OkHttpClient okHttpClient, Call call) {
AsyncTimeout asyncTimeout = new AsyncTimeout() { // from class: okhttp3.internal.connection.Transmitter.1
@Override // okio.AsyncTimeout
public void timedOut() {
Transmitter.this.cancel();
}
};
this.timeout = asyncTimeout;
this.client = okHttpClient;
this.connectionPool = Internal.instance.realConnectionPool(okHttpClient.connectionPool());
this.call = call;
this.eventListener = okHttpClient.eventListenerFactory().create(call);
asyncTimeout.timeout(okHttpClient.callTimeoutMillis(), TimeUnit.MILLISECONDS);
}
public void timeoutEnter() {
this.timeout.enter();
}
public void timeoutEarlyExit() {
if (this.timeoutEarlyExit) {
throw new IllegalStateException();
}
this.timeoutEarlyExit = true;
this.timeout.exit();
}
public final IOException timeoutExit(IOException iOException) {
if (this.timeoutEarlyExit || !this.timeout.exit()) {
return iOException;
}
InterruptedIOException interruptedIOException = new InterruptedIOException("timeout");
if (iOException != null) {
interruptedIOException.initCause(iOException);
}
return interruptedIOException;
}
public void callStart() {
this.callStackTrace = Platform.get().getStackTraceForCloseable("response.body().close()");
this.eventListener.callStart(this.call);
}
public void prepareToConnect(Request request) {
Request request2 = this.request;
if (request2 != null) {
if (Util.sameConnection(request2.url(), request.url()) && this.exchangeFinder.hasRouteToTry()) {
return;
}
if (this.exchange != null) {
throw new IllegalStateException();
}
if (this.exchangeFinder != null) {
maybeReleaseConnection(null, true);
this.exchangeFinder = null;
}
}
this.request = request;
this.exchangeFinder = new ExchangeFinder(this, this.connectionPool, createAddress(request.url()), this.call, this.eventListener);
}
public final Address createAddress(HttpUrl httpUrl) {
SSLSocketFactory sSLSocketFactory;
HostnameVerifier hostnameVerifier;
CertificatePinner certificatePinner;
if (httpUrl.isHttps()) {
sSLSocketFactory = this.client.sslSocketFactory();
hostnameVerifier = this.client.hostnameVerifier();
certificatePinner = this.client.certificatePinner();
} else {
sSLSocketFactory = null;
hostnameVerifier = null;
certificatePinner = null;
}
return new Address(httpUrl.host(), httpUrl.port(), this.client.dns(), this.client.socketFactory(), sSLSocketFactory, hostnameVerifier, certificatePinner, this.client.proxyAuthenticator(), this.client.proxy(), this.client.protocols(), this.client.connectionSpecs(), this.client.proxySelector());
}
public Exchange newExchange(Interceptor.Chain chain, boolean z) {
synchronized (this.connectionPool) {
if (this.noMoreExchanges) {
throw new IllegalStateException("released");
}
if (this.exchange != null) {
throw new IllegalStateException("cannot make a new request because the previous response is still open: please call response.close()");
}
}
Exchange exchange = new Exchange(this, this.call, this.eventListener, this.exchangeFinder, this.exchangeFinder.find(this.client, chain, z));
synchronized (this.connectionPool) {
this.exchange = exchange;
this.exchangeRequestDone = false;
this.exchangeResponseDone = false;
}
return exchange;
}
public void acquireConnectionNoEvents(RealConnection realConnection) {
if (this.connection != null) {
throw new IllegalStateException();
}
this.connection = realConnection;
realConnection.transmitters.add(new TransmitterReference(this, this.callStackTrace));
}
public Socket releaseConnectionNoEvents() {
int size = this.connection.transmitters.size();
int i = 0;
while (true) {
if (i >= size) {
i = -1;
break;
}
if (((Reference) this.connection.transmitters.get(i)).get() == this) {
break;
}
i++;
}
if (i == -1) {
throw new IllegalStateException();
}
RealConnection realConnection = this.connection;
realConnection.transmitters.remove(i);
this.connection = null;
if (realConnection.transmitters.isEmpty()) {
realConnection.idleAtNanos = System.nanoTime();
if (this.connectionPool.connectionBecameIdle(realConnection)) {
return realConnection.socket();
}
}
return null;
}
public void exchangeDoneDueToException() {
synchronized (this.connectionPool) {
try {
if (this.noMoreExchanges) {
throw new IllegalStateException();
}
this.exchange = null;
} catch (Throwable th) {
throw th;
}
}
}
public IOException exchangeMessageDone(Exchange exchange, boolean z, boolean z2, IOException iOException) {
boolean z3;
synchronized (this.connectionPool) {
try {
Exchange exchange2 = this.exchange;
if (exchange != exchange2) {
return iOException;
}
boolean z4 = true;
if (z) {
z3 = !this.exchangeRequestDone;
this.exchangeRequestDone = true;
} else {
z3 = false;
}
if (z2) {
if (!this.exchangeResponseDone) {
z3 = true;
}
this.exchangeResponseDone = true;
}
if (this.exchangeRequestDone && this.exchangeResponseDone && z3) {
exchange2.connection().successCount++;
this.exchange = null;
} else {
z4 = false;
}
return z4 ? maybeReleaseConnection(iOException, false) : iOException;
} catch (Throwable th) {
throw th;
}
}
}
public IOException noMoreExchanges(IOException iOException) {
synchronized (this.connectionPool) {
this.noMoreExchanges = true;
}
return maybeReleaseConnection(iOException, false);
}
public final IOException maybeReleaseConnection(IOException iOException, boolean z) {
RealConnection realConnection;
Socket releaseConnectionNoEvents;
boolean z2;
synchronized (this.connectionPool) {
if (z) {
try {
if (this.exchange != null) {
throw new IllegalStateException("cannot release connection while it is in use");
}
} catch (Throwable th) {
throw th;
}
}
realConnection = this.connection;
releaseConnectionNoEvents = (realConnection != null && this.exchange == null && (z || this.noMoreExchanges)) ? releaseConnectionNoEvents() : null;
if (this.connection != null) {
realConnection = null;
}
z2 = this.noMoreExchanges && this.exchange == null;
}
Util.closeQuietly(releaseConnectionNoEvents);
if (realConnection != null) {
this.eventListener.connectionReleased(this.call, realConnection);
}
if (z2) {
boolean z3 = iOException != null;
iOException = timeoutExit(iOException);
if (z3) {
this.eventListener.callFailed(this.call, iOException);
} else {
this.eventListener.callEnd(this.call);
}
}
return iOException;
}
public boolean canRetry() {
return this.exchangeFinder.hasStreamFailure() && this.exchangeFinder.hasRouteToTry();
}
public boolean hasExchange() {
boolean z;
synchronized (this.connectionPool) {
z = this.exchange != null;
}
return z;
}
public void cancel() {
Exchange exchange;
RealConnection connectingConnection;
synchronized (this.connectionPool) {
try {
this.canceled = true;
exchange = this.exchange;
ExchangeFinder exchangeFinder = this.exchangeFinder;
connectingConnection = (exchangeFinder == null || exchangeFinder.connectingConnection() == null) ? this.connection : this.exchangeFinder.connectingConnection();
} catch (Throwable th) {
throw th;
}
}
if (exchange != null) {
exchange.cancel();
} else if (connectingConnection != null) {
connectingConnection.cancel();
}
}
public boolean isCanceled() {
boolean z;
synchronized (this.connectionPool) {
z = this.canceled;
}
return z;
}
public static final class TransmitterReference extends WeakReference {
public final Object callStackTrace;
public TransmitterReference(Transmitter transmitter, Object obj) {
super(transmitter);
this.callStackTrace = obj;
}
}
}