杏吧 v5.0版本的 MD5 值为:6060d82046650ce71383e136711e525f
以下内容为反编译后的 HttpProxyCacheServer.java 源代码,内容仅作参考
package com.danikula.videocache;
import android.content.Context;
import android.net.Uri;
import android.text.TextUtils;
import com.danikula.videocache.Pinger;
import com.danikula.videocache.file.FileNameGenerator;
import com.danikula.videocache.file.LruDiskUsage;
import com.danikula.videocache.file.Md5FileNameGenerator;
import com.danikula.videocache.file.TotalSizeLruDiskUsage;
import com.danikula.videocache.headers.EmptyHeadersInjector;
import com.danikula.videocache.headers.HeaderInjector;
import com.danikula.videocache.sourcestorage.SourceInfoStorage;
import com.danikula.videocache.sourcestorage.SourceInfoStorageFactory;
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.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 javax.net.ssl.HostnameVerifier;
import javax.net.ssl.TrustManager;
import tv.danmaku.ijk.media.player.IjkMediaMeta;
public class HttpProxyCacheServer {
public final Object f660a = new Object();
public final ExecutorService f661b = Executors.newFixedThreadPool(8);
public final ConcurrentHashMap c = new ConcurrentHashMap();
public final ServerSocket d;
public final int e;
public final Thread f;
public final Config g;
public final Pinger h;
public static final class Builder {
public File f662a;
public final SourceInfoStorage d;
public HostnameVerifier f;
public TrustManager[] g;
public LruDiskUsage c = new TotalSizeLruDiskUsage(IjkMediaMeta.AV_CH_STEREO_LEFT);
public FileNameGenerator f663b = new Md5FileNameGenerator();
public HeaderInjector e = new EmptyHeadersInjector();
public Builder(Context context) {
this.d = SourceInfoStorageFactory.a(context);
this.f662a = StorageUtils.a(context);
}
public final HttpProxyCacheServer a() {
return new HttpProxyCacheServer(new Config(this.f662a, this.f663b, this.c, this.d, this.e, this.f, this.g));
}
}
public final class SocketProcessorRunnable implements Runnable {
public final Socket c;
public SocketProcessorRunnable(Socket socket) {
this.c = socket;
}
@Override
public final void run() {
StringBuilder sb;
Socket socket = this.c;
HttpProxyCacheServer httpProxyCacheServer = HttpProxyCacheServer.this;
Pinger pinger = httpProxyCacheServer.h;
try {
try {
GetRequest a2 = GetRequest.a(socket.getInputStream());
String a3 = ProxyCacheUtils.a(a2.f655a);
pinger.getClass();
if ("ping".equals(a3)) {
Pinger.b(socket);
} else {
httpProxyCacheServer.a(a3).b(a2, socket);
}
HttpProxyCacheServer.f(socket);
sb = new StringBuilder("Opened connections: ");
} catch (Throwable th) {
HttpProxyCacheServer.f(socket);
HttpProxyCacheDebuger.b("Opened connections: " + httpProxyCacheServer.b());
throw th;
}
} catch (ProxyCacheException e) {
e = e;
TextUtils.isEmpty(new ProxyCacheException("Error processing request", e).getMessage());
HttpProxyCacheServer.f(socket);
sb = new StringBuilder("Opened connections: ");
} catch (SocketException unused) {
HttpProxyCacheServer.f(socket);
sb = new StringBuilder("Opened connections: ");
} catch (IOException e2) {
e = e2;
TextUtils.isEmpty(new ProxyCacheException("Error processing request", e).getMessage());
HttpProxyCacheServer.f(socket);
sb = new StringBuilder("Opened connections: ");
}
sb.append(httpProxyCacheServer.b());
HttpProxyCacheDebuger.b(sb.toString());
}
}
public final class WaitRequestsRunnable implements Runnable {
public final CountDownLatch c;
public WaitRequestsRunnable(CountDownLatch countDownLatch) {
this.c = countDownLatch;
}
@Override
public final void run() {
this.c.countDown();
HttpProxyCacheServer httpProxyCacheServer = HttpProxyCacheServer.this;
httpProxyCacheServer.getClass();
while (!Thread.currentThread().isInterrupted()) {
try {
httpProxyCacheServer.f661b.submit(new SocketProcessorRunnable(httpProxyCacheServer.d.accept()));
} catch (IOException e) {
TextUtils.isEmpty(new ProxyCacheException("Error during waiting connection", e).getMessage());
return;
}
}
}
}
public HttpProxyCacheServer(Config config) {
this.g = config;
try {
ServerSocket serverSocket = new ServerSocket(0, 8, InetAddress.getByName("127.0.0.1"));
this.d = serverSocket;
int localPort = serverSocket.getLocalPort();
this.e = localPort;
List<Proxy> list = IgnoreHostProxySelector.d;
ProxySelector.setDefault(new IgnoreHostProxySelector(ProxySelector.getDefault(), localPort));
CountDownLatch countDownLatch = new CountDownLatch(1);
Thread thread = new Thread(new WaitRequestsRunnable(countDownLatch));
this.f = thread;
thread.start();
countDownLatch.await();
this.h = new Pinger(localPort);
HttpProxyCacheDebuger.b("Proxy cache server started. Is it alive? " + d());
} catch (IOException | InterruptedException e) {
this.f661b.shutdown();
throw new IllegalStateException("Error starting local proxy server", e);
}
}
public static void f(Socket socket) {
try {
if (!socket.isInputShutdown()) {
socket.shutdownInput();
}
} catch (SocketException | IOException unused) {
}
try {
if (!socket.isOutputShutdown()) {
socket.shutdownOutput();
}
} catch (IOException e) {
String message = e.getMessage();
if (message != null) {
TextUtils.isEmpty(message);
}
}
try {
if (!socket.isClosed()) {
socket.close();
}
} catch (IOException unused2) {
}
}
public final HttpProxyCacheServerClients a(String str) throws ProxyCacheException {
HttpProxyCacheServerClients httpProxyCacheServerClients;
synchronized (this.f660a) {
httpProxyCacheServerClients = (HttpProxyCacheServerClients) this.c.get(str);
if (httpProxyCacheServerClients == null) {
httpProxyCacheServerClients = new HttpProxyCacheServerClients(str, this.g);
this.c.put(str, httpProxyCacheServerClients);
}
}
return httpProxyCacheServerClients;
}
public final int b() {
int i2;
synchronized (this.f660a) {
i2 = 0;
for (HttpProxyCacheServerClients httpProxyCacheServerClients : this.c.values()) {
i2 += httpProxyCacheServerClients.f664a.get();
}
}
return i2;
}
public final String c(String str) {
if (str != null) {
Config config = this.g;
if (new File(config.f653a, config.f654b.a(str)).exists()) {
File file = new File(config.f653a, config.f654b.a(str));
try {
config.c.a(file);
} catch (IOException e) {
HttpProxyCacheDebuger.a("Error touching file " + file, e);
}
return Uri.fromFile(file).toString();
} else if (d()) {
Locale locale = Locale.US;
Object[] objArr = new Object[3];
objArr[0] = "127.0.0.1";
objArr[1] = Integer.valueOf(this.e);
try {
objArr[2] = URLEncoder.encode(str, "utf-8");
return String.format(locale, "http://%s:%d/%s", objArr);
} catch (UnsupportedEncodingException e2) {
throw new RuntimeException("Error encoding url", e2);
}
} else {
return str;
}
}
throw new NullPointerException("Url can't be null!");
}
public final boolean d() {
Pinger pinger = this.h;
pinger.getClass();
int i2 = 70;
int i3 = 0;
while (i3 < 3) {
try {
} catch (InterruptedException e) {
e = e;
HttpProxyCacheDebuger.a("Error pinging server due to unexpected error", e);
} catch (ExecutionException e2) {
e = e2;
HttpProxyCacheDebuger.a("Error pinging server due to unexpected error", e);
} catch (TimeoutException unused) {
String str = "Error pinging server (attempt: " + i3 + ", timeout: " + i2 + "). ";
if (str != null) {
TextUtils.isEmpty(str);
}
}
if (((Boolean) pinger.f670a.submit(new Pinger.PingCallable()).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(pinger.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);
HttpProxyCacheDebuger.a(format, new ProxyCacheException(format));
return false;
} catch (URISyntaxException e3) {
throw new IllegalStateException(e3);
}
}
public final void e(CacheListener cacheListener, String str) {
Object[] objArr = {cacheListener, str};
for (int i2 = 0; i2 < 2; i2++) {
objArr[i2].getClass();
}
synchronized (this.f660a) {
try {
try {
a(str).c.add(cacheListener);
} catch (ProxyCacheException e) {
String message = e.getMessage();
if (message != null) {
TextUtils.isEmpty(message);
}
}
} catch (Throwable th) {
throw th;
}
}
}
public final void g() {
HttpProxyCacheDebuger.b("Shutdown proxy server");
synchronized (this.f660a) {
for (HttpProxyCacheServerClients httpProxyCacheServerClients : this.c.values()) {
httpProxyCacheServerClients.c.clear();
if (httpProxyCacheServerClients.f != null) {
httpProxyCacheServerClients.f.f659k = null;
httpProxyCacheServerClients.f.e();
httpProxyCacheServerClients.f = null;
}
httpProxyCacheServerClients.f664a.set(0);
}
this.c.clear();
}
this.g.d.release();
this.f.interrupt();
try {
if (!this.d.isClosed()) {
this.d.close();
}
} catch (IOException e) {
TextUtils.isEmpty(new ProxyCacheException("Error shutting down proxy server", e).getMessage());
}
}
public final void h(CacheListener cacheListener) {
cacheListener.getClass();
synchronized (this.f660a) {
for (HttpProxyCacheServerClients httpProxyCacheServerClients : this.c.values()) {
httpProxyCacheServerClients.c.remove(cacheListener);
}
}
}
}