what-the-bank/sources/okhttp3/internal/connection/ExchangeFinder.java

143 lines
5.9 KiB
Java
Raw Permalink Normal View History

2024-07-27 18:17:47 +07:00
package okhttp3.internal.connection;
import java.io.IOException;
import o.C14957gcv;
import okhttp3.Address;
import okhttp3.EventListener;
import okhttp3.HttpUrl;
import okhttp3.OkHttpClient;
import okhttp3.Route;
import okhttp3.internal.Util;
import okhttp3.internal.connection.RouteSelector;
import okhttp3.internal.http.ExchangeCodec;
import okhttp3.internal.http.RealInterceptorChain;
import okhttp3.internal.http2.ConnectionShutdownException;
import okhttp3.internal.http2.ErrorCode;
import okhttp3.internal.http2.StreamResetException;
/* loaded from: classes.dex */
public final class ExchangeFinder {
private final Address address;
private final RealCall call;
private final RealConnectionPool connectionPool;
private int connectionShutdownCount;
private final EventListener eventListener;
private Route nextRouteToTry;
private int otherFailureCount;
private int refusedStreamCount;
private RouteSelector.Selection routeSelection;
private RouteSelector routeSelector;
public ExchangeFinder(RealConnectionPool realConnectionPool, Address address, RealCall realCall, EventListener eventListener) {
C14957gcv.e(realConnectionPool, "");
C14957gcv.e(address, "");
C14957gcv.e(realCall, "");
C14957gcv.e(eventListener, "");
this.connectionPool = realConnectionPool;
this.address = address;
this.call = realCall;
this.eventListener = eventListener;
}
public final ExchangeCodec find(OkHttpClient okHttpClient, RealInterceptorChain realInterceptorChain) {
C14957gcv.e(okHttpClient, "");
C14957gcv.e(realInterceptorChain, "");
try {
return findHealthyConnection(realInterceptorChain.getConnectTimeoutMillis$okhttp(), realInterceptorChain.getReadTimeoutMillis$okhttp(), realInterceptorChain.getWriteTimeoutMillis$okhttp(), okHttpClient.pingIntervalMillis(), okHttpClient.retryOnConnectionFailure(), !C14957gcv.b((Object) realInterceptorChain.getRequest$okhttp().method(), (Object) "GET")).newCodec$okhttp(okHttpClient, realInterceptorChain);
} catch (IOException e) {
trackFailure(e);
throw new RouteException(e);
} catch (RouteException e2) {
trackFailure(e2.getLastConnectException());
throw e2;
}
}
private final RealConnection findHealthyConnection(int i, int i2, int i3, int i4, boolean z, boolean z2) throws IOException {
RouteSelector.Selection selection;
RouteSelector routeSelector;
while (true) {
RealConnection findConnection = findConnection(i, i2, i3, i4, z);
if (findConnection.isHealthy(z2)) {
return findConnection;
}
findConnection.noNewExchanges$okhttp();
if (this.nextRouteToTry == null && (selection = this.routeSelection) != null && !selection.hasNext() && (routeSelector = this.routeSelector) != null && !routeSelector.hasNext()) {
throw new IOException("exhausted all routes");
}
}
}
/* JADX WARN: Removed duplicated region for block: B:42:0x0145 */
/* JADX WARN: Removed duplicated region for block: B:44:0x0164 */
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct add '--show-bad-code' argument
*/
private final okhttp3.internal.connection.RealConnection findConnection(int r15, int r16, int r17, int r18, boolean r19) throws java.io.IOException {
/*
Method dump skipped, instructions count: 409
To view this dump add '--comments-level debug' option
*/
throw new UnsupportedOperationException("Method not decompiled: okhttp3.internal.connection.ExchangeFinder.findConnection(int, int, int, int, boolean):okhttp3.internal.connection.RealConnection");
}
public final void trackFailure(IOException iOException) {
C14957gcv.e(iOException, "");
this.nextRouteToTry = null;
if ((iOException instanceof StreamResetException) && ((StreamResetException) iOException).errorCode == ErrorCode.REFUSED_STREAM) {
this.refusedStreamCount++;
} else if (iOException instanceof ConnectionShutdownException) {
this.connectionShutdownCount++;
} else {
this.otherFailureCount++;
}
}
public final boolean retryAfterFailure() {
RouteSelector routeSelector;
if (this.refusedStreamCount == 0 && this.connectionShutdownCount == 0 && this.otherFailureCount == 0) {
return false;
}
if (this.nextRouteToTry != null) {
return true;
}
Route retryRoute = retryRoute();
if (retryRoute != null) {
this.nextRouteToTry = retryRoute;
return true;
}
RouteSelector.Selection selection = this.routeSelection;
if ((selection == null || !selection.hasNext()) && (routeSelector = this.routeSelector) != null) {
return routeSelector.hasNext();
}
return true;
}
private final Route retryRoute() {
RealConnection connection;
if (this.refusedStreamCount > 1 || this.connectionShutdownCount > 1 || this.otherFailureCount > 0 || (connection = this.call.getConnection()) == null) {
return null;
}
synchronized (connection) {
if (connection.getRouteFailureCount$okhttp() != 0) {
return null;
}
if (Util.canReuseConnectionFor(connection.route().address().url(), getAddress$okhttp().url())) {
return connection.route();
}
return null;
}
}
public final boolean sameHostAndPort(HttpUrl httpUrl) {
C14957gcv.e(httpUrl, "");
HttpUrl url = this.address.url();
return httpUrl.port() == url.port() && C14957gcv.b((Object) httpUrl.host(), (Object) url.host());
}
public final Address getAddress$okhttp() {
return this.address;
}
}