package defpackage;

import java.io.IOException;
import java.net.Inet6Address;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.Socket;
import java.net.SocketAddress;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.net.UnknownServiceException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;

/* renamed from: ʾᵝ, reason: contains not printable characters */
/* loaded from: classes3.dex */
public final class C0290 {

    /* renamed from: ˇʼʤˎ, reason: contains not printable characters */
    public final int f1894;

    /* renamed from: ˌʾˀ, reason: contains not printable characters */
    public final C2366 f1895 = new C2366();

    /* renamed from: ˌᵜᵹᵩ, reason: contains not printable characters */
    public final boolean f1896;

    /* renamed from: ˎˏʜʾ, reason: contains not printable characters */
    public final boolean f1897;

    /* renamed from: ˏˋٴ, reason: contains not printable characters */
    public final int f1898;

    /* renamed from: ˏᵙ, reason: contains not printable characters */
    public final int f1899;

    /* renamed from: ᵝᵵᵺ, reason: contains not printable characters */
    public final C5145 f1900;

    /* renamed from: ᵥᵯˎ, reason: contains not printable characters */
    public final C3246 f1901;

    /* renamed from: ᵪʩ, reason: contains not printable characters */
    public C2951 f1902;

    /* renamed from: ᵯٴᵦ, reason: contains not printable characters */
    public C3877 f1903;

    /* renamed from: ᵳٴᵶ, reason: contains not printable characters */
    public C5057 f1904;

    /* renamed from: ᵴᵳ, reason: contains not printable characters */
    public final C5557 f1905;

    /* renamed from: ᵶᵷᵕ, reason: contains not printable characters */
    public final ᵿʤˑᵦ f1906;

    /* renamed from: ᵸˑ, reason: contains not printable characters */
    public final C1588 f1907;

    /* renamed from: ᵹᵝᵶ, reason: contains not printable characters */
    public final boolean f1908;

    /* renamed from: ᵻᵢﹳᵰ, reason: contains not printable characters */
    public final int f1909;

    public C0290(C3246 c3246, C5557 c5557, int i, int i2, int i3, int i4, boolean z, boolean z2, C5145 c5145, ᵿʤˑᵦ r10, C1588 c1588, C1947 c1947) {
        this.f1901 = c3246;
        this.f1905 = c5557;
        this.f1899 = i;
        this.f1909 = i2;
        this.f1894 = i3;
        this.f1898 = i4;
        this.f1897 = z;
        this.f1908 = z2;
        this.f1900 = c5145;
        this.f1906 = r10;
        this.f1907 = c1588;
        this.f1896 = !ᵲᵝᵪ.ᵹᵝᵶ(c1947.f7851, "GET");
    }

    /* JADX WARN: Removed duplicated region for block: B:22:0x003a A[Catch: all -> 0x0038, TryCatch #0 {all -> 0x0038, blocks: (B:14:0x002d, B:22:0x003a, B:25:0x0041), top: B:51:0x002d }] */
    /* renamed from: ˇʼʤˎ, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public final defpackage.C1006 m1632(defpackage.C4121 r11, java.util.List r12) {
        /*
            r10 = this;
            ﹳי r0 = r10.f1905
            boolean r1 = r10.f1896
            ᵺᵯ r2 = r10.f1900
            ˌˋˎᵚ r3 = r10.f1907
            r4 = 0
            r5 = 1
            if (r11 == 0) goto L14
            boolean r6 = r11.mo1054()
            if (r6 == 0) goto L14
            r6 = r5
            goto L15
        L14:
            r6 = r4
        L15:
            java.lang.Object r0 = r0.f20845
            java.util.concurrent.ConcurrentLinkedQueue r0 = (java.util.concurrent.ConcurrentLinkedQueue) r0
            java.util.Iterator r0 = r0.iterator()
        L1d:
            boolean r7 = r0.hasNext()
            r8 = 0
            if (r7 == 0) goto L62
            java.lang.Object r7 = r0.next()
            ˁᵕˏᵘ r7 = (defpackage.C0700) r7
            monitor-enter(r7)
            if (r6 == 0) goto L3a
            ᵳˋᵢ r9 = r7.f3404     // Catch: java.lang.Throwable -> L38
            if (r9 == 0) goto L33
            r9 = r5
            goto L34
        L33:
            r9 = r4
        L34:
            if (r9 != 0) goto L3a
        L36:
            r9 = r4
            goto L45
        L38:
            r10 = move-exception
            goto L60
        L3a:
            boolean r9 = r7.m2695(r2, r12)     // Catch: java.lang.Throwable -> L38
            if (r9 != 0) goto L41
            goto L36
        L41:
            r3.m4567(r7)     // Catch: java.lang.Throwable -> L38
            r9 = r5
        L45:
            monitor-exit(r7)
            if (r9 == 0) goto L1d
            boolean r9 = r7.m2696(r1)
            if (r9 == 0) goto L4f
            goto L63
        L4f:
            monitor-enter(r7)
            r7.f3410 = r5     // Catch: java.lang.Throwable -> L5d
            java.net.Socket r8 = r3.m4560()     // Catch: java.lang.Throwable -> L5d
            monitor-exit(r7)
            if (r8 == 0) goto L1d
            defpackage.AbstractC4061.m8927(r8)
            goto L1d
        L5d:
            r10 = move-exception
            monitor-exit(r7)
            throw r10
        L60:
            monitor-exit(r7)
            throw r10
        L62:
            r7 = r8
        L63:
            if (r7 != 0) goto L66
            return r8
        L66:
            if (r11 == 0) goto L73
            ᵹᵟʼﹳ r12 = r11.f15401
            r10.f1904 = r12
            java.net.Socket r10 = r11.f15394
            if (r10 == 0) goto L73
            defpackage.AbstractC4061.m8927(r10)
        L73:
            ˈʩʣ r10 = new ˈʩʣ
            r10.<init>(r7)
            return r10
        */
        throw new UnsupportedOperationException("Method not decompiled: defpackage.C0290.m1632(ᵭـᵡ, java.util.List):ˈʩʣ");
    }

    /* renamed from: ˏᵙ, reason: contains not printable characters */
    public final C4121 m1633() throws IOException {
        String hostName;
        int port;
        List listSingletonList;
        boolean zContains;
        C5057 c5057 = this.f1904;
        if (c5057 != null) {
            this.f1904 = null;
            return m1636(c5057, null);
        }
        C3877 c3877 = this.f1903;
        if (c3877 != null && c3877.f14416 < c3877.f14415.size()) {
            int i = c3877.f14416;
            ArrayList arrayList = c3877.f14415;
            if (i >= arrayList.size()) {
                C0190.m1427();
                return null;
            }
            int i2 = c3877.f14416;
            c3877.f14416 = i2 + 1;
            return m1636((C5057) arrayList.get(i2), null);
        }
        C2951 c2951 = this.f1902;
        if (c2951 == null) {
            c2951 = new C2951(this.f1900, this.f1906, this.f1907, this.f1908);
            this.f1902 = c2951;
        }
        if (!c2951.m7224()) {
            C0910.m3045("exhausted all routes");
            return null;
        }
        if (!c2951.m7224()) {
            C0190.m1427();
            return null;
        }
        ArrayList arrayList2 = new ArrayList();
        while (c2951.f11428 < c2951.f11434.size()) {
            C5145 c5145 = c2951.f11432;
            if (c2951.f11428 >= c2951.f11434.size()) {
                throw new SocketException("No route to " + c5145.f19157.f6002 + "; exhausted proxy configurations: " + c2951.f11434);
            }
            List list = c2951.f11434;
            int i3 = c2951.f11428;
            c2951.f11428 = i3 + 1;
            Proxy proxy = (Proxy) list.get(i3);
            ArrayList arrayList3 = new ArrayList();
            c2951.f11430 = arrayList3;
            if (proxy.type() == Proxy.Type.DIRECT || proxy.type() == Proxy.Type.SOCKS) {
                C1489 c1489 = c5145.f19157;
                hostName = c1489.f6002;
                port = c1489.f5994;
            } else {
                SocketAddress socketAddressAddress = proxy.address();
                if (!(socketAddressAddress instanceof InetSocketAddress)) {
                    C1260.m3815(socketAddressAddress.getClass(), "Proxy.address() is not an InetSocketAddress: ");
                    return null;
                }
                InetSocketAddress inetSocketAddress = (InetSocketAddress) socketAddressAddress;
                InetAddress address = inetSocketAddress.getAddress();
                hostName = address == null ? inetSocketAddress.getHostName() : address.getHostAddress();
                port = inetSocketAddress.getPort();
            }
            if (1 > port || port >= 65536) {
                throw new SocketException("No route to " + hostName + ':' + port + "; port is out of range");
            }
            if (proxy.type() == Proxy.Type.SOCKS) {
                arrayList3.add(InetSocketAddress.createUnresolved(hostName, port));
            } else {
                if (AbstractC1218.f5147.f14115.matcher(hostName).matches()) {
                    listSingletonList = Collections.singletonList(InetAddress.getByName(hostName));
                } else {
                    c5145.f19154.getClass();
                    try {
                        List listM4717 = AbstractC1658.m4717(InetAddress.getAllByName(hostName));
                        if (listM4717.isEmpty()) {
                            throw new UnknownHostException(c5145.f19154 + " returned no addresses for " + hostName);
                        }
                        listSingletonList = listM4717;
                    } catch (NullPointerException e) {
                        UnknownHostException unknownHostException = new UnknownHostException("Broken system behaviour for dns lookup of ".concat(hostName));
                        unknownHostException.initCause(e);
                        throw unknownHostException;
                    }
                }
                if (c2951.f11431 && listSingletonList.size() >= 2) {
                    ArrayList arrayList4 = new ArrayList();
                    ArrayList arrayList5 = new ArrayList();
                    for (Object obj : listSingletonList) {
                        if (((InetAddress) obj) instanceof Inet6Address) {
                            arrayList4.add(obj);
                        } else {
                            arrayList5.add(obj);
                        }
                    }
                    if (!arrayList4.isEmpty() && !arrayList5.isEmpty()) {
                        byte[] bArr = AbstractC1348.f5567;
                        Iterator it = arrayList4.iterator();
                        Iterator it2 = arrayList5.iterator();
                        C3947 c3947 = ᵿᵧ.ˎˏʜʾ();
                        while (true) {
                            if (!it.hasNext() && !it2.hasNext()) {
                                break;
                            }
                            if (it.hasNext()) {
                                c3947.add(it.next());
                            }
                            if (it2.hasNext()) {
                                c3947.add(it2.next());
                            }
                        }
                        listSingletonList = ᵿᵧ.ˏᵙ(c3947);
                    }
                }
                Iterator it3 = listSingletonList.iterator();
                while (it3.hasNext()) {
                    arrayList3.add(new InetSocketAddress((InetAddress) it3.next(), port));
                }
            }
            Iterator it4 = c2951.f11430.iterator();
            while (it4.hasNext()) {
                C5057 c50572 = new C5057(c2951.f11432, proxy, (InetSocketAddress) it4.next());
                ᵿʤˑᵦ r4 = c2951.f11433;
                synchronized (r4) {
                    zContains = ((LinkedHashSet) r4.ᵢˇᵭ).contains(c50572);
                }
                if (zContains) {
                    c2951.f11429.add(c50572);
                } else {
                    arrayList2.add(c50572);
                }
            }
            if (!arrayList2.isEmpty()) {
                break;
            }
        }
        if (arrayList2.isEmpty()) {
            AbstractC2767.m6826(c2951.f11429, arrayList2);
            c2951.f11429.clear();
        }
        C3877 c38772 = new C3877(arrayList2);
        this.f1903 = c38772;
        if (this.f1907.f6293) {
            C0910.m3045("Canceled");
            return null;
        }
        if (c38772.f14416 >= arrayList2.size()) {
            C0190.m1427();
            return null;
        }
        int i4 = c38772.f14416;
        c38772.f14416 = i4 + 1;
        return m1636((C5057) arrayList2.get(i4), arrayList2);
    }

    /* renamed from: ᵥᵯˎ, reason: contains not printable characters */
    public final boolean m1634(C0700 c0700) {
        C2951 c2951;
        C5057 c5057;
        if (this.f1895.isEmpty() && this.f1904 == null) {
            if (c0700 != null) {
                synchronized (c0700) {
                    c5057 = null;
                    if (c0700.f3400 == 0 && c0700.f3410 && AbstractC4061.m8926(c0700.f3403.f18888.f19157, this.f1900.f19157)) {
                        c5057 = c0700.f3403;
                    }
                }
                if (c5057 != null) {
                    this.f1904 = c5057;
                    return true;
                }
            }
            C3877 c3877 = this.f1903;
            if ((c3877 == null || c3877.f14416 >= c3877.f14415.size()) && (c2951 = this.f1902) != null) {
                return c2951.m7224();
            }
        }
        return true;
    }

    /* renamed from: ᵴᵳ, reason: contains not printable characters */
    public final InterfaceC0041 m1635() throws IOException {
        Socket socketM4560;
        C1006 c1006;
        C0700 c0700 = this.f1907.f6298;
        if (c0700 == null) {
            c1006 = null;
        } else {
            boolean zM2696 = c0700.m2696(this.f1896);
            synchronized (c0700) {
                boolean z = c0700.f3410;
                boolean z2 = true;
                try {
                    if (!zM2696) {
                        c0700.f3410 = true;
                        socketM4560 = this.f1907.m4560();
                    } else if (!z) {
                        C1489 c1489 = c0700.f3403.f18888.f19157;
                        C1489 c14892 = this.f1900.f19157;
                        if (c1489.f5994 != c14892.f5994 || !ᵲᵝᵪ.ᵹᵝᵶ(c1489.f6002, c14892.f6002)) {
                            z2 = false;
                        }
                        socketM4560 = !z2 ? this.f1907.m4560() : null;
                    }
                } finally {
                }
            }
            if (this.f1907.f6298 == null) {
                if (socketM4560 != null) {
                    AbstractC4061.m8927(socketM4560);
                }
                c1006 = null;
            } else {
                if (socketM4560 != null) {
                    ᵹˉᵞ.ᵳٴᵶ("Check failed.");
                    return null;
                }
                c1006 = new C1006(c0700);
            }
        }
        if (c1006 != null) {
            return c1006;
        }
        C1006 c1006M1632 = m1632(null, null);
        if (c1006M1632 != null) {
            return c1006M1632;
        }
        if (!this.f1895.isEmpty()) {
            return (InterfaceC0041) this.f1895.removeFirst();
        }
        C4121 c4121M1633 = m1633();
        C1006 c1006M16322 = m1632(c4121M1633, c4121M1633.f15403);
        return c1006M16322 != null ? c1006M16322 : c4121M1633;
    }

    /* renamed from: ᵻᵢﹳᵰ, reason: contains not printable characters */
    public final C4121 m1636(C5057 c5057, ArrayList arrayList) throws UnknownServiceException {
        EnumC3518 enumC3518 = EnumC3518.f13214;
        C5145 c5145 = c5057.f18888;
        if (c5145.f19152 == null) {
            if (!c5145.f19156.contains(C2630.f10211)) {
                throw new UnknownServiceException("CLEARTEXT communication not enabled for client");
            }
            String str = c5057.f18888.f19157.f6002;
            AbstractC0761 abstractC0761 = AbstractC0761.f3627;
            if (!AbstractC0761.f3627.mo2847(str)) {
                throw new UnknownServiceException(AbstractC4486.m9550("CLEARTEXT communication to ", str, " not permitted by network security policy"));
            }
        } else if (c5145.f19153.contains(enumC3518)) {
            throw new UnknownServiceException("H2_PRIOR_KNOWLEDGE cannot be used with HTTPS");
        }
        C1947 c1947 = null;
        if (c5057.f18889.type() == Proxy.Type.HTTP) {
            C5145 c51452 = c5057.f18888;
            if (c51452.f19152 != null || c51452.f19153.contains(enumC3518)) {
                ʽˋːᵜ r0 = new ʽˋːᵜ(7);
                r0.ᵢˇᵭ = c5057.f18888.f19157;
                r0.ᵞʡ("CONNECT", (AbstractC0523) null);
                C5145 c51453 = c5057.f18888;
                ((C3842) r0.ᵾᵬ).m8492("Host", AbstractC4061.m8929(c51453.f19157, true));
                ((C3842) r0.ᵾᵬ).m8492("Proxy-Connection", "Keep-Alive");
                ((C3842) r0.ᵾᵬ).m8492("User-Agent", "okhttp/5.3.2");
                c1947 = new C1947(r0);
                C1586 c1586 = AbstractC3866.f14378;
                C3842 c3842 = new C3842();
                c3842.m8492("Proxy-Authenticate", "OkHttp-Preemptive");
                c3842.m8495();
                c51453.f19151.getClass();
            }
        }
        return new C4121(this.f1901, this.f1905, this.f1899, this.f1909, this.f1894, this.f1898, this.f1897, this.f1907, this, c5057, arrayList, c1947, -1, false);
    }
}
