/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.gateway.common.resources.HttpProxyConfiguration
 *  com.l7tech.util.ExceptionUtils
 */
package com.l7tech.server.globalresources;

import com.l7tech.gateway.common.resources.HttpProxyConfiguration;
import com.l7tech.server.globalresources.HttpConfigurationCache;
import com.l7tech.server.globalresources.i;
import com.l7tech.util.ExceptionUtils;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.ProxySelector;
import java.net.SocketAddress;
import java.net.URI;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
import java.util.logging.Level;

final class t
extends ProxySelector {
    private static final List<Proxy> a;
    private final AtomicReference<i> b;
    private static final String[] c;

    private t(AtomicReference<i> atomicReference) {
        this.b = atomicReference;
    }

    @Override
    public void connectFailed(URI uRI, SocketAddress socketAddress, IOException iOException) {
        String[] stringArray = c;
        HttpConfigurationCache.a.log(Level.WARNING, stringArray[2] + String.valueOf(socketAddress) + stringArray[1] + ExceptionUtils.getMessage((Throwable)iOException), ExceptionUtils.getDebugException((Throwable)iOException));
    }

    @Override
    public List<Proxy> select(URI uRI) {
        HttpProxyConfiguration httpProxyConfiguration;
        List<Proxy> list = a;
        i i2 = this.b.get();
        if (i2 != null && uRI.getScheme() != null && uRI.getScheme().toLowerCase().startsWith(c[0]) && (httpProxyConfiguration = i2.getHttpProxyConfiguration(uRI)) != null) {
            Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(httpProxyConfiguration.getHost(), httpProxyConfiguration.getPort()));
            list = Collections.singletonList(proxy);
        }
        return list;
    }

    /*
     * Enabled aggressive block sorting
     */
    static {
        String[] stringArray = new String[3];
        int n2 = 0;
        String string = "C;B\u0003\f\fc\u0016\u0017D=\u001d_ \u0016I\u0011\u001dh X\u001dT;IB XSW9TG*RSW7O\u000b?D\u001cI!\u001d\f";
        int n3 = "C;B\u0003\f\fc\u0016\u0017D=\u001d_ \u0016I\u0011\u001dh X\u001dT;IB XSW9TG*RSW7O\u000b?D\u001cI!\u001d\f".length();
        int n4 = 4;
        int n5 = -1;
        while (true) {
            int n6 = ++n5;
            stringArray[n2++] = t.a(40, t.a(string.substring(n6, n6 + n4)));
            if ((n5 += n4) >= n3) {
                c = stringArray;
                a = Collections.singletonList(Proxy.NO_PROXY);
                return;
            }
            n4 = string.charAt(n5);
        }
    }

    private static char[] a(String string) {
        char[] cArray = string.toCharArray();
        if (cArray.length < 2) {
            cArray = cArray;
            cArray[0] = (char)(cArray[0] ^ 0x15);
        }
        return cArray;
    }

    /*
     * Handled impossible loop by duplicating code
     * Enabled aggressive block sorting
     */
    private static String a(int n2, char[] cArray) {
        char[] cArray2;
        block11: {
            int n3;
            int n4;
            int n5;
            block10: {
                n5 = n2;
                cArray2 = cArray;
                n4 = cArray.length;
                n3 = 0;
                if (!true) break block10;
                n4 = n4;
                if (n4 <= n3) break block11;
            }
            do {
                n5 = n5;
                cArray2 = cArray2;
                int n6 = n3;
                cArray2[n6] = (char)(cArray2[n6] ^ (n5 ^ (switch (n3 % 7) {
                    case 0 -> 3;
                    case 1 -> 103;
                    case 2 -> 30;
                    case 3 -> 91;
                    case 4 -> 25;
                    case 5 -> 112;
                    default -> 21;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

