正在查看: SpeedCash v6.5.1482 应用的 h.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: SpeedCash v6.5.1482 应用的 h.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package io.grpc.okhttp;
import com.google.common.base.Preconditions;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import defpackage.et1;
import defpackage.il1;
import defpackage.qe3;
import defpackage.rx5;
import io.grpc.Attributes;
import io.grpc.InternalChannelz;
import io.grpc.InternalLogId;
import io.grpc.InternalStatus;
import io.grpc.Metadata;
import io.grpc.ServerStreamTracer;
import io.grpc.Status;
import io.grpc.internal.GrpcUtil;
import io.grpc.internal.KeepAliveEnforcer;
import io.grpc.internal.KeepAliveManager;
import io.grpc.internal.LogExceptionRunnable;
import io.grpc.internal.MaxConnectionIdleManager;
import io.grpc.internal.ObjectPool;
import io.grpc.internal.SerializingExecutor;
import io.grpc.internal.ServerTransport;
import io.grpc.internal.ServerTransportListener;
import io.grpc.internal.StatsTraceContext;
import io.grpc.internal.TransportTracer;
import io.grpc.okhttp.HandshakerSocketFactory;
import io.grpc.okhttp.OutboundFlowController;
import io.grpc.okhttp.b;
import io.grpc.okhttp.e;
import io.grpc.okhttp.g;
import io.grpc.okhttp.h;
import io.grpc.okhttp.internal.framed.ErrorCode;
import io.grpc.okhttp.internal.framed.FrameReader;
import io.grpc.okhttp.internal.framed.FrameWriter;
import io.grpc.okhttp.internal.framed.HeadersMode;
import io.grpc.okhttp.internal.framed.Http2;
import io.grpc.okhttp.internal.framed.Settings;
import io.grpc.okhttp.internal.framed.Variant;
import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.TreeMap;
import java.util.concurrent.Executor;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.concurrent.GuardedBy;
import okhttp3.internal.http2.Header;
import okio.Buffer;
import okio.BufferedSource;
import okio.ByteString;
import okio.Okio;
public final class h implements ServerTransport, b.a, OutboundFlowController.Transport {
public static final Logger A = Logger.getLogger(h.class.getName());
public static final ByteString B = ByteString.encodeUtf8(Header.TARGET_METHOD_UTF8);
public static final ByteString C = ByteString.encodeUtf8("CONNECT");
public static final ByteString D = ByteString.encodeUtf8(GrpcUtil.HTTP_METHOD);
public static final ByteString E = ByteString.encodeUtf8(Header.TARGET_SCHEME_UTF8);
public static final ByteString F = ByteString.encodeUtf8(Header.TARGET_PATH_UTF8);
public static final ByteString G = ByteString.encodeUtf8(Header.TARGET_AUTHORITY_UTF8);
public static final ByteString H = ByteString.encodeUtf8("connection");
public static final ByteString I = ByteString.encodeUtf8("host");
public static final ByteString J = ByteString.encodeUtf8("te");
public static final ByteString K = ByteString.encodeUtf8(GrpcUtil.TE_TRAILERS);
public static final ByteString L = ByteString.encodeUtf8("content-type");
public static final ByteString M = ByteString.encodeUtf8("content-length");
public final b a;
public final Socket b;
public final TransportTracer d;
public final InternalLogId e;
public ServerTransportListener f;
public Executor g;
public ScheduledExecutorService h;
public Attributes i;
public KeepAliveManager j;
public MaxConnectionIdleManager k;
public ScheduledFuture<?> l;
public final KeepAliveEnforcer m;
@GuardedBy("lock")
public boolean o;
@GuardedBy("lock")
public boolean p;
@GuardedBy("lock")
public boolean q;
@GuardedBy("lock")
public InternalChannelz.Security r;
@GuardedBy("lock")
public io.grpc.okhttp.b s;
@GuardedBy("lock")
public OutboundFlowController t;
@GuardedBy("lock")
public int v;
@GuardedBy("lock")
public Status x;
@GuardedBy("lock")
public ScheduledFuture<?> y;
@GuardedBy("lock")
public ScheduledFuture<?> z;
public final Variant c = new Http2();
public final Object n = new Object();
@GuardedBy("lock")
public final Map<Integer, f> u = new TreeMap();
@GuardedBy("lock")
public int w = Integer.MAX_VALUE;
public class a extends il1 {
public a(FrameWriter frameWriter) {
super(frameWriter);
}
@Override
public void data(boolean z, int i, Buffer buffer, int i2) throws IOException {
h.this.m.resetCounters();
super.data(z, i, buffer, i2);
}
@Override
public void headers(int i, List<io.grpc.okhttp.internal.framed.Header> list) throws IOException {
h.this.m.resetCounters();
super.headers(i, list);
}
@Override
public void synReply(boolean z, int i, List<io.grpc.okhttp.internal.framed.Header> list) throws IOException {
h.this.m.resetCounters();
super.synReply(z, i, list);
}
}
public static final class b {
public final List<? extends ServerStreamTracer.Factory> a;
public final ObjectPool<Executor> b;
public final ObjectPool<ScheduledExecutorService> c;
public final TransportTracer.Factory d;
public final HandshakerSocketFactory e;
public final long f;
public final long g;
public final int h;
public final int i;
public final int j;
public final long k;
public final boolean l;
public final long m;
public final long n;
public final long o;
public b(OkHttpServerBuilder okHttpServerBuilder, List<? extends ServerStreamTracer.Factory> list) {
this.a = (List) Preconditions.checkNotNull(list, "streamTracerFactories");
this.b = (ObjectPool) Preconditions.checkNotNull(okHttpServerBuilder.e, "transportExecutorPool");
this.c = (ObjectPool) Preconditions.checkNotNull(okHttpServerBuilder.f, "scheduledExecutorServicePool");
this.d = (TransportTracer.Factory) Preconditions.checkNotNull(okHttpServerBuilder.d, "transportTracerFactory");
this.e = (HandshakerSocketFactory) Preconditions.checkNotNull(okHttpServerBuilder.c, "handshakerSocketFactory");
this.f = okHttpServerBuilder.h;
this.g = okHttpServerBuilder.i;
this.h = okHttpServerBuilder.j;
this.i = okHttpServerBuilder.l;
this.j = okHttpServerBuilder.k;
this.k = okHttpServerBuilder.m;
this.l = okHttpServerBuilder.n;
this.m = okHttpServerBuilder.o;
this.n = okHttpServerBuilder.p;
this.o = okHttpServerBuilder.q;
}
}
public class c implements FrameReader.Handler, Runnable {
public final io.grpc.okhttp.e a = new io.grpc.okhttp.e(Level.FINE, (Class<?>) h.class);
public final FrameReader b;
public boolean c;
public int d;
public c(FrameReader frameReader) {
this.b = frameReader;
}
@Override
public void ackSettings() {
}
@Override
public void alternateService(int i, String str, ByteString byteString, String str2, int i2, long j) {
}
public final void b(ErrorCode errorCode, String str) {
h.this.g(errorCode, str, GrpcUtil.Http2Error.statusForCode(errorCode.httpCode).withDescription(String.format("HTTP2 connection error: %s '%s'", errorCode, str)), false);
}
public final int c(List<io.grpc.okhttp.internal.framed.Header> list) {
long j = 0;
for (int i = 0; i < list.size(); i++) {
io.grpc.okhttp.internal.framed.Header header = list.get(i);
j += header.name.size() + 32 + header.value.size();
}
return (int) Math.min(j, 2147483647L);
}
@Override
public void data(boolean z, int i, BufferedSource bufferedSource, int i2) throws IOException {
this.a.b(e.a.INBOUND, i, bufferedSource.getBuffer(), i2, z);
if (i == 0) {
b(ErrorCode.PROTOCOL_ERROR, "Stream 0 is reserved for control messages. RFC7540 section 5.1.1");
return;
}
if ((i & 1) == 0) {
b(ErrorCode.PROTOCOL_ERROR, "Clients cannot open even numbered streams. RFC7540 section 5.1.1");
return;
}
long j = i2;
bufferedSource.require(j);
synchronized (h.this.n) {
f fVar = (f) h.this.u.get(Integer.valueOf(i));
if (fVar == null) {
bufferedSource.skip(j);
h(i, ErrorCode.STREAM_CLOSED, "Received data for closed stream");
return;
}
if (fVar.d()) {
bufferedSource.skip(j);
h(i, ErrorCode.STREAM_CLOSED, "Received DATA for half-closed (remote) stream. RFC7540 section 5.1");
return;
}
if (fVar.b() < i2) {
bufferedSource.skip(j);
h(i, ErrorCode.FLOW_CONTROL_ERROR, "Received DATA size exceeded window size. RFC7540 section 6.9");
return;
}
Buffer buffer = new Buffer();
buffer.write(bufferedSource.getBuffer(), j);
fVar.a(buffer, i2, z);
int i3 = this.d + i2;
this.d = i3;
if (i3 >= h.this.a.h * 0.5f) {
synchronized (h.this.n) {
h.this.s.windowUpdate(0, this.d);
h.this.s.flush();
}
this.d = 0;
}
}
}
public final void e(int i, boolean z, Status.Code code, String str) {
Metadata metadata = new Metadata();
metadata.put(InternalStatus.CODE_KEY, code.toStatus());
metadata.put(InternalStatus.MESSAGE_KEY, str);
List<io.grpc.okhttp.internal.framed.Header> e = et1.e(metadata, false);
synchronized (h.this.n) {
h.this.s.synReply(true, i, e);
if (!z) {
h.this.s.rstStream(i, ErrorCode.NO_ERROR);
}
h.this.s.flush();
}
}
public final void f(int i, boolean z, int i2, Status.Code code, String str) {
Metadata metadata = new Metadata();
metadata.put(InternalStatus.CODE_KEY, code.toStatus());
metadata.put(InternalStatus.MESSAGE_KEY, str);
List<io.grpc.okhttp.internal.framed.Header> b = et1.b(i2, "text/plain; charset=utf-8", metadata);
Buffer writeUtf8 = new Buffer().writeUtf8(str);
synchronized (h.this.n) {
final d dVar = new d(i, h.this.n, h.this.t, h.this.a.h);
if (h.this.u.isEmpty()) {
h.this.m.onTransportActive();
if (h.this.k != null) {
h.this.k.onTransportActive();
}
}
h.this.u.put(Integer.valueOf(i), dVar);
if (z) {
dVar.a(new Buffer(), 0, true);
}
h.this.s.headers(i, b);
h.this.t.d(true, dVar.e(), writeUtf8, true);
h.this.t.g(dVar.e(), new Runnable() {
@Override
public final void run() {
h.c.this.d(dVar);
}
});
}
}
public final void d(d dVar) {
synchronized (h.this.n) {
if (!dVar.d()) {
h.this.s.rstStream(dVar.a, ErrorCode.NO_ERROR);
}
h.this.f0(dVar.a, true);
}
}
@Override
public void goAway(int i, ErrorCode errorCode, ByteString byteString) {
this.a.c(e.a.INBOUND, i, errorCode, byteString);
Status withDescription = GrpcUtil.Http2Error.statusForCode(errorCode.httpCode).withDescription(String.format("Received GOAWAY: %s '%s'", errorCode, byteString.utf8()));
if (!ErrorCode.NO_ERROR.equals(errorCode)) {
h.A.log(Level.WARNING, "Received GOAWAY: {0} {1}", new Object[]{errorCode, byteString.utf8()});
}
synchronized (h.this.n) {
h.this.x = withDescription;
}
}
public final void h(int i, ErrorCode errorCode, String str) {
if (errorCode == ErrorCode.PROTOCOL_ERROR) {
h.A.log(Level.FINE, "Responding with RST_STREAM {0}: {1}", new Object[]{errorCode, str});
}
synchronized (h.this.n) {
h.this.s.rstStream(i, errorCode);
h.this.s.flush();
f fVar = (f) h.this.u.get(Integer.valueOf(i));
if (fVar != null) {
fVar.transportReportStatus(Status.INTERNAL.withDescription(String.format("Responded with RST_STREAM %s: %s", errorCode, str)));
h.this.f0(i, false);
}
}
}
@Override
public void headers(boolean z, boolean z2, int i, int i2, List<io.grpc.okhttp.internal.framed.Header> list, HeadersMode headersMode) {
int W;
this.a.d(e.a.INBOUND, i, list, z2);
if ((i & 1) == 0) {
b(ErrorCode.PROTOCOL_ERROR, "Clients cannot open even numbered streams. RFC7540 section 5.1.1");
return;
}
synchronized (h.this.n) {
if (i > h.this.w) {
return;
}
boolean z3 = i > h.this.v;
if (z3) {
h.this.v = i;
}
int c = c(list);
if (c > h.this.a.j) {
f(i, z2, 431, Status.Code.RESOURCE_EXHAUSTED, String.format(Locale.US, "Request metadata larger than %d: %d", Integer.valueOf(h.this.a.j), Integer.valueOf(c)));
return;
}
h.Y(list, ByteString.EMPTY);
String str = null;
ByteString byteString = null;
ByteString byteString2 = null;
ByteString byteString3 = null;
ByteString byteString4 = null;
while (list.size() > 0 && list.get(0).name.getByte(0) == 58) {
io.grpc.okhttp.internal.framed.Header remove = list.remove(0);
if (h.B.equals(remove.name) && byteString == null) {
byteString = remove.value;
} else if (h.E.equals(remove.name) && byteString2 == null) {
byteString2 = remove.value;
} else if (h.F.equals(remove.name) && byteString3 == null) {
byteString3 = remove.value;
} else {
if (!h.G.equals(remove.name) || byteString4 != null) {
h(i, ErrorCode.PROTOCOL_ERROR, "Unexpected pseudo header. RFC7540 section 8.1.2.1");
return;
}
byteString4 = remove.value;
}
}
for (int i3 = 0; i3 < list.size(); i3++) {
if (list.get(i3).name.getByte(0) == 58) {
h(i, ErrorCode.PROTOCOL_ERROR, "Pseudo header not before regular headers. RFC7540 section 8.1.2.1");
return;
}
}
if (!h.C.equals(byteString) && z3 && (byteString == null || byteString2 == null || byteString3 == null)) {
h(i, ErrorCode.PROTOCOL_ERROR, "Missing required pseudo header. RFC7540 section 8.1.2.3");
return;
}
if (h.V(list, h.H)) {
h(i, ErrorCode.PROTOCOL_ERROR, "Connection-specific headers not permitted. RFC7540 section 8.1.2.2");
return;
}
if (!z3) {
if (!z2) {
h(i, ErrorCode.PROTOCOL_ERROR, "Headers disallowed in the middle of the stream. RFC7540 section 8.1");
return;
}
synchronized (h.this.n) {
f fVar = (f) h.this.u.get(Integer.valueOf(i));
if (fVar == null) {
h(i, ErrorCode.STREAM_CLOSED, "Received headers for closed stream");
return;
} else if (fVar.d()) {
h(i, ErrorCode.STREAM_CLOSED, "Received HEADERS for half-closed (remote) stream. RFC7540 section 5.1");
return;
} else {
fVar.a(new Buffer(), 0, true);
return;
}
}
}
if (byteString4 == null && (W = h.W(list, h.I, 0)) != -1) {
if (h.W(list, h.I, W + 1) != -1) {
f(i, z2, 400, Status.Code.INTERNAL, "Multiple host headers disallowed. RFC7230 section 5.4");
return;
}
byteString4 = list.get(W).value;
}
ByteString byteString5 = byteString4;
h.Y(list, h.I);
if (byteString3.size() == 0 || byteString3.getByte(0) != 47) {
f(i, z2, 404, Status.Code.UNIMPLEMENTED, "Expected path to start with /: " + h.U(byteString3));
return;
}
String substring = h.U(byteString3).substring(1);
ByteString X = h.X(list, h.L);
if (X == null) {
f(i, z2, 415, Status.Code.INTERNAL, "Content-Type is missing or duplicated");
return;
}
String U = h.U(X);
if (!GrpcUtil.isGrpcContentType(U)) {
f(i, z2, 415, Status.Code.INTERNAL, "Content-Type is not supported: " + U);
return;
}
if (!h.D.equals(byteString)) {
f(i, z2, 405, Status.Code.INTERNAL, "HTTP Method is not supported: " + h.U(byteString));
return;
}
ByteString X2 = h.X(list, h.J);
if (!h.K.equals(X2)) {
Status.Code code = Status.Code.INTERNAL;
Object[] objArr = new Object[2];
objArr[0] = h.U(h.K);
objArr[1] = X2 == null ? "<missing>" : h.U(X2);
e(i, z2, code, String.format("Expected header TE: %s, but %s is received. Some intermediate proxy may not support trailers", objArr));
return;
}
h.Y(list, h.M);
Metadata a = rx5.a(list);
StatsTraceContext newServerContext = StatsTraceContext.newServerContext(h.this.a.a, substring, a);
synchronized (h.this.n) {
h hVar = h.this;
g.b bVar = new g.b(hVar, i, hVar.a.i, newServerContext, h.this.n, h.this.s, h.this.t, h.this.a.h, h.this.d, substring);
Attributes attributes = h.this.i;
if (byteString5 != null) {
str = h.U(byteString5);
}
g gVar = new g(bVar, attributes, str, newServerContext, h.this.d);
if (h.this.u.isEmpty()) {
h.this.m.onTransportActive();
if (h.this.k != null) {
h.this.k.onTransportActive();
}
}
h.this.u.put(Integer.valueOf(i), bVar);
h.this.f.streamCreated(gVar, substring, a);
bVar.onStreamAllocated();
if (z2) {
bVar.a(new Buffer(), 0, z2);
}
}
}
}
@Override
public void ping(boolean z, int i, int i2) {
if (!h.this.m.pingAcceptable()) {
h.this.g(ErrorCode.ENHANCE_YOUR_CALM, "too_many_pings", Status.RESOURCE_EXHAUSTED.withDescription("Too many pings from client"), false);
return;
}
long j = (i << 32) | (i2 & 4294967295L);
if (!z) {
this.a.e(e.a.INBOUND, j);
synchronized (h.this.n) {
h.this.s.ping(true, i, i2);
h.this.s.flush();
}
return;
}
this.a.f(e.a.INBOUND, j);
if (57005 == j) {
return;
}
if (4369 == j) {
h.this.i0();
return;
}
h.A.log(Level.INFO, "Received unexpected ping ack: " + j);
}
@Override
public void priority(int i, int i2, int i3, boolean z) {
this.a.g(e.a.INBOUND, i, i2, i3, z);
}
@Override
public void pushPromise(int i, int i2, List<io.grpc.okhttp.internal.framed.Header> list) throws IOException {
this.a.h(e.a.INBOUND, i, i2, list);
b(ErrorCode.PROTOCOL_ERROR, "PUSH_PROMISE only allowed on peer-initiated streams. RFC7540 section 6.6");
}
@Override
public void rstStream(int i, ErrorCode errorCode) {
this.a.i(e.a.INBOUND, i, errorCode);
if (!ErrorCode.NO_ERROR.equals(errorCode) && !ErrorCode.CANCEL.equals(errorCode) && !ErrorCode.STREAM_CLOSED.equals(errorCode)) {
h.A.log(Level.INFO, "Received RST_STREAM: " + errorCode);
}
Status withDescription = GrpcUtil.Http2Error.statusForCode(errorCode.httpCode).withDescription("RST_STREAM");
synchronized (h.this.n) {
f fVar = (f) h.this.u.get(Integer.valueOf(i));
if (fVar != null) {
fVar.c(withDescription);
h.this.f0(i, false);
}
}
}
@Override
public void run() {
InputStream inputStream;
Status status;
InputStream inputStream2;
String name = Thread.currentThread().getName();
Thread.currentThread().setName("OkHttpServerTransport");
try {
try {
this.b.readConnectionPreface();
} catch (IOException unused) {
}
} catch (Throwable th) {
try {
h.A.log(Level.WARNING, "Error decoding HTTP/2 frames", th);
h.this.g(ErrorCode.INTERNAL_ERROR, "Error in frame decoder", Status.INTERNAL.withDescription("Error decoding HTTP/2 frames").withCause(th), false);
inputStream = h.this.b.getInputStream();
} catch (Throwable th2) {
try {
GrpcUtil.exhaust(h.this.b.getInputStream());
} catch (IOException unused2) {
}
GrpcUtil.closeQuietly(h.this.b);
h.this.g0();
Thread.currentThread().setName(name);
throw th2;
}
}
if (!this.b.nextFrame(this)) {
b(ErrorCode.INTERNAL_ERROR, "Failed to read initial SETTINGS");
inputStream2 = h.this.b.getInputStream();
} else {
if (this.c) {
while (this.b.nextFrame(this)) {
if (h.this.j != null) {
h.this.j.onDataReceived();
}
}
synchronized (h.this.n) {
status = h.this.x;
}
if (status == null) {
status = Status.UNAVAILABLE.withDescription("TCP connection closed or IOException");
}
h.this.g(ErrorCode.INTERNAL_ERROR, "I/O failure", status, false);
inputStream = h.this.b.getInputStream();
GrpcUtil.exhaust(inputStream);
GrpcUtil.closeQuietly(h.this.b);
h.this.g0();
Thread.currentThread().setName(name);
return;
}
b(ErrorCode.PROTOCOL_ERROR, "First HTTP/2 frame must be SETTINGS. RFC7540 section 3.5");
inputStream2 = h.this.b.getInputStream();
}
GrpcUtil.exhaust(inputStream2);
GrpcUtil.closeQuietly(h.this.b);
h.this.g0();
Thread.currentThread().setName(name);
}
@Override
public void settings(boolean z, Settings settings) {
boolean z2;
this.a.j(e.a.INBOUND, settings);
synchronized (h.this.n) {
if (qe3.b(settings, 7)) {
z2 = h.this.t.f(qe3.a(settings, 7));
} else {
z2 = false;
}
h.this.s.ackSettings(settings);
h.this.s.flush();
if (!this.c) {
this.c = true;
h hVar = h.this;
hVar.i = hVar.f.transportReady(h.this.i);
}
if (z2) {
h.this.t.i();
}
}
}
@Override
public void windowUpdate(int i, long j) {
this.a.l(e.a.INBOUND, i, j);
synchronized (h.this.n) {
if (i == 0) {
h.this.t.h(null, (int) j);
} else {
f fVar = (f) h.this.u.get(Integer.valueOf(i));
if (fVar != null) {
h.this.t.h(fVar.e(), (int) j);
}
}
}
}
}
public static class d implements f, OutboundFlowController.Stream {
public final int a;
public final Object b;
public final OutboundFlowController.StreamState c;
@GuardedBy("lock")
public int d;
@GuardedBy("lock")
public boolean e;
public d(int i, Object obj, OutboundFlowController outboundFlowController, int i2) {
this.a = i;
this.b = obj;
this.c = outboundFlowController.c(this, i);
this.d = i2;
}
@Override
public void a(Buffer buffer, int i, boolean z) {
synchronized (this.b) {
if (z) {
this.e = true;
}
this.d -= i;
try {
buffer.skip(buffer.size());
} catch (IOException e) {
throw new AssertionError(e);
}
}
}
@Override
public int b() {
int i;
synchronized (this.b) {
i = this.d;
}
return i;
}
@Override
public void c(Status status) {
}
@Override
public boolean d() {
boolean z;
synchronized (this.b) {
z = this.e;
}
return z;
}
@Override
public OutboundFlowController.StreamState e() {
OutboundFlowController.StreamState streamState;
synchronized (this.b) {
streamState = this.c;
}
return streamState;
}
@Override
public void onSentBytes(int i) {
}
@Override
public void transportReportStatus(Status status) {
}
}
public final class e implements KeepAliveManager.KeepAlivePinger {
public e() {
}
@Override
public void onPingTimeout() {
synchronized (h.this.n) {
h.this.x = Status.UNAVAILABLE.withDescription("Keepalive failed. Considering connection dead");
GrpcUtil.closeQuietly(h.this.b);
}
}
@Override
public void ping() {
synchronized (h.this.n) {
h.this.s.ping(false, 0, 57005);
h.this.s.flush();
}
h.this.d.reportKeepAliveSent();
}
public e(h hVar, a aVar) {
this();
}
}
public interface f {
void a(Buffer buffer, int i, boolean z);
int b();
void c(Status status);
boolean d();
OutboundFlowController.StreamState e();
void transportReportStatus(Status status);
}
public h(b bVar, Socket socket) {
this.a = (b) Preconditions.checkNotNull(bVar, "config");
this.b = (Socket) Preconditions.checkNotNull(socket, "bareSocket");
TransportTracer create = bVar.d.create();
this.d = create;
create.setFlowControlWindowReader(new TransportTracer.FlowControlReader() {
@Override
public final TransportTracer.FlowControlWindows read() {
TransportTracer.FlowControlWindows b0;
b0 = h.this.b0();
return b0;
}
});
this.e = InternalLogId.allocate(h.class, socket.getRemoteSocketAddress().toString());
this.g = bVar.b.getObject();
this.h = bVar.c.getObject();
this.m = new KeepAliveEnforcer(bVar.l, bVar.m, TimeUnit.NANOSECONDS);
}
public static String U(ByteString byteString) {
for (int i = 0; i < byteString.size(); i++) {
if (byteString.getByte(i) >= 128) {
return byteString.string(GrpcUtil.US_ASCII);
}
}
return byteString.utf8();
}
public static boolean V(List<io.grpc.okhttp.internal.framed.Header> list, ByteString byteString) {
return W(list, byteString, 0) != -1;
}
public static int W(List<io.grpc.okhttp.internal.framed.Header> list, ByteString byteString, int i) {
while (i < list.size()) {
if (list.get(i).name.equals(byteString)) {
return i;
}
i++;
}
return -1;
}
public static ByteString X(List<io.grpc.okhttp.internal.framed.Header> list, ByteString byteString) {
int W = W(list, byteString, 0);
if (W != -1 && W(list, byteString, W + 1) == -1) {
return list.get(W).value;
}
return null;
}
public static void Y(List<io.grpc.okhttp.internal.framed.Header> list, ByteString byteString) {
int i = 0;
while (true) {
i = W(list, byteString, i);
if (i == -1) {
return;
} else {
list.remove(i);
}
}
}
public void a0() {
c0(Long.valueOf(this.a.o));
}
@Override
public void a(Throwable th) {
Preconditions.checkNotNull(th, "failureCause");
g(ErrorCode.INTERNAL_ERROR, "I/O failure", Status.UNAVAILABLE.withCause(th), false);
}
public final TransportTracer.FlowControlWindows b0() {
TransportTracer.FlowControlWindows flowControlWindows;
synchronized (this.n) {
flowControlWindows = new TransportTracer.FlowControlWindows(this.t == null ? -1L : r1.h(null, 0), (long) (this.a.h * 0.5f));
}
return flowControlWindows;
}
public final void c0(Long l) {
synchronized (this.n) {
if (!this.p && !this.o) {
this.p = true;
if (this.s == null) {
this.q = true;
GrpcUtil.closeQuietly(this.b);
} else {
this.y = this.h.schedule(new Runnable() {
@Override
public final void run() {
h.this.i0();
}
}, l.longValue(), TimeUnit.NANOSECONDS);
this.s.goAway(Integer.MAX_VALUE, ErrorCode.NO_ERROR, new byte[0]);
this.s.ping(false, 0, 4369);
this.s.flush();
}
}
}
}
public void d0(ServerTransportListener serverTransportListener) {
this.f = (ServerTransportListener) Preconditions.checkNotNull(serverTransportListener, "listener");
final SerializingExecutor serializingExecutor = new SerializingExecutor(this.g);
serializingExecutor.execute(new Runnable() {
@Override
public final void run() {
h.this.Z(serializingExecutor);
}
});
}
public final void Z(SerializingExecutor serializingExecutor) {
try {
this.b.setTcpNoDelay(true);
HandshakerSocketFactory.HandshakeResult a2 = this.a.e.a(this.b, Attributes.EMPTY);
Socket socket = a2.socket;
this.i = a2.attributes;
io.grpc.okhttp.a m = io.grpc.okhttp.a.m(serializingExecutor, this, 10000);
m.k(Okio.sink(socket), socket);
a aVar = new a(m.l(this.c.newWriter(Okio.buffer(m), false)));
synchronized (this.n) {
this.r = a2.securityInfo;
io.grpc.okhttp.b bVar = new io.grpc.okhttp.b(this, aVar);
this.s = bVar;
this.t = new OutboundFlowController(this, bVar);
this.s.connectionPreface();
Settings settings = new Settings();
qe3.c(settings, 7, this.a.h);
qe3.c(settings, 6, this.a.j);
this.s.settings(settings);
if (this.a.h > 65535) {
this.s.windowUpdate(0, r0 - 65535);
}
this.s.flush();
}
if (this.a.f != Long.MAX_VALUE) {
e eVar = new e(this, null);
ScheduledExecutorService scheduledExecutorService = this.h;
b bVar2 = this.a;
KeepAliveManager keepAliveManager = new KeepAliveManager(eVar, scheduledExecutorService, bVar2.f, bVar2.g, true);
this.j = keepAliveManager;
keepAliveManager.onTransportStarted();
}
if (this.a.k != Long.MAX_VALUE) {
MaxConnectionIdleManager maxConnectionIdleManager = new MaxConnectionIdleManager(this.a.k);
this.k = maxConnectionIdleManager;
maxConnectionIdleManager.start(new Runnable() {
@Override
public final void run() {
h.this.shutdown();
}
}, this.h);
}
if (this.a.n != Long.MAX_VALUE) {
this.l = this.h.schedule(new LogExceptionRunnable(new Runnable() {
@Override
public final void run() {
h.this.a0();
}
}), (long) (((Math.random() * 0.2d) + 0.9d) * this.a.n), TimeUnit.NANOSECONDS);
}
this.g.execute(new c(this.c.newReader(Okio.buffer(Okio.source(socket)), false)));
} catch (IOException | Error | RuntimeException e2) {
synchronized (this.n) {
if (!this.q) {
A.log(Level.INFO, "Socket failed to handshake", e2);
}
}
GrpcUtil.closeQuietly(this.b);
g0();
}
}
public void f0(int i, boolean z) {
synchronized (this.n) {
this.u.remove(Integer.valueOf(i));
if (this.u.isEmpty()) {
this.m.onTransportIdle();
MaxConnectionIdleManager maxConnectionIdleManager = this.k;
if (maxConnectionIdleManager != null) {
maxConnectionIdleManager.onTransportIdle();
}
}
if (this.p && this.u.isEmpty()) {
this.s.close();
} else if (z) {
this.s.flush();
}
}
}
public final void g(ErrorCode errorCode, String str, Status status, boolean z) {
synchronized (this.n) {
if (this.o) {
return;
}
this.o = true;
this.x = status;
ScheduledFuture<?> scheduledFuture = this.y;
if (scheduledFuture != null) {
scheduledFuture.cancel(false);
this.y = null;
}
for (Map.Entry<Integer, f> entry : this.u.entrySet()) {
if (z) {
this.s.rstStream(entry.getKey().intValue(), ErrorCode.CANCEL);
}
entry.getValue().transportReportStatus(status);
}
this.u.clear();
this.s.goAway(this.v, errorCode, str.getBytes(GrpcUtil.US_ASCII));
this.w = this.v;
this.s.close();
this.z = this.h.schedule(new Runnable() {
@Override
public final void run() {
h.this.h0();
}
}, 1L, TimeUnit.SECONDS);
}
}
public final void g0() {
synchronized (this.n) {
ScheduledFuture<?> scheduledFuture = this.z;
if (scheduledFuture != null) {
scheduledFuture.cancel(false);
this.z = null;
}
}
KeepAliveManager keepAliveManager = this.j;
if (keepAliveManager != null) {
keepAliveManager.onTransportTermination();
}
MaxConnectionIdleManager maxConnectionIdleManager = this.k;
if (maxConnectionIdleManager != null) {
maxConnectionIdleManager.onTransportTermination();
}
ScheduledFuture<?> scheduledFuture2 = this.l;
if (scheduledFuture2 != null) {
scheduledFuture2.cancel(false);
}
this.g = this.a.b.returnObject(this.g);
this.h = this.a.c.returnObject(this.h);
this.f.transportTerminated();
}
@Override
public OutboundFlowController.StreamState[] getActiveStreams() {
OutboundFlowController.StreamState[] streamStateArr;
synchronized (this.n) {
streamStateArr = new OutboundFlowController.StreamState[this.u.size()];
Iterator<f> it = this.u.values().iterator();
int i = 0;
while (it.hasNext()) {
streamStateArr[i] = it.next().e();
i++;
}
}
return streamStateArr;
}
public InternalLogId getLogId() {
return this.e;
}
@Override
public ScheduledExecutorService getScheduledExecutorService() {
return this.h;
}
public ListenableFuture<InternalChannelz.SocketStats> getStats() {
ListenableFuture<InternalChannelz.SocketStats> immediateFuture;
synchronized (this.n) {
immediateFuture = Futures.immediateFuture(new InternalChannelz.SocketStats(this.d.getStats(), this.b.getLocalSocketAddress(), this.b.getRemoteSocketAddress(), rx5.e(this.b), this.r));
}
return immediateFuture;
}
public final void h0() {
GrpcUtil.closeQuietly(this.b);
}
public final void i0() {
synchronized (this.n) {
ScheduledFuture<?> scheduledFuture = this.y;
if (scheduledFuture == null) {
return;
}
scheduledFuture.cancel(false);
this.y = null;
this.s.goAway(this.v, ErrorCode.NO_ERROR, new byte[0]);
this.w = this.v;
if (this.u.isEmpty()) {
this.s.close();
} else {
this.s.flush();
}
}
}
@Override
public void shutdown() {
c0(Long.valueOf(TimeUnit.SECONDS.toNanos(1L)));
}
@Override
public void shutdownNow(Status status) {
synchronized (this.n) {
if (this.s != null) {
g(ErrorCode.NO_ERROR, "", status, true);
} else {
this.q = true;
GrpcUtil.closeQuietly(this.b);
}
}
}
}