CAG v5.7.4版本的 MD5 值为:bc57ead76a7a30559f0708e9d60d749f

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


package i.f.a;

import com.danikula.videocache.ProxyCacheException;
import i.f.a.j;
import java.io.File;
import java.io.IOException;
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.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;
public class f {
    public static final d.i.b f9917i = d.i.c.c("HttpProxyCacheServer");
    public final Object a = new Object();
    public final ExecutorService b = Executors.newFixedThreadPool(8);
    public final Map<String, g> c = new ConcurrentHashMap();
    public final ServerSocket f9918d;
    public final int f9919e;
    public final Thread f9920f;
    public final i.f.a.c f9921g;
    public final j f9922h;

    public final class b implements Runnable {
        public final Socket f9923i;

        public b(Socket socket) {
            this.f9923i = socket;
        }

        @Override
        public void run() {
            f fVar = f.this;
            Socket socket = this.f9923i;
            Objects.requireNonNull(fVar);
            try {
                try {
                    d a = d.a(socket.getInputStream());
                    d.i.b bVar = f.f9917i;
                    bVar.debug("Request to cache proxy:" + a);
                    String b = l.b(a.a);
                    Objects.requireNonNull(fVar.f9922h);
                    if ("ping".equals(b)) {
                        fVar.f9922h.b(socket);
                    } else {
                        fVar.a(b).c(a, socket);
                    }
                    fVar.f(socket);
                    bVar.debug("Opened connections: " + fVar.b());
                } catch (ProxyCacheException e2) {
                    e = e2;
                    fVar.e(new ProxyCacheException("Error processing request", e));
                } catch (SocketException unused) {
                    d.i.b bVar2 = f.f9917i;
                    bVar2.debug("Closing socket… Socket is closed by client.");
                    fVar.f(socket);
                    bVar2.debug("Opened connections: " + fVar.b());
                } catch (IOException e3) {
                    e = e3;
                    fVar.e(new ProxyCacheException("Error processing request", e));
                }
            } finally {
                fVar.f(socket);
                d.i.b bVar3 = f.f9917i;
                StringBuilder J = i.a.b.a.a.J("Opened connections: ");
                J.append(fVar.b());
                bVar3.debug(J.toString());
            }
        }
    }

    public final class c implements Runnable {
        public final CountDownLatch f9925i;

        public c(CountDownLatch countDownLatch) {
            this.f9925i = countDownLatch;
        }

        @Override
        public void run() {
            this.f9925i.countDown();
            f fVar = f.this;
            Objects.requireNonNull(fVar);
            while (!Thread.currentThread().isInterrupted()) {
                try {
                    Socket accept = fVar.f9918d.accept();
                    d.i.b bVar = f.f9917i;
                    bVar.debug("Accept new socket " + accept);
                    fVar.b.submit(new b(accept));
                } catch (IOException e2) {
                    fVar.e(new ProxyCacheException("Error during waiting connection", e2));
                    return;
                }
            }
        }
    }

    public f(i.f.a.c cVar, a aVar) {
        this.f9921g = cVar;
        try {
            ServerSocket serverSocket = new ServerSocket(0, 8, InetAddress.getByName("127.0.0.1"));
            this.f9918d = serverSocket;
            int localPort = serverSocket.getLocalPort();
            this.f9919e = localPort;
            List<Proxy> list = i.f9935d;
            ProxySelector.setDefault(new i(ProxySelector.getDefault(), "127.0.0.1", localPort));
            CountDownLatch countDownLatch = new CountDownLatch(1);
            Thread thread = new Thread(new c(countDownLatch));
            this.f9920f = thread;
            thread.start();
            countDownLatch.await();
            this.f9922h = new j("127.0.0.1", localPort);
            d.i.b bVar = f9917i;
            bVar.info("Proxy cache server started. Is it alive? " + c());
        } catch (IOException | InterruptedException e2) {
            this.b.shutdown();
            throw new IllegalStateException("Error starting local proxy server", e2);
        }
    }

    public final g a(String str) throws ProxyCacheException {
        g gVar;
        synchronized (this.a) {
            gVar = this.c.get(str);
            if (gVar == null) {
                gVar = new g(str, this.f9921g);
                this.c.put(str, gVar);
            }
        }
        return gVar;
    }

    public final int b() {
        int i2;
        synchronized (this.a) {
            i2 = 0;
            for (g gVar : this.c.values()) {
                i2 += gVar.a.get();
            }
        }
        return i2;
    }

    public final boolean c() {
        j jVar = this.f9922h;
        Objects.requireNonNull(jVar);
        int i2 = 70;
        int i3 = 0;
        while (i3 < 3) {
            try {
            } catch (InterruptedException e2) {
                e = e2;
                j.f9936d.error("Error pinging server due to unexpected error", e);
            } catch (ExecutionException e3) {
                e = e3;
                j.f9936d.error("Error pinging server due to unexpected error", e);
            } catch (TimeoutException unused) {
                d.i.b bVar = j.f9936d;
                bVar.warn("Error pinging server (attempt: " + i3 + ", timeout: " + i2 + "). ");
            }
            if (((Boolean) jVar.a.submit(new j.b(null)).get(i2, TimeUnit.MILLISECONDS)).booleanValue()) {
                return true;
            }
            i3++;
            i2 *= 2;
        }
        Locale locale = Locale.US;
        Object[] objArr = new Object[3];
        objArr[0] = Integer.valueOf(i3);
        objArr[1] = Integer.valueOf(i2 / 2);
        try {
            objArr[2] = ProxySelector.getDefault().select(new URI(jVar.a()));
            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);
            j.f9936d.error(format, new ProxyCacheException(format));
            return false;
        } catch (URISyntaxException e4) {
            throw new IllegalStateException(e4);
        }
    }

    public boolean d(String str) {
        Objects.requireNonNull(str, "Url can't be null!");
        i.f.a.c cVar = this.f9921g;
        return new File(cVar.a, cVar.b.a(str)).exists();
    }

    public final void e(Throwable th) {
        f9917i.error("HttpProxyCacheServer error", th);
    }

    public final void f(Socket socket) {
        try {
            if (!socket.isInputShutdown()) {
                socket.shutdownInput();
            }
        } catch (SocketException unused) {
            f9917i.debug("Releasing input stream… Socket is closed by client.");
        } catch (IOException e2) {
            e(new ProxyCacheException("Error closing socket input stream", e2));
        }
        try {
            if (!socket.isOutputShutdown()) {
                socket.shutdownOutput();
            }
        } catch (IOException e3) {
            f9917i.warn("Failed to close socket on proxy side: {}. It seems client have already closed connection.", e3.getMessage());
        }
        try {
            if (socket.isClosed()) {
                return;
            }
            socket.close();
        } catch (IOException e4) {
            e(new ProxyCacheException("Error closing socket", e4));
        }
    }
}