what-the-bank/sources/okhttp3/repackaged/internal/framed/FramedConnection.java

1018 lines
37 KiB
Java
Raw Permalink Normal View History

2024-07-27 18:17:47 +07:00
package okhttp3.repackaged.internal.framed;
import java.io.Closeable;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
import o.C15145giV;
import o.InterfaceC15142giR;
import o.giM;
import o.giO;
import o.giP;
import okhttp3.repackaged.Protocol;
import okhttp3.repackaged.internal.Internal;
import okhttp3.repackaged.internal.NamedRunnable;
import okhttp3.repackaged.internal.Util;
import okhttp3.repackaged.internal.framed.FrameReader;
/* loaded from: classes6.dex */
public final class FramedConnection implements Closeable {
static final boolean $assertionsDisabled = false;
private static final int ajJ = 16777216;
private static final ExecutorService gt = new ThreadPoolExecutor(0, Integer.MAX_VALUE, 60, TimeUnit.SECONDS, new SynchronousQueue(), Util.threadFactory("OkHttp FramedConnection", true));
private final Listener ajC;
private long ajD;
private final ExecutorService ajE;
private Map<Integer, Ping> ajF;
private final PushObserver ajG;
private int ajH;
Settings ajI;
final Settings ajK;
final Variant ajL;
final FrameWriter ajM;
final a ajN;
long bytesLeftInWriteWindow;
final boolean client;
private final Set<Integer> currentPushRequests;
private final String hostname;
private int lastGoodStreamId;
private int nextStreamId;
final Protocol protocol;
private boolean receivedInitialPeerSettings;
private boolean shutdown;
final Socket socket;
private final Map<Integer, FramedStream> streams;
long unacknowledgedBytesRead;
/* loaded from: classes6.dex */
public static abstract class Listener {
public static final Listener REFUSE_INCOMING_STREAMS = new Listener() { // from class: okhttp3.repackaged.internal.framed.FramedConnection.Listener.1
@Override // okhttp3.repackaged.internal.framed.FramedConnection.Listener
public final void onStream(FramedStream framedStream) throws IOException {
framedStream.close(ErrorCode.REFUSED_STREAM);
}
};
public void onSettings(FramedConnection framedConnection) {
}
public abstract void onStream(FramedStream framedStream) throws IOException;
}
private FramedConnection(Builder builder) throws IOException {
this.streams = new HashMap();
this.ajD = System.nanoTime();
this.unacknowledgedBytesRead = 0L;
this.ajI = new Settings();
Settings settings = new Settings();
this.ajK = settings;
this.receivedInitialPeerSettings = false;
this.currentPushRequests = new LinkedHashSet();
Protocol protocol = builder.protocol;
this.protocol = protocol;
this.ajG = builder.ajG;
boolean z = builder.client;
this.client = z;
this.ajC = builder.ajC;
this.nextStreamId = builder.client ? 1 : 2;
if (builder.client && protocol == Protocol.HTTP_2) {
this.nextStreamId += 2;
}
this.ajH = builder.client ? 1 : 2;
if (builder.client) {
this.ajI.d(7, 0, 16777216);
}
String str = builder.hostname;
this.hostname = str;
if (protocol == Protocol.HTTP_2) {
this.ajL = new Http2();
this.ajE = new ThreadPoolExecutor(0, 1, 60L, TimeUnit.SECONDS, new LinkedBlockingQueue(), Util.threadFactory(String.format("OkHttp %s Push Observer", str), true));
settings.d(7, 0, 65535);
settings.d(5, 0, 16384);
} else if (protocol == Protocol.SPDY_3) {
this.ajL = new Spdy3();
this.ajE = null;
} else {
throw new AssertionError(protocol);
}
this.bytesLeftInWriteWindow = settings.M(65536);
this.socket = builder.socket;
this.ajM = this.ajL.newWriter(builder.sink, z);
a aVar = new a(this.ajL.newReader(builder.source, z));
this.ajN = aVar;
new Thread(aVar).start();
}
public final int openStreamCount() {
int size;
synchronized (this) {
size = this.streams.size();
}
return size;
}
final FramedStream u(int i) {
FramedStream framedStream;
synchronized (this) {
framedStream = this.streams.get(Integer.valueOf(i));
}
return framedStream;
}
/* JADX INFO: Access modifiers changed from: package-private */
public final FramedStream v(int i) {
FramedStream remove;
synchronized (this) {
remove = this.streams.remove(Integer.valueOf(i));
if (remove != null && this.streams.isEmpty()) {
z(true);
}
notifyAll();
}
return remove;
}
private void z(boolean z) {
long nanoTime;
synchronized (this) {
if (z) {
try {
nanoTime = System.nanoTime();
} catch (Throwable th) {
throw th;
}
} else {
nanoTime = Long.MAX_VALUE;
}
this.ajD = nanoTime;
}
}
public final boolean isIdle() {
boolean z;
synchronized (this) {
z = this.ajD != Long.MAX_VALUE;
}
return z;
}
public final int maxConcurrentStreams() {
int maxConcurrentStreams;
synchronized (this) {
maxConcurrentStreams = this.ajK.getMaxConcurrentStreams(Integer.MAX_VALUE);
}
return maxConcurrentStreams;
}
public final long getIdleStartTimeNs() {
long j;
synchronized (this) {
j = this.ajD;
}
return j;
}
public final FramedStream pushStream(int i, List<Header> list, boolean z) throws IOException {
if (this.client) {
throw new IllegalStateException("Client cannot push requests.");
}
if (this.protocol != Protocol.HTTP_2) {
throw new IllegalStateException("protocol != HTTP_2");
}
return a(i, list, z, false);
}
public final FramedStream newStream(List<Header> list, boolean z, boolean z2) throws IOException {
return a(0, list, z, z2);
}
private FramedStream a(int i, List<Header> list, boolean z, boolean z2) throws IOException {
int i2;
FramedStream framedStream;
boolean z3 = !z;
boolean z4 = !z2;
synchronized (this.ajM) {
synchronized (this) {
if (this.shutdown) {
throw new IOException("shutdown");
}
i2 = this.nextStreamId;
this.nextStreamId = i2 + 2;
framedStream = new FramedStream(i2, this, z3, z4, list);
if (framedStream.isOpen()) {
this.streams.put(Integer.valueOf(i2), framedStream);
z(false);
}
}
if (i == 0) {
this.ajM.synStream(z3, z4, i2, i, list);
} else {
if (this.client) {
throw new IllegalArgumentException("client streams shouldn't have associated stream IDs");
}
this.ajM.pushPromise(i, i2, list);
}
}
if (!z) {
this.ajM.flush();
}
return framedStream;
}
/* JADX INFO: Access modifiers changed from: package-private */
public final void writeSynReply(int i, boolean z, List<Header> list) throws IOException {
this.ajM.synReply(z, i, list);
}
/* JADX WARN: Code restructure failed: missing block: B:17:0x002f, code lost:
throw new java.io.IOException("stream closed");
*/
/* JADX WARN: Code restructure failed: missing block: B:20:0x0030, code lost:
r2 = java.lang.Math.min((int) java.lang.Math.min(r12, r4), r8.ajM.maxDataLength());
r6 = r2;
r8.bytesLeftInWriteWindow -= r6;
*/
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct add '--show-bad-code' argument
*/
public final void writeData(int r9, boolean r10, o.giM r11, long r12) throws java.io.IOException {
/*
r8 = this;
r0 = 0
int r2 = (r12 > r0 ? 1 : (r12 == r0 ? 0 : -1))
r3 = 0
if (r2 != 0) goto Ld
okhttp3.repackaged.internal.framed.FrameWriter r12 = r8.ajM
r12.data(r10, r9, r11, r3)
return
Ld:
int r2 = (r12 > r0 ? 1 : (r12 == r0 ? 0 : -1))
if (r2 <= 0) goto L60
monitor-enter(r8)
L12:
long r4 = r8.bytesLeftInWriteWindow // Catch: java.lang.Throwable -> L56 java.lang.InterruptedException -> L58
int r2 = (r4 > r0 ? 1 : (r4 == r0 ? 0 : -1))
if (r2 > 0) goto L30
java.util.Map<java.lang.Integer, okhttp3.repackaged.internal.framed.FramedStream> r2 = r8.streams // Catch: java.lang.Throwable -> L56 java.lang.InterruptedException -> L58
java.lang.Integer r4 = java.lang.Integer.valueOf(r9) // Catch: java.lang.Throwable -> L56 java.lang.InterruptedException -> L58
boolean r2 = r2.containsKey(r4) // Catch: java.lang.Throwable -> L56 java.lang.InterruptedException -> L58
if (r2 == 0) goto L28
r8.wait() // Catch: java.lang.Throwable -> L56 java.lang.InterruptedException -> L58
goto L12
L28:
java.io.IOException r9 = new java.io.IOException // Catch: java.lang.Throwable -> L56 java.lang.InterruptedException -> L58
java.lang.String r10 = "stream closed"
r9.<init>(r10) // Catch: java.lang.Throwable -> L56 java.lang.InterruptedException -> L58
throw r9 // Catch: java.lang.Throwable -> L56 java.lang.InterruptedException -> L58
L30:
long r4 = java.lang.Math.min(r12, r4) // Catch: java.lang.Throwable -> L56
int r2 = (int) r4 // Catch: java.lang.Throwable -> L56
okhttp3.repackaged.internal.framed.FrameWriter r4 = r8.ajM // Catch: java.lang.Throwable -> L56
int r4 = r4.maxDataLength() // Catch: java.lang.Throwable -> L56
int r2 = java.lang.Math.min(r2, r4) // Catch: java.lang.Throwable -> L56
long r4 = r8.bytesLeftInWriteWindow // Catch: java.lang.Throwable -> L56
long r6 = (long) r2 // Catch: java.lang.Throwable -> L56
long r4 = r4 - r6
r8.bytesLeftInWriteWindow = r4 // Catch: java.lang.Throwable -> L56
monitor-exit(r8)
long r12 = r12 - r6
okhttp3.repackaged.internal.framed.FrameWriter r4 = r8.ajM
if (r10 == 0) goto L51
int r5 = (r12 > r0 ? 1 : (r12 == r0 ? 0 : -1))
if (r5 != 0) goto L51
r5 = 1
goto L52
L51:
r5 = r3
L52:
r4.data(r5, r9, r11, r2)
goto Ld
L56:
r9 = move-exception
goto L5e
L58:
java.io.InterruptedIOException r9 = new java.io.InterruptedIOException // Catch: java.lang.Throwable -> L56
r9.<init>() // Catch: java.lang.Throwable -> L56
throw r9 // Catch: java.lang.Throwable -> L56
L5e:
monitor-exit(r8)
throw r9
L60:
return
*/
throw new UnsupportedOperationException("Method not decompiled: okhttp3.repackaged.internal.framed.FramedConnection.writeData(int, boolean, o.giM, long):void");
}
final void addBytesToWriteWindow(long j) {
this.bytesLeftInWriteWindow += j;
if (j > 0) {
notifyAll();
}
}
/* JADX INFO: Access modifiers changed from: package-private */
public final void a(int i, ErrorCode errorCode) {
gt.submit(new NamedRunnable(this, "OkHttp %s stream %d", new Object[]{this.hostname, Integer.valueOf(i)}, i, errorCode) { // from class: okhttp3.repackaged.internal.framed.FramedConnection.1
final ErrorCode ajO;
final FramedConnection ajP;
final int val$streamId;
{
this.ajP = this;
this.val$streamId = i;
this.ajO = errorCode;
}
@Override // okhttp3.repackaged.internal.NamedRunnable
public void execute() {
try {
this.ajP.b(this.val$streamId, this.ajO);
} catch (IOException unused) {
}
}
});
}
/* JADX INFO: Access modifiers changed from: package-private */
public final void b(int i, ErrorCode errorCode) throws IOException {
this.ajM.rstStream(i, errorCode);
}
/* JADX INFO: Access modifiers changed from: package-private */
public final void writeWindowUpdateLater(int i, long j) {
gt.execute(new NamedRunnable(this, "OkHttp Window Update %s stream %d", new Object[]{this.hostname, Integer.valueOf(i)}, i, j) { // from class: okhttp3.repackaged.internal.framed.FramedConnection.2
final FramedConnection ajP;
final int val$streamId;
final long val$unacknowledgedBytesRead;
{
this.ajP = this;
this.val$streamId = i;
this.val$unacknowledgedBytesRead = j;
}
@Override // okhttp3.repackaged.internal.NamedRunnable
public void execute() {
try {
this.ajP.ajM.windowUpdate(this.val$streamId, this.val$unacknowledgedBytesRead);
} catch (IOException unused) {
}
}
});
}
public final Ping ping() throws IOException {
int i;
Ping ping = new Ping();
synchronized (this) {
if (this.shutdown) {
throw new IOException("shutdown");
}
i = this.ajH;
this.ajH = i + 2;
if (this.ajF == null) {
this.ajF = new HashMap();
}
this.ajF.put(Integer.valueOf(i), ping);
}
b(false, i, 1330343787, ping);
return ping;
}
/* JADX INFO: Access modifiers changed from: private */
public void a(boolean z, int i, int i2, Ping ping) {
gt.execute(new NamedRunnable(this, "OkHttp %s ping %08x%08x", new Object[]{this.hostname, Integer.valueOf(i), Integer.valueOf(i2)}, z, i, i2, ping) { // from class: okhttp3.repackaged.internal.framed.FramedConnection.3
final FramedConnection ajP;
final boolean ajQ;
final int ajR;
final int ajS;
final Ping ajT;
{
this.ajP = this;
this.ajQ = z;
this.ajR = i;
this.ajS = i2;
this.ajT = ping;
}
@Override // okhttp3.repackaged.internal.NamedRunnable
public void execute() {
try {
this.ajP.b(this.ajQ, this.ajR, this.ajS, this.ajT);
} catch (IOException unused) {
}
}
});
}
/* JADX INFO: Access modifiers changed from: private */
public void b(boolean z, int i, int i2, Ping ping) throws IOException {
synchronized (this.ajM) {
if (ping != null) {
ping.send();
}
this.ajM.ping(z, i, i2);
}
}
/* JADX INFO: Access modifiers changed from: private */
public Ping w(int i) {
Ping remove;
synchronized (this) {
Map<Integer, Ping> map = this.ajF;
remove = map != null ? map.remove(Integer.valueOf(i)) : null;
}
return remove;
}
public final void flush() throws IOException {
this.ajM.flush();
}
public final void shutdown(ErrorCode errorCode) throws IOException {
synchronized (this.ajM) {
synchronized (this) {
if (this.shutdown) {
return;
}
this.shutdown = true;
this.ajM.goAway(this.lastGoodStreamId, errorCode, Util.EMPTY_BYTE_ARRAY);
}
}
}
@Override // java.io.Closeable, java.lang.AutoCloseable
public final void close() throws IOException {
a(ErrorCode.NO_ERROR, ErrorCode.CANCEL);
}
/* JADX INFO: Access modifiers changed from: private */
public void a(ErrorCode errorCode, ErrorCode errorCode2) throws IOException {
int i;
FramedStream[] framedStreamArr;
Ping[] pingArr = null;
try {
shutdown(errorCode);
e = null;
} catch (IOException e) {
e = e;
}
synchronized (this) {
if (this.streams.isEmpty()) {
framedStreamArr = null;
} else {
framedStreamArr = (FramedStream[]) this.streams.values().toArray(new FramedStream[this.streams.size()]);
this.streams.clear();
z(false);
}
Map<Integer, Ping> map = this.ajF;
if (map != null) {
Ping[] pingArr2 = (Ping[]) map.values().toArray(new Ping[this.ajF.size()]);
this.ajF = null;
pingArr = pingArr2;
}
}
if (framedStreamArr != null) {
for (FramedStream framedStream : framedStreamArr) {
try {
framedStream.close(errorCode2);
} catch (IOException e2) {
if (e != null) {
e = e2;
}
}
}
}
if (pingArr != null) {
for (Ping ping : pingArr) {
ping.cancel();
}
}
try {
this.ajM.close();
} catch (IOException e3) {
if (e == null) {
e = e3;
}
}
try {
this.socket.close();
} catch (IOException e4) {
e = e4;
}
if (e != null) {
throw e;
}
}
public final void sendConnectionPreface() throws IOException {
this.ajM.connectionPreface();
this.ajM.settings(this.ajI);
if (this.ajI.M(65536) != 65536) {
this.ajM.windowUpdate(0, r0 - 65536);
}
}
public final void setSettings(Settings settings) throws IOException {
synchronized (this.ajM) {
synchronized (this) {
if (this.shutdown) {
throw new IOException("shutdown");
}
this.ajI.b(settings);
this.ajM.settings(settings);
}
}
}
/* loaded from: classes6.dex */
public static class Builder {
private boolean client;
private String hostname;
private giO sink;
private Socket socket;
private InterfaceC15142giR source;
private Listener ajC = Listener.REFUSE_INCOMING_STREAMS;
private Protocol protocol = Protocol.SPDY_3;
private PushObserver ajG = PushObserver.CANCEL;
public Builder(boolean z) throws IOException {
this.client = z;
}
public Builder socket(Socket socket) throws IOException {
return socket(socket, ((InetSocketAddress) socket.getRemoteSocketAddress()).getHostName(), C15145giV.a(C15145giV.e(socket)), C15145giV.e(C15145giV.c(socket)));
}
public FramedConnection build() throws IOException {
return new FramedConnection(this);
}
public Builder socket(Socket socket, String str, InterfaceC15142giR interfaceC15142giR, giO gio) {
this.socket = socket;
this.hostname = str;
this.source = interfaceC15142giR;
this.sink = gio;
return this;
}
public Builder pushObserver(PushObserver pushObserver) {
this.ajG = pushObserver;
return this;
}
public Builder protocol(Protocol protocol) {
this.protocol = protocol;
return this;
}
public Builder listener(Listener listener) {
this.ajC = listener;
return this;
}
}
/* loaded from: classes6.dex */
class a extends NamedRunnable implements FrameReader.Handler {
final FramedConnection ajP;
final FrameReader ajV;
@Override // okhttp3.repackaged.internal.framed.FrameReader.Handler
public void ackSettings() {
}
@Override // okhttp3.repackaged.internal.framed.FrameReader.Handler
public void alternateService(int i, String str, giP gip, String str2, int i2, long j) {
}
@Override // okhttp3.repackaged.internal.framed.FrameReader.Handler
public void priority(int i, int i2, int i3, boolean z) {
}
/* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
private a(FramedConnection framedConnection, FrameReader frameReader) {
super("OkHttp %s", framedConnection.hostname);
this.ajP = framedConnection;
this.ajV = frameReader;
}
@Override // okhttp3.repackaged.internal.NamedRunnable
public void execute() {
ErrorCode errorCode;
FramedConnection framedConnection;
ErrorCode errorCode2 = ErrorCode.INTERNAL_ERROR;
ErrorCode errorCode3 = ErrorCode.INTERNAL_ERROR;
try {
try {
try {
if (!this.ajP.client) {
this.ajV.readConnectionPreface();
}
do {
} while (this.ajV.nextFrame(this));
errorCode2 = ErrorCode.NO_ERROR;
errorCode = ErrorCode.CANCEL;
framedConnection = this.ajP;
} catch (IOException unused) {
}
} catch (IOException unused2) {
errorCode2 = ErrorCode.PROTOCOL_ERROR;
errorCode = ErrorCode.PROTOCOL_ERROR;
framedConnection = this.ajP;
}
framedConnection.a(errorCode2, errorCode);
Util.closeQuietly(this.ajV);
} catch (Throwable th) {
try {
this.ajP.a(errorCode2, errorCode3);
} catch (IOException unused3) {
}
Util.closeQuietly(this.ajV);
throw th;
}
}
@Override // okhttp3.repackaged.internal.framed.FrameReader.Handler
public void data(boolean z, int i, InterfaceC15142giR interfaceC15142giR, int i2) throws IOException {
if (this.ajP.pushedStream(i)) {
this.ajP.a(i, interfaceC15142giR, i2, z);
return;
}
FramedStream u = this.ajP.u(i);
if (u == null) {
this.ajP.a(i, ErrorCode.INVALID_STREAM);
interfaceC15142giR.f(i2);
} else {
u.a(interfaceC15142giR, i2);
if (z) {
u.receiveFin();
}
}
}
@Override // okhttp3.repackaged.internal.framed.FrameReader.Handler
public void headers(boolean z, boolean z2, int i, int i2, List<Header> list, HeadersMode headersMode) {
if (this.ajP.pushedStream(i)) {
this.ajP.pushHeadersLater(i, list, z2);
return;
}
synchronized (this.ajP) {
if (this.ajP.shutdown) {
return;
}
FramedStream u = this.ajP.u(i);
if (u == null) {
if (!headersMode.failIfStreamAbsent()) {
if (i <= this.ajP.lastGoodStreamId) {
return;
}
if (i % 2 == this.ajP.nextStreamId % 2) {
return;
}
FramedStream framedStream = new FramedStream(i, this.ajP, z, z2, list);
this.ajP.lastGoodStreamId = i;
this.ajP.streams.put(Integer.valueOf(i), framedStream);
FramedConnection.gt.execute(new NamedRunnable(this, "OkHttp %s stream %d", new Object[]{this.ajP.hostname, Integer.valueOf(i)}, framedStream) { // from class: okhttp3.repackaged.internal.framed.FramedConnection.a.1
final FramedStream ajW;
final a ajX;
{
this.ajX = this;
this.ajW = framedStream;
}
@Override // okhttp3.repackaged.internal.NamedRunnable
public void execute() {
try {
this.ajX.ajP.ajC.onStream(this.ajW);
} catch (IOException e) {
Logger logger = Internal.logger;
Level level = Level.INFO;
StringBuilder sb = new StringBuilder("FramedConnection.Listener failure for ");
sb.append(this.ajX.ajP.hostname);
logger.log(level, sb.toString(), (Throwable) e);
try {
this.ajW.close(ErrorCode.PROTOCOL_ERROR);
} catch (IOException unused) {
}
}
}
});
return;
}
this.ajP.a(i, ErrorCode.INVALID_STREAM);
return;
}
if (headersMode.failIfStreamPresent()) {
u.closeLater(ErrorCode.PROTOCOL_ERROR);
this.ajP.v(i);
} else {
u.a(list, headersMode);
if (z2) {
u.receiveFin();
}
}
}
}
@Override // okhttp3.repackaged.internal.framed.FrameReader.Handler
public void rstStream(int i, ErrorCode errorCode) {
if (this.ajP.pushedStream(i)) {
this.ajP.c(i, errorCode);
return;
}
FramedStream v = this.ajP.v(i);
if (v != null) {
v.b(errorCode);
}
}
@Override // okhttp3.repackaged.internal.framed.FrameReader.Handler
public void settings(boolean z, Settings settings) {
FramedStream[] framedStreamArr;
long j;
int i;
synchronized (this.ajP) {
int M = this.ajP.ajK.M(65536);
if (z) {
this.ajP.ajK.clear();
}
this.ajP.ajK.b(settings);
if (this.ajP.getProtocol() == Protocol.HTTP_2) {
a(settings);
}
int M2 = this.ajP.ajK.M(65536);
framedStreamArr = null;
if (M2 == -1 || M2 == M) {
j = 0;
} else {
j = M2 - M;
if (!this.ajP.receivedInitialPeerSettings) {
this.ajP.addBytesToWriteWindow(j);
this.ajP.receivedInitialPeerSettings = true;
}
if (!this.ajP.streams.isEmpty()) {
framedStreamArr = (FramedStream[]) this.ajP.streams.values().toArray(new FramedStream[this.ajP.streams.size()]);
}
}
FramedConnection.gt.execute(new NamedRunnable(this, "OkHttp %s settings", this.ajP.hostname) { // from class: okhttp3.repackaged.internal.framed.FramedConnection.a.2
final a ajX;
{
this.ajX = this;
}
@Override // okhttp3.repackaged.internal.NamedRunnable
public void execute() {
this.ajX.ajP.ajC.onSettings(this.ajX.ajP);
}
});
}
if (framedStreamArr == null || j == 0) {
return;
}
for (FramedStream framedStream : framedStreamArr) {
synchronized (framedStream) {
framedStream.addBytesToWriteWindow(j);
}
}
}
private void a(Settings settings) {
FramedConnection.gt.execute(new NamedRunnable(this, "OkHttp %s ACK Settings", new Object[]{this.ajP.hostname}, settings) { // from class: okhttp3.repackaged.internal.framed.FramedConnection.a.3
final a ajX;
final Settings ajY;
{
this.ajX = this;
this.ajY = settings;
}
@Override // okhttp3.repackaged.internal.NamedRunnable
public void execute() {
try {
this.ajX.ajP.ajM.ackSettings(this.ajY);
} catch (IOException unused) {
}
}
});
}
@Override // okhttp3.repackaged.internal.framed.FrameReader.Handler
public void ping(boolean z, int i, int i2) {
if (z) {
Ping w = this.ajP.w(i);
if (w != null) {
w.uR();
return;
}
return;
}
this.ajP.a(true, i, i2, (Ping) null);
}
@Override // okhttp3.repackaged.internal.framed.FrameReader.Handler
public void goAway(int i, ErrorCode errorCode, giP gip) {
FramedStream[] framedStreamArr;
int length = gip.d.length;
synchronized (this.ajP) {
framedStreamArr = (FramedStream[]) this.ajP.streams.values().toArray(new FramedStream[this.ajP.streams.size()]);
this.ajP.shutdown = true;
}
for (FramedStream framedStream : framedStreamArr) {
if (framedStream.getId() > i && framedStream.isLocallyInitiated()) {
framedStream.b(ErrorCode.REFUSED_STREAM);
this.ajP.v(framedStream.getId());
}
}
}
@Override // okhttp3.repackaged.internal.framed.FrameReader.Handler
public void windowUpdate(int i, long j) {
if (i == 0) {
synchronized (this.ajP) {
this.ajP.bytesLeftInWriteWindow += j;
this.ajP.notifyAll();
}
return;
}
FramedStream u = this.ajP.u(i);
if (u != null) {
synchronized (u) {
u.addBytesToWriteWindow(j);
}
}
}
@Override // okhttp3.repackaged.internal.framed.FrameReader.Handler
public void pushPromise(int i, int i2, List<Header> list) {
this.ajP.pushRequestLater(i2, list);
}
}
/* JADX INFO: Access modifiers changed from: private */
public boolean pushedStream(int i) {
return this.protocol == Protocol.HTTP_2 && i != 0 && (i & 1) == 0;
}
/* JADX INFO: Access modifiers changed from: private */
public void pushRequestLater(int i, List<Header> list) {
synchronized (this) {
if (this.currentPushRequests.contains(Integer.valueOf(i))) {
a(i, ErrorCode.PROTOCOL_ERROR);
return;
}
this.currentPushRequests.add(Integer.valueOf(i));
this.ajE.execute(new NamedRunnable(this, "OkHttp %s Push Request[%s]", new Object[]{this.hostname, Integer.valueOf(i)}, i, list) { // from class: okhttp3.repackaged.internal.framed.FramedConnection.4
final FramedConnection ajP;
final List val$requestHeaders;
final int val$streamId;
{
this.ajP = this;
this.val$streamId = i;
this.val$requestHeaders = list;
}
@Override // okhttp3.repackaged.internal.NamedRunnable
public void execute() {
if (this.ajP.ajG.onRequest(this.val$streamId, this.val$requestHeaders)) {
try {
this.ajP.ajM.rstStream(this.val$streamId, ErrorCode.CANCEL);
synchronized (this.ajP) {
this.ajP.currentPushRequests.remove(Integer.valueOf(this.val$streamId));
}
} catch (IOException unused) {
}
}
}
});
}
}
/* JADX INFO: Access modifiers changed from: private */
public void pushHeadersLater(int i, List<Header> list, boolean z) {
this.ajE.execute(new NamedRunnable(this, "OkHttp %s Push Headers[%s]", new Object[]{this.hostname, Integer.valueOf(i)}, i, list, z) { // from class: okhttp3.repackaged.internal.framed.FramedConnection.5
final FramedConnection ajP;
final boolean val$inFinished;
final List val$requestHeaders;
final int val$streamId;
{
this.ajP = this;
this.val$streamId = i;
this.val$requestHeaders = list;
this.val$inFinished = z;
}
@Override // okhttp3.repackaged.internal.NamedRunnable
public void execute() {
boolean onHeaders = this.ajP.ajG.onHeaders(this.val$streamId, this.val$requestHeaders, this.val$inFinished);
if (onHeaders) {
try {
this.ajP.ajM.rstStream(this.val$streamId, ErrorCode.CANCEL);
} catch (IOException unused) {
return;
}
}
if (!onHeaders && !this.val$inFinished) {
return;
}
synchronized (this.ajP) {
this.ajP.currentPushRequests.remove(Integer.valueOf(this.val$streamId));
}
}
});
}
/* JADX INFO: Access modifiers changed from: private */
public void a(int i, InterfaceC15142giR interfaceC15142giR, int i2, boolean z) throws IOException {
giM gim = new giM();
long j = i2;
interfaceC15142giR.j(j);
interfaceC15142giR.read(gim, j);
if (gim.a != j) {
StringBuilder sb = new StringBuilder();
sb.append(gim.a);
sb.append(" != ");
sb.append(i2);
throw new IOException(sb.toString());
}
this.ajE.execute(new NamedRunnable(this, "OkHttp %s Push Data[%s]", new Object[]{this.hostname, Integer.valueOf(i)}, i, gim, i2, z) { // from class: okhttp3.repackaged.internal.framed.FramedConnection.6
final FramedConnection ajP;
final giM ajU;
final int val$byteCount;
final boolean val$inFinished;
final int val$streamId;
{
this.ajP = this;
this.val$streamId = i;
this.ajU = gim;
this.val$byteCount = i2;
this.val$inFinished = z;
}
@Override // okhttp3.repackaged.internal.NamedRunnable
public void execute() {
try {
boolean onData = this.ajP.ajG.onData(this.val$streamId, this.ajU, this.val$byteCount, this.val$inFinished);
if (onData) {
this.ajP.ajM.rstStream(this.val$streamId, ErrorCode.CANCEL);
}
if (!onData && !this.val$inFinished) {
return;
}
synchronized (this.ajP) {
this.ajP.currentPushRequests.remove(Integer.valueOf(this.val$streamId));
}
} catch (IOException unused) {
}
}
});
}
/* JADX INFO: Access modifiers changed from: private */
public void c(int i, ErrorCode errorCode) {
this.ajE.execute(new NamedRunnable(this, "OkHttp %s Push Reset[%s]", new Object[]{this.hostname, Integer.valueOf(i)}, i, errorCode) { // from class: okhttp3.repackaged.internal.framed.FramedConnection.7
final ErrorCode ajO;
final FramedConnection ajP;
final int val$streamId;
{
this.ajP = this;
this.val$streamId = i;
this.ajO = errorCode;
}
@Override // okhttp3.repackaged.internal.NamedRunnable
public void execute() {
this.ajP.ajG.onReset(this.val$streamId, this.ajO);
synchronized (this.ajP) {
this.ajP.currentPushRequests.remove(Integer.valueOf(this.val$streamId));
}
}
});
}
public final Protocol getProtocol() {
return this.protocol;
}
}