漫漫擼2 v1.3.9版本的 MD5 值为:e07b15db49ff38b958ff7c8268ff1c9b

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


package g.e.a;

import g.e.a.k;
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 a.d.b f5171a = a.d.c.c("HttpProxyCacheServer");
    public final Object f5172b = new Object();
    public final ExecutorService f5173c = Executors.newFixedThreadPool(8);
    public final Map<String, g> f5174d = new ConcurrentHashMap();
    public final ServerSocket f5175e;
    public final int f5176f;
    public final Thread f5177g;
    public final g.e.a.c f5178h;
    public final k f5179i;

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

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

        @Override
        public void run() {
            f fVar = f.this;
            Socket socket = this.f5180a;
            Objects.requireNonNull(fVar);
            try {
                try {
                    d a2 = d.a(socket.getInputStream());
                    a.d.b bVar = f.f5171a;
                    bVar.a("Request to cache proxy:" + a2);
                    String b2 = n.b(a2.f5165c);
                    Objects.requireNonNull(fVar.f5179i);
                    if ("ping".equals(b2)) {
                        fVar.f5179i.b(socket);
                    } else {
                        fVar.a(b2).c(a2, socket);
                    }
                    fVar.f(socket);
                    bVar.a("Opened connections: " + fVar.b());
                } catch (m e2) {
                    e = e2;
                    fVar.e(new m("Error processing request", e));
                } catch (SocketException unused) {
                    a.d.b bVar2 = f.f5171a;
                    bVar2.a("Closing socket… Socket is closed by client.");
                    fVar.f(socket);
                    bVar2.a("Opened connections: " + fVar.b());
                } catch (IOException e3) {
                    e = e3;
                    fVar.e(new m("Error processing request", e));
                }
            } finally {
                fVar.f(socket);
                a.d.b bVar3 = f.f5171a;
                StringBuilder D = g.b.a.a.a.D("Opened connections: ");
                D.append(fVar.b());
                bVar3.a(D.toString());
            }
        }
    }

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

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

        @Override
        public void run() {
            this.f5182a.countDown();
            f fVar = f.this;
            Objects.requireNonNull(fVar);
            while (!Thread.currentThread().isInterrupted()) {
                try {
                    Socket accept = fVar.f5175e.accept();
                    a.d.b bVar = f.f5171a;
                    bVar.a("Accept new socket " + accept);
                    fVar.f5173c.submit(new b(accept));
                } catch (IOException e2) {
                    fVar.e(new m("Error during waiting connection", e2));
                    return;
                }
            }
        }
    }

    public f(g.e.a.c cVar, a aVar) {
        this.f5178h = cVar;
        try {
            ServerSocket serverSocket = new ServerSocket(0, 8, InetAddress.getByName("127.0.0.1"));
            this.f5175e = serverSocket;
            int localPort = serverSocket.getLocalPort();
            this.f5176f = localPort;
            List<Proxy> list = i.f5197a;
            ProxySelector.setDefault(new i(ProxySelector.getDefault(), "127.0.0.1", localPort));
            CountDownLatch countDownLatch = new CountDownLatch(1);
            Thread thread = new Thread(new c(countDownLatch));
            this.f5177g = thread;
            thread.start();
            countDownLatch.await();
            this.f5179i = new k("127.0.0.1", localPort);
            a.d.b bVar = f5171a;
            bVar.b("Proxy cache server started. Is it alive? " + c());
        } catch (IOException | InterruptedException e2) {
            this.f5173c.shutdown();
            throw new IllegalStateException("Error starting local proxy server", e2);
        }
    }

    public final g a(String str) throws m {
        g gVar;
        synchronized (this.f5172b) {
            gVar = this.f5174d.get(str);
            if (gVar == null) {
                gVar = new g(str, this.f5178h);
                this.f5174d.put(str, gVar);
            }
        }
        return gVar;
    }

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

    public final boolean c() {
        k kVar = this.f5179i;
        Objects.requireNonNull(kVar);
        int i2 = 70;
        int i3 = 0;
        while (i3 < 3) {
            try {
            } catch (InterruptedException e2) {
                e = e2;
                k.f5201a.e("Error pinging server due to unexpected error", e);
            } catch (ExecutionException e3) {
                e = e3;
                k.f5201a.e("Error pinging server due to unexpected error", e);
            } catch (TimeoutException unused) {
                k.f5201a.h("Error pinging server (attempt: " + i3 + ", timeout: " + i2 + "). ");
            }
            if (((Boolean) kVar.f5202b.submit(new k.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(kVar.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);
            k.f5201a.e(format, new m(format));
            return false;
        } catch (URISyntaxException e4) {
            throw new IllegalStateException(e4);
        }
    }

    public boolean d(String str) {
        Objects.requireNonNull(str, "Url can't be null!");
        g.e.a.c cVar = this.f5178h;
        return new File(cVar.f5159a, cVar.f5160b.a(str)).exists();
    }

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

    public final void f(Socket socket) {
        try {
            if (!socket.isInputShutdown()) {
                socket.shutdownInput();
            }
        } catch (SocketException unused) {
            f5171a.a("Releasing input stream… Socket is closed by client.");
        } catch (IOException e2) {
            e(new m("Error closing socket input stream", e2));
        }
        try {
            if (!socket.isOutputShutdown()) {
                socket.shutdownOutput();
            }
        } catch (IOException e3) {
            f5171a.c("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 m("Error closing socket", e4));
        }
    }
}