Rabbit-R1/original r1/java/sources/okhttp3/internal/connection/ConnectionSpecSelector.java

78 lines
4.5 KiB
Java
Raw Normal View History

2024-05-21 16:08:36 -05:00
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 kotlin.Metadata;
import kotlin.jvm.internal.Intrinsics;
import okhttp3.ConnectionSpec;
/* compiled from: ConnectionSpecSelector.kt */
@Metadata(bv = {1, 0, 3}, d1 = {"\u00006\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0000\n\u0002\u0010 \n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\u000b\n\u0002\b\u0002\n\u0002\u0010\b\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\b\u0000\u0018\u00002\u00020\u0001B\u0013\u0012\f\u0010\u0002\u001a\b\u0012\u0004\u0012\u00020\u00040\u0003¢\u0006\u0002\u0010\u0005J\u000e\u0010\u000b\u001a\u00020\u00042\u0006\u0010\f\u001a\u00020\rJ\u000e\u0010\u000e\u001a\u00020\u00072\u0006\u0010\u000f\u001a\u00020\u0010J\u0010\u0010\b\u001a\u00020\u00072\u0006\u0010\u0011\u001a\u00020\rH\u0002R\u0014\u0010\u0002\u001a\b\u0012\u0004\u0012\u00020\u00040\u0003X\u0082\u0004¢\u0006\u0002\n\u0000R\u000e\u0010\u0006\u001a\u00020\u0007X\u0082\u000e¢\u0006\u0002\n\u0000R\u000e\u0010\b\u001a\u00020\u0007X\u0082\u000e¢\u0006\u0002\n\u0000R\u000e\u0010\t\u001a\u00020\nX\u0082\u000e¢\u0006\u0002\n\u0000¨\u0006\u0012"}, d2 = {"Lokhttp3/internal/connection/ConnectionSpecSelector;", "", "connectionSpecs", "", "Lokhttp3/ConnectionSpec;", "(Ljava/util/List;)V", "isFallback", "", "isFallbackPossible", "nextModeIndex", "", "configureSecureSocket", "sslSocket", "Ljavax/net/ssl/SSLSocket;", "connectionFailed", "e", "Ljava/io/IOException;", "socket", "okhttp"}, k = 1, mv = {1, 4, 0})
/* loaded from: classes3.dex */
public final class ConnectionSpecSelector {
private final List<ConnectionSpec> connectionSpecs;
private boolean isFallback;
private boolean isFallbackPossible;
private int nextModeIndex;
public ConnectionSpecSelector(List<ConnectionSpec> connectionSpecs) {
Intrinsics.checkNotNullParameter(connectionSpecs, "connectionSpecs");
this.connectionSpecs = connectionSpecs;
}
public final ConnectionSpec configureSecureSocket(SSLSocket sslSocket) throws IOException {
Intrinsics.checkNotNullParameter(sslSocket, "sslSocket");
ConnectionSpec connectionSpec = null;
int i = this.nextModeIndex;
int size = this.connectionSpecs.size();
while (true) {
if (i >= size) {
break;
}
ConnectionSpec connectionSpec2 = this.connectionSpecs.get(i);
if (connectionSpec2.isCompatible(sslSocket)) {
this.nextModeIndex = i + 1;
connectionSpec = connectionSpec2;
break;
}
i++;
}
if (connectionSpec == null) {
StringBuilder append = new StringBuilder("Unable to find acceptable protocols. isFallback=").append(this.isFallback).append(", modes=").append(this.connectionSpecs).append(", supported protocols=");
String[] enabledProtocols = sslSocket.getEnabledProtocols();
Intrinsics.checkNotNull(enabledProtocols);
String arrays = Arrays.toString(enabledProtocols);
Intrinsics.checkNotNullExpressionValue(arrays, "java.util.Arrays.toString(this)");
throw new UnknownServiceException(append.append(arrays).toString());
}
this.isFallbackPossible = isFallbackPossible(sslSocket);
connectionSpec.apply$okhttp(sslSocket, this.isFallback);
return connectionSpec;
}
public final boolean connectionFailed(IOException e) {
Intrinsics.checkNotNullParameter(e, "e");
this.isFallback = true;
return (!this.isFallbackPossible || (e instanceof ProtocolException) || (e instanceof InterruptedIOException) || ((e instanceof SSLHandshakeException) && (e.getCause() instanceof CertificateException)) || (e instanceof SSLPeerUnverifiedException) || !(e instanceof SSLException)) ? false : true;
}
private final boolean isFallbackPossible(SSLSocket socket) {
int size = this.connectionSpecs.size();
for (int i = this.nextModeIndex; i < size; i++) {
if (this.connectionSpecs.get(i).isCompatible(socket)) {
return true;
}
}
return false;
}
}