package com.mbridge.msdk.thrid.okhttp.internal.http2; import com.mbridge.msdk.thrid.okhttp.Protocol; import com.mbridge.msdk.thrid.okhttp.internal.NamedRunnable; import com.mbridge.msdk.thrid.okhttp.internal.Util; import com.mbridge.msdk.thrid.okhttp.internal.http2.Http2Reader; import com.mbridge.msdk.thrid.okhttp.internal.platform.Platform; import com.mbridge.msdk.thrid.okio.Buffer; import com.mbridge.msdk.thrid.okio.BufferedSink; import com.mbridge.msdk.thrid.okio.BufferedSource; import com.mbridge.msdk.thrid.okio.ByteString; import com.mbridge.msdk.thrid.okio.Okio; import java.io.Closeable; import java.io.IOException; import java.io.InterruptedIOException; import java.net.InetSocketAddress; 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; public final class Http2Connection implements Closeable { static final /* synthetic */ boolean $assertionsDisabled = false; static final int AWAIT_PING = 3; static final int DEGRADED_PING = 2; static final long DEGRADED_PONG_TIMEOUT_NS = 1000000000; static final int INTERVAL_PING = 1; static final int OKHTTP_CLIENT_WINDOW_SIZE = 16777216; private static final ExecutorService listenerExecutor = new ThreadPoolExecutor(0, Integer.MAX_VALUE, 60, TimeUnit.SECONDS, new SynchronousQueue(), Util.threadFactory("OkHttp Http2Connection", true)); private long awaitPingsSent = 0; private long awaitPongsReceived = 0; long bytesLeftInWriteWindow; final boolean client; final Set<Integer> currentPushRequests; private long degradedPingsSent = 0; private long degradedPongDeadlineNs = 0; private long degradedPongsReceived = 0; final String hostname; private long intervalPingsSent = 0; private long intervalPongsReceived = 0; int lastGoodStreamId; final Listener listener; int nextStreamId; Settings okHttpSettings = new Settings(); final Settings peerSettings; private final ExecutorService pushExecutor; final PushObserver pushObserver; final ReaderRunnable readerRunnable; private boolean shutdown; final Socket socket; final Map<Integer, Http2Stream> streams = new LinkedHashMap(); long unacknowledgedBytesRead = 0; final Http2Writer writer; private final ScheduledExecutorService writerExecutor; public static abstract class Listener { public static final Listener REFUSE_INCOMING_STREAMS = new Listener() { /* class com.mbridge.msdk.thrid.okhttp.internal.http2.Http2Connection.Listener.AnonymousClass1 */ @Override // com.mbridge.msdk.thrid.okhttp.internal.http2.Http2Connection.Listener public void onStream(Http2Stream http2Stream) throws IOException { http2Stream.close(ErrorCode.REFUSED_STREAM); } }; public void onSettings(Http2Connection http2Connection) { } public abstract void onStream(Http2Stream http2Stream) throws IOException; } /* access modifiers changed from: package-private */ public boolean pushedStream(int i) { return i != 0 && (i & 1) == 0; } static /* synthetic */ long access$108(Http2Connection http2Connection) { long j = http2Connection.intervalPongsReceived; http2Connection.intervalPongsReceived = 1 + j; return j; } static /* synthetic */ long access$208(Http2Connection http2Connection) { long j = http2Connection.intervalPingsSent; http2Connection.intervalPingsSent = 1 + j; return j; } static /* synthetic */ long access$608(Http2Connection http2Connection) { long j = http2Connection.degradedPongsReceived; http2Connection.degradedPongsReceived = 1 + j; return j; } static /* synthetic */ long access$708(Http2Connection http2Connection) { long j = http2Connection.awaitPongsReceived; http2Connection.awaitPongsReceived = 1 + j; return j; } 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; this.nextStreamId = builder.client ? 1 : 2; if (builder.client) { this.nextStreamId += 2; } if (builder.client) { this.okHttpSettings.set(7, 16777216); } String str = builder.hostname; this.hostname = str; ScheduledThreadPoolExecutor scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(1, Util.threadFactory(Util.format("OkHttp %s Writer", str), false)); this.writerExecutor = scheduledThreadPoolExecutor; if (builder.pingIntervalMillis != 0) { scheduledThreadPoolExecutor.scheduleAtFixedRate(new IntervalPingRunnable(), (long) builder.pingIntervalMillis, (long) builder.pingIntervalMillis, TimeUnit.MILLISECONDS); } this.pushExecutor = new ThreadPoolExecutor(0, 1, 60, TimeUnit.SECONDS, new LinkedBlockingQueue(), Util.threadFactory(Util.format("OkHttp %s Push Observer", str), true)); settings.set(7, 65535); settings.set(5, 16384); this.bytesLeftInWriteWindow = (long) settings.getInitialWindowSize(); this.socket = builder.socket; this.writer = new Http2Writer(builder.sink, z); this.readerRunnable = new ReaderRunnable(new Http2Reader(builder.source, z)); } public Protocol getProtocol() { return Protocol.HTTP_2; } public synchronized int openStreamCount() { return this.streams.size(); } /* access modifiers changed from: package-private */ public synchronized Http2Stream getStream(int i) { return this.streams.get(Integer.valueOf(i)); } /* access modifiers changed from: package-private */ public synchronized Http2Stream removeStream(int i) { Http2Stream remove; remove = this.streams.remove(Integer.valueOf(i)); notifyAll(); return remove; } public synchronized int maxConcurrentStreams() { return this.peerSettings.getMaxConcurrentStreams(Integer.MAX_VALUE); } /* access modifiers changed from: package-private */ public synchronized void updateConnectionFlowControl(long j) { long j2 = this.unacknowledgedBytesRead + j; this.unacknowledgedBytesRead = j2; if (j2 >= ((long) (this.okHttpSettings.getInitialWindowSize() / 2))) { writeWindowUpdateLater(0, this.unacknowledgedBytesRead); this.unacknowledgedBytesRead = 0; } } public Http2Stream pushStream(int i, List<Header> list, boolean z) throws IOException { if (!this.client) { return newStream(i, list, z); } throw new IllegalStateException("Client cannot push requests."); } public Http2Stream newStream(List<Header> list, boolean z) throws IOException { return newStream(0, list, z); } /* JADX WARNING: Removed duplicated region for block: B:21:0x0041 */ private Http2Stream newStream(int i, List<Header> list, boolean z) throws IOException { int i2; Http2Stream http2Stream; boolean z2; boolean z3 = !z; synchronized (this.writer) { synchronized (this) { if (this.nextStreamId > 1073741823) { shutdown(ErrorCode.REFUSED_STREAM); } if (!this.shutdown) { i2 = this.nextStreamId; this.nextStreamId = i2 + 2; http2Stream = new Http2Stream(i2, this, z3, false, null); if (z && this.bytesLeftInWriteWindow != 0) { if (http2Stream.bytesLeftInWriteWindow != 0) { z2 = false; if (http2Stream.isOpen()) { this.streams.put(Integer.valueOf(i2), http2Stream); } } } z2 = true; if (http2Stream.isOpen()) { } } else { throw new ConnectionShutdownException(); } } if (i == 0) { this.writer.synStream(z3, i2, i, list); } else if (!this.client) { this.writer.pushPromise(i, i2, list); } else { throw new IllegalArgumentException("client streams shouldn't have associated stream IDs"); } } if (z2) { this.writer.flush(); } return http2Stream; } /* access modifiers changed from: package-private */ public void writeSynReply(int i, boolean z, List<Header> list) throws IOException { this.writer.synReply(z, i, list); } /* JADX WARNING: Code restructure failed: missing block: B:16:?, code lost: r3 = java.lang.Math.min((int) java.lang.Math.min(r12, r3), r8.writer.maxDataLength()); r6 = (long) r3; r8.bytesLeftInWriteWindow -= r6; */ public void writeData(int i, boolean z, Buffer buffer, long j) throws IOException { int min; long j2; if (j == 0) { this.writer.data(z, i, buffer, 0); return; } while (j > 0) { synchronized (this) { while (true) { try { long j3 = this.bytesLeftInWriteWindow; if (j3 > 0) { break; } else if (this.streams.containsKey(Integer.valueOf(i))) { wait(); } else { throw new IOException("stream closed"); } } catch (InterruptedException unused) { Thread.currentThread().interrupt(); throw new InterruptedIOException(); } } } j -= j2; this.writer.data(z && j == 0, i, buffer, min); } } /* access modifiers changed from: package-private */ public void writeSynResetLater(final int i, final ErrorCode errorCode) { try { this.writerExecutor.execute(new NamedRunnable("OkHttp %s stream %d", new Object[]{this.hostname, Integer.valueOf(i)}) { /* class com.mbridge.msdk.thrid.okhttp.internal.http2.Http2Connection.AnonymousClass1 */ @Override // com.mbridge.msdk.thrid.okhttp.internal.NamedRunnable public void execute() { try { Http2Connection.this.writeSynReset(i, errorCode); } catch (IOException unused) { Http2Connection.this.failConnection(); } } }); } catch (RejectedExecutionException unused) { } } /* access modifiers changed from: package-private */ public void writeSynReset(int i, ErrorCode errorCode) throws IOException { this.writer.rstStream(i, errorCode); } /* access modifiers changed from: package-private */ public void writeWindowUpdateLater(final int i, final long j) { try { this.writerExecutor.execute(new NamedRunnable("OkHttp Window Update %s stream %d", new Object[]{this.hostname, Integer.valueOf(i)}) { /* class com.mbridge.msdk.thrid.okhttp.internal.http2.Http2Connection.AnonymousClass2 */ @Override // com.mbridge.msdk.thrid.okhttp.internal.NamedRunnable public void execute() { try { Http2Connection.this.writer.windowUpdate(i, j); } catch (IOException unused) { Http2Connection.this.failConnection(); } } }); } catch (RejectedExecutionException unused) { } } final class PingRunnable extends NamedRunnable { final int payload1; final int payload2; final boolean reply; PingRunnable(boolean z, int i, int i2) { super("OkHttp %s ping %08x%08x", Http2Connection.this.hostname, Integer.valueOf(i), Integer.valueOf(i2)); this.reply = z; this.payload1 = i; this.payload2 = i2; } @Override // com.mbridge.msdk.thrid.okhttp.internal.NamedRunnable public void execute() { Http2Connection.this.writePing(this.reply, this.payload1, this.payload2); } } final class IntervalPingRunnable extends NamedRunnable { IntervalPingRunnable() { super("OkHttp %s ping", Http2Connection.this.hostname); } @Override // com.mbridge.msdk.thrid.okhttp.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(); } else { Http2Connection.this.writePing(false, 1, 0); } } } /* access modifiers changed from: package-private */ public void writePing(boolean z, int i, int i2) { try { this.writer.ping(z, i, i2); } catch (IOException unused) { failConnection(); } } /* access modifiers changed from: package-private */ public void writePingAndAwaitPong() throws InterruptedException { writePing(); awaitPong(); } /* access modifiers changed from: package-private */ public void writePing() { synchronized (this) { this.awaitPingsSent++; } writePing(false, 3, 1330343787); } /* access modifiers changed from: package-private */ public synchronized void awaitPong() throws InterruptedException { while (this.awaitPongsReceived < this.awaitPingsSent) { wait(); } } public void flush() throws IOException { this.writer.flush(); } public void shutdown(ErrorCode errorCode) throws IOException { synchronized (this.writer) { synchronized (this) { if (!this.shutdown) { this.shutdown = true; this.writer.goAway(this.lastGoodStreamId, errorCode, Util.EMPTY_BYTE_ARRAY); } } } } @Override // java.io.Closeable, java.lang.AutoCloseable public void close() throws IOException { close(ErrorCode.NO_ERROR, ErrorCode.CANCEL); } /* access modifiers changed from: package-private */ public void close(ErrorCode errorCode, ErrorCode errorCode2) throws IOException { IOException e; Http2Stream[] http2StreamArr = null; try { shutdown(errorCode); e = null; } catch (IOException e2) { e = e2; } synchronized (this) { if (!this.streams.isEmpty()) { http2StreamArr = (Http2Stream[]) this.streams.values().toArray(new Http2Stream[this.streams.size()]); this.streams.clear(); } } if (http2StreamArr != null) { for (Http2Stream http2Stream : http2StreamArr) { try { http2Stream.close(errorCode2); } catch (IOException e3) { if (e != null) { e = e3; } } } } try { this.writer.close(); } catch (IOException e4) { if (e == null) { e = e4; } } try { this.socket.close(); } catch (IOException e5) { e = e5; } this.writerExecutor.shutdown(); this.pushExecutor.shutdown(); if (e != null) { throw e; } } /* access modifiers changed from: private */ /* access modifiers changed from: public */ private void failConnection() { try { close(ErrorCode.PROTOCOL_ERROR, ErrorCode.PROTOCOL_ERROR); } catch (IOException unused) { } } public void start() throws IOException { start(true); } /* access modifiers changed from: package-private */ public void start(boolean z) throws IOException { if (z) { this.writer.connectionPreface(); this.writer.settings(this.okHttpSettings); int initialWindowSize = this.okHttpSettings.getInitialWindowSize(); if (initialWindowSize != 65535) { this.writer.windowUpdate(0, (long) (initialWindowSize - 65535)); } } new Thread(this.readerRunnable).start(); } public void setSettings(Settings settings) throws IOException { synchronized (this.writer) { synchronized (this) { if (!this.shutdown) { this.okHttpSettings.merge(settings); } else { throw new ConnectionShutdownException(); } } this.writer.settings(settings); } } public synchronized boolean isHealthy(long j) { if (this.shutdown) { return false; } if (this.degradedPongsReceived >= this.degradedPingsSent || j < this.degradedPongDeadlineNs) { return true; } return false; } /* access modifiers changed from: package-private */ public void sendDegradedPingLater() { synchronized (this) { long j = this.degradedPongsReceived; long j2 = this.degradedPingsSent; if (j >= j2) { this.degradedPingsSent = j2 + 1; this.degradedPongDeadlineNs = System.nanoTime() + 1000000000; try { this.writerExecutor.execute(new NamedRunnable("OkHttp %s ping", this.hostname) { /* class com.mbridge.msdk.thrid.okhttp.internal.http2.Http2Connection.AnonymousClass3 */ @Override // com.mbridge.msdk.thrid.okhttp.internal.NamedRunnable public void execute() { Http2Connection.this.writePing(false, 2, 0); } }); } catch (RejectedExecutionException unused) { } } } } public static class Builder { boolean client; String hostname; Listener listener = Listener.REFUSE_INCOMING_STREAMS; int pingIntervalMillis; PushObserver pushObserver = PushObserver.CANCEL; BufferedSink sink; Socket socket; BufferedSource source; public Builder(boolean z) { this.client = z; } public Builder socket(Socket socket2) throws IOException { return socket(socket2, ((InetSocketAddress) socket2.getRemoteSocketAddress()).getHostName(), Okio.buffer(Okio.source(socket2)), Okio.buffer(Okio.sink(socket2))); } public Builder socket(Socket socket2, String str, BufferedSource bufferedSource, BufferedSink bufferedSink) { this.socket = socket2; this.hostname = str; this.source = bufferedSource; this.sink = bufferedSink; return this; } public Builder listener(Listener listener2) { this.listener = listener2; return this; } public Builder pushObserver(PushObserver pushObserver2) { this.pushObserver = pushObserver2; return this; } public Builder pingIntervalMillis(int i) { this.pingIntervalMillis = i; return this; } public Http2Connection build() { return new Http2Connection(this); } } /* access modifiers changed from: package-private */ public class ReaderRunnable extends NamedRunnable implements Http2Reader.Handler { final Http2Reader reader; @Override // com.mbridge.msdk.thrid.okhttp.internal.http2.Http2Reader.Handler public void ackSettings() { } @Override // com.mbridge.msdk.thrid.okhttp.internal.http2.Http2Reader.Handler public void alternateService(int i, String str, ByteString byteString, String str2, int i2, long j) { } @Override // com.mbridge.msdk.thrid.okhttp.internal.http2.Http2Reader.Handler public void priority(int i, int i2, int i3, boolean z) { } ReaderRunnable(Http2Reader http2Reader) { super("OkHttp %s", Http2Connection.this.hostname); this.reader = http2Reader; } /* access modifiers changed from: protected */ /* JADX WARNING: Code restructure failed: missing block: B:11:?, code lost: r0 = com.mbridge.msdk.thrid.okhttp.internal.http2.ErrorCode.PROTOCOL_ERROR; r1 = com.mbridge.msdk.thrid.okhttp.internal.http2.ErrorCode.PROTOCOL_ERROR; */ /* JADX WARNING: Code restructure failed: missing block: B:12:0x0020, code lost: r2 = r4.this$0; */ /* JADX WARNING: Code restructure failed: missing block: B:18:?, code lost: r4.this$0.close(r0, r1); */ /* JADX WARNING: Code restructure failed: missing block: B:19:0x0030, code lost: com.mbridge.msdk.thrid.okhttp.internal.Util.closeQuietly(r4.reader); */ /* JADX WARNING: Code restructure failed: missing block: B:21:0x0035, code lost: throw r2; */ /* JADX WARNING: Code restructure failed: missing block: B:9:0x001a, code lost: r2 = move-exception; */ /* JADX WARNING: Failed to process nested try/catch */ /* JADX WARNING: Missing exception handler attribute for start block: B:10:0x001c */ @Override // com.mbridge.msdk.thrid.okhttp.internal.NamedRunnable public void execute() { ErrorCode errorCode = ErrorCode.INTERNAL_ERROR; ErrorCode errorCode2 = ErrorCode.INTERNAL_ERROR; this.reader.readConnectionPreface(this); while (this.reader.nextFrame(false, this)) { } errorCode = ErrorCode.NO_ERROR; ErrorCode errorCode3 = ErrorCode.CANCEL; try { Http2Connection http2Connection = Http2Connection.this; http2Connection.close(errorCode, errorCode3); } catch (IOException unused) { } Util.closeQuietly(this.reader); } @Override // com.mbridge.msdk.thrid.okhttp.internal.http2.Http2Reader.Handler public void data(boolean z, int i, BufferedSource bufferedSource, int i2) throws IOException { 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 = (long) i2; Http2Connection.this.updateConnectionFlowControl(j); bufferedSource.skip(j); return; } stream.receiveData(bufferedSource, i2); if (z) { stream.receiveFin(); } } /* JADX WARNING: Code restructure failed: missing block: B:25:0x0076, code lost: r0.receiveHeaders(r13); */ /* JADX WARNING: Code restructure failed: missing block: B:26:0x0079, code lost: if (r10 == false) goto L_?; */ /* JADX WARNING: Code restructure failed: missing block: B:27:0x007b, code lost: r0.receiveFin(); */ /* JADX WARNING: Code restructure failed: missing block: B:31:?, code lost: return; */ /* JADX WARNING: Code restructure failed: missing block: B:32:?, code lost: return; */ @Override // com.mbridge.msdk.thrid.okhttp.internal.http2.Http2Reader.Handler public void headers(boolean z, int i, int i2, List<Header> list) { if (Http2Connection.this.pushedStream(i)) { Http2Connection.this.pushHeadersLater(i, list, z); return; } synchronized (Http2Connection.this) { Http2Stream stream = Http2Connection.this.getStream(i); if (stream == null) { if (!Http2Connection.this.shutdown) { if (i > Http2Connection.this.lastGoodStreamId) { if (i % 2 != Http2Connection.this.nextStreamId % 2) { final Http2Stream http2Stream = new Http2Stream(i, Http2Connection.this, false, z, Util.toHeaders(list)); Http2Connection.this.lastGoodStreamId = i; Http2Connection.this.streams.put(Integer.valueOf(i), http2Stream); Http2Connection.listenerExecutor.execute(new NamedRunnable("OkHttp %s stream %d", new Object[]{Http2Connection.this.hostname, Integer.valueOf(i)}) { /* class com.mbridge.msdk.thrid.okhttp.internal.http2.Http2Connection.ReaderRunnable.AnonymousClass1 */ @Override // com.mbridge.msdk.thrid.okhttp.internal.NamedRunnable public void execute() { try { Http2Connection.this.listener.onStream(http2Stream); } catch (IOException e) { Platform platform = Platform.get(); platform.log(4, "Http2Connection.Listener failure for " + Http2Connection.this.hostname, e); try { http2Stream.close(ErrorCode.PROTOCOL_ERROR); } catch (IOException unused) { } } } }); } } } } } } @Override // com.mbridge.msdk.thrid.okhttp.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 // com.mbridge.msdk.thrid.okhttp.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.hostname}) { /* class com.mbridge.msdk.thrid.okhttp.internal.http2.Http2Connection.ReaderRunnable.AnonymousClass2 */ @Override // com.mbridge.msdk.thrid.okhttp.internal.NamedRunnable public void execute() { ReaderRunnable.this.applyAndAckSettings(z, settings); } }); } catch (RejectedExecutionException unused) { } } /* access modifiers changed from: package-private */ public void applyAndAckSettings(boolean z, Settings settings) { Http2Stream[] http2StreamArr; long j; synchronized (Http2Connection.this.writer) { synchronized (Http2Connection.this) { 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 = (long) (initialWindowSize2 - initialWindowSize); if (!Http2Connection.this.streams.isEmpty()) { http2StreamArr = (Http2Stream[]) Http2Connection.this.streams.values().toArray(new Http2Stream[Http2Connection.this.streams.size()]); } } } try { Http2Connection.this.writer.applyAndAckSettings(Http2Connection.this.peerSettings); } catch (IOException unused) { Http2Connection.this.failConnection(); } } if (http2StreamArr != null) { for (Http2Stream http2Stream : http2StreamArr) { synchronized (http2Stream) { http2Stream.addBytesToWriteWindow(j); } } } Http2Connection.listenerExecutor.execute(new NamedRunnable("OkHttp %s settings", Http2Connection.this.hostname) { /* class com.mbridge.msdk.thrid.okhttp.internal.http2.Http2Connection.ReaderRunnable.AnonymousClass3 */ @Override // com.mbridge.msdk.thrid.okhttp.internal.NamedRunnable public void execute() { Http2Connection.this.listener.onSettings(Http2Connection.this); } }); } @Override // com.mbridge.msdk.thrid.okhttp.internal.http2.Http2Reader.Handler public void ping(boolean z, int i, int i2) { if (z) { synchronized (Http2Connection.this) { if (i == 1) { try { Http2Connection.access$108(Http2Connection.this); } catch (Throwable th) { throw th; } } else if (i == 2) { Http2Connection.access$608(Http2Connection.this); } else if (i == 3) { Http2Connection.access$708(Http2Connection.this); Http2Connection.this.notifyAll(); } } return; } try { Http2Connection.this.writerExecutor.execute(new PingRunnable(true, i, i2)); } catch (RejectedExecutionException unused) { } } @Override // com.mbridge.msdk.thrid.okhttp.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 // com.mbridge.msdk.thrid.okhttp.internal.http2.Http2Reader.Handler public void windowUpdate(int i, long j) { if (i == 0) { synchronized (Http2Connection.this) { Http2Connection.this.bytesLeftInWriteWindow += j; Http2Connection.this.notifyAll(); } return; } Http2Stream stream = Http2Connection.this.getStream(i); if (stream != null) { synchronized (stream) { stream.addBytesToWriteWindow(j); } } } @Override // com.mbridge.msdk.thrid.okhttp.internal.http2.Http2Reader.Handler public void pushPromise(int i, int i2, List<Header> list) { Http2Connection.this.pushRequestLater(i2, list); } } /* access modifiers changed from: package-private */ public void pushRequestLater(final int i, final List<Header> list) { synchronized (this) { 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.hostname, Integer.valueOf(i)}) { /* class com.mbridge.msdk.thrid.okhttp.internal.http2.Http2Connection.AnonymousClass4 */ @Override // com.mbridge.msdk.thrid.okhttp.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) { } } } /* access modifiers changed from: package-private */ public void pushHeadersLater(final int i, final List<Header> list, final boolean z) { try { pushExecutorExecute(new NamedRunnable("OkHttp %s Push Headers[%s]", new Object[]{this.hostname, Integer.valueOf(i)}) { /* class com.mbridge.msdk.thrid.okhttp.internal.http2.Http2Connection.AnonymousClass5 */ @Override // com.mbridge.msdk.thrid.okhttp.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) { } } /* access modifiers changed from: package-private */ public void pushDataLater(final int i, BufferedSource bufferedSource, final int i2, final boolean z) throws IOException { final Buffer buffer = new Buffer(); long j = (long) i2; bufferedSource.require(j); bufferedSource.read(buffer, j); if (buffer.size() == j) { pushExecutorExecute(new NamedRunnable("OkHttp %s Push Data[%s]", new Object[]{this.hostname, Integer.valueOf(i)}) { /* class com.mbridge.msdk.thrid.okhttp.internal.http2.Http2Connection.AnonymousClass6 */ @Override // com.mbridge.msdk.thrid.okhttp.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) { } } }); return; } throw new IOException(buffer.size() + " != " + i2); } /* access modifiers changed from: package-private */ public void pushResetLater(final int i, final ErrorCode errorCode) { pushExecutorExecute(new NamedRunnable("OkHttp %s Push Reset[%s]", new Object[]{this.hostname, Integer.valueOf(i)}) { /* class com.mbridge.msdk.thrid.okhttp.internal.http2.Http2Connection.AnonymousClass7 */ @Override // com.mbridge.msdk.thrid.okhttp.internal.NamedRunnable public void execute() { Http2Connection.this.pushObserver.onReset(i, errorCode); synchronized (Http2Connection.this) { Http2Connection.this.currentPushRequests.remove(Integer.valueOf(i)); } } }); } private synchronized void pushExecutorExecute(NamedRunnable namedRunnable) { if (!this.shutdown) { this.pushExecutor.execute(namedRunnable); } } }