package io.netty.handler.codec.http2;

import g.a.a.a.a;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.http.HttpStatusClass;
import io.netty.handler.codec.http2.Http2Connection;
import io.netty.handler.codec.http2.Http2FrameReader;
import io.netty.handler.codec.http2.Http2HeadersDecoder;
import io.netty.handler.codec.http2.Http2Stream;
import io.netty.util.internal.ObjectUtil;
import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory;
import java.util.List;

/* JADX INFO: loaded from: classes.dex */
public class DefaultHttp2ConnectionDecoder implements Http2ConnectionDecoder {
    private static final InternalLogger logger = InternalLoggerFactory.getInstance((Class<?>) DefaultHttp2ConnectionDecoder.class);
    private final Http2Connection connection;
    private final Http2ConnectionEncoder encoder;
    private final Http2FrameReader frameReader;
    private Http2FrameListener internalFrameListener;
    private Http2LifecycleManager lifecycleManager;
    private Http2FrameListener listener;
    private final Http2PromisedRequestVerifier requestVerifier;

    /* JADX INFO: renamed from: io.netty.handler.codec.http2.DefaultHttp2ConnectionDecoder$1, reason: invalid class name */
    public static /* synthetic */ class AnonymousClass1 {
        public static final /* synthetic */ int[] $SwitchMap$io$netty$handler$codec$http2$Http2Stream$State;

        static {
            Http2Stream.State.values();
            int[] iArr = new int[7];
            $SwitchMap$io$netty$handler$codec$http2$Http2Stream$State = iArr;
            try {
                iArr[Http2Stream.State.OPEN.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                $SwitchMap$io$netty$handler$codec$http2$Http2Stream$State[Http2Stream.State.HALF_CLOSED_LOCAL.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            try {
                $SwitchMap$io$netty$handler$codec$http2$Http2Stream$State[Http2Stream.State.HALF_CLOSED_REMOTE.ordinal()] = 3;
            } catch (NoSuchFieldError unused3) {
            }
            try {
                $SwitchMap$io$netty$handler$codec$http2$Http2Stream$State[Http2Stream.State.CLOSED.ordinal()] = 4;
            } catch (NoSuchFieldError unused4) {
            }
            try {
                $SwitchMap$io$netty$handler$codec$http2$Http2Stream$State[Http2Stream.State.RESERVED_REMOTE.ordinal()] = 5;
            } catch (NoSuchFieldError unused5) {
            }
            try {
                $SwitchMap$io$netty$handler$codec$http2$Http2Stream$State[Http2Stream.State.IDLE.ordinal()] = 6;
            } catch (NoSuchFieldError unused6) {
            }
        }
    }

    public final class FrameReadListener implements Http2FrameListener {
        private FrameReadListener() {
        }

        public /* synthetic */ FrameReadListener(DefaultHttp2ConnectionDecoder defaultHttp2ConnectionDecoder, AnonymousClass1 anonymousClass1) {
            this();
        }

        private void applyLocalSettings(Http2Settings http2Settings) throws Http2Exception {
            Boolean boolPushEnabled = http2Settings.pushEnabled();
            Http2FrameReader.Configuration configuration = DefaultHttp2ConnectionDecoder.this.frameReader.configuration();
            Http2HeadersDecoder.Configuration configurationHeadersConfiguration = configuration.headersConfiguration();
            Http2FrameSizePolicy http2FrameSizePolicyFrameSizePolicy = configuration.frameSizePolicy();
            if (boolPushEnabled != null) {
                if (DefaultHttp2ConnectionDecoder.this.connection.isServer()) {
                    throw Http2Exception.connectionError(Http2Error.PROTOCOL_ERROR, "Server sending SETTINGS frame with ENABLE_PUSH specified", new Object[0]);
                }
                DefaultHttp2ConnectionDecoder.this.connection.local().allowPushTo(boolPushEnabled.booleanValue());
            }
            Long lMaxConcurrentStreams = http2Settings.maxConcurrentStreams();
            if (lMaxConcurrentStreams != null) {
                DefaultHttp2ConnectionDecoder.this.connection.remote().maxActiveStreams((int) Math.min(lMaxConcurrentStreams.longValue(), 2147483647L));
            }
            Long lHeaderTableSize = http2Settings.headerTableSize();
            if (lHeaderTableSize != null) {
                configurationHeadersConfiguration.maxHeaderTableSize(lHeaderTableSize.longValue());
            }
            Long lMaxHeaderListSize = http2Settings.maxHeaderListSize();
            if (lMaxHeaderListSize != null) {
                configurationHeadersConfiguration.maxHeaderListSize(lMaxHeaderListSize.longValue(), DefaultHttp2ConnectionDecoder.this.calculateMaxHeaderListSizeGoAway(lMaxHeaderListSize.longValue()));
            }
            Integer numMaxFrameSize = http2Settings.maxFrameSize();
            if (numMaxFrameSize != null) {
                http2FrameSizePolicyFrameSizePolicy.maxFrameSize(numMaxFrameSize.intValue());
            }
            Integer numInitialWindowSize = http2Settings.initialWindowSize();
            if (numInitialWindowSize != null) {
                DefaultHttp2ConnectionDecoder.this.flowController().initialWindowSize(numInitialWindowSize.intValue());
            }
        }

        private boolean shouldIgnoreHeadersOrDataFrame(ChannelHandlerContext channelHandlerContext, int i2, Http2Stream http2Stream, String str) throws Http2Exception {
            String string;
            if (http2Stream == null) {
                if (!streamCreatedAfterGoAwaySent(i2)) {
                    throw Http2Exception.streamError(i2, Http2Error.STREAM_CLOSED, "Received %s frame for an unknown stream %d", str, Integer.valueOf(i2));
                }
                DefaultHttp2ConnectionDecoder.logger.info("{} ignoring {} frame for stream {}. Stream sent after GOAWAY sent", channelHandlerContext.channel(), str, Integer.valueOf(i2));
                return true;
            }
            if (!http2Stream.isResetSent() && !streamCreatedAfterGoAwaySent(i2)) {
                return false;
            }
            if (DefaultHttp2ConnectionDecoder.logger.isInfoEnabled()) {
                InternalLogger internalLogger = DefaultHttp2ConnectionDecoder.logger;
                Object[] objArr = new Object[3];
                objArr[0] = channelHandlerContext.channel();
                objArr[1] = str;
                if (http2Stream.isResetSent()) {
                    string = "RST_STREAM sent.";
                } else {
                    StringBuilder sbF = a.F("Stream created after GOAWAY sent. Last known stream by peer ");
                    sbF.append(DefaultHttp2ConnectionDecoder.this.connection.remote().lastStreamKnownByPeer());
                    string = sbF.toString();
                }
                objArr[2] = string;
                internalLogger.info("{} ignoring {} frame for stream {} {}", objArr);
            }
            return true;
        }

        private boolean streamCreatedAfterGoAwaySent(int i2) {
            Http2Connection.Endpoint<Http2RemoteFlowController> endpointRemote = DefaultHttp2ConnectionDecoder.this.connection.remote();
            return DefaultHttp2ConnectionDecoder.this.connection.goAwaySent() && endpointRemote.isValidStreamId(i2) && i2 > endpointRemote.lastStreamKnownByPeer();
        }

        private void verifyStreamMayHaveExisted(int i2) throws Http2Exception {
            if (!DefaultHttp2ConnectionDecoder.this.connection.streamMayHaveExisted(i2)) {
                throw Http2Exception.connectionError(Http2Error.PROTOCOL_ERROR, "Stream %d does not exist", Integer.valueOf(i2));
            }
        }

        /* JADX WARN: Finally extract failed */
        @Override // io.netty.handler.codec.http2.Http2FrameListener
        public int onDataRead(ChannelHandlerContext channelHandlerContext, int i2, ByteBuf byteBuf, int i3, boolean z2) throws Http2Exception {
            int iUnconsumedBytes;
            int iUnconsumedBytes2;
            Http2Stream http2StreamStream = DefaultHttp2ConnectionDecoder.this.connection.stream(i2);
            Http2LocalFlowController http2LocalFlowControllerFlowController = DefaultHttp2ConnectionDecoder.this.flowController();
            int i4 = byteBuf.readableBytes() + i3;
            try {
                if (shouldIgnoreHeadersOrDataFrame(channelHandlerContext, i2, http2StreamStream, "DATA")) {
                    http2LocalFlowControllerFlowController.receiveFlowControlledFrame(http2StreamStream, byteBuf, i3, z2);
                    http2LocalFlowControllerFlowController.consumeBytes(http2StreamStream, i4);
                    verifyStreamMayHaveExisted(i2);
                    return i4;
                }
                Http2Exception http2ExceptionStreamError = null;
                int iOrdinal = http2StreamStream.state().ordinal();
                if (iOrdinal != 3 && iOrdinal != 4) {
                    http2ExceptionStreamError = (iOrdinal == 5 || iOrdinal == 6) ? Http2Exception.streamError(http2StreamStream.id(), Http2Error.STREAM_CLOSED, "Stream %d in unexpected state: %s", Integer.valueOf(http2StreamStream.id()), http2StreamStream.state()) : Http2Exception.streamError(http2StreamStream.id(), Http2Error.PROTOCOL_ERROR, "Stream %d in unexpected state: %s", Integer.valueOf(http2StreamStream.id()), http2StreamStream.state());
                }
                int iUnconsumedBytes3 = DefaultHttp2ConnectionDecoder.this.unconsumedBytes(http2StreamStream);
                try {
                    try {
                        http2LocalFlowControllerFlowController.receiveFlowControlledFrame(http2StreamStream, byteBuf, i3, z2);
                        iUnconsumedBytes2 = DefaultHttp2ConnectionDecoder.this.unconsumedBytes(http2StreamStream);
                    } catch (Throwable th) {
                        http2LocalFlowControllerFlowController.consumeBytes(http2StreamStream, i4);
                        if (z2) {
                            DefaultHttp2ConnectionDecoder.this.lifecycleManager.closeStreamRemote(http2StreamStream, channelHandlerContext.newSucceededFuture());
                        }
                        throw th;
                    }
                } catch (Http2Exception e2) {
                    e = e2;
                } catch (RuntimeException e3) {
                    e = e3;
                }
                try {
                    if (http2ExceptionStreamError != null) {
                        throw http2ExceptionStreamError;
                    }
                    int iOnDataRead = DefaultHttp2ConnectionDecoder.this.listener.onDataRead(channelHandlerContext, i2, byteBuf, i3, z2);
                    http2LocalFlowControllerFlowController.consumeBytes(http2StreamStream, iOnDataRead);
                    if (z2) {
                        DefaultHttp2ConnectionDecoder.this.lifecycleManager.closeStreamRemote(http2StreamStream, channelHandlerContext.newSucceededFuture());
                    }
                    return iOnDataRead;
                } catch (Http2Exception e4) {
                    e = e4;
                    iUnconsumedBytes3 = iUnconsumedBytes2;
                    iUnconsumedBytes = DefaultHttp2ConnectionDecoder.this.unconsumedBytes(http2StreamStream);
                    int i5 = i4 - (iUnconsumedBytes3 - iUnconsumedBytes);
                    throw e;
                } catch (RuntimeException e5) {
                    e = e5;
                    iUnconsumedBytes3 = iUnconsumedBytes2;
                    iUnconsumedBytes = DefaultHttp2ConnectionDecoder.this.unconsumedBytes(http2StreamStream);
                    int i52 = i4 - (iUnconsumedBytes3 - iUnconsumedBytes);
                    throw e;
                }
            } catch (Http2Exception e6) {
                http2LocalFlowControllerFlowController.receiveFlowControlledFrame(http2StreamStream, byteBuf, i3, z2);
                http2LocalFlowControllerFlowController.consumeBytes(http2StreamStream, i4);
                throw e6;
            } catch (Throwable th2) {
                throw Http2Exception.connectionError(Http2Error.INTERNAL_ERROR, th2, "Unhandled error on data stream id %d", Integer.valueOf(i2));
            }
        }

        @Override // io.netty.handler.codec.http2.Http2FrameListener
        public void onGoAwayRead(ChannelHandlerContext channelHandlerContext, int i2, long j2, ByteBuf byteBuf) throws Http2Exception {
            DefaultHttp2ConnectionDecoder.this.onGoAwayRead0(channelHandlerContext, i2, j2, byteBuf);
        }

        @Override // io.netty.handler.codec.http2.Http2FrameListener
        public void onHeadersRead(ChannelHandlerContext channelHandlerContext, int i2, Http2Headers http2Headers, int i3, short s2, boolean z2, int i4, boolean z3) throws Http2Exception {
            Http2Stream http2Stream;
            boolean z4;
            Http2Stream http2StreamStream = DefaultHttp2ConnectionDecoder.this.connection.stream(i2);
            if (http2StreamStream != null || DefaultHttp2ConnectionDecoder.this.connection.streamMayHaveExisted(i2)) {
                http2Stream = http2StreamStream;
                z4 = false;
            } else {
                Http2Stream http2StreamCreateStream = DefaultHttp2ConnectionDecoder.this.connection.remote().createStream(i2, z3);
                z4 = http2StreamCreateStream.state() == Http2Stream.State.HALF_CLOSED_REMOTE;
                http2Stream = http2StreamCreateStream;
            }
            if (shouldIgnoreHeadersOrDataFrame(channelHandlerContext, i2, http2Stream, "HEADERS")) {
                return;
            }
            boolean z5 = !DefaultHttp2ConnectionDecoder.this.connection.isServer() && HttpStatusClass.valueOf(http2Headers.status()) == HttpStatusClass.INFORMATIONAL;
            if (((z5 || !z3) && http2Stream.isHeadersReceived()) || http2Stream.isTrailersReceived()) {
                throw Http2Exception.streamError(i2, Http2Error.PROTOCOL_ERROR, "Stream %d received too many headers EOS: %s state: %s", Integer.valueOf(i2), Boolean.valueOf(z3), http2Stream.state());
            }
            int iOrdinal = http2Stream.state().ordinal();
            if (iOrdinal == 2) {
                http2Stream.open(z3);
            } else if (iOrdinal != 3 && iOrdinal != 4) {
                if (iOrdinal != 5) {
                    if (iOrdinal == 6) {
                        throw Http2Exception.streamError(http2Stream.id(), Http2Error.STREAM_CLOSED, "Stream %d in unexpected state: %s", Integer.valueOf(http2Stream.id()), http2Stream.state());
                    }
                    throw Http2Exception.connectionError(Http2Error.PROTOCOL_ERROR, "Stream %d in unexpected state: %s", Integer.valueOf(http2Stream.id()), http2Stream.state());
                }
                if (!z4) {
                    throw Http2Exception.streamError(http2Stream.id(), Http2Error.STREAM_CLOSED, "Stream %d in unexpected state: %s", Integer.valueOf(http2Stream.id()), http2Stream.state());
                }
            }
            http2Stream.headersReceived(z5);
            DefaultHttp2ConnectionDecoder.this.encoder.flowController().updateDependencyTree(i2, i3, s2, z2);
            DefaultHttp2ConnectionDecoder.this.listener.onHeadersRead(channelHandlerContext, i2, http2Headers, i3, s2, z2, i4, z3);
            if (z3) {
                DefaultHttp2ConnectionDecoder.this.lifecycleManager.closeStreamRemote(http2Stream, channelHandlerContext.newSucceededFuture());
            }
        }

        @Override // io.netty.handler.codec.http2.Http2FrameListener
        public void onHeadersRead(ChannelHandlerContext channelHandlerContext, int i2, Http2Headers http2Headers, int i3, boolean z2) throws Http2Exception {
            onHeadersRead(channelHandlerContext, i2, http2Headers, 0, (short) 16, false, i3, z2);
        }

        @Override // io.netty.handler.codec.http2.Http2FrameListener
        public void onPingAckRead(ChannelHandlerContext channelHandlerContext, long j2) {
            DefaultHttp2ConnectionDecoder.this.listener.onPingAckRead(channelHandlerContext, j2);
        }

        @Override // io.netty.handler.codec.http2.Http2FrameListener
        public void onPingRead(ChannelHandlerContext channelHandlerContext, long j2) {
            DefaultHttp2ConnectionDecoder.this.encoder.writePing(channelHandlerContext, true, j2, channelHandlerContext.newPromise());
            DefaultHttp2ConnectionDecoder.this.listener.onPingRead(channelHandlerContext, j2);
        }

        @Override // io.netty.handler.codec.http2.Http2FrameListener
        public void onPriorityRead(ChannelHandlerContext channelHandlerContext, int i2, int i3, short s2, boolean z2) {
            DefaultHttp2ConnectionDecoder.this.encoder.flowController().updateDependencyTree(i2, i3, s2, z2);
            DefaultHttp2ConnectionDecoder.this.listener.onPriorityRead(channelHandlerContext, i2, i3, s2, z2);
        }

        @Override // io.netty.handler.codec.http2.Http2FrameListener
        public void onPushPromiseRead(ChannelHandlerContext channelHandlerContext, int i2, int i3, Http2Headers http2Headers, int i4) throws Http2Exception {
            if (DefaultHttp2ConnectionDecoder.this.connection().isServer()) {
                throw Http2Exception.connectionError(Http2Error.PROTOCOL_ERROR, "A client cannot push.", new Object[0]);
            }
            Http2Stream http2StreamStream = DefaultHttp2ConnectionDecoder.this.connection.stream(i2);
            if (shouldIgnoreHeadersOrDataFrame(channelHandlerContext, i2, http2StreamStream, "PUSH_PROMISE")) {
                return;
            }
            if (http2StreamStream == null) {
                throw Http2Exception.connectionError(Http2Error.PROTOCOL_ERROR, "Stream %d does not exist", Integer.valueOf(i2));
            }
            int iOrdinal = http2StreamStream.state().ordinal();
            if (iOrdinal != 3 && iOrdinal != 4) {
                throw Http2Exception.connectionError(Http2Error.PROTOCOL_ERROR, "Stream %d in unexpected state for receiving push promise: %s", Integer.valueOf(http2StreamStream.id()), http2StreamStream.state());
            }
            if (!DefaultHttp2ConnectionDecoder.this.requestVerifier.isAuthoritative(channelHandlerContext, http2Headers)) {
                throw Http2Exception.streamError(i3, Http2Error.PROTOCOL_ERROR, "Promised request on stream %d for promised stream %d is not authoritative", Integer.valueOf(i2), Integer.valueOf(i3));
            }
            if (!DefaultHttp2ConnectionDecoder.this.requestVerifier.isCacheable(http2Headers)) {
                throw Http2Exception.streamError(i3, Http2Error.PROTOCOL_ERROR, "Promised request on stream %d for promised stream %d is not known to be cacheable", Integer.valueOf(i2), Integer.valueOf(i3));
            }
            if (!DefaultHttp2ConnectionDecoder.this.requestVerifier.isSafe(http2Headers)) {
                throw Http2Exception.streamError(i3, Http2Error.PROTOCOL_ERROR, "Promised request on stream %d for promised stream %d is not known to be safe", Integer.valueOf(i2), Integer.valueOf(i3));
            }
            DefaultHttp2ConnectionDecoder.this.connection.remote().reservePushStream(i3, http2StreamStream);
            DefaultHttp2ConnectionDecoder.this.listener.onPushPromiseRead(channelHandlerContext, i2, i3, http2Headers, i4);
        }

        @Override // io.netty.handler.codec.http2.Http2FrameListener
        public void onRstStreamRead(ChannelHandlerContext channelHandlerContext, int i2, long j2) throws Http2Exception {
            Http2Stream http2StreamStream = DefaultHttp2ConnectionDecoder.this.connection.stream(i2);
            if (http2StreamStream == null) {
                verifyStreamMayHaveExisted(i2);
                return;
            }
            int iOrdinal = http2StreamStream.state().ordinal();
            if (iOrdinal == 0) {
                throw Http2Exception.connectionError(Http2Error.PROTOCOL_ERROR, "RST_STREAM received for IDLE stream %d", Integer.valueOf(i2));
            }
            if (iOrdinal != 6) {
                DefaultHttp2ConnectionDecoder.this.listener.onRstStreamRead(channelHandlerContext, i2, j2);
                DefaultHttp2ConnectionDecoder.this.lifecycleManager.closeStream(http2StreamStream, channelHandlerContext.newSucceededFuture());
            }
        }

        @Override // io.netty.handler.codec.http2.Http2FrameListener
        public void onSettingsAckRead(ChannelHandlerContext channelHandlerContext) throws Http2Exception {
            Http2Settings http2SettingsPollSentSettings = DefaultHttp2ConnectionDecoder.this.encoder.pollSentSettings();
            if (http2SettingsPollSentSettings != null) {
                applyLocalSettings(http2SettingsPollSentSettings);
            }
            DefaultHttp2ConnectionDecoder.this.listener.onSettingsAckRead(channelHandlerContext);
        }

        @Override // io.netty.handler.codec.http2.Http2FrameListener
        public void onSettingsRead(ChannelHandlerContext channelHandlerContext, Http2Settings http2Settings) {
            DefaultHttp2ConnectionDecoder.this.encoder.writeSettingsAck(channelHandlerContext, channelHandlerContext.newPromise());
            DefaultHttp2ConnectionDecoder.this.encoder.remoteSettings(http2Settings);
            DefaultHttp2ConnectionDecoder.this.listener.onSettingsRead(channelHandlerContext, http2Settings);
        }

        @Override // io.netty.handler.codec.http2.Http2FrameListener
        public void onUnknownFrame(ChannelHandlerContext channelHandlerContext, byte b2, int i2, Http2Flags http2Flags, ByteBuf byteBuf) {
            DefaultHttp2ConnectionDecoder.this.onUnknownFrame0(channelHandlerContext, b2, i2, http2Flags, byteBuf);
        }

        @Override // io.netty.handler.codec.http2.Http2FrameListener
        public void onWindowUpdateRead(ChannelHandlerContext channelHandlerContext, int i2, int i3) throws Http2Exception {
            Http2Stream http2StreamStream = DefaultHttp2ConnectionDecoder.this.connection.stream(i2);
            if (http2StreamStream == null || http2StreamStream.state() == Http2Stream.State.CLOSED || streamCreatedAfterGoAwaySent(i2)) {
                verifyStreamMayHaveExisted(i2);
            } else {
                DefaultHttp2ConnectionDecoder.this.encoder.flowController().incrementWindowSize(http2StreamStream, i3);
                DefaultHttp2ConnectionDecoder.this.listener.onWindowUpdateRead(channelHandlerContext, i2, i3);
            }
        }
    }

    public final class PrefaceFrameListener implements Http2FrameListener {
        private PrefaceFrameListener() {
        }

        public /* synthetic */ PrefaceFrameListener(DefaultHttp2ConnectionDecoder defaultHttp2ConnectionDecoder, AnonymousClass1 anonymousClass1) {
            this();
        }

        private void verifyPrefaceReceived() throws Http2Exception {
            if (!DefaultHttp2ConnectionDecoder.this.prefaceReceived()) {
                throw Http2Exception.connectionError(Http2Error.PROTOCOL_ERROR, "Received non-SETTINGS as first frame.", new Object[0]);
            }
        }

        @Override // io.netty.handler.codec.http2.Http2FrameListener
        public int onDataRead(ChannelHandlerContext channelHandlerContext, int i2, ByteBuf byteBuf, int i3, boolean z2) throws Http2Exception {
            verifyPrefaceReceived();
            return DefaultHttp2ConnectionDecoder.this.internalFrameListener.onDataRead(channelHandlerContext, i2, byteBuf, i3, z2);
        }

        @Override // io.netty.handler.codec.http2.Http2FrameListener
        public void onGoAwayRead(ChannelHandlerContext channelHandlerContext, int i2, long j2, ByteBuf byteBuf) throws Http2Exception {
            DefaultHttp2ConnectionDecoder.this.onGoAwayRead0(channelHandlerContext, i2, j2, byteBuf);
        }

        @Override // io.netty.handler.codec.http2.Http2FrameListener
        public void onHeadersRead(ChannelHandlerContext channelHandlerContext, int i2, Http2Headers http2Headers, int i3, short s2, boolean z2, int i4, boolean z3) throws Http2Exception {
            verifyPrefaceReceived();
            DefaultHttp2ConnectionDecoder.this.internalFrameListener.onHeadersRead(channelHandlerContext, i2, http2Headers, i3, s2, z2, i4, z3);
        }

        @Override // io.netty.handler.codec.http2.Http2FrameListener
        public void onHeadersRead(ChannelHandlerContext channelHandlerContext, int i2, Http2Headers http2Headers, int i3, boolean z2) throws Http2Exception {
            verifyPrefaceReceived();
            DefaultHttp2ConnectionDecoder.this.internalFrameListener.onHeadersRead(channelHandlerContext, i2, http2Headers, i3, z2);
        }

        @Override // io.netty.handler.codec.http2.Http2FrameListener
        public void onPingAckRead(ChannelHandlerContext channelHandlerContext, long j2) throws Http2Exception {
            verifyPrefaceReceived();
            DefaultHttp2ConnectionDecoder.this.internalFrameListener.onPingAckRead(channelHandlerContext, j2);
        }

        @Override // io.netty.handler.codec.http2.Http2FrameListener
        public void onPingRead(ChannelHandlerContext channelHandlerContext, long j2) throws Http2Exception {
            verifyPrefaceReceived();
            DefaultHttp2ConnectionDecoder.this.internalFrameListener.onPingRead(channelHandlerContext, j2);
        }

        @Override // io.netty.handler.codec.http2.Http2FrameListener
        public void onPriorityRead(ChannelHandlerContext channelHandlerContext, int i2, int i3, short s2, boolean z2) throws Http2Exception {
            verifyPrefaceReceived();
            DefaultHttp2ConnectionDecoder.this.internalFrameListener.onPriorityRead(channelHandlerContext, i2, i3, s2, z2);
        }

        @Override // io.netty.handler.codec.http2.Http2FrameListener
        public void onPushPromiseRead(ChannelHandlerContext channelHandlerContext, int i2, int i3, Http2Headers http2Headers, int i4) throws Http2Exception {
            verifyPrefaceReceived();
            DefaultHttp2ConnectionDecoder.this.internalFrameListener.onPushPromiseRead(channelHandlerContext, i2, i3, http2Headers, i4);
        }

        @Override // io.netty.handler.codec.http2.Http2FrameListener
        public void onRstStreamRead(ChannelHandlerContext channelHandlerContext, int i2, long j2) throws Http2Exception {
            verifyPrefaceReceived();
            DefaultHttp2ConnectionDecoder.this.internalFrameListener.onRstStreamRead(channelHandlerContext, i2, j2);
        }

        @Override // io.netty.handler.codec.http2.Http2FrameListener
        public void onSettingsAckRead(ChannelHandlerContext channelHandlerContext) throws Http2Exception {
            verifyPrefaceReceived();
            DefaultHttp2ConnectionDecoder.this.internalFrameListener.onSettingsAckRead(channelHandlerContext);
        }

        @Override // io.netty.handler.codec.http2.Http2FrameListener
        public void onSettingsRead(ChannelHandlerContext channelHandlerContext, Http2Settings http2Settings) {
            if (!DefaultHttp2ConnectionDecoder.this.prefaceReceived()) {
                DefaultHttp2ConnectionDecoder defaultHttp2ConnectionDecoder = DefaultHttp2ConnectionDecoder.this;
                defaultHttp2ConnectionDecoder.internalFrameListener = new FrameReadListener(defaultHttp2ConnectionDecoder, null);
            }
            DefaultHttp2ConnectionDecoder.this.internalFrameListener.onSettingsRead(channelHandlerContext, http2Settings);
        }

        @Override // io.netty.handler.codec.http2.Http2FrameListener
        public void onUnknownFrame(ChannelHandlerContext channelHandlerContext, byte b2, int i2, Http2Flags http2Flags, ByteBuf byteBuf) {
            DefaultHttp2ConnectionDecoder.this.onUnknownFrame0(channelHandlerContext, b2, i2, http2Flags, byteBuf);
        }

        @Override // io.netty.handler.codec.http2.Http2FrameListener
        public void onWindowUpdateRead(ChannelHandlerContext channelHandlerContext, int i2, int i3) throws Http2Exception {
            verifyPrefaceReceived();
            DefaultHttp2ConnectionDecoder.this.internalFrameListener.onWindowUpdateRead(channelHandlerContext, i2, i3);
        }
    }

    public DefaultHttp2ConnectionDecoder(Http2Connection http2Connection, Http2ConnectionEncoder http2ConnectionEncoder, Http2FrameReader http2FrameReader) {
        this(http2Connection, http2ConnectionEncoder, http2FrameReader, Http2PromisedRequestVerifier.ALWAYS_VERIFY);
    }

    public DefaultHttp2ConnectionDecoder(Http2Connection http2Connection, Http2ConnectionEncoder http2ConnectionEncoder, Http2FrameReader http2FrameReader, Http2PromisedRequestVerifier http2PromisedRequestVerifier) {
        this.internalFrameListener = new PrefaceFrameListener(this, null);
        this.connection = (Http2Connection) ObjectUtil.checkNotNull(http2Connection, "connection");
        this.frameReader = (Http2FrameReader) ObjectUtil.checkNotNull(http2FrameReader, "frameReader");
        this.encoder = (Http2ConnectionEncoder) ObjectUtil.checkNotNull(http2ConnectionEncoder, "encoder");
        this.requestVerifier = (Http2PromisedRequestVerifier) ObjectUtil.checkNotNull(http2PromisedRequestVerifier, "requestVerifier");
        if (http2Connection.local().flowController() == null) {
            http2Connection.local().flowController(new DefaultHttp2LocalFlowController(http2Connection));
        }
        ((Http2LocalFlowController) http2Connection.local().flowController()).frameWriter(http2ConnectionEncoder.frameWriter());
    }

    /* JADX INFO: Access modifiers changed from: private */
    public int unconsumedBytes(Http2Stream http2Stream) {
        return flowController().unconsumedBytes(http2Stream);
    }

    public long calculateMaxHeaderListSizeGoAway(long j2) {
        return Http2CodecUtil.calculateMaxHeaderListSizeGoAway(j2);
    }

    @Override // io.netty.handler.codec.http2.Http2ConnectionDecoder, java.io.Closeable, java.lang.AutoCloseable
    public void close() {
        this.frameReader.close();
    }

    @Override // io.netty.handler.codec.http2.Http2ConnectionDecoder
    public Http2Connection connection() {
        return this.connection;
    }

    @Override // io.netty.handler.codec.http2.Http2ConnectionDecoder
    public void decodeFrame(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf, List<Object> list) {
        this.frameReader.readFrame(channelHandlerContext, byteBuf, this.internalFrameListener);
    }

    @Override // io.netty.handler.codec.http2.Http2ConnectionDecoder
    public final Http2LocalFlowController flowController() {
        return (Http2LocalFlowController) this.connection.local().flowController();
    }

    @Override // io.netty.handler.codec.http2.Http2ConnectionDecoder
    public Http2FrameListener frameListener() {
        return this.listener;
    }

    @Override // io.netty.handler.codec.http2.Http2ConnectionDecoder
    public void frameListener(Http2FrameListener http2FrameListener) {
        this.listener = (Http2FrameListener) ObjectUtil.checkNotNull(http2FrameListener, "listener");
    }

    public Http2FrameListener internalFrameListener() {
        return this.internalFrameListener;
    }

    @Override // io.netty.handler.codec.http2.Http2ConnectionDecoder
    public void lifecycleManager(Http2LifecycleManager http2LifecycleManager) {
        this.lifecycleManager = (Http2LifecycleManager) ObjectUtil.checkNotNull(http2LifecycleManager, "lifecycleManager");
    }

    @Override // io.netty.handler.codec.http2.Http2ConnectionDecoder
    public Http2Settings localSettings() {
        Http2Settings http2Settings = new Http2Settings();
        Http2FrameReader.Configuration configuration = this.frameReader.configuration();
        Http2HeadersDecoder.Configuration configurationHeadersConfiguration = configuration.headersConfiguration();
        Http2FrameSizePolicy http2FrameSizePolicyFrameSizePolicy = configuration.frameSizePolicy();
        http2Settings.initialWindowSize(flowController().initialWindowSize());
        http2Settings.maxConcurrentStreams(this.connection.remote().maxActiveStreams());
        http2Settings.headerTableSize(configurationHeadersConfiguration.maxHeaderTableSize());
        http2Settings.maxFrameSize(http2FrameSizePolicyFrameSizePolicy.maxFrameSize());
        http2Settings.maxHeaderListSize(configurationHeadersConfiguration.maxHeaderListSize());
        if (!this.connection.isServer()) {
            http2Settings.pushEnabled(this.connection.local().allowPushTo());
        }
        return http2Settings;
    }

    public void onGoAwayRead0(ChannelHandlerContext channelHandlerContext, int i2, long j2, ByteBuf byteBuf) throws Http2Exception {
        if (this.connection.goAwayReceived() && this.connection.local().lastStreamKnownByPeer() < i2) {
            throw Http2Exception.connectionError(Http2Error.PROTOCOL_ERROR, "lastStreamId MUST NOT increase. Current value: %d new value: %d", Integer.valueOf(this.connection.local().lastStreamKnownByPeer()), Integer.valueOf(i2));
        }
        this.listener.onGoAwayRead(channelHandlerContext, i2, j2, byteBuf);
        this.connection.goAwayReceived(i2, j2, byteBuf);
    }

    public void onUnknownFrame0(ChannelHandlerContext channelHandlerContext, byte b2, int i2, Http2Flags http2Flags, ByteBuf byteBuf) {
        this.listener.onUnknownFrame(channelHandlerContext, b2, i2, http2Flags, byteBuf);
    }

    @Override // io.netty.handler.codec.http2.Http2ConnectionDecoder
    public boolean prefaceReceived() {
        return FrameReadListener.class == this.internalFrameListener.getClass();
    }
}
