package q9; import java.io.IOException; import java.net.ConnectException; import java.net.Proxy; import java.net.Socket; import java.net.SocketTimeoutException; import java.security.cert.X509Certificate; import java.util.ArrayList; import java.util.List; import java.util.concurrent.TimeUnit; import javax.net.ssl.SSLPeerUnverifiedException; import javax.net.ssl.SSLSession; import javax.net.ssl.SSLSocket; import n9.b0; import n9.c0; import n9.e0; import n9.g0; import n9.i0; import n9.l; import n9.v; import n9.w; import n9.y; import n9.z; import t9.f; import x9.n; /* loaded from: classes2.dex */ public final class e extends f.j implements l { /* renamed from: b, reason: collision with root package name */ public final g f13535b; /* renamed from: c, reason: collision with root package name */ private final i0 f13536c; /* renamed from: d, reason: collision with root package name */ private Socket f13537d; /* renamed from: e, reason: collision with root package name */ private Socket f13538e; /* renamed from: f, reason: collision with root package name */ private w f13539f; /* renamed from: g, reason: collision with root package name */ private c0 f13540g; /* renamed from: h, reason: collision with root package name */ private t9.f f13541h; /* renamed from: i, reason: collision with root package name */ private x9.e f13542i; /* renamed from: j, reason: collision with root package name */ private x9.d f13543j; /* renamed from: k, reason: collision with root package name */ boolean f13544k; /* renamed from: l, reason: collision with root package name */ int f13545l; /* renamed from: m, reason: collision with root package name */ int f13546m; /* renamed from: n, reason: collision with root package name */ private int f13547n; /* renamed from: o, reason: collision with root package name */ private int f13548o = 1; /* renamed from: p, reason: collision with root package name */ final List f13549p = new ArrayList(); /* renamed from: q, reason: collision with root package name */ long f13550q = Long.MAX_VALUE; public e(g gVar, i0 i0Var) { this.f13535b = gVar; this.f13536c = i0Var; } private void e(int i10, int i11, n9.g gVar, v vVar) { Proxy b10 = this.f13536c.b(); this.f13537d = (b10.type() == Proxy.Type.DIRECT || b10.type() == Proxy.Type.HTTP) ? this.f13536c.a().j().createSocket() : new Socket(b10); vVar.g(gVar, this.f13536c.d(), b10); this.f13537d.setSoTimeout(i11); try { u9.j.l().h(this.f13537d, this.f13536c.d(), i10); try { this.f13542i = n.c(n.k(this.f13537d)); this.f13543j = n.b(n.h(this.f13537d)); } catch (NullPointerException e10) { if ("throw with null exception".equals(e10.getMessage())) { throw new IOException(e10); } } } catch (ConnectException e11) { ConnectException connectException = new ConnectException("Failed to connect to " + this.f13536c.d()); connectException.initCause(e11); throw connectException; } } private void f(b bVar) { n9.a a10 = this.f13536c.a(); SSLSocket sSLSocket = null; try { try { SSLSocket sSLSocket2 = (SSLSocket) a10.k().createSocket(this.f13537d, a10.l().l(), a10.l().y(), true); try { n9.n a11 = bVar.a(sSLSocket2); if (a11.f()) { u9.j.l().g(sSLSocket2, a10.l().l(), a10.f()); } sSLSocket2.startHandshake(); SSLSession session = sSLSocket2.getSession(); w b10 = w.b(session); if (a10.e().verify(a10.l().l(), session)) { a10.a().a(a10.l().l(), b10.d()); String n10 = a11.f() ? u9.j.l().n(sSLSocket2) : null; this.f13538e = sSLSocket2; this.f13542i = n.c(n.k(sSLSocket2)); this.f13543j = n.b(n.h(this.f13538e)); this.f13539f = b10; this.f13540g = n10 != null ? c0.a(n10) : c0.HTTP_1_1; u9.j.l().a(sSLSocket2); return; } List d10 = b10.d(); if (d10.isEmpty()) { throw new SSLPeerUnverifiedException("Hostname " + a10.l().l() + " not verified (no certificates)"); } X509Certificate x509Certificate = (X509Certificate) d10.get(0); throw new SSLPeerUnverifiedException("Hostname " + a10.l().l() + " not verified:\n certificate: " + n9.i.c(x509Certificate) + "\n DN: " + x509Certificate.getSubjectDN().getName() + "\n subjectAltNames: " + w9.d.a(x509Certificate)); } catch (AssertionError e10) { e = e10; if (!o9.e.A(e)) { throw e; } throw new IOException(e); } catch (Throwable th) { th = th; sSLSocket = sSLSocket2; if (sSLSocket != null) { u9.j.l().a(sSLSocket); } o9.e.h(sSLSocket); throw th; } } catch (Throwable th2) { th = th2; } } catch (AssertionError e11) { e = e11; } } private void g(int i10, int i11, int i12, n9.g gVar, v vVar) { e0 i13 = i(); y h10 = i13.h(); for (int i14 = 0; i14 < 21; i14++) { e(i10, i11, gVar, vVar); i13 = h(i11, i12, i13, h10); if (i13 == null) { return; } o9.e.h(this.f13537d); this.f13537d = null; this.f13543j = null; this.f13542i = null; vVar.e(gVar, this.f13536c.d(), this.f13536c.b(), null); } } private e0 h(int i10, int i11, e0 e0Var, y yVar) { String str = "CONNECT " + o9.e.s(yVar, true) + " HTTP/1.1"; while (true) { s9.a aVar = new s9.a(null, null, this.f13542i, this.f13543j); TimeUnit timeUnit = TimeUnit.MILLISECONDS; this.f13542i.b().g(i10, timeUnit); this.f13543j.b().g(i11, timeUnit); aVar.B(e0Var.d(), str); aVar.a(); g0 c10 = aVar.b(false).q(e0Var).c(); aVar.A(c10); int G = c10.G(); if (G == 200) { if (this.f13542i.K().g() && this.f13543j.a().g()) { return null; } throw new IOException("TLS tunnel buffered too many bytes!"); } if (G != 407) { throw new IOException("Unexpected response code for CONNECT: " + c10.G()); } e0 a10 = this.f13536c.a().h().a(this.f13536c, c10); if (a10 == null) { throw new IOException("Failed to authenticate with proxy"); } if ("close".equalsIgnoreCase(c10.O("Connection"))) { return a10; } e0Var = a10; } } private e0 i() { e0 b10 = new e0.a().j(this.f13536c.a().l()).f("CONNECT", null).d("Host", o9.e.s(this.f13536c.a().l(), true)).d("Proxy-Connection", "Keep-Alive").d("User-Agent", o9.f.a()).b(); e0 a10 = this.f13536c.a().h().a(this.f13536c, new g0.a().q(b10).o(c0.HTTP_1_1).g(407).l("Preemptive Authenticate").b(o9.e.f12829d).r(-1L).p(-1L).i("Proxy-Authenticate", "OkHttp-Preemptive").c()); return a10 != null ? a10 : b10; } private void j(b bVar, int i10, n9.g gVar, v vVar) { if (this.f13536c.a().k() != null) { vVar.y(gVar); f(bVar); vVar.x(gVar, this.f13539f); if (this.f13540g == c0.HTTP_2) { t(i10); return; } return; } List f10 = this.f13536c.a().f(); c0 c0Var = c0.H2_PRIOR_KNOWLEDGE; if (!f10.contains(c0Var)) { this.f13538e = this.f13537d; this.f13540g = c0.HTTP_1_1; } else { this.f13538e = this.f13537d; this.f13540g = c0Var; t(i10); } } private boolean r(List list) { int size = list.size(); for (int i10 = 0; i10 < size; i10++) { i0 i0Var = (i0) list.get(i10); if (i0Var.b().type() == Proxy.Type.DIRECT && this.f13536c.b().type() == Proxy.Type.DIRECT && this.f13536c.d().equals(i0Var.d())) { return true; } } return false; } private void t(int i10) { this.f13538e.setSoTimeout(0); t9.f a10 = new f.h(true).d(this.f13538e, this.f13536c.a().l().l(), this.f13542i, this.f13543j).b(this).c(i10).a(); this.f13541h = a10; a10.K0(); } @Override // t9.f.j public void a(t9.f fVar) { synchronized (this.f13535b) { this.f13548o = fVar.q0(); } } @Override // t9.f.j public void b(t9.i iVar) { iVar.d(t9.b.REFUSED_STREAM, null); } public void c() { o9.e.h(this.f13537d); } /* JADX WARN: Removed duplicated region for block: B:32:0x00e4 */ /* JADX WARN: Removed duplicated region for block: B:43:0x00f4 A[ORIG_RETURN, RETURN] */ /* JADX WARN: Removed duplicated region for block: B:47:0x012f */ /* JADX WARN: Removed duplicated region for block: B:49:0x013a */ /* JADX WARN: Removed duplicated region for block: B:54:0x0142 A[SYNTHETIC] */ /* JADX WARN: Removed duplicated region for block: B:56:0x0135 */ /* Code decompiled incorrectly, please refer to instructions dump. To view partially-correct code enable 'Show inconsistent code' option in preferences */ public void d(int r17, int r18, int r19, int r20, boolean r21, n9.g r22, n9.v r23) { /* Method dump skipped, instructions count: 344 To view this dump change 'Code comments level' option to 'DEBUG' */ throw new UnsupportedOperationException("Method not decompiled: q9.e.d(int, int, int, int, boolean, n9.g, n9.v):void"); } public w k() { return this.f13539f; } boolean l(n9.a aVar, List list) { if (this.f13549p.size() >= this.f13548o || this.f13544k || !o9.a.f12822a.e(this.f13536c.a(), aVar)) { return false; } if (aVar.l().l().equals(q().a().l().l())) { return true; } if (this.f13541h == null || list == null || !r(list) || aVar.e() != w9.d.f15210a || !u(aVar.l())) { return false; } try { aVar.a().a(aVar.l().l(), k().d()); return true; } catch (SSLPeerUnverifiedException unused) { return false; } } public boolean m(boolean z10) { if (this.f13538e.isClosed() || this.f13538e.isInputShutdown() || this.f13538e.isOutputShutdown()) { return false; } t9.f fVar = this.f13541h; if (fVar != null) { return fVar.n0(System.nanoTime()); } if (z10) { try { int soTimeout = this.f13538e.getSoTimeout(); try { this.f13538e.setSoTimeout(1); return !this.f13542i.g(); } finally { this.f13538e.setSoTimeout(soTimeout); } } catch (SocketTimeoutException unused) { } catch (IOException unused2) { return false; } } return true; } public boolean n() { return this.f13541h != null; } r9.c o(b0 b0Var, z.a aVar) { if (this.f13541h != null) { return new t9.g(b0Var, this, aVar, this.f13541h); } this.f13538e.setSoTimeout(aVar.a()); x9.w b10 = this.f13542i.b(); long a10 = aVar.a(); TimeUnit timeUnit = TimeUnit.MILLISECONDS; b10.g(a10, timeUnit); this.f13543j.b().g(aVar.b(), timeUnit); return new s9.a(b0Var, this, this.f13542i, this.f13543j); } public void p() { synchronized (this.f13535b) { this.f13544k = true; } } public i0 q() { return this.f13536c; } public Socket s() { return this.f13538e; } public String toString() { StringBuilder sb = new StringBuilder(); sb.append("Connection{"); sb.append(this.f13536c.a().l().l()); sb.append(":"); sb.append(this.f13536c.a().l().y()); sb.append(", proxy="); sb.append(this.f13536c.b()); sb.append(" hostAddress="); sb.append(this.f13536c.d()); sb.append(" cipherSuite="); w wVar = this.f13539f; sb.append(wVar != null ? wVar.a() : "none"); sb.append(" protocol="); sb.append(this.f13540g); sb.append('}'); return sb.toString(); } public boolean u(y yVar) { if (yVar.y() != this.f13536c.a().l().y()) { return false; } if (yVar.l().equals(this.f13536c.a().l().l())) { return true; } return this.f13539f != null && w9.d.f15210a.c(yVar.l(), (X509Certificate) this.f13539f.d().get(0)); } void v(IOException iOException) { synchronized (this.f13535b) { if (iOException instanceof t9.n) { t9.b bVar = ((t9.n) iOException).f14635a; if (bVar == t9.b.REFUSED_STREAM) { int i10 = this.f13547n + 1; this.f13547n = i10; if (i10 > 1) { this.f13544k = true; this.f13545l++; } } else if (bVar != t9.b.CANCEL) { this.f13544k = true; this.f13545l++; } } else if (!n() || (iOException instanceof t9.a)) { this.f13544k = true; if (this.f13546m == 0) { if (iOException != null) { this.f13535b.c(this.f13536c, iOException); } this.f13545l++; } } } } }