Files
rr3-apk/decompiled-community/sources/okhttp3/internal/http2/Http2Connection.java
Daniel Elliott c080f0d97f Add Discord community version (64-bit only)
- Added realracing3-community.apk (71.57 MB)
- Removed 32-bit support (armeabi-v7a)
- Only includes arm64-v8a libraries
- Decompiled source code included
- Added README-community.md with analysis
2026-02-18 15:48:36 -08:00

947 lines
40 KiB
Java

package okhttp3.internal.http2;
import androidx.core.internal.view.SupportMenu;
import com.mbridge.msdk.playercommon.exoplayer2.C;
import java.io.Closeable;
import java.io.IOException;
import java.net.Socket;
import java.util.LinkedHashMap;
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.RejectedExecutionException;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import okhttp3.internal.NamedRunnable;
import okhttp3.internal.Util;
import okhttp3.internal.http2.Http2Reader;
import okhttp3.internal.platform.Platform;
import okio.Buffer;
import okio.BufferedSink;
import okio.BufferedSource;
import okio.ByteString;
/* loaded from: classes5.dex */
public final class Http2Connection implements Closeable {
public static final ExecutorService listenerExecutor = new ThreadPoolExecutor(0, Integer.MAX_VALUE, 60, TimeUnit.SECONDS, new SynchronousQueue(), Util.threadFactory("OkHttp Http2Connection", true));
public long bytesLeftInWriteWindow;
public final boolean client;
public final String connectionName;
public final Set currentPushRequests;
public int lastGoodStreamId;
public final Listener listener;
public int nextStreamId;
public final Settings peerSettings;
public final ExecutorService pushExecutor;
public final PushObserver pushObserver;
public final ReaderRunnable readerRunnable;
public boolean shutdown;
public final Socket socket;
public final Http2Writer writer;
public final ScheduledExecutorService writerExecutor;
public final Map streams = new LinkedHashMap();
public long intervalPingsSent = 0;
public long intervalPongsReceived = 0;
public long degradedPingsSent = 0;
public long degradedPongsReceived = 0;
public long awaitPingsSent = 0;
public long awaitPongsReceived = 0;
public long degradedPongDeadlineNs = 0;
public long unacknowledgedBytesRead = 0;
public Settings okHttpSettings = new Settings();
public static abstract class Listener {
public static final Listener REFUSE_INCOMING_STREAMS = new Listener() { // from class: okhttp3.internal.http2.Http2Connection.Listener.1
@Override // okhttp3.internal.http2.Http2Connection.Listener
public void onStream(Http2Stream http2Stream) {
http2Stream.close(ErrorCode.REFUSED_STREAM, null);
}
};
public void onSettings(Http2Connection http2Connection) {
}
public abstract void onStream(Http2Stream http2Stream);
}
public boolean pushedStream(int i) {
return i != 0 && (i & 1) == 0;
}
public static /* synthetic */ long access$108(Http2Connection http2Connection) {
long j = http2Connection.intervalPongsReceived;
http2Connection.intervalPongsReceived = 1 + j;
return j;
}
public static /* synthetic */ long access$208(Http2Connection http2Connection) {
long j = http2Connection.intervalPingsSent;
http2Connection.intervalPingsSent = 1 + j;
return j;
}
public static /* synthetic */ long access$608(Http2Connection http2Connection) {
long j = http2Connection.degradedPongsReceived;
http2Connection.degradedPongsReceived = 1 + j;
return j;
}
public static /* synthetic */ long access$708(Http2Connection http2Connection) {
long j = http2Connection.awaitPongsReceived;
http2Connection.awaitPongsReceived = 1 + j;
return j;
}
public Http2Connection(Builder builder) {
Settings settings = new Settings();
this.peerSettings = settings;
this.currentPushRequests = new LinkedHashSet();
this.pushObserver = builder.pushObserver;
boolean z = builder.client;
this.client = z;
this.listener = builder.listener;
int i = z ? 1 : 2;
this.nextStreamId = i;
if (z) {
this.nextStreamId = i + 2;
}
if (z) {
this.okHttpSettings.set(7, 16777216);
}
String str = builder.connectionName;
this.connectionName = str;
ScheduledThreadPoolExecutor scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(1, Util.threadFactory(Util.format("OkHttp %s Writer", str), false));
this.writerExecutor = scheduledThreadPoolExecutor;
if (builder.pingIntervalMillis != 0) {
IntervalPingRunnable intervalPingRunnable = new IntervalPingRunnable();
int i2 = builder.pingIntervalMillis;
scheduledThreadPoolExecutor.scheduleAtFixedRate(intervalPingRunnable, i2, i2, TimeUnit.MILLISECONDS);
}
this.pushExecutor = new ThreadPoolExecutor(0, 1, 60L, TimeUnit.SECONDS, new LinkedBlockingQueue(), Util.threadFactory(Util.format("OkHttp %s Push Observer", str), true));
settings.set(7, SupportMenu.USER_MASK);
settings.set(5, 16384);
this.bytesLeftInWriteWindow = settings.getInitialWindowSize();
this.socket = builder.socket;
this.writer = new Http2Writer(builder.sink, z);
this.readerRunnable = new ReaderRunnable(new Http2Reader(builder.source, z));
}
public synchronized Http2Stream getStream(int i) {
return (Http2Stream) this.streams.get(Integer.valueOf(i));
}
public synchronized Http2Stream removeStream(int i) {
Http2Stream http2Stream;
http2Stream = (Http2Stream) this.streams.remove(Integer.valueOf(i));
notifyAll();
return http2Stream;
}
public synchronized int maxConcurrentStreams() {
return this.peerSettings.getMaxConcurrentStreams(Integer.MAX_VALUE);
}
public synchronized void updateConnectionFlowControl(long j) {
long j2 = this.unacknowledgedBytesRead + j;
this.unacknowledgedBytesRead = j2;
if (j2 >= this.okHttpSettings.getInitialWindowSize() / 2) {
writeWindowUpdateLater(0, this.unacknowledgedBytesRead);
this.unacknowledgedBytesRead = 0L;
}
}
public Http2Stream newStream(List list, boolean z) {
return newStream(0, list, z);
}
/* JADX WARN: Removed duplicated region for block: B:21:0x0044 A[Catch: all -> 0x0014, TryCatch #0 {all -> 0x0014, blocks: (B:6:0x0007, B:8:0x000e, B:9:0x0016, B:11:0x001a, B:13:0x002c, B:15:0x0034, B:19:0x003e, B:21:0x0044, B:22:0x004d, B:36:0x0072, B:37:0x0077), top: B:5:0x0007, outer: #1 }] */
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct add '--show-bad-code' argument
*/
public final okhttp3.internal.http2.Http2Stream newStream(int r11, java.util.List r12, boolean r13) {
/*
r10 = this;
r6 = r13 ^ 1
r4 = 0
okhttp3.internal.http2.Http2Writer r7 = r10.writer
monitor-enter(r7)
monitor-enter(r10) // Catch: java.lang.Throwable -> L56
int r0 = r10.nextStreamId // Catch: java.lang.Throwable -> L14
r1 = 1073741823(0x3fffffff, float:1.9999999)
if (r0 <= r1) goto L16
okhttp3.internal.http2.ErrorCode r0 = okhttp3.internal.http2.ErrorCode.REFUSED_STREAM // Catch: java.lang.Throwable -> L14
r10.shutdown(r0) // Catch: java.lang.Throwable -> L14
goto L16
L14:
r11 = move-exception
goto L78
L16:
boolean r0 = r10.shutdown // Catch: java.lang.Throwable -> L14
if (r0 != 0) goto L72
int r8 = r10.nextStreamId // Catch: java.lang.Throwable -> L14
int r0 = r8 + 2
r10.nextStreamId = r0 // Catch: java.lang.Throwable -> L14
okhttp3.internal.http2.Http2Stream r9 = new okhttp3.internal.http2.Http2Stream // Catch: java.lang.Throwable -> L14
r5 = 0
r0 = r9
r1 = r8
r2 = r10
r3 = r6
r0.<init>(r1, r2, r3, r4, r5) // Catch: java.lang.Throwable -> L14
if (r13 == 0) goto L3d
long r0 = r10.bytesLeftInWriteWindow // Catch: java.lang.Throwable -> L14
r2 = 0
int r13 = (r0 > r2 ? 1 : (r0 == r2 ? 0 : -1))
if (r13 == 0) goto L3d
long r0 = r9.bytesLeftInWriteWindow // Catch: java.lang.Throwable -> L14
int r13 = (r0 > r2 ? 1 : (r0 == r2 ? 0 : -1))
if (r13 != 0) goto L3b
goto L3d
L3b:
r13 = 0
goto L3e
L3d:
r13 = 1
L3e:
boolean r0 = r9.isOpen() // Catch: java.lang.Throwable -> L14
if (r0 == 0) goto L4d
java.util.Map r0 = r10.streams // Catch: java.lang.Throwable -> L14
java.lang.Integer r1 = java.lang.Integer.valueOf(r8) // Catch: java.lang.Throwable -> L14
r0.put(r1, r9) // Catch: java.lang.Throwable -> L14
L4d:
monitor-exit(r10) // Catch: java.lang.Throwable -> L14
if (r11 != 0) goto L58
okhttp3.internal.http2.Http2Writer r11 = r10.writer // Catch: java.lang.Throwable -> L56
r11.headers(r6, r8, r12) // Catch: java.lang.Throwable -> L56
goto L61
L56:
r11 = move-exception
goto L7a
L58:
boolean r0 = r10.client // Catch: java.lang.Throwable -> L56
if (r0 != 0) goto L6a
okhttp3.internal.http2.Http2Writer r0 = r10.writer // Catch: java.lang.Throwable -> L56
r0.pushPromise(r11, r8, r12) // Catch: java.lang.Throwable -> L56
L61:
monitor-exit(r7) // Catch: java.lang.Throwable -> L56
if (r13 == 0) goto L69
okhttp3.internal.http2.Http2Writer r11 = r10.writer
r11.flush()
L69:
return r9
L6a:
java.lang.IllegalArgumentException r11 = new java.lang.IllegalArgumentException // Catch: java.lang.Throwable -> L56
java.lang.String r12 = "client streams shouldn't have associated stream IDs"
r11.<init>(r12) // Catch: java.lang.Throwable -> L56
throw r11 // Catch: java.lang.Throwable -> L56
L72:
okhttp3.internal.http2.ConnectionShutdownException r11 = new okhttp3.internal.http2.ConnectionShutdownException // Catch: java.lang.Throwable -> L14
r11.<init>() // Catch: java.lang.Throwable -> L14
throw r11 // Catch: java.lang.Throwable -> L14
L78:
monitor-exit(r10) // Catch: java.lang.Throwable -> L14
throw r11 // Catch: java.lang.Throwable -> L56
L7a:
monitor-exit(r7) // Catch: java.lang.Throwable -> L56
throw r11
*/
throw new UnsupportedOperationException("Method not decompiled: okhttp3.internal.http2.Http2Connection.newStream(int, java.util.List, boolean):okhttp3.internal.http2.Http2Stream");
}
public void writeHeaders(int i, boolean z, List list) {
this.writer.headers(z, i, list);
}
/* JADX WARN: Code restructure failed: missing block: B:20:0x0032, code lost:
r2 = java.lang.Math.min((int) java.lang.Math.min(r12, r4), r8.writer.maxDataLength());
r6 = r2;
r8.bytesLeftInWriteWindow -= r6;
*/
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct add '--show-bad-code' argument
*/
public void writeData(int r9, boolean r10, okio.Buffer r11, long r12) {
/*
r8 = this;
r0 = 0
int r2 = (r12 > r0 ? 1 : (r12 == r0 ? 0 : -1))
r3 = 0
if (r2 != 0) goto Ld
okhttp3.internal.http2.Http2Writer r12 = r8.writer
r12.data(r10, r9, r11, r3)
return
Ld:
int r2 = (r12 > r0 ? 1 : (r12 == r0 ? 0 : -1))
if (r2 <= 0) goto L67
monitor-enter(r8)
L12:
long r4 = r8.bytesLeftInWriteWindow // Catch: java.lang.Throwable -> L28 java.lang.InterruptedException -> L58
int r2 = (r4 > r0 ? 1 : (r4 == r0 ? 0 : -1))
if (r2 > 0) goto L32
java.util.Map r2 = r8.streams // Catch: java.lang.Throwable -> L28 java.lang.InterruptedException -> L58
java.lang.Integer r4 = java.lang.Integer.valueOf(r9) // Catch: java.lang.Throwable -> L28 java.lang.InterruptedException -> L58
boolean r2 = r2.containsKey(r4) // Catch: java.lang.Throwable -> L28 java.lang.InterruptedException -> L58
if (r2 == 0) goto L2a
r8.wait() // Catch: java.lang.Throwable -> L28 java.lang.InterruptedException -> L58
goto L12
L28:
r9 = move-exception
goto L65
L2a:
java.io.IOException r9 = new java.io.IOException // Catch: java.lang.Throwable -> L28 java.lang.InterruptedException -> L58
java.lang.String r10 = "stream closed"
r9.<init>(r10) // Catch: java.lang.Throwable -> L28 java.lang.InterruptedException -> L58
throw r9 // Catch: java.lang.Throwable -> L28 java.lang.InterruptedException -> L58
L32:
long r4 = java.lang.Math.min(r12, r4) // Catch: java.lang.Throwable -> L28
int r2 = (int) r4 // Catch: java.lang.Throwable -> L28
okhttp3.internal.http2.Http2Writer r4 = r8.writer // Catch: java.lang.Throwable -> L28
int r4 = r4.maxDataLength() // Catch: java.lang.Throwable -> L28
int r2 = java.lang.Math.min(r2, r4) // Catch: java.lang.Throwable -> L28
long r4 = r8.bytesLeftInWriteWindow // Catch: java.lang.Throwable -> L28
long r6 = (long) r2 // Catch: java.lang.Throwable -> L28
long r4 = r4 - r6
r8.bytesLeftInWriteWindow = r4 // Catch: java.lang.Throwable -> L28
monitor-exit(r8) // Catch: java.lang.Throwable -> L28
long r12 = r12 - r6
okhttp3.internal.http2.Http2Writer r4 = r8.writer
if (r10 == 0) goto L53
int r5 = (r12 > r0 ? 1 : (r12 == r0 ? 0 : -1))
if (r5 != 0) goto L53
r5 = 1
goto L54
L53:
r5 = r3
L54:
r4.data(r5, r9, r11, r2)
goto Ld
L58:
java.lang.Thread r9 = java.lang.Thread.currentThread() // Catch: java.lang.Throwable -> L28
r9.interrupt() // Catch: java.lang.Throwable -> L28
java.io.InterruptedIOException r9 = new java.io.InterruptedIOException // Catch: java.lang.Throwable -> L28
r9.<init>() // Catch: java.lang.Throwable -> L28
throw r9 // Catch: java.lang.Throwable -> L28
L65:
monitor-exit(r8) // Catch: java.lang.Throwable -> L28
throw r9
L67:
return
*/
throw new UnsupportedOperationException("Method not decompiled: okhttp3.internal.http2.Http2Connection.writeData(int, boolean, okio.Buffer, long):void");
}
public void writeSynResetLater(final int i, final ErrorCode errorCode) {
try {
this.writerExecutor.execute(new NamedRunnable("OkHttp %s stream %d", new Object[]{this.connectionName, Integer.valueOf(i)}) { // from class: okhttp3.internal.http2.Http2Connection.1
@Override // okhttp3.internal.NamedRunnable
public void execute() {
try {
Http2Connection.this.writeSynReset(i, errorCode);
} catch (IOException e) {
Http2Connection.this.failConnection(e);
}
}
});
} catch (RejectedExecutionException unused) {
}
}
public void writeSynReset(int i, ErrorCode errorCode) {
this.writer.rstStream(i, errorCode);
}
public void writeWindowUpdateLater(final int i, final long j) {
try {
this.writerExecutor.execute(new NamedRunnable("OkHttp Window Update %s stream %d", new Object[]{this.connectionName, Integer.valueOf(i)}) { // from class: okhttp3.internal.http2.Http2Connection.2
@Override // okhttp3.internal.NamedRunnable
public void execute() {
try {
Http2Connection.this.writer.windowUpdate(i, j);
} catch (IOException e) {
Http2Connection.this.failConnection(e);
}
}
});
} catch (RejectedExecutionException unused) {
}
}
public final class PingRunnable extends NamedRunnable {
public final int payload1;
public final int payload2;
public final boolean reply;
public PingRunnable(boolean z, int i, int i2) {
super("OkHttp %s ping %08x%08x", Http2Connection.this.connectionName, Integer.valueOf(i), Integer.valueOf(i2));
this.reply = z;
this.payload1 = i;
this.payload2 = i2;
}
@Override // okhttp3.internal.NamedRunnable
public void execute() {
Http2Connection.this.writePing(this.reply, this.payload1, this.payload2);
}
}
public final class IntervalPingRunnable extends NamedRunnable {
public IntervalPingRunnable() {
super("OkHttp %s ping", Http2Connection.this.connectionName);
}
@Override // okhttp3.internal.NamedRunnable
public void execute() {
boolean z;
synchronized (Http2Connection.this) {
if (Http2Connection.this.intervalPongsReceived < Http2Connection.this.intervalPingsSent) {
z = true;
} else {
Http2Connection.access$208(Http2Connection.this);
z = false;
}
}
if (z) {
Http2Connection.this.failConnection(null);
} else {
Http2Connection.this.writePing(false, 1, 0);
}
}
}
public void writePing(boolean z, int i, int i2) {
try {
this.writer.ping(z, i, i2);
} catch (IOException e) {
failConnection(e);
}
}
public void flush() {
this.writer.flush();
}
public void shutdown(ErrorCode errorCode) {
synchronized (this.writer) {
synchronized (this) {
if (this.shutdown) {
return;
}
this.shutdown = true;
this.writer.goAway(this.lastGoodStreamId, errorCode, Util.EMPTY_BYTE_ARRAY);
}
}
}
@Override // java.io.Closeable, java.lang.AutoCloseable
public void close() {
close(ErrorCode.NO_ERROR, ErrorCode.CANCEL, null);
}
public void close(ErrorCode errorCode, ErrorCode errorCode2, IOException iOException) {
Http2Stream[] http2StreamArr;
try {
shutdown(errorCode);
} catch (IOException unused) {
}
synchronized (this) {
try {
if (this.streams.isEmpty()) {
http2StreamArr = null;
} else {
http2StreamArr = (Http2Stream[]) this.streams.values().toArray(new Http2Stream[this.streams.size()]);
this.streams.clear();
}
} catch (Throwable th) {
throw th;
}
}
if (http2StreamArr != null) {
for (Http2Stream http2Stream : http2StreamArr) {
try {
http2Stream.close(errorCode2, iOException);
} catch (IOException unused2) {
}
}
}
try {
this.writer.close();
} catch (IOException unused3) {
}
try {
this.socket.close();
} catch (IOException unused4) {
}
this.writerExecutor.shutdown();
this.pushExecutor.shutdown();
}
public final void failConnection(IOException iOException) {
ErrorCode errorCode = ErrorCode.PROTOCOL_ERROR;
close(errorCode, errorCode, iOException);
}
public void start() {
start(true);
}
public void start(boolean z) {
if (z) {
this.writer.connectionPreface();
this.writer.settings(this.okHttpSettings);
if (this.okHttpSettings.getInitialWindowSize() != 65535) {
this.writer.windowUpdate(0, r5 - SupportMenu.USER_MASK);
}
}
new Thread(this.readerRunnable).start();
}
public synchronized boolean isHealthy(long j) {
if (this.shutdown) {
return false;
}
if (this.degradedPongsReceived < this.degradedPingsSent) {
if (j >= this.degradedPongDeadlineNs) {
return false;
}
}
return true;
}
public void sendDegradedPingLater() {
synchronized (this) {
try {
long j = this.degradedPongsReceived;
long j2 = this.degradedPingsSent;
if (j < j2) {
return;
}
this.degradedPingsSent = j2 + 1;
this.degradedPongDeadlineNs = System.nanoTime() + C.NANOS_PER_SECOND;
try {
this.writerExecutor.execute(new NamedRunnable("OkHttp %s ping", this.connectionName) { // from class: okhttp3.internal.http2.Http2Connection.3
@Override // okhttp3.internal.NamedRunnable
public void execute() {
Http2Connection.this.writePing(false, 2, 0);
}
});
} catch (RejectedExecutionException unused) {
}
} catch (Throwable th) {
throw th;
}
}
}
public static class Builder {
public boolean client;
public String connectionName;
public int pingIntervalMillis;
public BufferedSink sink;
public Socket socket;
public BufferedSource source;
public Listener listener = Listener.REFUSE_INCOMING_STREAMS;
public PushObserver pushObserver = PushObserver.CANCEL;
public Builder listener(Listener listener) {
this.listener = listener;
return this;
}
public Builder pingIntervalMillis(int i) {
this.pingIntervalMillis = i;
return this;
}
public Builder socket(Socket socket, String str, BufferedSource bufferedSource, BufferedSink bufferedSink) {
this.socket = socket;
this.connectionName = str;
this.source = bufferedSource;
this.sink = bufferedSink;
return this;
}
public Builder(boolean z) {
this.client = z;
}
public Http2Connection build() {
return new Http2Connection(this);
}
}
public class ReaderRunnable extends NamedRunnable implements Http2Reader.Handler {
public final Http2Reader reader;
@Override // okhttp3.internal.http2.Http2Reader.Handler
public void ackSettings() {
}
@Override // okhttp3.internal.http2.Http2Reader.Handler
public void priority(int i, int i2, int i3, boolean z) {
}
public ReaderRunnable(Http2Reader http2Reader) {
super("OkHttp %s", Http2Connection.this.connectionName);
this.reader = http2Reader;
}
/* JADX WARN: Multi-variable type inference failed */
/* JADX WARN: Type inference failed for: r0v0, types: [okhttp3.internal.http2.ErrorCode] */
/* JADX WARN: Type inference failed for: r0v3 */
/* JADX WARN: Type inference failed for: r0v5, types: [java.io.Closeable, okhttp3.internal.http2.Http2Reader] */
@Override // okhttp3.internal.NamedRunnable
public void execute() {
ErrorCode errorCode;
ErrorCode errorCode2 = ErrorCode.INTERNAL_ERROR;
IOException e = null;
try {
try {
this.reader.readConnectionPreface(this);
while (this.reader.nextFrame(false, this)) {
}
ErrorCode errorCode3 = ErrorCode.NO_ERROR;
try {
Http2Connection.this.close(errorCode3, ErrorCode.CANCEL, null);
errorCode = errorCode3;
} catch (IOException e2) {
e = e2;
ErrorCode errorCode4 = ErrorCode.PROTOCOL_ERROR;
Http2Connection http2Connection = Http2Connection.this;
http2Connection.close(errorCode4, errorCode4, e);
errorCode = http2Connection;
errorCode2 = this.reader;
Util.closeQuietly((Closeable) errorCode2);
}
} catch (Throwable th) {
th = th;
Http2Connection.this.close(errorCode, errorCode2, e);
Util.closeQuietly(this.reader);
throw th;
}
} catch (IOException e3) {
e = e3;
} catch (Throwable th2) {
th = th2;
errorCode = errorCode2;
Http2Connection.this.close(errorCode, errorCode2, e);
Util.closeQuietly(this.reader);
throw th;
}
errorCode2 = this.reader;
Util.closeQuietly((Closeable) errorCode2);
}
@Override // okhttp3.internal.http2.Http2Reader.Handler
public void data(boolean z, int i, BufferedSource bufferedSource, int i2) {
if (Http2Connection.this.pushedStream(i)) {
Http2Connection.this.pushDataLater(i, bufferedSource, i2, z);
return;
}
Http2Stream stream = Http2Connection.this.getStream(i);
if (stream == null) {
Http2Connection.this.writeSynResetLater(i, ErrorCode.PROTOCOL_ERROR);
long j = i2;
Http2Connection.this.updateConnectionFlowControl(j);
bufferedSource.skip(j);
return;
}
stream.receiveData(bufferedSource, i2);
if (z) {
stream.receiveHeaders(Util.EMPTY_HEADERS, true);
}
}
@Override // okhttp3.internal.http2.Http2Reader.Handler
public void headers(boolean z, int i, int i2, List list) {
if (Http2Connection.this.pushedStream(i)) {
Http2Connection.this.pushHeadersLater(i, list, z);
return;
}
synchronized (Http2Connection.this) {
try {
Http2Stream stream = Http2Connection.this.getStream(i);
if (stream == null) {
if (Http2Connection.this.shutdown) {
return;
}
Http2Connection http2Connection = Http2Connection.this;
if (i <= http2Connection.lastGoodStreamId) {
return;
}
if (i % 2 == http2Connection.nextStreamId % 2) {
return;
}
final Http2Stream http2Stream = new Http2Stream(i, Http2Connection.this, false, z, Util.toHeaders(list));
Http2Connection http2Connection2 = Http2Connection.this;
http2Connection2.lastGoodStreamId = i;
http2Connection2.streams.put(Integer.valueOf(i), http2Stream);
Http2Connection.listenerExecutor.execute(new NamedRunnable("OkHttp %s stream %d", new Object[]{Http2Connection.this.connectionName, Integer.valueOf(i)}) { // from class: okhttp3.internal.http2.Http2Connection.ReaderRunnable.1
@Override // okhttp3.internal.NamedRunnable
public void execute() {
try {
Http2Connection.this.listener.onStream(http2Stream);
} catch (IOException e) {
Platform.get().log(4, "Http2Connection.Listener failure for " + Http2Connection.this.connectionName, e);
try {
http2Stream.close(ErrorCode.PROTOCOL_ERROR, e);
} catch (IOException unused) {
}
}
}
});
return;
}
stream.receiveHeaders(Util.toHeaders(list), z);
} catch (Throwable th) {
throw th;
}
}
}
@Override // okhttp3.internal.http2.Http2Reader.Handler
public void rstStream(int i, ErrorCode errorCode) {
if (Http2Connection.this.pushedStream(i)) {
Http2Connection.this.pushResetLater(i, errorCode);
return;
}
Http2Stream removeStream = Http2Connection.this.removeStream(i);
if (removeStream != null) {
removeStream.receiveRstStream(errorCode);
}
}
@Override // okhttp3.internal.http2.Http2Reader.Handler
public void settings(final boolean z, final Settings settings) {
try {
Http2Connection.this.writerExecutor.execute(new NamedRunnable("OkHttp %s ACK Settings", new Object[]{Http2Connection.this.connectionName}) { // from class: okhttp3.internal.http2.Http2Connection.ReaderRunnable.2
@Override // okhttp3.internal.NamedRunnable
public void execute() {
ReaderRunnable.this.applyAndAckSettings(z, settings);
}
});
} catch (RejectedExecutionException unused) {
}
}
public void applyAndAckSettings(boolean z, Settings settings) {
Http2Stream[] http2StreamArr;
long j;
synchronized (Http2Connection.this.writer) {
synchronized (Http2Connection.this) {
try {
int initialWindowSize = Http2Connection.this.peerSettings.getInitialWindowSize();
if (z) {
Http2Connection.this.peerSettings.clear();
}
Http2Connection.this.peerSettings.merge(settings);
int initialWindowSize2 = Http2Connection.this.peerSettings.getInitialWindowSize();
http2StreamArr = null;
if (initialWindowSize2 == -1 || initialWindowSize2 == initialWindowSize) {
j = 0;
} else {
j = initialWindowSize2 - initialWindowSize;
if (!Http2Connection.this.streams.isEmpty()) {
http2StreamArr = (Http2Stream[]) Http2Connection.this.streams.values().toArray(new Http2Stream[Http2Connection.this.streams.size()]);
}
}
} finally {
}
}
try {
Http2Connection http2Connection = Http2Connection.this;
http2Connection.writer.applyAndAckSettings(http2Connection.peerSettings);
} catch (IOException e) {
Http2Connection.this.failConnection(e);
}
}
if (http2StreamArr != null) {
for (Http2Stream http2Stream : http2StreamArr) {
synchronized (http2Stream) {
http2Stream.addBytesToWriteWindow(j);
}
}
}
Http2Connection.listenerExecutor.execute(new NamedRunnable("OkHttp %s settings", Http2Connection.this.connectionName) { // from class: okhttp3.internal.http2.Http2Connection.ReaderRunnable.3
@Override // okhttp3.internal.NamedRunnable
public void execute() {
Http2Connection http2Connection2 = Http2Connection.this;
http2Connection2.listener.onSettings(http2Connection2);
}
});
}
@Override // okhttp3.internal.http2.Http2Reader.Handler
public void ping(boolean z, int i, int i2) {
if (!z) {
try {
Http2Connection.this.writerExecutor.execute(Http2Connection.this.new PingRunnable(true, i, i2));
return;
} catch (RejectedExecutionException unused) {
return;
}
}
synchronized (Http2Connection.this) {
try {
if (i == 1) {
Http2Connection.access$108(Http2Connection.this);
} else if (i == 2) {
Http2Connection.access$608(Http2Connection.this);
} else if (i == 3) {
Http2Connection.access$708(Http2Connection.this);
Http2Connection.this.notifyAll();
}
} finally {
}
}
}
@Override // okhttp3.internal.http2.Http2Reader.Handler
public void goAway(int i, ErrorCode errorCode, ByteString byteString) {
Http2Stream[] http2StreamArr;
byteString.size();
synchronized (Http2Connection.this) {
http2StreamArr = (Http2Stream[]) Http2Connection.this.streams.values().toArray(new Http2Stream[Http2Connection.this.streams.size()]);
Http2Connection.this.shutdown = true;
}
for (Http2Stream http2Stream : http2StreamArr) {
if (http2Stream.getId() > i && http2Stream.isLocallyInitiated()) {
http2Stream.receiveRstStream(ErrorCode.REFUSED_STREAM);
Http2Connection.this.removeStream(http2Stream.getId());
}
}
}
@Override // okhttp3.internal.http2.Http2Reader.Handler
public void windowUpdate(int i, long j) {
if (i == 0) {
synchronized (Http2Connection.this) {
Http2Connection http2Connection = Http2Connection.this;
http2Connection.bytesLeftInWriteWindow += j;
http2Connection.notifyAll();
}
return;
}
Http2Stream stream = Http2Connection.this.getStream(i);
if (stream != null) {
synchronized (stream) {
stream.addBytesToWriteWindow(j);
}
}
}
@Override // okhttp3.internal.http2.Http2Reader.Handler
public void pushPromise(int i, int i2, List list) {
Http2Connection.this.pushRequestLater(i2, list);
}
}
public void pushRequestLater(final int i, final List list) {
synchronized (this) {
try {
if (this.currentPushRequests.contains(Integer.valueOf(i))) {
writeSynResetLater(i, ErrorCode.PROTOCOL_ERROR);
return;
}
this.currentPushRequests.add(Integer.valueOf(i));
try {
pushExecutorExecute(new NamedRunnable("OkHttp %s Push Request[%s]", new Object[]{this.connectionName, Integer.valueOf(i)}) { // from class: okhttp3.internal.http2.Http2Connection.4
@Override // okhttp3.internal.NamedRunnable
public void execute() {
if (Http2Connection.this.pushObserver.onRequest(i, list)) {
try {
Http2Connection.this.writer.rstStream(i, ErrorCode.CANCEL);
synchronized (Http2Connection.this) {
Http2Connection.this.currentPushRequests.remove(Integer.valueOf(i));
}
} catch (IOException unused) {
}
}
}
});
} catch (RejectedExecutionException unused) {
}
} catch (Throwable th) {
throw th;
}
}
}
public void pushHeadersLater(final int i, final List list, final boolean z) {
try {
pushExecutorExecute(new NamedRunnable("OkHttp %s Push Headers[%s]", new Object[]{this.connectionName, Integer.valueOf(i)}) { // from class: okhttp3.internal.http2.Http2Connection.5
@Override // okhttp3.internal.NamedRunnable
public void execute() {
boolean onHeaders = Http2Connection.this.pushObserver.onHeaders(i, list, z);
if (onHeaders) {
try {
Http2Connection.this.writer.rstStream(i, ErrorCode.CANCEL);
} catch (IOException unused) {
return;
}
}
if (onHeaders || z) {
synchronized (Http2Connection.this) {
Http2Connection.this.currentPushRequests.remove(Integer.valueOf(i));
}
}
}
});
} catch (RejectedExecutionException unused) {
}
}
public void pushDataLater(final int i, BufferedSource bufferedSource, final int i2, final boolean z) {
final Buffer buffer = new Buffer();
long j = i2;
bufferedSource.require(j);
bufferedSource.read(buffer, j);
if (buffer.size() != j) {
throw new IOException(buffer.size() + " != " + i2);
}
pushExecutorExecute(new NamedRunnable("OkHttp %s Push Data[%s]", new Object[]{this.connectionName, Integer.valueOf(i)}) { // from class: okhttp3.internal.http2.Http2Connection.6
@Override // okhttp3.internal.NamedRunnable
public void execute() {
try {
boolean onData = Http2Connection.this.pushObserver.onData(i, buffer, i2, z);
if (onData) {
Http2Connection.this.writer.rstStream(i, ErrorCode.CANCEL);
}
if (onData || z) {
synchronized (Http2Connection.this) {
Http2Connection.this.currentPushRequests.remove(Integer.valueOf(i));
}
}
} catch (IOException unused) {
}
}
});
}
public void pushResetLater(final int i, final ErrorCode errorCode) {
pushExecutorExecute(new NamedRunnable("OkHttp %s Push Reset[%s]", new Object[]{this.connectionName, Integer.valueOf(i)}) { // from class: okhttp3.internal.http2.Http2Connection.7
@Override // okhttp3.internal.NamedRunnable
public void execute() {
Http2Connection.this.pushObserver.onReset(i, errorCode);
synchronized (Http2Connection.this) {
Http2Connection.this.currentPushRequests.remove(Integer.valueOf(i));
}
}
});
}
public final synchronized void pushExecutorExecute(NamedRunnable namedRunnable) {
if (!this.shutdown) {
this.pushExecutor.execute(namedRunnable);
}
}
}