导航菜单

页面标题

页面副标题

SpeedCash v6.5.1482 - d.java 源代码

正在查看: SpeedCash v6.5.1482 应用的 d.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package io.grpc.okhttp;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.MoreObjects;
import com.google.common.base.Preconditions;
import com.google.common.base.Stopwatch;
import com.google.common.base.Supplier;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.SettableFuture;
import defpackage.qe3;
import defpackage.re3;
import defpackage.rx5;
import io.grpc.Attributes;
import io.grpc.CallOptions;
import io.grpc.ClientStreamTracer;
import io.grpc.Grpc;
import io.grpc.HttpConnectProxiedSocketAddress;
import io.grpc.InternalChannelz;
import io.grpc.InternalLogId;
import io.grpc.Metadata;
import io.grpc.MethodDescriptor;
import io.grpc.SecurityLevel;
import io.grpc.Status;
import io.grpc.StatusException;
import io.grpc.internal.ClientStreamListener;
import io.grpc.internal.ClientTransport;
import io.grpc.internal.ConnectionClientTransport;
import io.grpc.internal.GrpcAttributes;
import io.grpc.internal.GrpcUtil;
import io.grpc.internal.Http2Ping;
import io.grpc.internal.InUseStateAggregator;
import io.grpc.internal.KeepAliveManager;
import io.grpc.internal.ManagedClientTransport;
import io.grpc.internal.SerializingExecutor;
import io.grpc.internal.StatsTraceContext;
import io.grpc.internal.TransportTracer;
import io.grpc.okhttp.OkHttpChannelBuilder;
import io.grpc.okhttp.OutboundFlowController;
import io.grpc.okhttp.b;
import io.grpc.okhttp.c;
import io.grpc.okhttp.e;
import io.grpc.okhttp.internal.ConnectionSpec;
import io.grpc.okhttp.internal.Credentials;
import io.grpc.okhttp.internal.StatusLine;
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.Header;
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 io.grpc.okhttp.internal.proxy.HttpUrl;
import io.grpc.okhttp.internal.proxy.Request;
import io.perfmark.PerfMark;
import java.io.EOFException;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketAddress;
import java.net.URI;
import java.util.Collections;
import java.util.Deque;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor;
import java.util.concurrent.ScheduledExecutorService;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.Nullable;
import javax.annotation.concurrent.GuardedBy;
import javax.net.SocketFactory;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
import okhttp3.internal.ws.RealWebSocket;
import okio.Buffer;
import okio.BufferedSink;
import okio.BufferedSource;
import okio.ByteString;
import okio.Okio;
import okio.Source;
import okio.Timeout;

public class d implements ConnectionClientTransport, b.a, OutboundFlowController.Transport {
    public static final Map<ErrorCode, Status> W = J();
    public static final Logger X = Logger.getLogger(d.class.getName());
    public final SocketFactory A;
    public SSLSocketFactory B;
    public HostnameVerifier C;
    public Socket D;

    @GuardedBy("lock")
    public int E;

    @GuardedBy("lock")
    public final Deque<io.grpc.okhttp.c> F;
    public final ConnectionSpec G;
    public KeepAliveManager H;
    public boolean I;
    public long J;
    public long K;
    public boolean L;
    public final Runnable M;
    public final int N;
    public final boolean O;

    @GuardedBy("lock")
    public final TransportTracer P;

    @GuardedBy("lock")
    public final InUseStateAggregator<io.grpc.okhttp.c> Q;

    @GuardedBy("lock")
    public InternalChannelz.Security R;

    @VisibleForTesting
    @Nullable
    public final HttpConnectProxiedSocketAddress S;

    @VisibleForTesting
    public int T;
    public Runnable U;
    public SettableFuture<Void> V;
    public final InetSocketAddress a;
    public final String b;
    public final String c;
    public final Random d;
    public final Supplier<Stopwatch> e;
    public final int f;
    public final Variant g;
    public ManagedClientTransport.Listener h;

    @GuardedBy("lock")
    public io.grpc.okhttp.b i;
    public OutboundFlowController j;
    public final Object k;
    public final InternalLogId l;

    @GuardedBy("lock")
    public int m;

    @GuardedBy("lock")
    public final Map<Integer, io.grpc.okhttp.c> n;
    public final Executor o;
    public final SerializingExecutor p;
    public final ScheduledExecutorService q;
    public final int r;
    public int s;
    public e t;
    public Attributes u;

    @GuardedBy("lock")
    public Status v;

    @GuardedBy("lock")
    public boolean w;

    @GuardedBy("lock")
    public Http2Ping x;

    @GuardedBy("lock")
    public boolean y;

    @GuardedBy("lock")
    public boolean z;

    public class a extends InUseStateAggregator<io.grpc.okhttp.c> {
        public a() {
        }

        @Override
        public void handleInUse() {
            d.this.h.transportInUse(true);
        }

        @Override
        public void handleNotInUse() {
            d.this.h.transportInUse(false);
        }
    }

    public class b implements TransportTracer.FlowControlReader {
        public b() {
        }

        @Override
        public TransportTracer.FlowControlWindows read() {
            TransportTracer.FlowControlWindows flowControlWindows;
            synchronized (d.this.k) {
                flowControlWindows = new TransportTracer.FlowControlWindows(d.this.j == null ? -1L : d.this.j.h(null, 0), (long) (d.this.f * 0.5f));
            }
            return flowControlWindows;
        }
    }

    public class c implements Runnable {
        public final CountDownLatch a;
        public final io.grpc.okhttp.a b;

        public class a implements Source {
            public a() {
            }

            @Override
            public void close() {
            }

            @Override
            public long read(Buffer buffer, long j) {
                return -1L;
            }

            @Override
            public Timeout getTimeout() {
                return Timeout.NONE;
            }
        }

        public c(CountDownLatch countDownLatch, io.grpc.okhttp.a aVar) {
            this.a = countDownLatch;
            this.b = aVar;
        }

        @Override
        public void run() {
            d dVar;
            e eVar;
            Socket L;
            SSLSession sSLSession;
            Socket socket;
            try {
                this.a.await();
            } catch (InterruptedException unused) {
                Thread.currentThread().interrupt();
            }
            BufferedSource buffer = Okio.buffer(new a());
            try {
                try {
                    d dVar2 = d.this;
                    HttpConnectProxiedSocketAddress httpConnectProxiedSocketAddress = dVar2.S;
                    if (httpConnectProxiedSocketAddress == null) {
                        L = dVar2.A.createSocket(d.this.a.getAddress(), d.this.a.getPort());
                    } else {
                        if (!(httpConnectProxiedSocketAddress.getProxyAddress() instanceof InetSocketAddress)) {
                            throw Status.INTERNAL.withDescription("Unsupported SocketAddress implementation " + d.this.S.getProxyAddress().getClass()).asException();
                        }
                        d dVar3 = d.this;
                        L = dVar3.L(dVar3.S.getTargetAddress(), (InetSocketAddress) d.this.S.getProxyAddress(), d.this.S.getUsername(), d.this.S.getPassword());
                    }
                    Socket socket2 = L;
                    if (d.this.B != null) {
                        SSLSocket b = re3.b(d.this.B, d.this.C, socket2, d.this.O(), d.this.P(), d.this.G);
                        sSLSession = b.getSession();
                        socket = b;
                    } else {
                        sSLSession = null;
                        socket = socket2;
                    }
                    socket.setTcpNoDelay(true);
                    BufferedSource buffer2 = Okio.buffer(Okio.source(socket));
                    this.b.k(Okio.sink(socket), socket);
                    d dVar4 = d.this;
                    dVar4.u = dVar4.u.toBuilder().set(Grpc.TRANSPORT_ATTR_REMOTE_ADDR, socket.getRemoteSocketAddress()).set(Grpc.TRANSPORT_ATTR_LOCAL_ADDR, socket.getLocalSocketAddress()).set(Grpc.TRANSPORT_ATTR_SSL_SESSION, sSLSession).set(GrpcAttributes.ATTR_SECURITY_LEVEL, sSLSession == null ? SecurityLevel.NONE : SecurityLevel.PRIVACY_AND_INTEGRITY).build();
                    d dVar5 = d.this;
                    dVar5.t = dVar5.new e(dVar5.g.newReader(buffer2, true));
                    synchronized (d.this.k) {
                        d.this.D = (Socket) Preconditions.checkNotNull(socket, "socket");
                        if (sSLSession != null) {
                            d.this.R = new InternalChannelz.Security(new InternalChannelz.Tls(sSLSession));
                        }
                    }
                } catch (Exception e) {
                    d.this.a(e);
                    dVar = d.this;
                    eVar = dVar.new e(dVar.g.newReader(buffer, true));
                    dVar.t = eVar;
                } catch (StatusException e2) {
                    d.this.c0(0, ErrorCode.INTERNAL_ERROR, e2.getStatus());
                    dVar = d.this;
                    eVar = dVar.new e(dVar.g.newReader(buffer, true));
                    dVar.t = eVar;
                }
            } catch (Throwable th) {
                d dVar6 = d.this;
                dVar6.t = dVar6.new e(dVar6.g.newReader(buffer, true));
                throw th;
            }
        }
    }

    public class RunnableC0016d implements Runnable {
        public RunnableC0016d() {
        }

        @Override
        public void run() {
            Runnable runnable = d.this.U;
            if (runnable != null) {
                runnable.run();
            }
            d.this.o.execute(d.this.t);
            synchronized (d.this.k) {
                d.this.E = Integer.MAX_VALUE;
                d.this.d0();
            }
            SettableFuture<Void> settableFuture = d.this.V;
            if (settableFuture != null) {
                settableFuture.set((Object) null);
            }
        }
    }

    public class e implements FrameReader.Handler, Runnable {
        public FrameReader b;
        public final io.grpc.okhttp.e a = new io.grpc.okhttp.e(Level.FINE, (Class<?>) d.class);
        public boolean c = true;

        public e(FrameReader frameReader) {
            this.b = frameReader;
        }

        public final int a(List<Header> list) {
            long j = 0;
            for (int i = 0; i < list.size(); i++) {
                Header header = list.get(i);
                j += header.name.size() + 32 + header.value.size();
            }
            return (int) Math.min(j, 2147483647L);
        }

        @Override
        public void ackSettings() {
        }

        @Override
        public void alternateService(int i, String str, ByteString byteString, String str2, int i2, long j) {
        }

        @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);
            io.grpc.okhttp.c R = d.this.R(i);
            if (R != null) {
                long j = i2;
                bufferedSource.require(j);
                Buffer buffer = new Buffer();
                buffer.write(bufferedSource.getBuffer(), j);
                PerfMark.event("OkHttpClientTransport$ClientFrameHandler.data", R.transportState().L());
                synchronized (d.this.k) {
                    R.transportState().M(buffer, z);
                }
            } else {
                if (!d.this.U(i)) {
                    d.this.X(ErrorCode.PROTOCOL_ERROR, "Received data for unknown stream: " + i);
                    return;
                }
                synchronized (d.this.k) {
                    d.this.i.rstStream(i, ErrorCode.STREAM_CLOSED);
                }
                bufferedSource.skip(i2);
            }
            d.w(d.this, i2);
            if (d.this.s >= d.this.f * 0.5f) {
                synchronized (d.this.k) {
                    d.this.i.windowUpdate(0, d.this.s);
                }
                d.this.s = 0;
            }
        }

        @Override
        public void goAway(int i, ErrorCode errorCode, ByteString byteString) {
            this.a.c(e.a.INBOUND, i, errorCode, byteString);
            if (errorCode == ErrorCode.ENHANCE_YOUR_CALM) {
                String utf8 = byteString.utf8();
                d.X.log(Level.WARNING, String.format("%s: Received GOAWAY with ENHANCE_YOUR_CALM. Debug data: %s", this, utf8));
                if ("too_many_pings".equals(utf8)) {
                    d.this.M.run();
                }
            }
            Status augmentDescription = GrpcUtil.Http2Error.statusForCode(errorCode.httpCode).augmentDescription("Received Goaway");
            if (byteString.size() > 0) {
                augmentDescription = augmentDescription.augmentDescription(byteString.utf8());
            }
            d.this.c0(i, null, augmentDescription);
        }

        @Override
        public void headers(boolean z, boolean z2, int i, int i2, List<Header> list, HeadersMode headersMode) {
            Status status;
            int a;
            this.a.d(e.a.INBOUND, i, list, z2);
            boolean z3 = true;
            if (d.this.N == Integer.MAX_VALUE || (a = a(list)) <= d.this.N) {
                status = null;
            } else {
                Status status2 = Status.RESOURCE_EXHAUSTED;
                Locale locale = Locale.US;
                Object[] objArr = new Object[3];
                objArr[0] = z2 ? "trailer" : "header";
                objArr[1] = Integer.valueOf(d.this.N);
                objArr[2] = Integer.valueOf(a);
                status = status2.withDescription(String.format(locale, "Response %s metadata larger than %d: %d", objArr));
            }
            synchronized (d.this.k) {
                io.grpc.okhttp.c cVar = (io.grpc.okhttp.c) d.this.n.get(Integer.valueOf(i));
                if (cVar == null) {
                    if (d.this.U(i)) {
                        d.this.i.rstStream(i, ErrorCode.STREAM_CLOSED);
                    }
                } else if (status == null) {
                    PerfMark.event("OkHttpClientTransport$ClientFrameHandler.headers", cVar.transportState().L());
                    cVar.transportState().N(list, z2);
                } else {
                    if (!z2) {
                        d.this.i.rstStream(i, ErrorCode.CANCEL);
                    }
                    cVar.transportState().transportReportStatus(status, false, new Metadata());
                }
                z3 = false;
            }
            if (z3) {
                d.this.X(ErrorCode.PROTOCOL_ERROR, "Received header for unknown stream: " + i);
            }
        }

        @Override
        public void ping(boolean z, int i, int i2) {
            Http2Ping http2Ping;
            long j = (i << 32) | (i2 & 4294967295L);
            this.a.e(e.a.INBOUND, j);
            if (!z) {
                synchronized (d.this.k) {
                    d.this.i.ping(true, i, i2);
                }
                return;
            }
            synchronized (d.this.k) {
                http2Ping = null;
                if (d.this.x == null) {
                    d.X.warning("Received unexpected ping ack. No ping outstanding");
                } else if (d.this.x.payload() == j) {
                    Http2Ping http2Ping2 = d.this.x;
                    d.this.x = null;
                    http2Ping = http2Ping2;
                } else {
                    d.X.log(Level.WARNING, String.format(Locale.US, "Received unexpected ping ack. Expecting %d, got %d", Long.valueOf(d.this.x.payload()), Long.valueOf(j)));
                }
            }
            if (http2Ping != null) {
                http2Ping.complete();
            }
        }

        @Override
        public void priority(int i, int i2, int i3, boolean z) {
        }

        @Override
        public void pushPromise(int i, int i2, List<Header> list) throws IOException {
            this.a.h(e.a.INBOUND, i, i2, list);
            synchronized (d.this.k) {
                d.this.i.rstStream(i, ErrorCode.PROTOCOL_ERROR);
            }
        }

        @Override
        public void rstStream(int i, ErrorCode errorCode) {
            this.a.i(e.a.INBOUND, i, errorCode);
            Status augmentDescription = d.h0(errorCode).augmentDescription("Rst Stream");
            boolean z = augmentDescription.getCode() == Status.Code.CANCELLED || augmentDescription.getCode() == Status.Code.DEADLINE_EXCEEDED;
            synchronized (d.this.k) {
                io.grpc.okhttp.c cVar = (io.grpc.okhttp.c) d.this.n.get(Integer.valueOf(i));
                if (cVar != null) {
                    PerfMark.event("OkHttpClientTransport$ClientFrameHandler.rstStream", cVar.transportState().L());
                    d.this.N(i, augmentDescription, errorCode == ErrorCode.REFUSED_STREAM ? ClientStreamListener.RpcProgress.REFUSED : ClientStreamListener.RpcProgress.PROCESSED, z, null, null);
                }
            }
        }

        @Override
        public void run() {
            Status status;
            String name = Thread.currentThread().getName();
            Thread.currentThread().setName("OkHttpClientTransport");
            while (this.b.nextFrame(this)) {
                try {
                    if (d.this.H != null) {
                        d.this.H.onDataReceived();
                    }
                } catch (Throwable th) {
                    try {
                        d.this.c0(0, ErrorCode.PROTOCOL_ERROR, Status.INTERNAL.withDescription("error in frame handler").withCause(th));
                        try {
                            this.b.close();
                        } catch (IOException e) {
                            e = e;
                            d.X.log(Level.INFO, "Exception closing frame reader", (Throwable) e);
                            d.this.h.transportTerminated();
                            Thread.currentThread().setName(name);
                        }
                    } catch (Throwable th2) {
                        try {
                            this.b.close();
                        } catch (IOException e2) {
                            d.X.log(Level.INFO, "Exception closing frame reader", (Throwable) e2);
                        }
                        d.this.h.transportTerminated();
                        Thread.currentThread().setName(name);
                        throw th2;
                    }
                }
            }
            synchronized (d.this.k) {
                status = d.this.v;
            }
            if (status == null) {
                status = Status.UNAVAILABLE.withDescription("End of stream or IOException");
            }
            d.this.c0(0, ErrorCode.INTERNAL_ERROR, status);
            try {
                this.b.close();
            } catch (IOException e3) {
                e = e3;
                d.X.log(Level.INFO, "Exception closing frame reader", (Throwable) e);
                d.this.h.transportTerminated();
                Thread.currentThread().setName(name);
            }
            d.this.h.transportTerminated();
            Thread.currentThread().setName(name);
        }

        @Override
        public void settings(boolean z, Settings settings) {
            boolean z2;
            this.a.j(e.a.INBOUND, settings);
            synchronized (d.this.k) {
                if (qe3.b(settings, 4)) {
                    d.this.E = qe3.a(settings, 4);
                }
                if (qe3.b(settings, 7)) {
                    z2 = d.this.j.f(qe3.a(settings, 7));
                } else {
                    z2 = false;
                }
                if (this.c) {
                    d.this.h.transportReady();
                    this.c = false;
                }
                d.this.i.ackSettings(settings);
                if (z2) {
                    d.this.j.i();
                }
                d.this.d0();
            }
        }

        @Override
        public void windowUpdate(int r8, long r9) {
            throw new UnsupportedOperationException("Method not decompiled: io.grpc.okhttp.d.e.windowUpdate(int, long):void");
        }
    }

    public d(OkHttpChannelBuilder.f fVar, InetSocketAddress inetSocketAddress, String str, @Nullable String str2, Attributes attributes, @Nullable HttpConnectProxiedSocketAddress httpConnectProxiedSocketAddress, Runnable runnable) {
        this(fVar, inetSocketAddress, str, str2, attributes, GrpcUtil.STOPWATCH_SUPPLIER, new Http2(), httpConnectProxiedSocketAddress, runnable);
    }

    public static Map<ErrorCode, Status> J() {
        EnumMap enumMap = new EnumMap(ErrorCode.class);
        ErrorCode errorCode = ErrorCode.NO_ERROR;
        Status status = Status.INTERNAL;
        enumMap.put((EnumMap) errorCode, (ErrorCode) status.withDescription("No error: A GRPC status of OK should have been sent"));
        enumMap.put((EnumMap) ErrorCode.PROTOCOL_ERROR, (ErrorCode) status.withDescription("Protocol error"));
        enumMap.put((EnumMap) ErrorCode.INTERNAL_ERROR, (ErrorCode) status.withDescription("Internal error"));
        enumMap.put((EnumMap) ErrorCode.FLOW_CONTROL_ERROR, (ErrorCode) status.withDescription("Flow control error"));
        enumMap.put((EnumMap) ErrorCode.STREAM_CLOSED, (ErrorCode) status.withDescription("Stream closed"));
        enumMap.put((EnumMap) ErrorCode.FRAME_TOO_LARGE, (ErrorCode) status.withDescription("Frame too large"));
        enumMap.put((EnumMap) ErrorCode.REFUSED_STREAM, (ErrorCode) Status.UNAVAILABLE.withDescription("Refused stream"));
        enumMap.put((EnumMap) ErrorCode.CANCEL, (ErrorCode) Status.CANCELLED.withDescription("Cancelled"));
        enumMap.put((EnumMap) ErrorCode.COMPRESSION_ERROR, (ErrorCode) status.withDescription("Compression error"));
        enumMap.put((EnumMap) ErrorCode.CONNECT_ERROR, (ErrorCode) status.withDescription("Connect error"));
        enumMap.put((EnumMap) ErrorCode.ENHANCE_YOUR_CALM, (ErrorCode) Status.RESOURCE_EXHAUSTED.withDescription("Enhance your calm"));
        enumMap.put((EnumMap) ErrorCode.INADEQUATE_SECURITY, (ErrorCode) Status.PERMISSION_DENIED.withDescription("Inadequate security"));
        return Collections.unmodifiableMap(enumMap);
    }

    public static String Y(Source source) throws IOException {
        Buffer buffer = new Buffer();
        while (source.read(buffer, 1L) != -1) {
            if (buffer.getByte(buffer.size() - 1) == 10) {
                return buffer.readUtf8LineStrict();
            }
        }
        throw new EOFException("\\n not found: " + buffer.readByteString().hex());
    }

    @VisibleForTesting
    public static Status h0(ErrorCode errorCode) {
        Status status = W.get(errorCode);
        if (status != null) {
            return status;
        }
        return Status.UNKNOWN.withDescription("Unknown http2 error code: " + errorCode.httpCode);
    }

    public static int w(d dVar, int i) {
        int i2 = dVar.s + i;
        dVar.s = i2;
        return i2;
    }

    public final Request K(InetSocketAddress inetSocketAddress, String str, String str2) {
        HttpUrl build = new HttpUrl.Builder().scheme("https").host(inetSocketAddress.getHostName()).port(inetSocketAddress.getPort()).build();
        Request.Builder header = new Request.Builder().url(build).header("Host", build.host() + ":" + build.port()).header("User-Agent", this.c);
        if (str != null && str2 != null) {
            header.header("Proxy-Authorization", Credentials.basic(str, str2));
        }
        return header.build();
    }

    public final Socket L(InetSocketAddress inetSocketAddress, InetSocketAddress inetSocketAddress2, String str, String str2) throws StatusException {
        Socket socket = null;
        try {
            socket = inetSocketAddress2.getAddress() != null ? this.A.createSocket(inetSocketAddress2.getAddress(), inetSocketAddress2.getPort()) : this.A.createSocket(inetSocketAddress2.getHostName(), inetSocketAddress2.getPort());
            socket.setTcpNoDelay(true);
            socket.setSoTimeout(this.T);
            Source source = Okio.source(socket);
            BufferedSink buffer = Okio.buffer(Okio.sink(socket));
            Request K = K(inetSocketAddress, str, str2);
            HttpUrl httpUrl = K.httpUrl();
            buffer.writeUtf8(String.format(Locale.US, "CONNECT %s:%d HTTP/1.1", httpUrl.host(), Integer.valueOf(httpUrl.port()))).writeUtf8("\r\n");
            int size = K.headers().size();
            for (int i = 0; i < size; i++) {
                buffer.writeUtf8(K.headers().name(i)).writeUtf8(": ").writeUtf8(K.headers().value(i)).writeUtf8("\r\n");
            }
            buffer.writeUtf8("\r\n");
            buffer.flush();
            StatusLine parse = StatusLine.parse(Y(source));
            while (!Y(source).equals("")) {
            }
            int i2 = parse.code;
            if (i2 >= 200 && i2 < 300) {
                socket.setSoTimeout(0);
                return socket;
            }
            Buffer buffer2 = new Buffer();
            try {
                socket.shutdownOutput();
                source.read(buffer2, RealWebSocket.DEFAULT_MINIMUM_DEFLATE_SIZE);
            } catch (IOException e2) {
                buffer2.writeUtf8("Unable to read body: " + e2.toString());
            }
            try {
                socket.close();
            } catch (IOException unused) {
            }
            throw Status.UNAVAILABLE.withDescription(String.format(Locale.US, "Response returned from proxy was not successful (expected 2xx, got %d %s). Response body:\n%s", Integer.valueOf(parse.code), parse.message, buffer2.readUtf8())).asException();
        } catch (IOException e3) {
            if (socket != null) {
                GrpcUtil.closeQuietly(socket);
            }
            throw Status.UNAVAILABLE.withDescription("Failed trying to connect with proxy").withCause(e3).asException();
        }
    }

    public void M(boolean z, long j, long j2, boolean z2) {
        this.I = z;
        this.J = j;
        this.K = j2;
        this.L = z2;
    }

    public void N(int i, @Nullable Status status, ClientStreamListener.RpcProgress rpcProgress, boolean z, @Nullable ErrorCode errorCode, @Nullable Metadata metadata) {
        synchronized (this.k) {
            io.grpc.okhttp.c remove = this.n.remove(Integer.valueOf(i));
            if (remove != null) {
                if (errorCode != null) {
                    this.i.rstStream(i, ErrorCode.CANCEL);
                }
                if (status != null) {
                    c.b transportState = remove.transportState();
                    if (metadata == null) {
                        metadata = new Metadata();
                    }
                    transportState.transportReportStatus(status, rpcProgress, z, metadata);
                }
                if (!d0()) {
                    f0();
                    V(remove);
                }
            }
        }
    }

    @VisibleForTesting
    public String O() {
        URI authorityToUri = GrpcUtil.authorityToUri(this.b);
        return authorityToUri.getHost() != null ? authorityToUri.getHost() : this.b;
    }

    @VisibleForTesting
    public int P() {
        URI authorityToUri = GrpcUtil.authorityToUri(this.b);
        return authorityToUri.getPort() != -1 ? authorityToUri.getPort() : this.a.getPort();
    }

    public final Throwable Q() {
        synchronized (this.k) {
            Status status = this.v;
            if (status != null) {
                return status.asException();
            }
            return Status.UNAVAILABLE.withDescription("Connection closed").asException();
        }
    }

    public io.grpc.okhttp.c R(int i) {
        io.grpc.okhttp.c cVar;
        synchronized (this.k) {
            cVar = this.n.get(Integer.valueOf(i));
        }
        return cVar;
    }

    public final void S() {
        synchronized (this.k) {
            this.P.setFlowControlWindowReader(new b());
        }
    }

    public boolean T() {
        return this.B == null;
    }

    public boolean U(int i) {
        boolean z;
        synchronized (this.k) {
            if (i < this.m) {
                z = true;
                if ((i & 1) == 1) {
                }
            }
            z = false;
        }
        return z;
    }

    @GuardedBy("lock")
    public final void V(io.grpc.okhttp.c cVar) {
        if (this.z && this.F.isEmpty() && this.n.isEmpty()) {
            this.z = false;
            KeepAliveManager keepAliveManager = this.H;
            if (keepAliveManager != null) {
                keepAliveManager.onTransportIdle();
            }
        }
        if (cVar.shouldBeCountedForInUse()) {
            this.Q.updateObjectInUse(cVar, false);
        }
    }

    @Override
    public io.grpc.okhttp.c newStream(MethodDescriptor<?, ?> methodDescriptor, Metadata metadata, CallOptions callOptions, ClientStreamTracer[] clientStreamTracerArr) {
        Preconditions.checkNotNull(methodDescriptor, "method");
        Preconditions.checkNotNull(metadata, "headers");
        StatsTraceContext newClientContext = StatsTraceContext.newClientContext(clientStreamTracerArr, getAttributes(), metadata);
        synchronized (this.k) {
            try {
                try {
                    return new io.grpc.okhttp.c(methodDescriptor, metadata, this.i, this, this.j, this.k, this.r, this.f, this.b, this.c, newClientContext, this.P, callOptions, this.O);
                } catch (Throwable th) {
                    th = th;
                    throw th;
                }
            } catch (Throwable th2) {
                th = th2;
            }
        }
    }

    public final void X(ErrorCode errorCode, String str) {
        c0(0, errorCode, h0(errorCode).augmentDescription(str));
    }

    @GuardedBy("lock")
    public void Z(io.grpc.okhttp.c cVar) {
        this.F.remove(cVar);
        V(cVar);
    }

    @Override
    public void a(Throwable th) {
        Preconditions.checkNotNull(th, "failureCause");
        c0(0, ErrorCode.INTERNAL_ERROR, Status.UNAVAILABLE.withCause(th));
    }

    public final void a0() {
        synchronized (this.k) {
            this.i.connectionPreface();
            Settings settings = new Settings();
            qe3.c(settings, 7, this.f);
            this.i.settings(settings);
            if (this.f > 65535) {
                this.i.windowUpdate(0, r1 - 65535);
            }
        }
    }

    @GuardedBy("lock")
    public final void b0(io.grpc.okhttp.c cVar) {
        if (!this.z) {
            this.z = true;
            KeepAliveManager keepAliveManager = this.H;
            if (keepAliveManager != null) {
                keepAliveManager.onTransportActive();
            }
        }
        if (cVar.shouldBeCountedForInUse()) {
            this.Q.updateObjectInUse(cVar, true);
        }
    }

    public final void c0(int i, ErrorCode errorCode, Status status) {
        synchronized (this.k) {
            if (this.v == null) {
                this.v = status;
                this.h.transportShutdown(status);
            }
            if (errorCode != null && !this.w) {
                this.w = true;
                this.i.goAway(0, errorCode, new byte[0]);
            }
            Iterator<Map.Entry<Integer, io.grpc.okhttp.c>> it = this.n.entrySet().iterator();
            while (it.hasNext()) {
                Map.Entry<Integer, io.grpc.okhttp.c> next = it.next();
                if (next.getKey().intValue() > i) {
                    it.remove();
                    next.getValue().transportState().transportReportStatus(status, ClientStreamListener.RpcProgress.REFUSED, false, new Metadata());
                    V(next.getValue());
                }
            }
            for (io.grpc.okhttp.c cVar : this.F) {
                cVar.transportState().transportReportStatus(status, ClientStreamListener.RpcProgress.MISCARRIED, true, new Metadata());
                V(cVar);
            }
            this.F.clear();
            f0();
        }
    }

    @GuardedBy("lock")
    public final boolean d0() {
        boolean z = false;
        while (!this.F.isEmpty() && this.n.size() < this.E) {
            e0(this.F.poll());
            z = true;
        }
        return z;
    }

    @GuardedBy("lock")
    public final void e0(io.grpc.okhttp.c cVar) {
        Preconditions.checkState(cVar.transportState().G() == -1, "StreamId already assigned");
        this.n.put(Integer.valueOf(this.m), cVar);
        b0(cVar);
        cVar.transportState().J(this.m);
        if ((cVar.n() != MethodDescriptor.MethodType.UNARY && cVar.n() != MethodDescriptor.MethodType.SERVER_STREAMING) || cVar.p()) {
            this.i.flush();
        }
        int i = this.m;
        if (i < 2147483645) {
            this.m = i + 2;
        } else {
            this.m = Integer.MAX_VALUE;
            c0(Integer.MAX_VALUE, ErrorCode.NO_ERROR, Status.UNAVAILABLE.withDescription("Stream ids exhausted"));
        }
    }

    @GuardedBy("lock")
    public final void f0() {
        if (this.v == null || !this.n.isEmpty() || !this.F.isEmpty() || this.y) {
            return;
        }
        this.y = true;
        KeepAliveManager keepAliveManager = this.H;
        if (keepAliveManager != null) {
            keepAliveManager.onTransportTermination();
        }
        Http2Ping http2Ping = this.x;
        if (http2Ping != null) {
            http2Ping.failed(Q());
            this.x = null;
        }
        if (!this.w) {
            this.w = true;
            this.i.goAway(0, ErrorCode.NO_ERROR, new byte[0]);
        }
        this.i.close();
    }

    @GuardedBy("lock")
    public void g0(io.grpc.okhttp.c cVar) {
        if (this.v != null) {
            cVar.transportState().transportReportStatus(this.v, ClientStreamListener.RpcProgress.MISCARRIED, true, new Metadata());
        } else if (this.n.size() < this.E) {
            e0(cVar);
        } else {
            this.F.add(cVar);
            b0(cVar);
        }
    }

    @Override
    public OutboundFlowController.StreamState[] getActiveStreams() {
        OutboundFlowController.StreamState[] streamStateArr;
        synchronized (this.k) {
            streamStateArr = new OutboundFlowController.StreamState[this.n.size()];
            Iterator<io.grpc.okhttp.c> it = this.n.values().iterator();
            int i = 0;
            while (it.hasNext()) {
                streamStateArr[i] = it.next().transportState().e();
                i++;
            }
        }
        return streamStateArr;
    }

    @Override
    public Attributes getAttributes() {
        return this.u;
    }

    public InternalLogId getLogId() {
        return this.l;
    }

    public ListenableFuture<InternalChannelz.SocketStats> getStats() {
        SettableFuture create = SettableFuture.create();
        synchronized (this.k) {
            if (this.D == null) {
                create.set(new InternalChannelz.SocketStats(this.P.getStats(), (SocketAddress) null, (SocketAddress) null, new InternalChannelz.SocketOptions.Builder().build(), (InternalChannelz.Security) null));
            } else {
                create.set(new InternalChannelz.SocketStats(this.P.getStats(), this.D.getLocalSocketAddress(), this.D.getRemoteSocketAddress(), rx5.e(this.D), this.R));
            }
        }
        return create;
    }

    @Override
    public void ping(ClientTransport.PingCallback pingCallback, Executor executor) {
        long nextLong;
        synchronized (this.k) {
            boolean z = true;
            Preconditions.checkState(this.i != null);
            if (this.y) {
                Http2Ping.notifyFailed(pingCallback, executor, Q());
                return;
            }
            Http2Ping http2Ping = this.x;
            if (http2Ping != null) {
                nextLong = 0;
                z = false;
            } else {
                nextLong = this.d.nextLong();
                Stopwatch stopwatch = (Stopwatch) this.e.get();
                stopwatch.start();
                Http2Ping http2Ping2 = new Http2Ping(nextLong, stopwatch);
                this.x = http2Ping2;
                this.P.reportKeepAliveSent();
                http2Ping = http2Ping2;
            }
            if (z) {
                this.i.ping(false, (int) (nextLong >>> 32), (int) nextLong);
            }
            http2Ping.addCallback(pingCallback, executor);
        }
    }

    @Override
    public void shutdown(Status status) {
        synchronized (this.k) {
            if (this.v != null) {
                return;
            }
            this.v = status;
            this.h.transportShutdown(status);
            f0();
        }
    }

    @Override
    public void shutdownNow(Status status) {
        shutdown(status);
        synchronized (this.k) {
            Iterator<Map.Entry<Integer, io.grpc.okhttp.c>> it = this.n.entrySet().iterator();
            while (it.hasNext()) {
                Map.Entry<Integer, io.grpc.okhttp.c> next = it.next();
                it.remove();
                next.getValue().transportState().transportReportStatus(status, false, new Metadata());
                V(next.getValue());
            }
            for (io.grpc.okhttp.c cVar : this.F) {
                cVar.transportState().transportReportStatus(status, ClientStreamListener.RpcProgress.MISCARRIED, true, new Metadata());
                V(cVar);
            }
            this.F.clear();
            f0();
        }
    }

    @Override
    public Runnable start(ManagedClientTransport.Listener listener) {
        this.h = (ManagedClientTransport.Listener) Preconditions.checkNotNull(listener, "listener");
        if (this.I) {
            KeepAliveManager keepAliveManager = new KeepAliveManager(new KeepAliveManager.ClientKeepAlivePinger(this), this.q, this.J, this.K, this.L);
            this.H = keepAliveManager;
            keepAliveManager.onTransportStarted();
        }
        io.grpc.okhttp.a m = io.grpc.okhttp.a.m(this.p, this, 10000);
        FrameWriter l = m.l(this.g.newWriter(Okio.buffer(m), true));
        synchronized (this.k) {
            io.grpc.okhttp.b bVar = new io.grpc.okhttp.b(this, l);
            this.i = bVar;
            this.j = new OutboundFlowController(this, bVar);
        }
        CountDownLatch countDownLatch = new CountDownLatch(1);
        this.p.execute(new c(countDownLatch, m));
        try {
            a0();
            countDownLatch.countDown();
            this.p.execute(new RunnableC0016d());
            return null;
        } catch (Throwable th) {
            countDownLatch.countDown();
            throw th;
        }
    }

    public String toString() {
        return MoreObjects.toStringHelper(this).add("logId", this.l.getId()).add("address", this.a).toString();
    }

    public d(OkHttpChannelBuilder.f fVar, InetSocketAddress inetSocketAddress, String str, @Nullable String str2, Attributes attributes, Supplier<Stopwatch> supplier, Variant variant, @Nullable HttpConnectProxiedSocketAddress httpConnectProxiedSocketAddress, Runnable runnable) {
        this.d = new Random();
        this.k = new Object();
        this.n = new HashMap();
        this.E = 0;
        this.F = new LinkedList();
        this.Q = new a();
        this.T = 30000;
        this.a = (InetSocketAddress) Preconditions.checkNotNull(inetSocketAddress, "address");
        this.b = str;
        this.r = fVar.j;
        this.f = fVar.o;
        this.o = (Executor) Preconditions.checkNotNull(fVar.b, "executor");
        this.p = new SerializingExecutor(fVar.b);
        this.q = (ScheduledExecutorService) Preconditions.checkNotNull(fVar.d, "scheduledExecutorService");
        this.m = 3;
        SocketFactory socketFactory = fVar.f;
        this.A = socketFactory == null ? SocketFactory.getDefault() : socketFactory;
        this.B = fVar.g;
        this.C = fVar.h;
        this.G = (ConnectionSpec) Preconditions.checkNotNull(fVar.i, "connectionSpec");
        this.e = (Supplier) Preconditions.checkNotNull(supplier, "stopwatchFactory");
        this.g = (Variant) Preconditions.checkNotNull(variant, "variant");
        this.c = GrpcUtil.getGrpcUserAgent("okhttp", str2);
        this.S = httpConnectProxiedSocketAddress;
        this.M = (Runnable) Preconditions.checkNotNull(runnable, "tooManyPingsRunnable");
        this.N = fVar.q;
        this.P = fVar.e.create();
        this.l = InternalLogId.allocate(getClass(), inetSocketAddress.toString());
        this.u = Attributes.newBuilder().set(GrpcAttributes.ATTR_CLIENT_EAG_ATTRS, attributes).build();
        this.O = fVar.r;
        S();
    }
}