밤친구 v4.7.3版本的 MD5 值为:a58175795b36d9d722726efa7eb4c52a
以下内容为反编译后的 f.java 源代码,内容仅作参考
package w;
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.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 qh.v0;
import w.n;
import x.e;
public final class f {
public final Object f17409a = new Object();
public final ExecutorService f17410b = Executors.newFixedThreadPool(8);
public final ConcurrentHashMap f17411c = new ConcurrentHashMap();
public final ServerSocket f17412d;
public final int f17413e;
public final Thread f17414f;
public final c f17415g;
public final n f17416h;
public final class a implements Runnable {
public final Socket f17417a;
public a(Socket socket) {
this.f17417a = socket;
}
@Override
public final void run() {
String message;
StringBuilder sb2;
Socket socket = this.f17417a;
f fVar = f.this;
n nVar = fVar.f17416h;
try {
try {
d a10 = d.a(socket.getInputStream());
String S = v0.S(a10.f17404a);
nVar.getClass();
if ("ping".equals(S)) {
n.b(socket);
} else {
fVar.a(S).c(a10, socket);
}
f.e(socket);
sb2 = new StringBuilder("Opened connections: ");
} catch (Throwable th2) {
f.e(socket);
cl.d.O0("Opened connections: " + fVar.b());
throw th2;
}
} catch (SocketException unused) {
f.e(socket);
sb2 = new StringBuilder("Opened connections: ");
} catch (IOException e10) {
e = e10;
message = new p("Error processing request", e).getMessage();
if (!TextUtils.isEmpty(message)) {
Log.e("HttpProxyCacheServer error", message);
}
f.e(socket);
sb2 = new StringBuilder("Opened connections: ");
} catch (p e11) {
e = e11;
message = new p("Error processing request", e).getMessage();
if (!TextUtils.isEmpty(message)) {
}
f.e(socket);
sb2 = new StringBuilder("Opened connections: ");
}
sb2.append(fVar.b());
cl.d.O0(sb2.toString());
}
}
public final class b implements Runnable {
public final CountDownLatch f17419a;
public b(CountDownLatch countDownLatch) {
this.f17419a = countDownLatch;
}
@Override
public final void run() {
this.f17419a.countDown();
f fVar = f.this;
fVar.getClass();
while (!Thread.currentThread().isInterrupted()) {
try {
fVar.f17410b.submit(new a(fVar.f17412d.accept()));
} catch (IOException e10) {
String message = new p("Error during waiting connection", e10).getMessage();
if (!TextUtils.isEmpty(message)) {
Log.e("HttpProxyCacheServer error", message);
return;
}
return;
}
}
}
}
public f(c cVar) {
this.f17415g = cVar;
try {
ServerSocket serverSocket = new ServerSocket(0, 8, InetAddress.getByName("127.0.0.1"));
this.f17412d = serverSocket;
int localPort = serverSocket.getLocalPort();
this.f17413e = localPort;
List<Proxy> list = l.f17433d;
ProxySelector.setDefault(new l(ProxySelector.getDefault(), localPort));
CountDownLatch countDownLatch = new CountDownLatch(1);
Thread thread = new Thread(new b(countDownLatch));
this.f17414f = thread;
thread.start();
countDownLatch.await();
this.f17416h = new n(localPort);
cl.d.O0("Proxy cache server started. Is it alive? " + d());
} catch (IOException | InterruptedException e10) {
this.f17410b.shutdown();
throw new IllegalStateException("Error starting local proxy server", e10);
}
}
public static void e(Socket socket) {
try {
if (!socket.isInputShutdown()) {
socket.shutdownInput();
}
} catch (SocketException | IOException unused) {
}
try {
if (!socket.isOutputShutdown()) {
socket.shutdownOutput();
}
} catch (IOException e10) {
String message = e10.getMessage();
if (message != null && !TextUtils.isEmpty(message)) {
Log.w("Failed to close socket on proxy side: {}. It seems client have already closed connection.", message);
}
}
try {
if (!socket.isClosed()) {
socket.close();
}
} catch (IOException unused2) {
}
}
public final g a(String str) throws p {
g gVar;
synchronized (this.f17409a) {
gVar = (g) this.f17411c.get(str);
if (gVar == null) {
gVar = new g(str, this.f17415g);
this.f17411c.put(str, gVar);
}
}
return gVar;
}
public final int b() {
int i;
synchronized (this.f17409a) {
Iterator it2 = this.f17411c.values().iterator();
i = 0;
while (it2.hasNext()) {
i += ((g) it2.next()).f17421a.get();
}
}
return i;
}
public final String c(String str) {
if (str != null) {
c cVar = this.f17415g;
if (new File(cVar.f17397a, cVar.f17398b.b(str)).exists()) {
File file = new File(cVar.f17397a, cVar.f17398b.b(str));
try {
x.e eVar = (x.e) cVar.f17399c;
eVar.getClass();
eVar.f17769a.submit(new e.a(file));
} catch (IOException e10) {
cl.d.N0("Error touching file " + file, e10);
}
return Uri.fromFile(file).toString();
}
if (d()) {
Locale locale = Locale.US;
Object[] objArr = new Object[3];
objArr[0] = "127.0.0.1";
objArr[1] = Integer.valueOf(this.f17413e);
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);
}
}
return str;
}
throw new NullPointerException("Url can't be null!");
}
public final boolean d() {
n nVar = this.f17416h;
nVar.getClass();
int i = 70;
int i2 = 0;
while (i2 < 3) {
try {
} catch (InterruptedException e10) {
e = e10;
cl.d.N0("Error pinging server due to unexpected error", e);
} catch (ExecutionException e11) {
e = e11;
cl.d.N0("Error pinging server due to unexpected error", e);
} catch (TimeoutException unused) {
cl.d.P0("Error pinging server (attempt: " + i2 + ", timeout: " + i + "). ");
}
if (((Boolean) nVar.f17437a.submit(new n.a()).get(i, TimeUnit.MILLISECONDS)).booleanValue()) {
return true;
}
i2++;
i *= 2;
}
Locale locale = Locale.US;
Object[] objArr = new Object[3];
objArr[0] = Integer.valueOf(i2);
objArr[1] = Integer.valueOf(i / 2);
try {
objArr[2] = ProxySelector.getDefault().select(new URI(nVar.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);
cl.d.N0(format, new p(format));
return false;
} catch (URISyntaxException e12) {
throw new IllegalStateException(e12);
}
}
public final void f(w.b bVar) {
bVar.getClass();
synchronized (this.f17409a) {
Iterator it2 = this.f17411c.values().iterator();
while (it2.hasNext()) {
((g) it2.next()).f17424d.remove(bVar);
}
}
}
}