what-the-bank/sources/io/grpc/okhttp/Utils.java

128 lines
5.4 KiB
Java
Raw Permalink Normal View History

2024-07-27 18:17:47 +07:00
package io.grpc.okhttp;
import com.google.common.base.Preconditions;
import io.grpc.InternalChannelz;
import io.grpc.InternalMetadata;
import io.grpc.Metadata;
import io.grpc.internal.TransportFrameUtil;
import io.grpc.okhttp.internal.CipherSuite;
import io.grpc.okhttp.internal.ConnectionSpec;
import io.grpc.okhttp.internal.framed.Header;
import java.net.Socket;
import java.net.SocketException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import o.C12990fNc;
import o.EnumC12989fNb;
import o.EnumC12998fNk;
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes6.dex */
public class Utils {
static final int CONNECTION_STREAM_ID = 0;
static final int DEFAULT_WINDOW_SIZE = 65535;
static final float DEFAULT_WINDOW_UPDATE_RATIO = 0.5f;
private static final Logger log = Logger.getLogger(Utils.class.getName());
public static Metadata convertHeaders(List<Header> list) {
return InternalMetadata.newMetadata(convertHeadersToArray(list));
}
public static Metadata convertTrailers(List<Header> list) {
return InternalMetadata.newMetadata(convertHeadersToArray(list));
}
private static byte[][] convertHeadersToArray(List<Header> list) {
byte[][] bArr = new byte[list.size() << 1];
int i = 0;
for (Header header : list) {
bArr[i] = header.name.j();
bArr[i + 1] = header.value.j();
i += 2;
}
return TransportFrameUtil.toRawSerializedHeaders(bArr);
}
/* JADX INFO: Access modifiers changed from: package-private */
public static InternalChannelz.SocketOptions getSocketOptions(Socket socket) {
InternalChannelz.SocketOptions.Builder builder = new InternalChannelz.SocketOptions.Builder();
try {
builder.setSocketOptionLingerSeconds(Integer.valueOf(socket.getSoLinger()));
} catch (SocketException e) {
log.log(Level.SEVERE, "Exception caught while reading socket option", (Throwable) e);
builder.addOption("SO_LINGER", "channelz_internal_error");
}
try {
builder.setSocketOptionTimeoutMillis(Integer.valueOf(socket.getSoTimeout()));
} catch (Exception e2) {
log.log(Level.SEVERE, "Exception caught while reading socket option", (Throwable) e2);
builder.addOption("SO_TIMEOUT", "channelz_internal_error");
}
try {
builder.addOption("TCP_NODELAY", socket.getTcpNoDelay());
} catch (SocketException e3) {
log.log(Level.SEVERE, "Exception caught while reading socket option", (Throwable) e3);
builder.addOption("TCP_NODELAY", "channelz_internal_error");
}
try {
builder.addOption("SO_REUSEADDR", socket.getReuseAddress());
} catch (SocketException e4) {
log.log(Level.SEVERE, "Exception caught while reading socket option", (Throwable) e4);
builder.addOption("SO_REUSEADDR", "channelz_internal_error");
}
try {
builder.addOption("SO_SNDBUF", socket.getSendBufferSize());
} catch (SocketException e5) {
log.log(Level.SEVERE, "Exception caught while reading socket option", (Throwable) e5);
builder.addOption("SO_SNDBUF", "channelz_internal_error");
}
try {
builder.addOption("SO_RECVBUF", socket.getReceiveBufferSize());
} catch (SocketException e6) {
log.log(Level.SEVERE, "Exception caught while reading socket option", (Throwable) e6);
builder.addOption("SO_RECVBUF", "channelz_internal_error");
}
try {
builder.addOption("SO_KEEPALIVE", socket.getKeepAlive());
} catch (SocketException e7) {
log.log(Level.SEVERE, "Exception caught while reading socket option", (Throwable) e7);
builder.addOption("SO_KEEPALIVE", "channelz_internal_error");
}
try {
builder.addOption("SO_OOBINLINE", socket.getOOBInline());
} catch (SocketException e8) {
log.log(Level.SEVERE, "Exception caught while reading socket option", (Throwable) e8);
builder.addOption("SO_OOBINLINE", "channelz_internal_error");
}
try {
builder.addOption("IP_TOS", socket.getTrafficClass());
} catch (SocketException e9) {
log.log(Level.SEVERE, "Exception caught while reading socket option", (Throwable) e9);
builder.addOption("IP_TOS", "channelz_internal_error");
}
return builder.build();
}
private Utils() {
}
/* JADX INFO: Access modifiers changed from: package-private */
public static ConnectionSpec convertSpec(C12990fNc c12990fNc) {
Preconditions.checkArgument(c12990fNc.b, "plaintext ConnectionSpec is not accepted");
List<EnumC12998fNk> b = c12990fNc.b();
int size = b.size();
String[] strArr = new String[size];
for (int i = 0; i < size; i++) {
strArr[i] = b.get(i).javaName;
}
List<EnumC12989fNb> e = c12990fNc.e();
int size2 = e.size();
CipherSuite[] cipherSuiteArr = new CipherSuite[size2];
for (int i2 = 0; i2 < size2; i2++) {
cipherSuiteArr[i2] = CipherSuite.valueOf(e.get(i2).name());
}
return new ConnectionSpec.Builder(c12990fNc.b).supportsTlsExtensions(c12990fNc.d).tlsVersions(strArr).cipherSuites(cipherSuiteArr).build();
}
}