package u6; import java.io.IOException; import java.io.OutputStream; import java.net.Proxy; import java.net.ProxySelector; import java.net.Socket; import java.net.URI; import java.net.URISyntaxException; import java.util.Arrays; import java.util.List; import java.util.Locale; import java.util.concurrent.Callable; 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; /* compiled from: Pinger */ public class n { /* renamed from: d reason: collision with root package name */ public static final String f136163d = "ping"; /* renamed from: e reason: collision with root package name */ public static final String f136164e = "ping ok"; /* renamed from: a reason: collision with root package name */ public final ExecutorService f136165a = Executors.newSingleThreadExecutor(); /* renamed from: b reason: collision with root package name */ public final String f136166b; /* renamed from: c reason: collision with root package name */ public final int f136167c; /* compiled from: Pinger */ public class b implements Callable<Boolean> { public b() { } /* renamed from: a */ public Boolean call() throws Exception { return Boolean.valueOf(n.this.f()); } } public n(String str, int i10) { this.f136166b = (String) o.d(str); this.f136167c = i10; } public final List<Proxy> b() { try { return ProxySelector.getDefault().select(new URI(c())); } catch (URISyntaxException e10) { throw new IllegalStateException(e10); } } public final String c() { return String.format(Locale.US, "http://%s:%d/%s", this.f136166b, Integer.valueOf(this.f136167c), f136163d); } public boolean d(String str) { return f136163d.equals(str); } public boolean e(int i10, int i11) { o.b(i10 >= 1); o.b(i11 > 0); int i12 = 0; while (i12 < i10) { try { if (((Boolean) this.f136165a.submit(new b()).get((long) i11, TimeUnit.MILLISECONDS)).booleanValue()) { return true; } i12++; i11 *= 2; } catch (TimeoutException unused) { h.j("Error pinging server (attempt: " + i12 + ", timeout: " + i11 + "). "); } catch (InterruptedException | ExecutionException e10) { h.f("Error pinging server due to unexpected error", e10); } } String format = String.format(Locale.US, "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", Integer.valueOf(i12), Integer.valueOf(i11 / 2), b()); h.f(format, new q(format)); return false; } public final boolean f() throws q { k kVar = new k(c(), null, null); try { byte[] bytes = f136164e.getBytes(); kVar.a(0); byte[] bArr = new byte[bytes.length]; kVar.read(bArr); boolean equals = Arrays.equals(bytes, bArr); h.h("Ping response: `" + new String(bArr) + "`, pinged? " + equals); return equals; } catch (q e10) { h.f("Error reading ping response", e10); return false; } finally { kVar.close(); } } public void g(Socket socket) throws IOException { OutputStream outputStream = socket.getOutputStream(); outputStream.write("HTTP/1.1 200 OK\n\n".getBytes()); outputStream.write(f136164e.getBytes()); } }