package p447.p448.p455;

import java.io.Closeable;
import java.io.EOFException;
import java.io.IOException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import kotlin.jvm.internal.DefaultConstructorMarker;
import p138.p139.p143.p144.C2803;
import p402.InterfaceC6540;
import p402.p403.C6560;
import p402.p411.p413.C6635;
import p402.p417.C6659;
import p402.p417.C6664;
import p447.p448.C6943;
import p447.p448.p455.C7007;
import p461.C7103;
import p461.C7108;
import p461.C7130;
import p461.InterfaceC7107;
import p461.InterfaceC7129;

/* JADX INFO: renamed from: ސ.ޣ.އ.އ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
@InterfaceC6540
public final class C7032 implements Closeable {

    /* JADX INFO: renamed from: އ, reason: contains not printable characters */
    public static final Logger f20501;

    /* JADX INFO: renamed from: ވ, reason: contains not printable characters */
    public static final C7033 f20502 = new C7033(null);

    /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
    public final C7034 f20503;

    /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
    public final C7007.C7008 f20504;

    /* JADX INFO: renamed from: ޅ, reason: contains not printable characters */
    public final InterfaceC7107 f20505;

    /* JADX INFO: renamed from: ކ, reason: contains not printable characters */
    public final boolean f20506;

    /* JADX INFO: renamed from: ސ.ޣ.އ.އ$֏, reason: contains not printable characters */
    public static final class C7033 {
        public C7033() {
        }

        public /* synthetic */ C7033(DefaultConstructorMarker defaultConstructorMarker) {
        }

        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public final int m10325(int i, int i2, int i3) throws IOException {
            if ((i2 & 8) != 0) {
                i--;
            }
            if (i3 <= i) {
                return i - i3;
            }
            throw new IOException(C2803.m4873("PROTOCOL_ERROR padding ", i3, " > remaining length ", i));
        }
    }

    /* JADX INFO: renamed from: ސ.ޣ.އ.އ$ؠ, reason: contains not printable characters */
    public static final class C7034 implements InterfaceC7129 {

        /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
        public int f20507;

        /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
        public int f20508;

        /* JADX INFO: renamed from: ޅ, reason: contains not printable characters */
        public int f20509;

        /* JADX INFO: renamed from: ކ, reason: contains not printable characters */
        public int f20510;

        /* JADX INFO: renamed from: އ, reason: contains not printable characters */
        public int f20511;

        /* JADX INFO: renamed from: ވ, reason: contains not printable characters */
        public final InterfaceC7107 f20512;

        public C7034(InterfaceC7107 interfaceC7107) {
            if (interfaceC7107 != null) {
                this.f20512 = interfaceC7107;
            } else {
                C6635.m9824("source");
                throw null;
            }
        }

        @Override // p461.InterfaceC7129, java.io.Closeable, java.lang.AutoCloseable
        public void close() {
        }

        @Override // p461.InterfaceC7129
        /* JADX INFO: renamed from: ؠ */
        public long mo10207(C7103 c7103, long j) throws IOException {
            int i;
            int i2;
            if (c7103 == null) {
                C6635.m9824("sink");
                throw null;
            }
            do {
                int i3 = this.f20510;
                if (i3 != 0) {
                    long jMo10207 = this.f20512.mo10207(c7103, Math.min(j, i3));
                    if (jMo10207 == -1) {
                        return -1L;
                    }
                    this.f20510 -= (int) jMo10207;
                    return jMo10207;
                }
                this.f20512.skip(this.f20511);
                this.f20511 = 0;
                if ((this.f20508 & 4) != 0) {
                    return -1L;
                }
                i = this.f20509;
                int iM10151 = C6943.m10151(this.f20512);
                this.f20510 = iM10151;
                this.f20507 = iM10151;
                int i4 = this.f20512.readByte() & 255;
                this.f20508 = this.f20512.readByte() & 255;
                if (C7032.f20502 == null) {
                    throw null;
                }
                if (C7032.f20501.isLoggable(Level.FINE)) {
                    if (C7032.f20502 == null) {
                        throw null;
                    }
                    C7032.f20501.fine(C7010.f20415.m10294(true, this.f20509, this.f20507, i4, this.f20508));
                }
                i2 = this.f20512.readInt() & Integer.MAX_VALUE;
                this.f20509 = i2;
                if (i4 != 9) {
                    throw new IOException(i4 + " != TYPE_CONTINUATION");
                }
            } while (i2 == i);
            throw new IOException("TYPE_CONTINUATION streamId changed");
        }

        @Override // p461.InterfaceC7129
        /* JADX INFO: renamed from: ށ */
        public C7130 mo10277() {
            return this.f20512.mo10277();
        }
    }

    /* JADX INFO: renamed from: ސ.ޣ.އ.އ$ހ, reason: contains not printable characters */
    public interface InterfaceC7035 {
        /* JADX INFO: renamed from: ֏ */
        void mo10310();

        /* JADX INFO: renamed from: ֏ */
        void mo10311(int i, int i2, int i3, boolean z);

        /* JADX INFO: renamed from: ֏ */
        void mo10312(int i, int i2, List<C7005> list);

        /* JADX INFO: renamed from: ֏ */
        void mo10313(int i, long j);

        /* JADX INFO: renamed from: ֏ */
        void mo10314(int i, EnumC7003 enumC7003);

        /* JADX INFO: renamed from: ֏ */
        void mo10315(int i, EnumC7003 enumC7003, C7108 c7108);

        /* JADX INFO: renamed from: ֏ */
        void mo10316(boolean z, int i, int i2);

        /* JADX INFO: renamed from: ֏ */
        void mo10317(boolean z, int i, int i2, List<C7005> list);

        /* JADX INFO: renamed from: ֏ */
        void mo10318(boolean z, int i, InterfaceC7107 interfaceC7107, int i2);

        /* JADX INFO: renamed from: ֏ */
        void mo10319(boolean z, C7048 c7048);
    }

    static {
        Logger logger = Logger.getLogger(C7010.class.getName());
        C6635.m9823((Object) logger, "Logger.getLogger(Http2::class.java.name)");
        f20501 = logger;
    }

    public C7032(InterfaceC7107 interfaceC7107, boolean z) {
        if (interfaceC7107 == null) {
            C6635.m9824("source");
            throw null;
        }
        this.f20505 = interfaceC7107;
        this.f20506 = z;
        C7034 c7034 = new C7034(interfaceC7107);
        this.f20503 = c7034;
        this.f20504 = new C7007.C7008(c7034, 4096, 0, 4, null);
    }

    @Override // java.io.Closeable, java.lang.AutoCloseable
    public void close() {
        this.f20505.close();
    }

    /* JADX WARN: Removed duplicated region for block: B:14:0x003f  */
    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final List<C7005> m10321(int i, int i2, int i3, int i4) throws IOException {
        C7034 c7034 = this.f20503;
        c7034.f20510 = i;
        c7034.f20507 = i;
        c7034.f20511 = i2;
        c7034.f20508 = i3;
        c7034.f20509 = i4;
        C7007.C7008 c7008 = this.f20504;
        while (!c7008.f20394.mo10436()) {
            int iM10141 = C6943.m10141(c7008.f20394.readByte(), 255);
            if (iM10141 == 128) {
                throw new IOException("index == 0");
            }
            if ((iM10141 & 128) == 128) {
                int iM10282 = c7008.m10282(iM10141, 127) - 1;
                if (iM10282 >= 0) {
                    C7007 c7007 = C7007.f20392;
                    boolean z = iM10282 <= C7007.f20390.length + (-1);
                    if (!z) {
                        C7007 c70072 = C7007.f20392;
                        int iM10281 = c7008.m10281(iM10282 - C7007.f20390.length);
                        if (iM10281 >= 0) {
                            C7005[] c7005Arr = c7008.f20395;
                            if (iM10281 < c7005Arr.length) {
                                List<C7005> list = c7008.f20393;
                                C7005 c7005 = c7005Arr[iM10281];
                                if (c7005 == null) {
                                    C6635.m9822();
                                    throw null;
                                }
                                list.add(c7005);
                            }
                        }
                        StringBuilder sbM4889 = C2803.m4889("Header index too large ");
                        sbM4889.append(iM10282 + 1);
                        throw new IOException(sbM4889.toString());
                    }
                    C7007 c70073 = C7007.f20392;
                    c7008.f20393.add(C7007.f20390[iM10282]);
                }
            } else if (iM10141 == 64) {
                C7007 c70074 = C7007.f20392;
                C7108 c7108M10286 = c7008.m10286();
                c70074.m10280(c7108M10286);
                c7008.m10284(-1, new C7005(c7108M10286, c7008.m10286()));
            } else if ((iM10141 & 64) == 64) {
                c7008.m10284(-1, new C7005(c7008.m10287(c7008.m10282(iM10141, 63) - 1), c7008.m10286()));
            } else if ((iM10141 & 32) == 32) {
                int iM102822 = c7008.m10282(iM10141, 31);
                c7008.f20400 = iM102822;
                if (iM102822 < 0 || iM102822 > c7008.f20399) {
                    StringBuilder sbM48892 = C2803.m4889("Invalid dynamic table size update ");
                    sbM48892.append(c7008.f20400);
                    throw new IOException(sbM48892.toString());
                }
                int i5 = c7008.f20398;
                if (iM102822 < i5) {
                    if (iM102822 == 0) {
                        c7008.m10283();
                    } else {
                        c7008.m10285(i5 - iM102822);
                    }
                }
            } else if (iM10141 == 16 || iM10141 == 0) {
                C7007 c70075 = C7007.f20392;
                C7108 c7108M102862 = c7008.m10286();
                c70075.m10280(c7108M102862);
                c7008.f20393.add(new C7005(c7108M102862, c7008.m10286()));
            } else {
                c7008.f20393.add(new C7005(c7008.m10287(c7008.m10282(iM10141, 15) - 1), c7008.m10286()));
            }
        }
        C7007.C7008 c70082 = this.f20504;
        List<C7005> listM9777 = C6560.m9777((Iterable) c70082.f20393);
        c70082.f20393.clear();
        return listM9777;
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final void m10322(InterfaceC7035 interfaceC7035) throws IOException {
        if (interfaceC7035 == null) {
            C6635.m9824("handler");
            throw null;
        }
        if (this.f20506) {
            if (!m10324(true, interfaceC7035)) {
                throw new IOException("Required SETTINGS preface not received");
            }
            return;
        }
        C7108 c7108Mo10427 = this.f20505.mo10427(C7010.f20411.mo10450());
        if (f20501.isLoggable(Level.FINE)) {
            Logger logger = f20501;
            StringBuilder sbM4889 = C2803.m4889("<< CONNECTION ");
            sbM4889.append(c7108Mo10427.mo10451());
            logger.fine(C6943.m10156(sbM4889.toString(), new Object[0]));
        }
        if (!C6635.m9825(C7010.f20411, c7108Mo10427)) {
            StringBuilder sbM48892 = C2803.m4889("Expected a connection header but was ");
            sbM48892.append(c7108Mo10427.m10454());
            throw new IOException(sbM48892.toString());
        }
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final void m10323(InterfaceC7035 interfaceC7035, int i) {
        int i2 = this.f20505.readInt();
        interfaceC7035.mo10311(i, i2 & Integer.MAX_VALUE, C6943.m10141(this.f20505.readByte(), 255) + 1, (i2 & ((int) 2147483648L)) != 0);
    }

    /* JADX WARN: Code restructure failed: missing block: B:86:0x01ac, code lost:
    
        throw new java.io.IOException(p138.p139.p143.p144.C2803.m4871("PROTOCOL_ERROR SETTINGS_MAX_FRAME_SIZE: ", r6));
     */
    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final boolean m10324(boolean z, InterfaceC7035 interfaceC7035) throws IOException {
        if (interfaceC7035 == null) {
            C6635.m9824("handler");
            throw null;
        }
        try {
            this.f20505.mo10431(9L);
            int iM10151 = C6943.m10151(this.f20505);
            if (iM10151 > 16384) {
                throw new IOException(C2803.m4871("FRAME_SIZE_ERROR: ", iM10151));
            }
            int i = this.f20505.readByte() & 255;
            if (z && i != 4) {
                throw new IOException(C2803.m4871("Expected a SETTINGS frame but was ", i));
            }
            int i2 = this.f20505.readByte() & 255;
            int i3 = this.f20505.readInt() & Integer.MAX_VALUE;
            if (f20501.isLoggable(Level.FINE)) {
                f20501.fine(C7010.f20415.m10294(true, i3, iM10151, i, i2));
            }
            switch (i) {
                case 0:
                    if (i3 == 0) {
                        throw new IOException("PROTOCOL_ERROR: TYPE_DATA streamId == 0");
                    }
                    boolean z2 = (i2 & 1) != 0;
                    if ((i2 & 32) != 0) {
                        throw new IOException("PROTOCOL_ERROR: FLAG_COMPRESSED without SETTINGS_COMPRESS_DATA");
                    }
                    int iM10141 = (i2 & 8) != 0 ? C6943.m10141(this.f20505.readByte(), 255) : 0;
                    interfaceC7035.mo10318(z2, i3, this.f20505, f20502.m10325(iM10151, i2, iM10141));
                    this.f20505.skip(iM10141);
                    return true;
                case 1:
                    if (i3 == 0) {
                        throw new IOException("PROTOCOL_ERROR: TYPE_HEADERS streamId == 0");
                    }
                    boolean z3 = (i2 & 1) != 0;
                    int iM101412 = (i2 & 8) != 0 ? C6943.m10141(this.f20505.readByte(), 255) : 0;
                    if ((i2 & 32) != 0) {
                        m10323(interfaceC7035, i3);
                        iM10151 -= 5;
                    }
                    interfaceC7035.mo10317(z3, i3, -1, m10321(f20502.m10325(iM10151, i2, iM101412), iM101412, i2, i3));
                    return true;
                case 2:
                    if (iM10151 != 5) {
                        throw new IOException(C2803.m4872("TYPE_PRIORITY length: ", iM10151, " != 5"));
                    }
                    if (i3 == 0) {
                        throw new IOException("TYPE_PRIORITY streamId == 0");
                    }
                    m10323(interfaceC7035, i3);
                    return true;
                case 3:
                    if (iM10151 != 4) {
                        throw new IOException(C2803.m4872("TYPE_RST_STREAM length: ", iM10151, " != 4"));
                    }
                    if (i3 == 0) {
                        throw new IOException("TYPE_RST_STREAM streamId == 0");
                    }
                    int i4 = this.f20505.readInt();
                    EnumC7003 enumC7003M10279 = EnumC7003.f20379.m10279(i4);
                    if (enumC7003M10279 == null) {
                        throw new IOException(C2803.m4871("TYPE_RST_STREAM unexpected error code: ", i4));
                    }
                    interfaceC7035.mo10314(i3, enumC7003M10279);
                    return true;
                case 4:
                    if (i3 != 0) {
                        throw new IOException("TYPE_SETTINGS streamId != 0");
                    }
                    if ((i2 & 1) == 0) {
                        if (iM10151 % 6 != 0) {
                            throw new IOException(C2803.m4871("TYPE_SETTINGS length % 6 != 0: ", iM10151));
                        }
                        C7048 c7048 = new C7048();
                        C6659 c6659M9845 = C6664.m9845(C6664.m9846(0, iM10151), 6);
                        int i5 = c6659M9845.f19412;
                        int i6 = c6659M9845.f19413;
                        int i7 = c6659M9845.f19414;
                        if (i7 < 0 ? i5 >= i6 : i5 <= i6) {
                            while (true) {
                                int iM10152 = C6943.m10152(this.f20505.readShort(), 65535);
                                int i8 = this.f20505.readInt();
                                if (iM10152 != 2) {
                                    if (iM10152 == 3) {
                                        iM10152 = 4;
                                    } else if (iM10152 == 4) {
                                        iM10152 = 7;
                                        if (i8 < 0) {
                                            throw new IOException("PROTOCOL_ERROR SETTINGS_INITIAL_WINDOW_SIZE > 2^31 - 1");
                                        }
                                    } else if (iM10152 == 5 && (i8 < 16384 || i8 > 16777215)) {
                                    }
                                } else if (i8 != 0 && i8 != 1) {
                                    throw new IOException("PROTOCOL_ERROR SETTINGS_ENABLE_PUSH != 0 or 1");
                                }
                                c7048.m10362(iM10152, i8);
                                if (i5 != i6) {
                                    i5 += i7;
                                }
                            }
                        }
                        interfaceC7035.mo10319(false, c7048);
                        break;
                    } else {
                        if (iM10151 != 0) {
                            throw new IOException("FRAME_SIZE_ERROR ack frame should be empty!");
                        }
                        interfaceC7035.mo10310();
                    }
                    return true;
                case 5:
                    if (i3 == 0) {
                        throw new IOException("PROTOCOL_ERROR: TYPE_PUSH_PROMISE streamId == 0");
                    }
                    int iM101413 = (i2 & 8) != 0 ? C6943.m10141(this.f20505.readByte(), 255) : 0;
                    interfaceC7035.mo10312(i3, this.f20505.readInt() & Integer.MAX_VALUE, m10321(f20502.m10325(iM10151 - 4, i2, iM101413), iM101413, i2, i3));
                    return true;
                case 6:
                    if (iM10151 != 8) {
                        throw new IOException(C2803.m4871("TYPE_PING length != 8: ", iM10151));
                    }
                    if (i3 != 0) {
                        throw new IOException("TYPE_PING streamId != 0");
                    }
                    interfaceC7035.mo10316((i2 & 1) != 0, this.f20505.readInt(), this.f20505.readInt());
                    return true;
                case 7:
                    if (iM10151 < 8) {
                        throw new IOException(C2803.m4871("TYPE_GOAWAY length < 8: ", iM10151));
                    }
                    if (i3 != 0) {
                        throw new IOException("TYPE_GOAWAY streamId != 0");
                    }
                    int i9 = this.f20505.readInt();
                    int i10 = this.f20505.readInt();
                    int i11 = iM10151 - 8;
                    EnumC7003 enumC7003M102792 = EnumC7003.f20379.m10279(i10);
                    if (enumC7003M102792 == null) {
                        throw new IOException(C2803.m4871("TYPE_GOAWAY unexpected error code: ", i10));
                    }
                    C7108 c7108Mo10427 = C7108.f20633;
                    if (i11 > 0) {
                        c7108Mo10427 = this.f20505.mo10427(i11);
                    }
                    interfaceC7035.mo10315(i9, enumC7003M102792, c7108Mo10427);
                    return true;
                case 8:
                    if (iM10151 != 4) {
                        throw new IOException(C2803.m4871("TYPE_WINDOW_UPDATE length !=4: ", iM10151));
                    }
                    long jM10154 = C6943.m10154(this.f20505.readInt(), 2147483647L);
                    if (jM10154 == 0) {
                        throw new IOException("windowSizeIncrement was 0");
                    }
                    interfaceC7035.mo10313(i3, jM10154);
                    return true;
                default:
                    this.f20505.skip(iM10151);
                    return true;
            }
        } catch (EOFException unused) {
            return false;
        }
    }
}
