正在查看: SpeedCash v6.5.1482 应用的 OkHttpServerBuilder.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: SpeedCash v6.5.1482 应用的 OkHttpServerBuilder.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package io.grpc.okhttp;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.DoNotCall;
import io.grpc.ChoiceServerCredentials;
import io.grpc.ExperimentalApi;
import io.grpc.ForwardingServerBuilder;
import io.grpc.InsecureServerCredentials;
import io.grpc.Internal;
import io.grpc.ServerBuilder;
import io.grpc.ServerCredentials;
import io.grpc.ServerStreamTracer;
import io.grpc.TlsServerCredentials;
import io.grpc.internal.FixedObjectPool;
import io.grpc.internal.GrpcUtil;
import io.grpc.internal.InternalServer;
import io.grpc.internal.KeepAliveManager;
import io.grpc.internal.ObjectPool;
import io.grpc.internal.ServerImplBuilder;
import io.grpc.internal.SharedResourcePool;
import io.grpc.internal.TransportTracer;
import io.grpc.okhttp.OkHttpServerBuilder;
import io.grpc.okhttp.SslSocketFactoryServerCredentials;
import io.grpc.okhttp.internal.Platform;
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketAddress;
import java.security.GeneralSecurityException;
import java.util.EnumSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.concurrent.Executor;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.net.ServerSocketFactory;
import javax.net.ssl.KeyManager;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/1785")
public final class OkHttpServerBuilder extends ForwardingServerBuilder<OkHttpServerBuilder> {
public static final Logger r = Logger.getLogger(OkHttpServerBuilder.class.getName());
public static final long s;
public static final long t;
public static final long u;
public static final ObjectPool<Executor> v;
public static final EnumSet<TlsServerCredentials.Feature> w;
public final SocketAddress b;
public final HandshakerSocketFactory c;
public boolean n;
public final ServerImplBuilder a = new ServerImplBuilder(new ServerImplBuilder.ClientTransportServersBuilder() {
@Override
public final InternalServer buildClientTransportServers(List list) {
return OkHttpServerBuilder.this.b(list);
}
});
public TransportTracer.Factory d = TransportTracer.getDefaultFactory();
public ObjectPool<Executor> e = v;
public ObjectPool<ScheduledExecutorService> f = SharedResourcePool.forResource(GrpcUtil.TIMER_SERVICE);
public ServerSocketFactory g = ServerSocketFactory.getDefault();
public long h = GrpcUtil.DEFAULT_SERVER_KEEPALIVE_TIME_NANOS;
public long i = GrpcUtil.DEFAULT_SERVER_KEEPALIVE_TIMEOUT_NANOS;
public int j = 65535;
public int k = 8192;
public int l = GrpcUtil.DEFAULT_MAX_MESSAGE_SIZE;
public long m = Long.MAX_VALUE;
public long o = TimeUnit.MINUTES.toNanos(5);
public long p = Long.MAX_VALUE;
public long q = Long.MAX_VALUE;
public static class a {
public static final int[] a;
static {
int[] iArr = new int[TlsServerCredentials.ClientAuth.values().length];
a = iArr;
try {
iArr[TlsServerCredentials.ClientAuth.OPTIONAL.ordinal()] = 1;
} catch (NoSuchFieldError unused) {
}
try {
a[TlsServerCredentials.ClientAuth.REQUIRE.ordinal()] = 2;
} catch (NoSuchFieldError unused2) {
}
try {
a[TlsServerCredentials.ClientAuth.NONE.ordinal()] = 3;
} catch (NoSuchFieldError unused3) {
}
}
}
public static final class b extends SSLSocketFactory {
public final SSLSocketFactory a;
public final boolean b;
public b(SSLSocketFactory sSLSocketFactory, boolean z) {
this.a = (SSLSocketFactory) Preconditions.checkNotNull(sSLSocketFactory, "socketFactory");
this.b = z;
}
public final Socket a(Socket socket) throws IOException {
if (socket instanceof SSLSocket) {
SSLSocket sSLSocket = (SSLSocket) socket;
if (this.b) {
sSLSocket.setNeedClientAuth(true);
} else {
sSLSocket.setWantClientAuth(true);
}
return sSLSocket;
}
throw new IOException("SocketFactory " + this.a + " did not produce an SSLSocket: " + socket.getClass());
}
@Override
public Socket createSocket(Socket socket, String str, int i, boolean z) throws IOException {
return a(this.a.createSocket(socket, str, i, z));
}
@Override
public String[] getDefaultCipherSuites() {
return this.a.getDefaultCipherSuites();
}
@Override
public String[] getSupportedCipherSuites() {
return this.a.getSupportedCipherSuites();
}
@Override
public Socket createSocket(String str, int i) throws IOException {
return a(this.a.createSocket(str, i));
}
@Override
public Socket createSocket(String str, int i, InetAddress inetAddress, int i2) throws IOException {
return a(this.a.createSocket(str, i, inetAddress, i2));
}
@Override
public Socket createSocket(InetAddress inetAddress, int i) throws IOException {
return a(this.a.createSocket(inetAddress, i));
}
@Override
public Socket createSocket(InetAddress inetAddress, int i, InetAddress inetAddress2, int i2) throws IOException {
return a(this.a.createSocket(inetAddress, i, inetAddress2, i2));
}
}
public static final class c {
public final HandshakerSocketFactory a;
public final String b;
public c(HandshakerSocketFactory handshakerSocketFactory, String str) {
this.a = handshakerSocketFactory;
this.b = str;
}
public static c a(String str) {
return new c(null, (String) Preconditions.checkNotNull(str, "error"));
}
public static c b(HandshakerSocketFactory handshakerSocketFactory) {
return new c((HandshakerSocketFactory) Preconditions.checkNotNull(handshakerSocketFactory, "factory"), null);
}
}
static {
TimeUnit timeUnit = TimeUnit.SECONDS;
s = timeUnit.toNanos(1L);
t = timeUnit.toNanos(1L);
u = TimeUnit.DAYS.toNanos(1000L);
v = OkHttpChannelBuilder.u;
w = EnumSet.of(TlsServerCredentials.Feature.MTLS, TlsServerCredentials.Feature.CUSTOM_MANAGERS);
}
@VisibleForTesting
public OkHttpServerBuilder(SocketAddress socketAddress, HandshakerSocketFactory handshakerSocketFactory) {
this.b = (SocketAddress) Preconditions.checkNotNull(socketAddress, "address");
this.c = (HandshakerSocketFactory) Preconditions.checkNotNull(handshakerSocketFactory, "handshakerSocketFactory");
}
public static c c(ServerCredentials serverCredentials) {
KeyManager[] keyManagerArr;
TrustManager[] e;
b bVar;
if (!(serverCredentials instanceof TlsServerCredentials)) {
if (serverCredentials instanceof InsecureServerCredentials) {
return c.b(new i());
}
if (serverCredentials instanceof SslSocketFactoryServerCredentials.a) {
return c.b(new j((SslSocketFactoryServerCredentials.a) serverCredentials));
}
if (!(serverCredentials instanceof ChoiceServerCredentials)) {
return c.a("Unsupported credential type: " + serverCredentials.getClass().getName());
}
StringBuilder sb = new StringBuilder();
Iterator it = ((ChoiceServerCredentials) serverCredentials).getCredentialsList().iterator();
while (it.hasNext()) {
c c2 = c((ServerCredentials) it.next());
if (c2.b == null) {
return c2;
}
sb.append(", ");
sb.append(c2.b);
}
return c.a(sb.substring(2));
}
TlsServerCredentials tlsServerCredentials = (TlsServerCredentials) serverCredentials;
Set incomprehensible = tlsServerCredentials.incomprehensible(w);
if (!incomprehensible.isEmpty()) {
return c.a("TLS features not understood: " + incomprehensible);
}
if (tlsServerCredentials.getKeyManagers() != null) {
keyManagerArr = (KeyManager[]) tlsServerCredentials.getKeyManagers().toArray(new KeyManager[0]);
} else if (tlsServerCredentials.getPrivateKey() == null) {
keyManagerArr = null;
} else {
if (tlsServerCredentials.getPrivateKeyPassword() != null) {
return c.a("byte[]-based private key with password unsupported. Use unencrypted file or KeyManager");
}
try {
keyManagerArr = OkHttpChannelBuilder.c(tlsServerCredentials.getCertificateChain(), tlsServerCredentials.getPrivateKey());
} catch (GeneralSecurityException e2) {
r.log(Level.FINE, "Exception loading private key from credential", (Throwable) e2);
return c.a("Unable to load private key: " + e2.getMessage());
}
}
if (tlsServerCredentials.getTrustManagers() != null) {
e = (TrustManager[]) tlsServerCredentials.getTrustManagers().toArray(new TrustManager[0]);
} else if (tlsServerCredentials.getRootCertificates() != null) {
try {
e = OkHttpChannelBuilder.e(tlsServerCredentials.getRootCertificates());
} catch (GeneralSecurityException e3) {
r.log(Level.FINE, "Exception loading root certificates from credential", (Throwable) e3);
return c.a("Unable to load root certificates: " + e3.getMessage());
}
} else {
e = null;
}
try {
SSLContext sSLContext = SSLContext.getInstance("TLS", Platform.get().getProvider());
sSLContext.init(keyManagerArr, e, null);
SSLSocketFactory socketFactory = sSLContext.getSocketFactory();
int i = a.a[tlsServerCredentials.getClientAuth().ordinal()];
if (i == 1) {
bVar = new b(socketFactory, false);
} else {
if (i != 2) {
if (i != 3) {
return c.a("Unknown TlsServerCredentials.ClientAuth value: " + tlsServerCredentials.getClientAuth());
}
return c.b(new j(new SslSocketFactoryServerCredentials.a(socketFactory)));
}
bVar = new b(socketFactory, true);
}
socketFactory = bVar;
return c.b(new j(new SslSocketFactoryServerCredentials.a(socketFactory)));
} catch (GeneralSecurityException e4) {
throw new RuntimeException("TLS Provider failure", e4);
}
}
@DoNotCall("Always throws. Use forPort(int, ServerCredentials) instead")
@Deprecated
public static OkHttpServerBuilder forPort(int i) {
throw new UnsupportedOperationException();
}
public InternalServer b(List<? extends ServerStreamTracer.Factory> list) {
return new f(this, list, this.a.getChannelz());
}
public OkHttpServerBuilder d(TransportTracer.Factory factory) {
this.d = factory;
return this;
}
@Internal
public ServerBuilder<?> delegate() {
return this.a;
}
public OkHttpServerBuilder flowControlWindow(int i) {
Preconditions.checkState(i > 0, "flowControlWindow must be positive");
this.j = i;
return this;
}
public OkHttpServerBuilder scheduledExecutorService(ScheduledExecutorService scheduledExecutorService) {
this.f = new FixedObjectPool((ScheduledExecutorService) Preconditions.checkNotNull(scheduledExecutorService, "scheduledExecutorService"));
return this;
}
public void setStatsEnabled(boolean z) {
this.a.setStatsEnabled(z);
}
public OkHttpServerBuilder socketFactory(ServerSocketFactory serverSocketFactory) {
if (serverSocketFactory == null) {
this.g = ServerSocketFactory.getDefault();
} else {
this.g = serverSocketFactory;
}
return this;
}
public OkHttpServerBuilder transportExecutor(Executor executor) {
if (executor == null) {
this.e = v;
} else {
this.e = new FixedObjectPool(executor);
}
return this;
}
public static OkHttpServerBuilder forPort(int i, ServerCredentials serverCredentials) {
return forPort(new InetSocketAddress(i), serverCredentials);
}
public OkHttpServerBuilder keepAliveTime(long j, TimeUnit timeUnit) {
Preconditions.checkArgument(j > 0, "keepalive time must be positive");
long nanos = timeUnit.toNanos(j);
this.h = nanos;
long clampKeepAliveTimeInNanos = KeepAliveManager.clampKeepAliveTimeInNanos(nanos);
this.h = clampKeepAliveTimeInNanos;
if (clampKeepAliveTimeInNanos >= u) {
this.h = Long.MAX_VALUE;
}
return this;
}
public OkHttpServerBuilder keepAliveTimeout(long j, TimeUnit timeUnit) {
Preconditions.checkArgument(j > 0, "keepalive timeout must be positive");
long nanos = timeUnit.toNanos(j);
this.i = nanos;
this.i = KeepAliveManager.clampKeepAliveTimeoutInNanos(nanos);
return this;
}
public OkHttpServerBuilder maxConnectionAge(long j, TimeUnit timeUnit) {
Preconditions.checkArgument(j > 0, "max connection age must be positive: %s", j);
long nanos = timeUnit.toNanos(j);
this.p = nanos;
if (nanos >= u) {
this.p = Long.MAX_VALUE;
}
long j2 = this.p;
long j3 = t;
if (j2 < j3) {
this.p = j3;
}
return this;
}
public OkHttpServerBuilder maxConnectionAgeGrace(long j, TimeUnit timeUnit) {
Preconditions.checkArgument(j >= 0, "max connection age grace must be non-negative: %s", j);
long nanos = timeUnit.toNanos(j);
this.q = nanos;
if (nanos >= u) {
this.q = Long.MAX_VALUE;
}
return this;
}
public OkHttpServerBuilder maxConnectionIdle(long j, TimeUnit timeUnit) {
Preconditions.checkArgument(j > 0, "max connection idle must be positive: %s", j);
long nanos = timeUnit.toNanos(j);
this.m = nanos;
if (nanos >= u) {
this.m = Long.MAX_VALUE;
}
long j2 = this.m;
long j3 = s;
if (j2 < j3) {
this.m = j3;
}
return this;
}
public OkHttpServerBuilder maxInboundMessageSize(int i) {
Preconditions.checkArgument(i >= 0, "negative max bytes");
this.l = i;
return this;
}
public OkHttpServerBuilder maxInboundMetadataSize(int i) {
Preconditions.checkArgument(i > 0, "maxInboundMetadataSize must be > 0");
this.k = i;
return this;
}
@CanIgnoreReturnValue
public OkHttpServerBuilder permitKeepAliveTime(long j, TimeUnit timeUnit) {
Preconditions.checkArgument(j >= 0, "permit keepalive time must be non-negative: %s", j);
this.o = timeUnit.toNanos(j);
return this;
}
@CanIgnoreReturnValue
public OkHttpServerBuilder permitKeepAliveWithoutCalls(boolean z) {
this.n = z;
return this;
}
public static OkHttpServerBuilder forPort(SocketAddress socketAddress, ServerCredentials serverCredentials) {
c c2 = c(serverCredentials);
if (c2.b == null) {
return new OkHttpServerBuilder(socketAddress, c2.a);
}
throw new IllegalArgumentException(c2.b);
}
}