YourPorn v1.2.4版本的 MD5 值为:25af0cc492747d0d721ef41054943bde

以下内容为反编译后的 Ccase.java 源代码,内容仅作参考


package w2;

import android.net.Uri;
import android.text.TextUtils;
import android.util.Log;
import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.InetAddress;
import java.net.Proxy;
import java.net.ProxySelector;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URLEncoder;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import k8.Cpackage;
import w2.Ccatch;
import x2.Ctry;

public class Ccase {

    public final Thread f9657case;

    public final w2.Cfor f9659else;

    public final Ccatch f9661goto;

    public final ServerSocket f9663new;

    public final int f9664try;

    public final Object f9658do = new Object();

    public final ExecutorService f9662if = Executors.newFixedThreadPool(8);

    public final Map<String, Celse> f9660for = new ConcurrentHashMap();

    public final class Cfor implements Runnable {

        public final CountDownLatch f9665else;

        public Cfor(CountDownLatch countDownLatch) {
            this.f9665else = countDownLatch;
        }

        @Override
        public void run() {
            this.f9665else.countDown();
            Ccase ccase = Ccase.this;
            Objects.requireNonNull(ccase);
            while (!Thread.currentThread().isInterrupted()) {
                try {
                    ccase.f9662if.submit(new Cif(ccase.f9663new.accept()));
                } catch (IOException e10) {
                    ccase.m4085try(new Cconst("Error during waiting connection", e10));
                    return;
                }
            }
        }
    }

    public final class Cif implements Runnable {

        public final Socket f9667else;

        public Cif(Socket socket) {
            this.f9667else = socket;
        }

        @Override
        public void run() {
            StringBuilder sb;
            Ccase ccase = Ccase.this;
            Socket socket = this.f9667else;
            Objects.requireNonNull(ccase);
            try {
                try {
                    Cnew m4103do = Cnew.m4103do(socket.getInputStream());
                    String m2993return = Cpackage.m2993return(m4103do.f9706do);
                    Objects.requireNonNull(ccase.f9661goto);
                    if ("ping".equals(m2993return)) {
                        ccase.f9661goto.m4087if(socket);
                    } else {
                        ccase.m4080do(m2993return).m4098for(m4103do, socket);
                    }
                    ccase.m4079case(socket);
                    sb = new StringBuilder();
                } catch (Throwable th) {
                    ccase.m4079case(socket);
                    b.Cdo.m581throws("Opened connections: " + ccase.m4083if());
                    throw th;
                }
            } catch (SocketException unused) {
                ccase.m4079case(socket);
                sb = new StringBuilder();
            } catch (IOException e10) {
                e = e10;
                ccase.m4085try(new Cconst("Error processing request", e));
                ccase.m4079case(socket);
                sb = new StringBuilder();
            } catch (Cconst e11) {
                e = e11;
                ccase.m4085try(new Cconst("Error processing request", e));
                ccase.m4079case(socket);
                sb = new StringBuilder();
            }
            sb.append("Opened connections: ");
            sb.append(ccase.m4083if());
            b.Cdo.m581throws(sb.toString());
        }
    }

    public Ccase(w2.Cfor cfor, Cdo cdo) {
        this.f9659else = cfor;
        try {
            ServerSocket serverSocket = new ServerSocket(0, 8, InetAddress.getByName("127.0.0.1"));
            this.f9663new = serverSocket;
            int localPort = serverSocket.getLocalPort();
            this.f9664try = localPort;
            List<Proxy> list = Cthis.f9712new;
            ProxySelector.setDefault(new Cthis(ProxySelector.getDefault(), "127.0.0.1", localPort));
            CountDownLatch countDownLatch = new CountDownLatch(1);
            Thread thread = new Thread(new Cfor(countDownLatch));
            this.f9657case = thread;
            thread.start();
            countDownLatch.await();
            this.f9661goto = new Ccatch("127.0.0.1", localPort);
            b.Cdo.m581throws("Proxy cache server started. Is it alive? " + m4084new());
        } catch (IOException | InterruptedException e10) {
            this.f9662if.shutdown();
            throw new IllegalStateException("Error starting local proxy server", e10);
        }
    }

    public final void m4079case(Socket socket) {
        try {
            if (!socket.isInputShutdown()) {
                socket.shutdownInput();
            }
        } catch (SocketException | IOException unused) {
        }
        try {
            if (!socket.isOutputShutdown()) {
                socket.shutdownOutput();
            }
        } catch (IOException e10) {
            b.Cdo.m575default("Failed to close socket on proxy side: {}. It seems client have already closed connection.", e10.getMessage());
        }
        try {
            if (socket.isClosed()) {
                return;
            }
            socket.close();
        } catch (IOException unused2) {
        }
    }

    public final Celse m4080do(String str) {
        Celse celse;
        synchronized (this.f9658do) {
            celse = this.f9660for.get(str);
            if (celse == null) {
                celse = new Celse(str, this.f9659else);
                this.f9660for.put(str, celse);
            }
        }
        return celse;
    }

    public void m4081else(w2.Cif cif) {
        synchronized (this.f9658do) {
            Iterator<Celse> it = this.f9660for.values().iterator();
            while (it.hasNext()) {
                it.next().f9684for.remove(cif);
            }
        }
    }

    public String m4082for(String str) {
        Objects.requireNonNull(str, "Url can't be null!");
        w2.Cfor cfor = this.f9659else;
        if (new File(cfor.f9691do, cfor.f9694if.mo2692new(str)).exists()) {
            w2.Cfor cfor2 = this.f9659else;
            File file = new File(cfor2.f9691do, cfor2.f9694if.mo2692new(str));
            try {
                Ctry ctry = (Ctry) this.f9659else.f9693for;
                ctry.f9777do.submit(new Ctry.Cdo(file));
            } catch (IOException e10) {
                b.Cdo.m579switch("Error touching file " + file, e10);
            }
            return Uri.fromFile(file).toString();
        }
        if (!m4084new()) {
            return str;
        }
        Locale locale = Locale.US;
        Object[] objArr = new Object[3];
        objArr[0] = "127.0.0.1";
        objArr[1] = Integer.valueOf(this.f9664try);
        try {
            objArr[2] = URLEncoder.encode(str, "utf-8");
            return String.format(locale, "http://%s:%d/%s", objArr);
        } catch (UnsupportedEncodingException e11) {
            throw new RuntimeException("Error encoding url", e11);
        }
    }

    public final int m4083if() {
        int i10;
        synchronized (this.f9658do) {
            i10 = 0;
            Iterator<Celse> it = this.f9660for.values().iterator();
            while (it.hasNext()) {
                i10 += it.next().f9683do.get();
            }
        }
        return i10;
    }

    public final boolean m4084new() {
        Ccatch ccatch = this.f9661goto;
        Objects.requireNonNull(ccatch);
        int i10 = 70;
        int i11 = 0;
        while (i11 < 3) {
            try {
            } catch (InterruptedException e10) {
                e = e10;
                b.Cdo.m579switch("Error pinging server due to unexpected error", e);
            } catch (ExecutionException e11) {
                e = e11;
                b.Cdo.m579switch("Error pinging server due to unexpected error", e);
            } catch (TimeoutException unused) {
                b.Cdo.m575default("HttpProxyCacheDebuger", "Error pinging server (attempt: " + i11 + ", timeout: " + i10 + "). ");
            }
            if (((Boolean) ccatch.f9669do.submit(new Ccatch.Cif(null)).get(i10, TimeUnit.MILLISECONDS)).booleanValue()) {
                return true;
            }
            i11++;
            i10 *= 2;
        }
        Locale locale = Locale.US;
        Object[] objArr = new Object[3];
        objArr[0] = Integer.valueOf(i11);
        objArr[1] = Integer.valueOf(i10 / 2);
        try {
            objArr[2] = ProxySelector.getDefault().select(new URI(ccatch.m4086do()));
            String format = String.format(locale, "Error pinging server (attempts: %d, max timeout: %d). If you see this message, please, report at https://github.com/danikula/AndroidVideoCache/issues/134. Default proxies are: %s", objArr);
            b.Cdo.m579switch(format, new Cconst(format));
            return false;
        } catch (URISyntaxException e12) {
            throw new IllegalStateException(e12);
        }
    }

    public final void m4085try(Throwable th) {
        String message = th.getMessage();
        if (TextUtils.isEmpty(message)) {
            return;
        }
        Log.e("HttpProxyCacheServer error", message);
    }
}