/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.gateway.common.cluster.ClusterNodeInfo
 *  com.l7tech.objectmodel.FindException
 *  com.l7tech.objectmodel.UpdateException
 *  com.l7tech.util.ConfigFactory
 *  com.l7tech.util.ExceptionUtils
 *  com.l7tech.util.InetAddressUtil
 *  org.springframework.dao.DataIntegrityViolationException
 */
package com.l7tech.server.cluster;

import com.l7tech.gateway.common.cluster.ClusterNodeInfo;
import com.l7tech.objectmodel.FindException;
import com.l7tech.objectmodel.UpdateException;
import com.l7tech.server.LifecycleException;
import com.l7tech.server.ServerComponentLifecycle;
import com.l7tech.server.cluster.ClusterInfoManager;
import com.l7tech.server.cluster.ClusterInfoManagerImpl;
import com.l7tech.util.ConfigFactory;
import com.l7tech.util.ExceptionUtils;
import com.l7tech.util.InetAddressUtil;
import java.net.Inet6Address;
import java.net.InetAddress;
import java.net.InterfaceAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.security.SecureRandom;
import java.util.Collection;
import java.util.Iterator;
import java.util.Random;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.springframework.dao.DataIntegrityViolationException;

public class ClusterBootProcess
implements ServerComponentLifecycle {
    private static final Logger a;
    private static final String b;
    private static final Random c;
    private String d;
    private final ClusterInfoManager e;
    private static final String[] f;

    public ClusterBootProcess(ClusterInfoManager clusterInfoManager) {
        if (clusterInfoManager instanceof ClusterInfoManagerImpl) {
            throw new IllegalArgumentException(f[15]);
        }
        this.e = clusterInfoManager;
    }

    @Override
    public void start() throws LifecycleException {
        block10: {
            String[] stringArray;
            ClusterNodeInfo clusterNodeInfo = this.e.getSelfNodeInf();
            try {
                this.e.updateSelfUptime();
            }
            catch (DataIntegrityViolationException dataIntegrityViolationException) {
                stringArray = f;
                a.log(Level.SEVERE, stringArray[5], dataIntegrityViolationException);
            }
            catch (UpdateException updateException) {
                stringArray = f;
                a.log(Level.SEVERE, stringArray[0], updateException);
            }
            try {
                if (this.d != null && this.d.length() != 0) break block10;
            }
            catch (DataIntegrityViolationException dataIntegrityViolationException) {
                throw ClusterBootProcess.a((Exception)((Object)dataIntegrityViolationException));
            }
            this.d = this.b(this.d);
            try {
                block11: {
                    if (this.d != null) break block10;
                    try {
                        this.d = ClusterBootProcess.a(clusterNodeInfo);
                        if (!this.e.attemptClusterFirstMulticastAddressUpdate(clusterNodeInfo.getNodeIdentifier(), this.d)) break block11;
                        clusterNodeInfo.setMulticastAddress(this.d);
                        break block10;
                    }
                    catch (DataIntegrityViolationException dataIntegrityViolationException) {
                        throw ClusterBootProcess.a((Exception)((Object)dataIntegrityViolationException));
                    }
                }
                stringArray = f;
                a.log(Level.INFO, stringArray[18]);
                this.d = this.b(null);
            }
            catch (DataIntegrityViolationException dataIntegrityViolationException) {
                stringArray = f;
                a.log(Level.SEVERE, stringArray[10], dataIntegrityViolationException);
            }
            catch (UpdateException updateException) {
                a.log(Level.SEVERE, f[14], updateException);
            }
        }
    }

    @Override
    public void stop() {
    }

    @Override
    public void close() {
    }

    public String toString() {
        return f[20];
    }

    static String a(ClusterNodeInfo clusterNodeInfo) throws LifecycleException {
        String string;
        String string2 = clusterNodeInfo.getAddress();
        try {
            string = InetAddressUtil.isValidIpv6Address((String)string2) ? ClusterBootProcess.a(string2) : ClusterBootProcess.a();
        }
        catch (LifecycleException lifecycleException) {
            throw ClusterBootProcess.a(lifecycleException);
        }
        return string;
    }

    static String a() {
        StringBuilder stringBuilder;
        block4: {
            block3: {
                stringBuilder = new StringBuilder();
                try {
                    if (!ConfigFactory.getBooleanProperty((String)f[11], (boolean)false)) break block3;
                    stringBuilder.append(f[9]);
                    stringBuilder.append(Math.abs(c.nextInt() % 256));
                    break block4;
                }
                catch (IllegalArgumentException illegalArgumentException) {
                    throw ClusterBootProcess.a(illegalArgumentException);
                }
            }
            stringBuilder.append(f[1]);
            int n2 = 0;
            while (n2 < 2) {
                n2 = Math.abs(c.nextInt() % 256);
            }
            stringBuilder.append(n2);
            stringBuilder.append(".");
            stringBuilder.append(Math.abs(c.nextInt() % 256));
        }
        return stringBuilder.toString();
    }

    /*
     * Loose catch block
     * Enabled force condition propagation
     * Lifted jumps to return sites
     */
    static String a(String string) throws LifecycleException {
        Inet6Address inet6Address = InetAddressUtil.getIpv6Address((String)string);
        try {
            String[] stringArray;
            int n2;
            int n3;
            block17: {
                block16: {
                    n3 = -1;
                    n2 = -1;
                    NetworkInterface networkInterface = NetworkInterface.getByInetAddress(inet6Address);
                    for (InterfaceAddress interfaceAddress : networkInterface.getInterfaceAddresses()) {
                        if (!inet6Address.equals(interfaceAddress.getAddress())) continue;
                        n3 = interfaceAddress.getNetworkPrefixLength();
                        n2 = ClusterBootProcess.a(inet6Address);
                        break;
                    }
                    if (n3 == -1) throw new LifecycleException(f[17] + string);
                    try {
                        if (n2 != -1) break block16;
                        throw new LifecycleException(f[17] + string);
                        catch (SocketException socketException) {
                            throw ClusterBootProcess.a(socketException);
                        }
                    }
                    catch (SocketException socketException) {
                        throw ClusterBootProcess.a(socketException);
                    }
                }
                if (n3 <= 64) break block17;
                stringArray = f;
                a.log(Level.WARNING, stringArray[8], new Object[]{string, (short)n3});
                n3 = 64;
            }
            Object object = InetAddressUtil.getNetworkPrefix((Inet6Address)inet6Address, (short)n3);
            try {
                if (((Object)object).length > 8) {
                    throw new LifecycleException(f[6] + string + f[2]);
                }
            }
            catch (SocketException socketException) {
                throw ClusterBootProcess.a(socketException);
            }
            int n4 = c.nextInt() | Integer.MIN_VALUE;
            byte[] byArray = new byte[16];
            byArray[0] = -1;
            byArray[1] = (byte)(0x30 | 0xF & n2);
            byArray[2] = 0;
            byArray[3] = (byte)n3;
            int n5 = 0;
            while (true) {
                Object object2;
                block19: {
                    block18: {
                        if (n5 >= 8) break;
                        try {
                            block20: {
                                byte[] byArray2 = byArray;
                                int n6 = 4 + n5;
                                if (n5 >= ((Object)object).length) break block18;
                                break block20;
                                catch (SocketException socketException) {
                                    throw ClusterBootProcess.a(socketException);
                                }
                            }
                            object2 = object[n5];
                            break block19;
                        }
                        catch (SocketException socketException) {
                            throw ClusterBootProcess.a(socketException);
                        }
                    }
                    object2 = 0;
                }
                byArray2[n6] = object2;
                ++n5;
            }
            byArray[12] = (byte)(n4 >>> 24);
            byArray[13] = (byte)(n4 >>> 16);
            byArray[14] = (byte)(n4 >>> 8);
            byArray[15] = (byte)n4;
            InetAddress inetAddress = Inet6Address.getByAddress(byArray);
            stringArray = f;
            a.log(Level.INFO, stringArray[4] + inetAddress.getHostAddress());
            return inetAddress.getHostAddress();
        }
        catch (SocketException socketException) {
            String[] stringArray = f;
            throw new LifecycleException(stringArray[12] + string, ExceptionUtils.getDebugException((Throwable)socketException));
        }
        catch (UnknownHostException unknownHostException) {
            throw new LifecycleException(f[19] + string, ExceptionUtils.getDebugException((Throwable)unknownHostException));
        }
    }

    static int a(Inet6Address inet6Address) {
        try {
            if (inet6Address.isMulticastAddress()) {
                return inet6Address.getAddress()[1] & 0xF;
            }
        }
        catch (IllegalArgumentException illegalArgumentException) {
            throw ClusterBootProcess.a(illegalArgumentException);
        }
        try {
            if (inet6Address.isLoopbackAddress()) {
                return 1;
            }
        }
        catch (IllegalArgumentException illegalArgumentException) {
            throw ClusterBootProcess.a(illegalArgumentException);
        }
        try {
            if (inet6Address.isLinkLocalAddress()) {
                return 2;
            }
        }
        catch (IllegalArgumentException illegalArgumentException) {
            throw ClusterBootProcess.a(illegalArgumentException);
        }
        try {
            if (inet6Address.isSiteLocalAddress()) {
                return 5;
            }
        }
        catch (IllegalArgumentException illegalArgumentException) {
            throw ClusterBootProcess.a(illegalArgumentException);
        }
        return 14;
    }

    private String b(String string) throws LifecycleException {
        String[] stringArray;
        String string2 = string;
        Collection<ClusterNodeInfo> collection = null;
        try {
            collection = this.e.retrieveClusterStatus();
        }
        catch (FindException findException) {
            stringArray = f;
            a.log(Level.SEVERE, stringArray[16], findException);
        }
        Iterator<ClusterNodeInfo> iterator = collection.iterator();
        while (iterator.hasNext()) {
            String string3;
            block7: {
                ClusterNodeInfo clusterNodeInfo;
                ClusterNodeInfo clusterNodeInfo2 = clusterNodeInfo = iterator.next();
                string3 = clusterNodeInfo2.getMulticastAddress();
                try {
                    if (string3 == null) continue;
                    if (string2 != null) break block7;
                }
                catch (FindException findException) {
                    throw ClusterBootProcess.a((Exception)((Object)findException));
                }
                stringArray = f;
                a.log(Level.INFO, stringArray[13], string3);
                string2 = string3;
                continue;
            }
            try {
                if (string2.equals(string3)) continue;
                throw new LifecycleException(f[3]);
            }
            catch (FindException findException) {
                throw ClusterBootProcess.a((Exception)((Object)findException));
            }
        }
        return string2;
    }

    /*
     * Unable to fully structure code
     */
    static {
        block10: {
            block9: {
                var5 = new String[21];
                var3_1 = 0;
                var2_2 = "[\u0003\u007f\u000ek\u001bmn\u0015l\u0015pU\u007f>\u0013b\u000em\u001blw\u001chAv]8p\u001ei\u00047\u0006,C9O)\u0015->\u0018~AuTvy\u0014\u007fAmSypQ;U{Rl%Qc\u000em\u001by>\u0004c\bzZkjQl\u0005}I}m\u00022A_\u0005-\r|ZkjQy\u0016v\u001bvq\u0015h\u00129Rv>\u0015l\u0015xYym\u0014-\txM}>\u0015d\u0007\u007f^j{\u001fyAtNtj\u0018n\u0000jO8\u007f\u0015i\u0013|Hk{\u0002\"Y\u0014c\u0004kZl{\u0015-(IM.>\u001cx\rmR{\u007f\u0002yAx_|l\u0014~\u0012#\u001bFZ\u0010y\u0000PUl{\u0016\u007f\bmBNw\u001ea\u0000mRwp4u\u0002|Klw\u001ecAzZmy\u0019yAnS}pQx\u0011}Zlw\u001fjAmS}>\u0012a\u0014jO}lQd\u000f\u007fT6\u001bP\u0014y\u0016vIs>\u0001\u007f\u0004\u007fR`>\u0017b\u00139Z|z\u0003h\u0012j\u001b#}\u001e`Ou\fl{\u0012eOzWmm\u0005h\u00137Vy}0i\u0005k^km>a\u0005^^vbP\u0014y\u0016vIs>\u0001\u007f\u0004\u007fR`>\u0017b\u00139Z|z\u0003h\u0012j\u001bc.\f-\bj\u001bc/\f!AuTvy\u0014\u007fAmSypQ;U{Rl%Qc\u000em\u001by>\u0004c\bzZkjQl\u0005}I}m\u00022ALHqp\u0016-W-\u001bqp\u0002y\u0004x_6\b,C9O)\u0015/0FZ\u0010y\u0000PUl{\u0016\u007f\bmBNw\u001ea\u0000mRwp4u\u0002|Klw\u001ecAzZmy\u0019yAnS}pQx\u0011}Zlw\u001fjAmS}>\u0012a\u0014jO}lQd\u000f\u007fT6#}\u001e`Ou\fl{\u0012eOzWmm\u0005h\u00137Vy}0i\u0005k^km>a\u0005^^v0]\u001ex\r}\u001bvq\u0005-\u0005|O}l\u001cd\u000f|\u001bv{\u0005z\u000ekP8n\u0003h\u0007pC8x\u001e\u007fAx_|l\u0014~\u0012#\u001b9X\u001ex\u000f}\u001bypQh\u0019pHlw\u001fjAzWmm\u0005h\u00139Uwz\u0014-\u0016pOp>\u001cx\rmR{\u007f\u0002yAx_|l\u0014~\u00129@(c)[\u0003\u007f\u000ek\u001bmn\u0015l\u0015pU\u007f>\u001cx\rmR{\u007f\u0002yAx_|l\u0014~\u00129T~>\u001fb\u0005|\u0015\u0015}\u0018`AxNlq\u0001\u007f\u000eaB8x\u0010d\rlI}$[\u0003\u007f\u000ek\u001bj{\u0005\u007f\b|Mqp\u0016-\u0015q^8}\u001dx\u0012m^j>\u0002y\u0000mNk08]\u001ex\r}\u001bvq\u0005-\u0005|O}l\u001cd\u000f|\u001bv{\u0005z\u000ekP8n\u0003h\u0007pC8q\u0003-\u0012zTh{Qk\u000ek\u001byz\u0015\u007f\u0004jH8D_\u001fb\u0015q^j>\u001fb\u0005|\u001bp\u007f\u0002-\u0014i_yj\u0014iApOk>\u001cx\rmR{\u007f\u0002yAx_|l\u0014~\u00129]ql\u0002yM9\\}j\u0005d\u000f~\u001bqjQ#O7";
                var4_3 = "[\u0003\u007f\u000ek\u001bmn\u0015l\u0015pU\u007f>\u0013b\u000em\u001blw\u001chAv]8p\u001ei\u00047\u0006,C9O)\u0015->\u0018~AuTvy\u0014\u007fAmSypQ;U{Rl%Qc\u000em\u001by>\u0004c\bzZkjQl\u0005}I}m\u00022A_\u0005-\r|ZkjQy\u0016v\u001bvq\u0015h\u00129Rv>\u0015l\u0015xYym\u0014-\txM}>\u0015d\u0007\u007f^j{\u001fyAtNtj\u0018n\u0000jO8\u007f\u0015i\u0013|Hk{\u0002\"Y\u0014c\u0004kZl{\u0015-(IM.>\u001cx\rmR{\u007f\u0002yAx_|l\u0014~\u0012#\u001bFZ\u0010y\u0000PUl{\u0016\u007f\bmBNw\u001ea\u0000mRwp4u\u0002|Klw\u001ecAzZmy\u0019yAnS}pQx\u0011}Zlw\u001fjAmS}>\u0012a\u0014jO}lQd\u000f\u007fT6\u001bP\u0014y\u0016vIs>\u0001\u007f\u0004\u007fR`>\u0017b\u00139Z|z\u0003h\u0012j\u001b#}\u001e`Ou\fl{\u0012eOzWmm\u0005h\u00137Vy}0i\u0005k^km>a\u0005^^vbP\u0014y\u0016vIs>\u0001\u007f\u0004\u007fR`>\u0017b\u00139Z|z\u0003h\u0012j\u001bc.\f-\bj\u001bc/\f!AuTvy\u0014\u007fAmSypQ;U{Rl%Qc\u000em\u001by>\u0004c\bzZkjQl\u0005}I}m\u00022ALHqp\u0016-W-\u001bqp\u0002y\u0004x_6\b,C9O)\u0015/0FZ\u0010y\u0000PUl{\u0016\u007f\bmBNw\u001ea\u0000mRwp4u\u0002|Klw\u001ecAzZmy\u0019yAnS}pQx\u0011}Zlw\u001fjAmS}>\u0012a\u0014jO}lQd\u000f\u007fT6#}\u001e`Ou\fl{\u0012eOzWmm\u0005h\u00137Vy}0i\u0005k^km>a\u0005^^v0]\u001ex\r}\u001bvq\u0005-\u0005|O}l\u001cd\u000f|\u001bv{\u0005z\u000ekP8n\u0003h\u0007pC8x\u001e\u007fAx_|l\u0014~\u0012#\u001b9X\u001ex\u000f}\u001bypQh\u0019pHlw\u001fjAzWmm\u0005h\u00139Uwz\u0014-\u0016pOp>\u001cx\rmR{\u007f\u0002yAx_|l\u0014~\u00129@(c)[\u0003\u007f\u000ek\u001bmn\u0015l\u0015pU\u007f>\u001cx\rmR{\u007f\u0002yAx_|l\u0014~\u00129T~>\u001fb\u0005|\u0015\u0015}\u0018`AxNlq\u0001\u007f\u000eaB8x\u0010d\rlI}$[\u0003\u007f\u000ek\u001bj{\u0005\u007f\b|Mqp\u0016-\u0015q^8}\u001dx\u0012m^j>\u0002y\u0000mNk08]\u001ex\r}\u001bvq\u0005-\u0005|O}l\u001cd\u000f|\u001bv{\u0005z\u000ekP8n\u0003h\u0007pC8q\u0003-\u0012zTh{Qk\u000ek\u001byz\u0015\u007f\u0004jH8D_\u001fb\u0015q^j>\u001fb\u0005|\u001bp\u007f\u0002-\u0014i_yj\u0014iApOk>\u001cx\rmR{\u007f\u0002yAx_|l\u0014~\u00129]ql\u0002yM9\\}j\u0005d\u000f~\u001bqjQ#O7".length();
                var1_4 = 33;
                var0_5 = -1;
lbl7:
                // 2 sources

                while (true) {
                    v0 = 93;
                    v1 = ++var0_5;
                    v2 = var2_2.substring(v1, v1 + var1_4);
                    v3 = -1;
                    break block9;
                    break;
                }
lbl13:
                // 1 sources

                while (true) {
                    var5[var3_1++] = ClusterBootProcess.a(v0, ClusterBootProcess.c(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    var2_2 = "O\fj\u001fo\tdc\u0017?\u0014nGo~\u0002k\u0016+D\u007f`\u0017v\u0010jZ~,\u0005p\u0001+Hnh\u0011z\u0000x\u0013*\u0014O\u000fj\u0000\u007fLx,!p\u001c\u007f\tZ~\f|\u0016xZ";
                    var4_3 = "O\fj\u001fo\tdc\u0017?\u0014nGo~\u0002k\u0016+D\u007f`\u0017v\u0010jZ~,\u0005p\u0001+Hnh\u0011z\u0000x\u0013*\u0014O\u000fj\u0000\u007fLx,!p\u001c\u007f\tZ~\f|\u0016xZ".length();
                    var1_4 = 42;
                    var0_5 = -1;
lbl22:
                    // 2 sources

                    while (true) {
                        v0 = 79;
                        v4 = ++var0_5;
                        v2 = var2_2.substring(v4, v4 + var1_4);
                        v3 = 0;
                        break block9;
                        break;
                    }
                    break;
                }
lbl28:
                // 1 sources

                while (true) {
                    var5[var3_1++] = ClusterBootProcess.a(v0, ClusterBootProcess.c(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    break block10;
                    break;
                }
            }
            switch (v3) {
                default: {
                    ** continue;
                }
                ** case 0:
lbl39:
                // 1 sources

                ** continue;
            }
        }
        ClusterBootProcess.f = var5;
        ClusterBootProcess.b = ClusterBootProcess.f[7];
        ClusterBootProcess.a = Logger.getLogger(ClusterBootProcess.class.getName());
        ClusterBootProcess.c = new SecureRandom();
    }

    private static Exception a(Exception exception) {
        return exception;
    }

    private static char[] c(String string) {
        char[] cArray = string.toCharArray();
        if (cArray.length < 2) {
            cArray = cArray;
            cArray[0] = (char)(cArray[0] ^ 0x45);
        }
        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 -> 67;
                    case 1 -> 44;
                    case 2 -> 80;
                    case 3 -> 60;
                    case 4 -> 68;
                    case 5 -> 102;
                    default -> 69;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

