package io.netty.handler.codec.http2;

import g.a.a.a.a;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPromise;
import io.netty.channel.CoalescingBufferQueue;
import io.netty.handler.codec.http.HttpStatusClass;
import io.netty.handler.codec.http2.Http2FrameWriter;
import io.netty.handler.codec.http2.Http2HeadersEncoder;
import io.netty.handler.codec.http2.Http2RemoteFlowController;
import io.netty.handler.codec.http2.Http2Stream;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.GenericFutureListener;
import io.netty.util.internal.ObjectUtil;
import java.util.ArrayDeque;

/* JADX INFO: loaded from: classes.dex */
public class DefaultHttp2ConnectionEncoder implements Http2ConnectionEncoder {
    private final Http2Connection connection;
    private final Http2FrameWriter frameWriter;
    private Http2LifecycleManager lifecycleManager;
    private final ArrayDeque<Http2Settings> outstandingLocalSettingsQueue = new ArrayDeque<>(4);

    /* JADX INFO: renamed from: io.netty.handler.codec.http2.DefaultHttp2ConnectionEncoder$3, reason: invalid class name */
    public static /* synthetic */ class AnonymousClass3 {
        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_REMOTE.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            try {
                $SwitchMap$io$netty$handler$codec$http2$Http2Stream$State[Http2Stream.State.RESERVED_LOCAL.ordinal()] = 3;
            } catch (NoSuchFieldError unused3) {
            }
        }
    }

    public abstract class FlowControlledBase implements Http2RemoteFlowController.FlowControlled, ChannelFutureListener {
        public boolean endOfStream;
        public int padding;
        public ChannelPromise promise;
        public final Http2Stream stream;

        public FlowControlledBase(Http2Stream http2Stream, int i2, boolean z2, ChannelPromise channelPromise) {
            if (i2 < 0) {
                throw new IllegalArgumentException("padding must be >= 0");
            }
            this.padding = i2;
            this.endOfStream = z2;
            this.stream = http2Stream;
            this.promise = channelPromise;
        }

        @Override // io.netty.util.concurrent.GenericFutureListener
        public void operationComplete(ChannelFuture channelFuture) {
            if (channelFuture.isSuccess()) {
                return;
            }
            error(DefaultHttp2ConnectionEncoder.this.flowController().channelHandlerContext(), channelFuture.cause());
        }

        @Override // io.netty.handler.codec.http2.Http2RemoteFlowController.FlowControlled
        public void writeComplete() {
            if (this.endOfStream) {
                DefaultHttp2ConnectionEncoder.this.lifecycleManager.closeStreamLocal(this.stream, this.promise);
            }
        }
    }

    public final class FlowControlledData extends FlowControlledBase {
        private int dataSize;
        private final CoalescingBufferQueue queue;

        public FlowControlledData(Http2Stream http2Stream, ByteBuf byteBuf, int i2, boolean z2, ChannelPromise channelPromise) {
            super(http2Stream, i2, z2, channelPromise);
            CoalescingBufferQueue coalescingBufferQueue = new CoalescingBufferQueue(channelPromise.channel());
            this.queue = coalescingBufferQueue;
            coalescingBufferQueue.add(byteBuf, channelPromise);
            this.dataSize = coalescingBufferQueue.readableBytes();
        }

        @Override // io.netty.handler.codec.http2.Http2RemoteFlowController.FlowControlled
        public void error(ChannelHandlerContext channelHandlerContext, Throwable th) {
            this.queue.releaseAndFailAll(th);
            DefaultHttp2ConnectionEncoder.this.lifecycleManager.onError(channelHandlerContext, true, th);
        }

        @Override // io.netty.handler.codec.http2.Http2RemoteFlowController.FlowControlled
        public boolean merge(ChannelHandlerContext channelHandlerContext, Http2RemoteFlowController.FlowControlled flowControlled) {
            if (FlowControlledData.class != flowControlled.getClass()) {
                return false;
            }
            FlowControlledData flowControlledData = (FlowControlledData) flowControlled;
            if (Integer.MAX_VALUE - flowControlledData.size() < size()) {
                return false;
            }
            flowControlledData.queue.copyTo(this.queue);
            this.dataSize = this.queue.readableBytes();
            this.padding = Math.max(this.padding, flowControlledData.padding);
            this.endOfStream = flowControlledData.endOfStream;
            return true;
        }

        @Override // io.netty.handler.codec.http2.Http2RemoteFlowController.FlowControlled
        public int size() {
            return this.dataSize + this.padding;
        }

        /* JADX WARN: Multi-variable type inference failed */
        /* JADX WARN: Type inference failed for: r12v9, types: [io.netty.channel.ChannelPromise] */
        /* JADX WARN: Type inference failed for: r9v0, types: [io.netty.channel.ChannelPromise] */
        /* JADX WARN: Type inference fix 'apply assigned field type' failed
        java.lang.UnsupportedOperationException: ArgType.getObject(), call class: class jadx.core.dex.instructions.args.ArgType$PrimitiveArg
        	at jadx.core.dex.instructions.args.ArgType.getObject(ArgType.java:593)
        	at jadx.core.dex.attributes.nodes.ClassTypeVarsAttr.getTypeVarsMapFor(ClassTypeVarsAttr.java:35)
        	at jadx.core.dex.nodes.utils.TypeUtils.replaceClassGenerics(TypeUtils.java:177)
        	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.insertExplicitUseCast(FixTypesVisitor.java:397)
        	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.tryFieldTypeWithNewCasts(FixTypesVisitor.java:359)
        	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.applyFieldType(FixTypesVisitor.java:309)
        	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.visit(FixTypesVisitor.java:94)
         */
        @Override // io.netty.handler.codec.http2.Http2RemoteFlowController.FlowControlled
        public void write(ChannelHandlerContext channelHandlerContext, int i2) {
            int i3 = this.queue.readableBytes();
            boolean z2 = false;
            if (!this.endOfStream) {
                if (i3 == 0) {
                    ?? AddListener = channelHandlerContext.newPromise().addListener((GenericFutureListener<? extends Future<? super Void>>) this);
                    channelHandlerContext.write(this.queue.remove(0, AddListener), AddListener);
                    return;
                } else if (i2 == 0) {
                    return;
                }
            }
            int iMin = Math.min(i3, i2);
            ?? AddListener2 = channelHandlerContext.newPromise().addListener((GenericFutureListener<? extends Future<? super Void>>) this);
            ByteBuf byteBufRemove = this.queue.remove(iMin, AddListener2);
            this.dataSize = this.queue.readableBytes();
            int iMin2 = Math.min(i2 - iMin, this.padding);
            this.padding -= iMin2;
            Http2FrameWriter http2FrameWriterFrameWriter = DefaultHttp2ConnectionEncoder.this.frameWriter();
            int iId = this.stream.id();
            if (this.endOfStream && size() == 0) {
                z2 = true;
            }
            http2FrameWriterFrameWriter.writeData(channelHandlerContext, iId, byteBufRemove, iMin2, z2, AddListener2);
        }
    }

    public final class FlowControlledHeaders extends FlowControlledBase {
        private final boolean exclusive;
        private final Http2Headers headers;
        private final int streamDependency;
        private final short weight;

        public FlowControlledHeaders(Http2Stream http2Stream, Http2Headers http2Headers, int i2, short s2, boolean z2, int i3, boolean z3, ChannelPromise channelPromise) {
            super(http2Stream, i3, z3, channelPromise);
            this.headers = http2Headers;
            this.streamDependency = i2;
            this.weight = s2;
            this.exclusive = z2;
        }

        @Override // io.netty.handler.codec.http2.Http2RemoteFlowController.FlowControlled
        public void error(ChannelHandlerContext channelHandlerContext, Throwable th) {
            if (channelHandlerContext != null) {
                DefaultHttp2ConnectionEncoder.this.lifecycleManager.onError(channelHandlerContext, true, th);
            }
            this.promise.tryFailure(th);
        }

        @Override // io.netty.handler.codec.http2.Http2RemoteFlowController.FlowControlled
        public boolean merge(ChannelHandlerContext channelHandlerContext, Http2RemoteFlowController.FlowControlled flowControlled) {
            return false;
        }

        @Override // io.netty.handler.codec.http2.Http2RemoteFlowController.FlowControlled
        public int size() {
            return 0;
        }

        @Override // io.netty.handler.codec.http2.Http2RemoteFlowController.FlowControlled
        public void write(ChannelHandlerContext channelHandlerContext, int i2) {
            boolean zValidateHeadersSentState = DefaultHttp2ConnectionEncoder.validateHeadersSentState(this.stream, this.headers, DefaultHttp2ConnectionEncoder.this.connection.isServer(), this.endOfStream);
            if (this.promise.isVoid()) {
                this.promise = channelHandlerContext.newPromise();
            }
            this.promise.addListener((GenericFutureListener<? extends Future<? super Void>>) this);
            if (DefaultHttp2ConnectionEncoder.this.frameWriter.writeHeaders(channelHandlerContext, this.stream.id(), this.headers, this.streamDependency, this.weight, this.exclusive, this.padding, this.endOfStream, this.promise).cause() == null) {
                this.stream.headersSent(zValidateHeadersSentState);
            }
        }
    }

    public DefaultHttp2ConnectionEncoder(Http2Connection http2Connection, Http2FrameWriter http2FrameWriter) {
        this.connection = (Http2Connection) ObjectUtil.checkNotNull(http2Connection, "connection");
        this.frameWriter = (Http2FrameWriter) ObjectUtil.checkNotNull(http2FrameWriter, "frameWriter");
        if (http2Connection.remote().flowController() == null) {
            http2Connection.remote().flowController(new DefaultHttp2RemoteFlowController(http2Connection));
        }
    }

    private void notifyLifecycleManagerOnError(ChannelFuture channelFuture, final ChannelHandlerContext channelHandlerContext) {
        channelFuture.addListener((GenericFutureListener<? extends Future<? super Void>>) new ChannelFutureListener() { // from class: io.netty.handler.codec.http2.DefaultHttp2ConnectionEncoder.2
            @Override // io.netty.util.concurrent.GenericFutureListener
            public void operationComplete(ChannelFuture channelFuture2) {
                Throwable thCause = channelFuture2.cause();
                if (thCause != null) {
                    DefaultHttp2ConnectionEncoder.this.lifecycleManager.onError(channelHandlerContext, true, thCause);
                }
            }
        });
    }

    private Http2Stream requireStream(int i2) {
        StringBuilder sb;
        String str;
        Http2Stream http2StreamStream = this.connection.stream(i2);
        if (http2StreamStream != null) {
            return http2StreamStream;
        }
        if (this.connection.streamMayHaveExisted(i2)) {
            sb = new StringBuilder();
            str = "Stream no longer exists: ";
        } else {
            sb = new StringBuilder();
            str = "Stream does not exist: ";
        }
        sb.append(str);
        sb.append(i2);
        throw new IllegalArgumentException(sb.toString());
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static boolean validateHeadersSentState(Http2Stream http2Stream, Http2Headers http2Headers, boolean z2, boolean z3) {
        boolean z4 = z2 && HttpStatusClass.valueOf(http2Headers.status()) == HttpStatusClass.INFORMATIONAL;
        if (((!z4 && z3) || !http2Stream.isHeadersSent()) && !http2Stream.isTrailersSent()) {
            return z4;
        }
        StringBuilder sbF = a.F("Stream ");
        sbF.append(http2Stream.id());
        sbF.append(" sent too many headers EOS: ");
        sbF.append(z3);
        throw new IllegalStateException(sbF.toString());
    }

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

    @Override // io.netty.handler.codec.http2.Http2FrameWriter
    public Http2FrameWriter.Configuration configuration() {
        return this.frameWriter.configuration();
    }

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

    @Override // io.netty.handler.codec.http2.Http2ConnectionEncoder
    public final Http2RemoteFlowController flowController() {
        return (Http2RemoteFlowController) connection().remote().flowController();
    }

    @Override // io.netty.handler.codec.http2.Http2ConnectionEncoder
    public Http2FrameWriter frameWriter() {
        return this.frameWriter;
    }

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

    @Override // io.netty.handler.codec.http2.Http2ConnectionEncoder
    public Http2Settings pollSentSettings() {
        return this.outstandingLocalSettingsQueue.poll();
    }

    @Override // io.netty.handler.codec.http2.Http2ConnectionEncoder
    public void remoteSettings(Http2Settings http2Settings) throws Http2Exception {
        Boolean boolPushEnabled = http2Settings.pushEnabled();
        Http2FrameWriter.Configuration configuration = configuration();
        Http2HeadersEncoder.Configuration configurationHeadersConfiguration = configuration.headersConfiguration();
        Http2FrameSizePolicy http2FrameSizePolicyFrameSizePolicy = configuration.frameSizePolicy();
        if (boolPushEnabled != null) {
            if (!this.connection.isServer() && boolPushEnabled.booleanValue()) {
                throw Http2Exception.connectionError(Http2Error.PROTOCOL_ERROR, "Client received a value of ENABLE_PUSH specified to other than 0", new Object[0]);
            }
            this.connection.remote().allowPushTo(boolPushEnabled.booleanValue());
        }
        Long lMaxConcurrentStreams = http2Settings.maxConcurrentStreams();
        if (lMaxConcurrentStreams != null) {
            this.connection.local().maxActiveStreams((int) Math.min(lMaxConcurrentStreams.longValue(), 2147483647L));
        }
        if (http2Settings.headerTableSize() != null) {
            configurationHeadersConfiguration.maxHeaderTableSize((int) Math.min(r0.longValue(), 2147483647L));
        }
        Long lMaxHeaderListSize = http2Settings.maxHeaderListSize();
        if (lMaxHeaderListSize != null) {
            configurationHeadersConfiguration.maxHeaderListSize(lMaxHeaderListSize.longValue());
        }
        Integer numMaxFrameSize = http2Settings.maxFrameSize();
        if (numMaxFrameSize != null) {
            http2FrameSizePolicyFrameSizePolicy.maxFrameSize(numMaxFrameSize.intValue());
        }
        Integer numInitialWindowSize = http2Settings.initialWindowSize();
        if (numInitialWindowSize != null) {
            flowController().initialWindowSize(numInitialWindowSize.intValue());
        }
    }

    @Override // io.netty.handler.codec.http2.Http2DataWriter
    public ChannelFuture writeData(ChannelHandlerContext channelHandlerContext, int i2, ByteBuf byteBuf, int i3, boolean z2, ChannelPromise channelPromise) {
        try {
            Http2Stream http2StreamRequireStream = requireStream(i2);
            int iOrdinal = http2StreamRequireStream.state().ordinal();
            if (iOrdinal != 3 && iOrdinal != 5) {
                throw new IllegalStateException("Stream " + http2StreamRequireStream.id() + " in unexpected state " + http2StreamRequireStream.state());
            }
            flowController().addFlowControlled(http2StreamRequireStream, new FlowControlledData(http2StreamRequireStream, byteBuf, i3, z2, channelPromise));
            return channelPromise;
        } catch (Throwable th) {
            byteBuf.release();
            return channelPromise.setFailure(th);
        }
    }

    @Override // io.netty.handler.codec.http2.Http2ConnectionEncoder, io.netty.handler.codec.http2.Http2FrameWriter
    public ChannelFuture writeFrame(ChannelHandlerContext channelHandlerContext, byte b2, int i2, Http2Flags http2Flags, ByteBuf byteBuf, ChannelPromise channelPromise) {
        return this.frameWriter.writeFrame(channelHandlerContext, b2, i2, http2Flags, byteBuf, channelPromise);
    }

    @Override // io.netty.handler.codec.http2.Http2FrameWriter
    public ChannelFuture writeGoAway(ChannelHandlerContext channelHandlerContext, int i2, long j2, ByteBuf byteBuf, ChannelPromise channelPromise) {
        return this.lifecycleManager.goAway(channelHandlerContext, i2, j2, byteBuf, channelPromise);
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Type inference failed for: r10v1, types: [io.netty.channel.ChannelPromise] */
    /* JADX WARN: Type inference failed for: r1v13, types: [io.netty.handler.codec.http2.Http2FrameWriter] */
    /* JADX WARN: Type inference fix 'apply assigned field type' failed
    java.lang.UnsupportedOperationException: ArgType.getObject(), call class: class jadx.core.dex.instructions.args.ArgType$PrimitiveArg
    	at jadx.core.dex.instructions.args.ArgType.getObject(ArgType.java:593)
    	at jadx.core.dex.attributes.nodes.ClassTypeVarsAttr.getTypeVarsMapFor(ClassTypeVarsAttr.java:35)
    	at jadx.core.dex.nodes.utils.TypeUtils.replaceClassGenerics(TypeUtils.java:177)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.insertExplicitUseCast(FixTypesVisitor.java:397)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.tryFieldTypeWithNewCasts(FixTypesVisitor.java:359)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.applyFieldType(FixTypesVisitor.java:309)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.visit(FixTypesVisitor.java:94)
     */
    @Override // io.netty.handler.codec.http2.Http2FrameWriter
    public ChannelFuture writeHeaders(ChannelHandlerContext channelHandlerContext, int i2, Http2Headers http2Headers, int i3, short s2, boolean z2, int i4, boolean z3, ChannelPromise channelPromise) {
        ChannelPromise channelPromise2 = channelPromise;
        try {
            Http2Stream http2StreamStream = this.connection.stream(i2);
            if (http2StreamStream == null) {
                try {
                    http2StreamStream = this.connection.local().createStream(i2, z3);
                } catch (Http2Exception e2) {
                    if (!this.connection.remote().mayHaveCreatedStream(i2)) {
                        throw e2;
                    }
                    channelPromise2.tryFailure(new IllegalStateException("Stream no longer exists: " + i2, e2));
                    return channelPromise2;
                }
            } else {
                int iOrdinal = http2StreamStream.state().ordinal();
                if (iOrdinal == 1) {
                    http2StreamStream.open(z3);
                } else if (iOrdinal != 3 && iOrdinal != 5) {
                    throw new IllegalStateException("Stream " + http2StreamStream.id() + " in unexpected state " + http2StreamStream.state());
                }
            }
            final Http2Stream http2Stream = http2StreamStream;
            Http2RemoteFlowController http2RemoteFlowControllerFlowController = flowController();
            if (z3 && http2RemoteFlowControllerFlowController.hasFlowControlled(http2Stream)) {
                http2RemoteFlowControllerFlowController.addFlowControlled(http2Stream, new FlowControlledHeaders(http2Stream, http2Headers, i3, s2, z2, i4, true, channelPromise));
                return channelPromise2;
            }
            boolean zValidateHeadersSentState = validateHeadersSentState(http2Stream, http2Headers, this.connection.isServer(), z3);
            Future<Void> futureAddListener = channelPromise2;
            if (z3) {
                futureAddListener = channelPromise.unvoid().addListener((GenericFutureListener<? extends Future<? super Void>>) new ChannelFutureListener() { // from class: io.netty.handler.codec.http2.DefaultHttp2ConnectionEncoder.1
                    @Override // io.netty.util.concurrent.GenericFutureListener
                    public void operationComplete(ChannelFuture channelFuture) {
                        DefaultHttp2ConnectionEncoder.this.lifecycleManager.closeStreamLocal(http2Stream, channelFuture);
                    }
                });
            }
            ChannelFuture channelFutureWriteHeaders = this.frameWriter.writeHeaders(channelHandlerContext, i2, http2Headers, i3, s2, z2, i4, z3, futureAddListener);
            Throwable thCause = channelFutureWriteHeaders.cause();
            if (thCause == null) {
                http2Stream.headersSent(zValidateHeadersSentState);
                if (!channelFutureWriteHeaders.isSuccess()) {
                    notifyLifecycleManagerOnError(channelFutureWriteHeaders, channelHandlerContext);
                }
            } else {
                this.lifecycleManager.onError(channelHandlerContext, true, thCause);
            }
            return channelFutureWriteHeaders;
        } catch (Throwable th) {
            this.lifecycleManager.onError(channelHandlerContext, true, th);
            channelPromise2.tryFailure(th);
            return channelPromise2;
        }
    }

    @Override // io.netty.handler.codec.http2.Http2FrameWriter
    public ChannelFuture writeHeaders(ChannelHandlerContext channelHandlerContext, int i2, Http2Headers http2Headers, int i3, boolean z2, ChannelPromise channelPromise) {
        return writeHeaders(channelHandlerContext, i2, http2Headers, 0, (short) 16, false, i3, z2, channelPromise);
    }

    @Override // io.netty.handler.codec.http2.Http2FrameWriter
    public ChannelFuture writePing(ChannelHandlerContext channelHandlerContext, boolean z2, long j2, ChannelPromise channelPromise) {
        return this.frameWriter.writePing(channelHandlerContext, z2, j2, channelPromise);
    }

    @Override // io.netty.handler.codec.http2.Http2FrameWriter
    public ChannelFuture writePriority(ChannelHandlerContext channelHandlerContext, int i2, int i3, short s2, boolean z2, ChannelPromise channelPromise) {
        return this.frameWriter.writePriority(channelHandlerContext, i2, i3, s2, z2, channelPromise);
    }

    @Override // io.netty.handler.codec.http2.Http2FrameWriter
    public ChannelFuture writePushPromise(ChannelHandlerContext channelHandlerContext, int i2, int i3, Http2Headers http2Headers, int i4, ChannelPromise channelPromise) {
        try {
            if (this.connection.goAwayReceived()) {
                throw Http2Exception.connectionError(Http2Error.PROTOCOL_ERROR, "Sending PUSH_PROMISE after GO_AWAY received.", new Object[0]);
            }
            Http2Stream http2StreamRequireStream = requireStream(i2);
            this.connection.local().reservePushStream(i3, http2StreamRequireStream);
            ChannelFuture channelFutureWritePushPromise = this.frameWriter.writePushPromise(channelHandlerContext, i2, i3, http2Headers, i4, channelPromise);
            Throwable thCause = channelFutureWritePushPromise.cause();
            if (thCause == null) {
                http2StreamRequireStream.pushPromiseSent();
                if (!channelFutureWritePushPromise.isSuccess()) {
                    notifyLifecycleManagerOnError(channelFutureWritePushPromise, channelHandlerContext);
                }
            } else {
                this.lifecycleManager.onError(channelHandlerContext, true, thCause);
            }
            return channelFutureWritePushPromise;
        } catch (Throwable th) {
            this.lifecycleManager.onError(channelHandlerContext, true, th);
            channelPromise.tryFailure(th);
            return channelPromise;
        }
    }

    @Override // io.netty.handler.codec.http2.Http2FrameWriter
    public ChannelFuture writeRstStream(ChannelHandlerContext channelHandlerContext, int i2, long j2, ChannelPromise channelPromise) {
        return this.lifecycleManager.resetStream(channelHandlerContext, i2, j2, channelPromise);
    }

    @Override // io.netty.handler.codec.http2.Http2FrameWriter
    public ChannelFuture writeSettings(ChannelHandlerContext channelHandlerContext, Http2Settings http2Settings, ChannelPromise channelPromise) {
        this.outstandingLocalSettingsQueue.add(http2Settings);
        try {
            if (http2Settings.pushEnabled() != null && this.connection.isServer()) {
                throw Http2Exception.connectionError(Http2Error.PROTOCOL_ERROR, "Server sending SETTINGS frame with ENABLE_PUSH specified", new Object[0]);
            }
            return this.frameWriter.writeSettings(channelHandlerContext, http2Settings, channelPromise);
        } catch (Throwable th) {
            return channelPromise.setFailure(th);
        }
    }

    @Override // io.netty.handler.codec.http2.Http2FrameWriter
    public ChannelFuture writeSettingsAck(ChannelHandlerContext channelHandlerContext, ChannelPromise channelPromise) {
        return this.frameWriter.writeSettingsAck(channelHandlerContext, channelPromise);
    }

    @Override // io.netty.handler.codec.http2.Http2FrameWriter
    public ChannelFuture writeWindowUpdate(ChannelHandlerContext channelHandlerContext, int i2, int i3, ChannelPromise channelPromise) {
        return channelPromise.setFailure((Throwable) new UnsupportedOperationException("Use the Http2[Inbound|Outbound]FlowController objects to control window sizes"));
    }
}
