Add decompiled APK source code (JADX)

- 28,932 files
- Full Java source code
- Smali files
- Resources

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
2026-02-18 14:52:23 -08:00
parent cc210a65ea
commit f9d20bb3fc
26991 changed files with 2541449 additions and 0 deletions

View File

@@ -0,0 +1,7 @@
package okhttp3.internal.http2;
import java.io.IOException;
/* loaded from: classes5.dex */
public final class ConnectionShutdownException extends IOException {
}

View File

@@ -0,0 +1,31 @@
package okhttp3.internal.http2;
/* loaded from: classes5.dex */
public enum ErrorCode {
NO_ERROR(0),
PROTOCOL_ERROR(1),
INTERNAL_ERROR(2),
FLOW_CONTROL_ERROR(3),
REFUSED_STREAM(7),
CANCEL(8),
COMPRESSION_ERROR(9),
CONNECT_ERROR(10),
ENHANCE_YOUR_CALM(11),
INADEQUATE_SECURITY(12),
HTTP_1_1_REQUIRED(13);
public final int httpCode;
ErrorCode(int i) {
this.httpCode = i;
}
public static ErrorCode fromHttp2(int i) {
for (ErrorCode errorCode : values()) {
if (errorCode.httpCode == i) {
return errorCode;
}
}
return null;
}
}

View File

@@ -0,0 +1,49 @@
package okhttp3.internal.http2;
import com.facebook.internal.security.CertificateUtil;
import com.ironsource.mediationsdk.logger.IronSourceError;
import okhttp3.internal.Util;
import okio.ByteString;
/* loaded from: classes5.dex */
public final class Header {
public final int hpackSize;
public final ByteString name;
public final ByteString value;
public static final ByteString PSEUDO_PREFIX = ByteString.encodeUtf8(CertificateUtil.DELIMITER);
public static final ByteString RESPONSE_STATUS = ByteString.encodeUtf8(com.mbridge.msdk.thrid.okhttp.internal.http2.Header.RESPONSE_STATUS_UTF8);
public static final ByteString TARGET_METHOD = ByteString.encodeUtf8(com.mbridge.msdk.thrid.okhttp.internal.http2.Header.TARGET_METHOD_UTF8);
public static final ByteString TARGET_PATH = ByteString.encodeUtf8(com.mbridge.msdk.thrid.okhttp.internal.http2.Header.TARGET_PATH_UTF8);
public static final ByteString TARGET_SCHEME = ByteString.encodeUtf8(com.mbridge.msdk.thrid.okhttp.internal.http2.Header.TARGET_SCHEME_UTF8);
public static final ByteString TARGET_AUTHORITY = ByteString.encodeUtf8(com.mbridge.msdk.thrid.okhttp.internal.http2.Header.TARGET_AUTHORITY_UTF8);
public Header(String str, String str2) {
this(ByteString.encodeUtf8(str), ByteString.encodeUtf8(str2));
}
public Header(ByteString byteString, String str) {
this(byteString, ByteString.encodeUtf8(str));
}
public Header(ByteString byteString, ByteString byteString2) {
this.name = byteString;
this.value = byteString2;
this.hpackSize = byteString.size() + 32 + byteString2.size();
}
public boolean equals(Object obj) {
if (!(obj instanceof Header)) {
return false;
}
Header header = (Header) obj;
return this.name.equals(header.name) && this.value.equals(header.value);
}
public int hashCode() {
return ((IronSourceError.ERROR_NON_EXISTENT_INSTANCE + this.name.hashCode()) * 31) + this.value.hashCode();
}
public String toString() {
return Util.format("%s: %s", this.name.utf8(), this.value.utf8());
}
}

View File

@@ -0,0 +1,499 @@
package okhttp3.internal.http2;
import com.ironsource.zk;
import com.mbridge.msdk.foundation.download.database.DownloadModel;
import com.mbridge.msdk.mbsignalcommon.commonwebview.ToolBar;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import kotlin.jvm.internal.ByteCompanionObject;
import okio.Buffer;
import okio.BufferedSource;
import okio.ByteString;
import okio.Okio;
import okio.Source;
import org.apache.http.cookie.ClientCookie;
/* loaded from: classes5.dex */
public abstract class Hpack {
public static final Map NAME_TO_FIRST_INDEX;
public static final Header[] STATIC_HEADER_TABLE;
static {
Header header = new Header(Header.TARGET_AUTHORITY, "");
ByteString byteString = Header.TARGET_METHOD;
Header header2 = new Header(byteString, "GET");
Header header3 = new Header(byteString, "POST");
ByteString byteString2 = Header.TARGET_PATH;
Header header4 = new Header(byteString2, "/");
Header header5 = new Header(byteString2, "/index.html");
ByteString byteString3 = Header.TARGET_SCHEME;
Header header6 = new Header(byteString3, "http");
Header header7 = new Header(byteString3, "https");
ByteString byteString4 = Header.RESPONSE_STATUS;
STATIC_HEADER_TABLE = new Header[]{header, header2, header3, header4, header5, header6, header7, new Header(byteString4, "200"), new Header(byteString4, "204"), new Header(byteString4, "206"), new Header(byteString4, "304"), new Header(byteString4, "400"), new Header(byteString4, "404"), new Header(byteString4, "500"), new Header("accept-charset", ""), new Header("accept-encoding", "gzip, deflate"), new Header("accept-language", ""), new Header("accept-ranges", ""), new Header("accept", ""), new Header("access-control-allow-origin", ""), new Header("age", ""), new Header("allow", ""), new Header("authorization", ""), new Header("cache-control", ""), new Header("content-disposition", ""), new Header("content-encoding", ""), new Header("content-language", ""), new Header("content-length", ""), new Header("content-location", ""), new Header("content-range", ""), new Header("content-type", ""), new Header("cookie", ""), new Header("date", ""), new Header(DownloadModel.ETAG, ""), new Header("expect", ""), new Header(ClientCookie.EXPIRES_ATTR, ""), new Header("from", ""), new Header("host", ""), new Header("if-match", ""), new Header("if-modified-since", ""), new Header("if-none-match", ""), new Header("if-range", ""), new Header("if-unmodified-since", ""), new Header("last-modified", ""), new Header("link", ""), new Header("location", ""), new Header("max-forwards", ""), new Header("proxy-authenticate", ""), new Header("proxy-authorization", ""), new Header("range", ""), new Header("referer", ""), new Header(ToolBar.REFRESH, ""), new Header("retry-after", ""), new Header(zk.a, ""), new Header("set-cookie", ""), new Header("strict-transport-security", ""), new Header("transfer-encoding", ""), new Header("user-agent", ""), new Header("vary", ""), new Header("via", ""), new Header("www-authenticate", "")};
NAME_TO_FIRST_INDEX = nameToFirstIndex();
}
public static final class Reader {
public Header[] dynamicTable;
public int dynamicTableByteCount;
public int headerCount;
public final List headerList;
public final int headerTableSizeSetting;
public int maxDynamicTableByteCount;
public int nextHeaderIndex;
public final BufferedSource source;
public final int dynamicTableIndex(int i) {
return this.nextHeaderIndex + 1 + i;
}
public Reader(int i, Source source) {
this(i, i, source);
}
public Reader(int i, int i2, Source source) {
this.headerList = new ArrayList();
this.dynamicTable = new Header[8];
this.nextHeaderIndex = r0.length - 1;
this.headerCount = 0;
this.dynamicTableByteCount = 0;
this.headerTableSizeSetting = i;
this.maxDynamicTableByteCount = i2;
this.source = Okio.buffer(source);
}
public final void adjustDynamicTableByteCount() {
int i = this.maxDynamicTableByteCount;
int i2 = this.dynamicTableByteCount;
if (i < i2) {
if (i == 0) {
clearDynamicTable();
} else {
evictToRecoverBytes(i2 - i);
}
}
}
public final void clearDynamicTable() {
Arrays.fill(this.dynamicTable, (Object) null);
this.nextHeaderIndex = this.dynamicTable.length - 1;
this.headerCount = 0;
this.dynamicTableByteCount = 0;
}
public final int evictToRecoverBytes(int i) {
int i2;
int i3 = 0;
if (i > 0) {
int length = this.dynamicTable.length;
while (true) {
length--;
i2 = this.nextHeaderIndex;
if (length < i2 || i <= 0) {
break;
}
int i4 = this.dynamicTable[length].hpackSize;
i -= i4;
this.dynamicTableByteCount -= i4;
this.headerCount--;
i3++;
}
Header[] headerArr = this.dynamicTable;
System.arraycopy(headerArr, i2 + 1, headerArr, i2 + 1 + i3, this.headerCount);
this.nextHeaderIndex += i3;
}
return i3;
}
public void readHeaders() {
while (!this.source.exhausted()) {
byte readByte = this.source.readByte();
int i = readByte & 255;
if (i == 128) {
throw new IOException("index == 0");
}
if ((readByte & ByteCompanionObject.MIN_VALUE) == 128) {
readIndexedHeader(readInt(i, 127) - 1);
} else if (i == 64) {
readLiteralHeaderWithIncrementalIndexingNewName();
} else if ((readByte & 64) == 64) {
readLiteralHeaderWithIncrementalIndexingIndexedName(readInt(i, 63) - 1);
} else if ((readByte & 32) == 32) {
int readInt = readInt(i, 31);
this.maxDynamicTableByteCount = readInt;
if (readInt < 0 || readInt > this.headerTableSizeSetting) {
throw new IOException("Invalid dynamic table size update " + this.maxDynamicTableByteCount);
}
adjustDynamicTableByteCount();
} else if (i == 16 || i == 0) {
readLiteralHeaderWithoutIndexingNewName();
} else {
readLiteralHeaderWithoutIndexingIndexedName(readInt(i, 15) - 1);
}
}
}
public List getAndResetHeaderList() {
ArrayList arrayList = new ArrayList(this.headerList);
this.headerList.clear();
return arrayList;
}
public final void readIndexedHeader(int i) {
if (isStaticHeader(i)) {
this.headerList.add(Hpack.STATIC_HEADER_TABLE[i]);
return;
}
int dynamicTableIndex = dynamicTableIndex(i - Hpack.STATIC_HEADER_TABLE.length);
if (dynamicTableIndex >= 0) {
Header[] headerArr = this.dynamicTable;
if (dynamicTableIndex < headerArr.length) {
this.headerList.add(headerArr[dynamicTableIndex]);
return;
}
}
throw new IOException("Header index too large " + (i + 1));
}
public final void readLiteralHeaderWithoutIndexingIndexedName(int i) {
this.headerList.add(new Header(getName(i), readByteString()));
}
public final void readLiteralHeaderWithoutIndexingNewName() {
this.headerList.add(new Header(Hpack.checkLowercase(readByteString()), readByteString()));
}
public final void readLiteralHeaderWithIncrementalIndexingIndexedName(int i) {
insertIntoDynamicTable(-1, new Header(getName(i), readByteString()));
}
public final void readLiteralHeaderWithIncrementalIndexingNewName() {
insertIntoDynamicTable(-1, new Header(Hpack.checkLowercase(readByteString()), readByteString()));
}
public final ByteString getName(int i) {
if (isStaticHeader(i)) {
return Hpack.STATIC_HEADER_TABLE[i].name;
}
int dynamicTableIndex = dynamicTableIndex(i - Hpack.STATIC_HEADER_TABLE.length);
if (dynamicTableIndex >= 0) {
Header[] headerArr = this.dynamicTable;
if (dynamicTableIndex < headerArr.length) {
return headerArr[dynamicTableIndex].name;
}
}
throw new IOException("Header index too large " + (i + 1));
}
public final boolean isStaticHeader(int i) {
return i >= 0 && i <= Hpack.STATIC_HEADER_TABLE.length - 1;
}
public final void insertIntoDynamicTable(int i, Header header) {
this.headerList.add(header);
int i2 = header.hpackSize;
if (i != -1) {
i2 -= this.dynamicTable[dynamicTableIndex(i)].hpackSize;
}
int i3 = this.maxDynamicTableByteCount;
if (i2 > i3) {
clearDynamicTable();
return;
}
int evictToRecoverBytes = evictToRecoverBytes((this.dynamicTableByteCount + i2) - i3);
if (i == -1) {
int i4 = this.headerCount + 1;
Header[] headerArr = this.dynamicTable;
if (i4 > headerArr.length) {
Header[] headerArr2 = new Header[headerArr.length * 2];
System.arraycopy(headerArr, 0, headerArr2, headerArr.length, headerArr.length);
this.nextHeaderIndex = this.dynamicTable.length - 1;
this.dynamicTable = headerArr2;
}
int i5 = this.nextHeaderIndex;
this.nextHeaderIndex = i5 - 1;
this.dynamicTable[i5] = header;
this.headerCount++;
} else {
this.dynamicTable[i + dynamicTableIndex(i) + evictToRecoverBytes] = header;
}
this.dynamicTableByteCount += i2;
}
public final int readByte() {
return this.source.readByte() & 255;
}
public int readInt(int i, int i2) {
int i3 = i & i2;
if (i3 < i2) {
return i3;
}
int i4 = 0;
while (true) {
int readByte = readByte();
if ((readByte & 128) == 0) {
return i2 + (readByte << i4);
}
i2 += (readByte & 127) << i4;
i4 += 7;
}
}
public ByteString readByteString() {
int readByte = readByte();
boolean z = (readByte & 128) == 128;
int readInt = readInt(readByte, 127);
if (z) {
return ByteString.of(Huffman.get().decode(this.source.readByteArray(readInt)));
}
return this.source.readByteString(readInt);
}
}
public static Map nameToFirstIndex() {
LinkedHashMap linkedHashMap = new LinkedHashMap(STATIC_HEADER_TABLE.length);
int i = 0;
while (true) {
Header[] headerArr = STATIC_HEADER_TABLE;
if (i < headerArr.length) {
if (!linkedHashMap.containsKey(headerArr[i].name)) {
linkedHashMap.put(headerArr[i].name, Integer.valueOf(i));
}
i++;
} else {
return Collections.unmodifiableMap(linkedHashMap);
}
}
}
public static final class Writer {
public Header[] dynamicTable;
public int dynamicTableByteCount;
public boolean emitDynamicTableSizeUpdate;
public int headerCount;
public int headerTableSizeSetting;
public int maxDynamicTableByteCount;
public int nextHeaderIndex;
public final Buffer out;
public int smallestHeaderTableSizeSetting;
public final boolean useCompression;
public Writer(Buffer buffer) {
this(4096, true, buffer);
}
public Writer(int i, boolean z, Buffer buffer) {
this.smallestHeaderTableSizeSetting = Integer.MAX_VALUE;
this.dynamicTable = new Header[8];
this.nextHeaderIndex = r0.length - 1;
this.headerCount = 0;
this.dynamicTableByteCount = 0;
this.headerTableSizeSetting = i;
this.maxDynamicTableByteCount = i;
this.useCompression = z;
this.out = buffer;
}
public final void clearDynamicTable() {
Arrays.fill(this.dynamicTable, (Object) null);
this.nextHeaderIndex = this.dynamicTable.length - 1;
this.headerCount = 0;
this.dynamicTableByteCount = 0;
}
public final int evictToRecoverBytes(int i) {
int i2;
int i3 = 0;
if (i > 0) {
int length = this.dynamicTable.length;
while (true) {
length--;
i2 = this.nextHeaderIndex;
if (length < i2 || i <= 0) {
break;
}
int i4 = this.dynamicTable[length].hpackSize;
i -= i4;
this.dynamicTableByteCount -= i4;
this.headerCount--;
i3++;
}
Header[] headerArr = this.dynamicTable;
System.arraycopy(headerArr, i2 + 1, headerArr, i2 + 1 + i3, this.headerCount);
Header[] headerArr2 = this.dynamicTable;
int i5 = this.nextHeaderIndex;
Arrays.fill(headerArr2, i5 + 1, i5 + 1 + i3, (Object) null);
this.nextHeaderIndex += i3;
}
return i3;
}
public final void insertIntoDynamicTable(Header header) {
int i = header.hpackSize;
int i2 = this.maxDynamicTableByteCount;
if (i > i2) {
clearDynamicTable();
return;
}
evictToRecoverBytes((this.dynamicTableByteCount + i) - i2);
int i3 = this.headerCount + 1;
Header[] headerArr = this.dynamicTable;
if (i3 > headerArr.length) {
Header[] headerArr2 = new Header[headerArr.length * 2];
System.arraycopy(headerArr, 0, headerArr2, headerArr.length, headerArr.length);
this.nextHeaderIndex = this.dynamicTable.length - 1;
this.dynamicTable = headerArr2;
}
int i4 = this.nextHeaderIndex;
this.nextHeaderIndex = i4 - 1;
this.dynamicTable[i4] = header;
this.headerCount++;
this.dynamicTableByteCount += i;
}
public void writeHeaders(List list) {
int i;
int i2;
if (this.emitDynamicTableSizeUpdate) {
int i3 = this.smallestHeaderTableSizeSetting;
if (i3 < this.maxDynamicTableByteCount) {
writeInt(i3, 31, 32);
}
this.emitDynamicTableSizeUpdate = false;
this.smallestHeaderTableSizeSetting = Integer.MAX_VALUE;
writeInt(this.maxDynamicTableByteCount, 31, 32);
}
int size = list.size();
for (int i4 = 0; i4 < size; i4++) {
Header header = (Header) list.get(i4);
ByteString asciiLowercase = header.name.toAsciiLowercase();
ByteString byteString = header.value;
Integer num = (Integer) Hpack.NAME_TO_FIRST_INDEX.get(asciiLowercase);
if (num != null) {
int intValue = num.intValue();
i2 = intValue + 1;
if (i2 > 1 && i2 < 8) {
Header[] headerArr = Hpack.STATIC_HEADER_TABLE;
if (Objects.equals(headerArr[intValue].value, byteString)) {
i = i2;
} else if (Objects.equals(headerArr[i2].value, byteString)) {
i2 = intValue + 2;
i = i2;
}
}
i = i2;
i2 = -1;
} else {
i = -1;
i2 = -1;
}
if (i2 == -1) {
int i5 = this.nextHeaderIndex + 1;
int length = this.dynamicTable.length;
while (true) {
if (i5 >= length) {
break;
}
if (Objects.equals(this.dynamicTable[i5].name, asciiLowercase)) {
if (Objects.equals(this.dynamicTable[i5].value, byteString)) {
i2 = (i5 - this.nextHeaderIndex) + Hpack.STATIC_HEADER_TABLE.length;
break;
} else if (i == -1) {
i = (i5 - this.nextHeaderIndex) + Hpack.STATIC_HEADER_TABLE.length;
}
}
i5++;
}
}
if (i2 != -1) {
writeInt(i2, 127, 128);
} else if (i == -1) {
this.out.writeByte(64);
writeByteString(asciiLowercase);
writeByteString(byteString);
insertIntoDynamicTable(header);
} else if (asciiLowercase.startsWith(Header.PSEUDO_PREFIX) && !Header.TARGET_AUTHORITY.equals(asciiLowercase)) {
writeInt(i, 15, 0);
writeByteString(byteString);
} else {
writeInt(i, 63, 64);
writeByteString(byteString);
insertIntoDynamicTable(header);
}
}
}
public void writeInt(int i, int i2, int i3) {
if (i < i2) {
this.out.writeByte(i | i3);
return;
}
this.out.writeByte(i3 | i2);
int i4 = i - i2;
while (i4 >= 128) {
this.out.writeByte(128 | (i4 & 127));
i4 >>>= 7;
}
this.out.writeByte(i4);
}
public void writeByteString(ByteString byteString) {
if (this.useCompression && Huffman.get().encodedLength(byteString) < byteString.size()) {
Buffer buffer = new Buffer();
Huffman.get().encode(byteString, buffer);
ByteString readByteString = buffer.readByteString();
writeInt(readByteString.size(), 127, 128);
this.out.write(readByteString);
return;
}
writeInt(byteString.size(), 127, 0);
this.out.write(byteString);
}
public void setHeaderTableSizeSetting(int i) {
this.headerTableSizeSetting = i;
int min = Math.min(i, 16384);
int i2 = this.maxDynamicTableByteCount;
if (i2 == min) {
return;
}
if (min < i2) {
this.smallestHeaderTableSizeSetting = Math.min(this.smallestHeaderTableSizeSetting, min);
}
this.emitDynamicTableSizeUpdate = true;
this.maxDynamicTableByteCount = min;
adjustDynamicTableByteCount();
}
public final void adjustDynamicTableByteCount() {
int i = this.maxDynamicTableByteCount;
int i2 = this.dynamicTableByteCount;
if (i < i2) {
if (i == 0) {
clearDynamicTable();
} else {
evictToRecoverBytes(i2 - i);
}
}
}
}
public static ByteString checkLowercase(ByteString byteString) {
int size = byteString.size();
for (int i = 0; i < size; i++) {
byte b = byteString.getByte(i);
if (b >= 65 && b <= 90) {
throw new IOException("PROTOCOL_ERROR response malformed: mixed case name: " + byteString.utf8());
}
}
return byteString;
}
}

View File

@@ -0,0 +1,96 @@
package okhttp3.internal.http2;
import java.io.IOException;
import okhttp3.internal.Util;
import okio.ByteString;
/* loaded from: classes5.dex */
public abstract class Http2 {
public static final ByteString CONNECTION_PREFACE = ByteString.encodeUtf8("PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n");
public static final String[] FRAME_NAMES = {"DATA", "HEADERS", "PRIORITY", "RST_STREAM", "SETTINGS", "PUSH_PROMISE", "PING", "GOAWAY", "WINDOW_UPDATE", "CONTINUATION"};
public static final String[] FLAGS = new String[64];
public static final String[] BINARY = new String[256];
static {
int i = 0;
int i2 = 0;
while (true) {
String[] strArr = BINARY;
if (i2 >= strArr.length) {
break;
}
strArr[i2] = Util.format("%8s", Integer.toBinaryString(i2)).replace(' ', '0');
i2++;
}
String[] strArr2 = FLAGS;
strArr2[0] = "";
strArr2[1] = "END_STREAM";
int[] iArr = {1};
strArr2[8] = "PADDED";
int i3 = iArr[0];
strArr2[i3 | 8] = strArr2[i3] + "|PADDED";
strArr2[4] = "END_HEADERS";
strArr2[32] = "PRIORITY";
strArr2[36] = "END_HEADERS|PRIORITY";
int[] iArr2 = {4, 32, 36};
for (int i4 = 0; i4 < 3; i4++) {
int i5 = iArr2[i4];
int i6 = iArr[0];
String[] strArr3 = FLAGS;
int i7 = i6 | i5;
strArr3[i7] = strArr3[i6] + '|' + strArr3[i5];
strArr3[i7 | 8] = strArr3[i6] + '|' + strArr3[i5] + "|PADDED";
}
while (true) {
String[] strArr4 = FLAGS;
if (i >= strArr4.length) {
return;
}
if (strArr4[i] == null) {
strArr4[i] = BINARY[i];
}
i++;
}
}
public static IllegalArgumentException illegalArgument(String str, Object... objArr) {
throw new IllegalArgumentException(Util.format(str, objArr));
}
public static IOException ioException(String str, Object... objArr) {
throw new IOException(Util.format(str, objArr));
}
public static String frameLog(boolean z, int i, int i2, byte b, byte b2) {
String[] strArr = FRAME_NAMES;
String format = b < strArr.length ? strArr[b] : Util.format("0x%02x", Byte.valueOf(b));
String formatFlags = formatFlags(b, b2);
Object[] objArr = new Object[5];
objArr[0] = z ? "<<" : ">>";
objArr[1] = Integer.valueOf(i);
objArr[2] = Integer.valueOf(i2);
objArr[3] = format;
objArr[4] = formatFlags;
return Util.format("%s 0x%08x %5d %-13s %s", objArr);
}
public static String formatFlags(byte b, byte b2) {
if (b2 == 0) {
return "";
}
if (b != 2 && b != 3) {
if (b == 4 || b == 6) {
return b2 == 1 ? "ACK" : BINARY[b2];
}
if (b != 7 && b != 8) {
String[] strArr = FLAGS;
String str = b2 < strArr.length ? strArr[b2] : BINARY[b2];
if (b != 5 || (b2 & 4) == 0) {
return (b != 0 || (b2 & 32) == 0) ? str : str.replace("PRIORITY", "COMPRESSED");
}
return str.replace("HEADERS", "PUSH_PROMISE");
}
}
return BINARY[b2];
}
}

View File

@@ -0,0 +1,946 @@
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);
}
}
}

View File

@@ -0,0 +1,149 @@
package okhttp3.internal.http2;
import java.io.IOException;
import java.net.ProtocolException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.TimeUnit;
import okhttp3.Headers;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Protocol;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.internal.Internal;
import okhttp3.internal.Util;
import okhttp3.internal.connection.RealConnection;
import okhttp3.internal.http.ExchangeCodec;
import okhttp3.internal.http.HttpHeaders;
import okhttp3.internal.http.RequestLine;
import okhttp3.internal.http.StatusLine;
import okio.Sink;
import okio.Source;
import okio.Timeout;
import org.apache.http.protocol.HTTP;
/* loaded from: classes5.dex */
public final class Http2ExchangeCodec implements ExchangeCodec {
public static final List HTTP_2_SKIPPED_REQUEST_HEADERS = Util.immutableList("connection", "host", "keep-alive", "proxy-connection", "te", "transfer-encoding", "encoding", "upgrade", com.mbridge.msdk.thrid.okhttp.internal.http2.Header.TARGET_METHOD_UTF8, com.mbridge.msdk.thrid.okhttp.internal.http2.Header.TARGET_PATH_UTF8, com.mbridge.msdk.thrid.okhttp.internal.http2.Header.TARGET_SCHEME_UTF8, com.mbridge.msdk.thrid.okhttp.internal.http2.Header.TARGET_AUTHORITY_UTF8);
public static final List HTTP_2_SKIPPED_RESPONSE_HEADERS = Util.immutableList("connection", "host", "keep-alive", "proxy-connection", "te", "transfer-encoding", "encoding", "upgrade");
public volatile boolean canceled;
public final Interceptor.Chain chain;
public final Http2Connection connection;
public final Protocol protocol;
public final RealConnection realConnection;
public volatile Http2Stream stream;
@Override // okhttp3.internal.http.ExchangeCodec
public RealConnection connection() {
return this.realConnection;
}
public Http2ExchangeCodec(OkHttpClient okHttpClient, RealConnection realConnection, Interceptor.Chain chain, Http2Connection http2Connection) {
this.realConnection = realConnection;
this.chain = chain;
this.connection = http2Connection;
List protocols = okHttpClient.protocols();
Protocol protocol = Protocol.H2_PRIOR_KNOWLEDGE;
this.protocol = protocols.contains(protocol) ? protocol : Protocol.HTTP_2;
}
@Override // okhttp3.internal.http.ExchangeCodec
public Sink createRequestBody(Request request, long j) {
return this.stream.getSink();
}
@Override // okhttp3.internal.http.ExchangeCodec
public void writeRequestHeaders(Request request) {
if (this.stream != null) {
return;
}
this.stream = this.connection.newStream(http2HeadersList(request), request.body() != null);
if (this.canceled) {
this.stream.closeLater(ErrorCode.CANCEL);
throw new IOException("Canceled");
}
Timeout readTimeout = this.stream.readTimeout();
long readTimeoutMillis = this.chain.readTimeoutMillis();
TimeUnit timeUnit = TimeUnit.MILLISECONDS;
readTimeout.timeout(readTimeoutMillis, timeUnit);
this.stream.writeTimeout().timeout(this.chain.writeTimeoutMillis(), timeUnit);
}
@Override // okhttp3.internal.http.ExchangeCodec
public void flushRequest() {
this.connection.flush();
}
@Override // okhttp3.internal.http.ExchangeCodec
public void finishRequest() {
this.stream.getSink().close();
}
@Override // okhttp3.internal.http.ExchangeCodec
public Response.Builder readResponseHeaders(boolean z) {
Response.Builder readHttp2HeadersList = readHttp2HeadersList(this.stream.takeHeaders(), this.protocol);
if (z && Internal.instance.code(readHttp2HeadersList) == 100) {
return null;
}
return readHttp2HeadersList;
}
public static List http2HeadersList(Request request) {
Headers headers = request.headers();
ArrayList arrayList = new ArrayList(headers.size() + 4);
arrayList.add(new Header(Header.TARGET_METHOD, request.method()));
arrayList.add(new Header(Header.TARGET_PATH, RequestLine.requestPath(request.url())));
String header = request.header(HTTP.TARGET_HOST);
if (header != null) {
arrayList.add(new Header(Header.TARGET_AUTHORITY, header));
}
arrayList.add(new Header(Header.TARGET_SCHEME, request.url().scheme()));
int size = headers.size();
for (int i = 0; i < size; i++) {
String lowerCase = headers.name(i).toLowerCase(Locale.US);
if (!HTTP_2_SKIPPED_REQUEST_HEADERS.contains(lowerCase) || (lowerCase.equals("te") && headers.value(i).equals("trailers"))) {
arrayList.add(new Header(lowerCase, headers.value(i)));
}
}
return arrayList;
}
public static Response.Builder readHttp2HeadersList(Headers headers, Protocol protocol) {
Headers.Builder builder = new Headers.Builder();
int size = headers.size();
StatusLine statusLine = null;
for (int i = 0; i < size; i++) {
String name = headers.name(i);
String value = headers.value(i);
if (name.equals(com.mbridge.msdk.thrid.okhttp.internal.http2.Header.RESPONSE_STATUS_UTF8)) {
statusLine = StatusLine.parse("HTTP/1.1 " + value);
} else if (!HTTP_2_SKIPPED_RESPONSE_HEADERS.contains(name)) {
Internal.instance.addLenient(builder, name, value);
}
}
if (statusLine == null) {
throw new ProtocolException("Expected ':status' header not present");
}
return new Response.Builder().protocol(protocol).code(statusLine.code).message(statusLine.message).headers(builder.build());
}
@Override // okhttp3.internal.http.ExchangeCodec
public long reportedContentLength(Response response) {
return HttpHeaders.contentLength(response);
}
@Override // okhttp3.internal.http.ExchangeCodec
public Source openResponseBodySource(Response response) {
return this.stream.getSource();
}
@Override // okhttp3.internal.http.ExchangeCodec
public void cancel() {
this.canceled = true;
if (this.stream != null) {
this.stream.closeLater(ErrorCode.CANCEL);
}
}
}

View File

@@ -0,0 +1,364 @@
package okhttp3.internal.http2;
import java.io.Closeable;
import java.io.EOFException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import okhttp3.internal.Util;
import okhttp3.internal.http2.Hpack;
import okio.Buffer;
import okio.BufferedSource;
import okio.ByteString;
import okio.Source;
import okio.Timeout;
/* loaded from: classes5.dex */
public final class Http2Reader implements Closeable {
public static final Logger logger = Logger.getLogger(Http2.class.getName());
public final boolean client;
public final ContinuationSource continuation;
public final Hpack.Reader hpackReader;
public final BufferedSource source;
public interface Handler {
void ackSettings();
void data(boolean z, int i, BufferedSource bufferedSource, int i2);
void goAway(int i, ErrorCode errorCode, ByteString byteString);
void headers(boolean z, int i, int i2, List list);
void ping(boolean z, int i, int i2);
void priority(int i, int i2, int i3, boolean z);
void pushPromise(int i, int i2, List list);
void rstStream(int i, ErrorCode errorCode);
void settings(boolean z, Settings settings);
void windowUpdate(int i, long j);
}
public Http2Reader(BufferedSource bufferedSource, boolean z) {
this.source = bufferedSource;
this.client = z;
ContinuationSource continuationSource = new ContinuationSource(bufferedSource);
this.continuation = continuationSource;
this.hpackReader = new Hpack.Reader(4096, continuationSource);
}
public void readConnectionPreface(Handler handler) {
if (this.client) {
if (!nextFrame(true, handler)) {
throw Http2.ioException("Required SETTINGS preface not received", new Object[0]);
}
return;
}
BufferedSource bufferedSource = this.source;
ByteString byteString = Http2.CONNECTION_PREFACE;
ByteString readByteString = bufferedSource.readByteString(byteString.size());
Logger logger2 = logger;
if (logger2.isLoggable(Level.FINE)) {
logger2.fine(Util.format("<< CONNECTION %s", readByteString.hex()));
}
if (!byteString.equals(readByteString)) {
throw Http2.ioException("Expected a connection header but was %s", readByteString.utf8());
}
}
public boolean nextFrame(boolean z, Handler handler) {
try {
this.source.require(9L);
int readMedium = readMedium(this.source);
if (readMedium < 0 || readMedium > 16384) {
throw Http2.ioException("FRAME_SIZE_ERROR: %s", Integer.valueOf(readMedium));
}
byte readByte = (byte) (this.source.readByte() & 255);
if (z && readByte != 4) {
throw Http2.ioException("Expected a SETTINGS frame but was %s", Byte.valueOf(readByte));
}
byte readByte2 = (byte) (this.source.readByte() & 255);
int readInt = this.source.readInt() & Integer.MAX_VALUE;
Logger logger2 = logger;
if (logger2.isLoggable(Level.FINE)) {
logger2.fine(Http2.frameLog(true, readInt, readMedium, readByte, readByte2));
}
switch (readByte) {
case 0:
readData(handler, readMedium, readByte2, readInt);
return true;
case 1:
readHeaders(handler, readMedium, readByte2, readInt);
return true;
case 2:
readPriority(handler, readMedium, readByte2, readInt);
return true;
case 3:
readRstStream(handler, readMedium, readByte2, readInt);
return true;
case 4:
readSettings(handler, readMedium, readByte2, readInt);
return true;
case 5:
readPushPromise(handler, readMedium, readByte2, readInt);
return true;
case 6:
readPing(handler, readMedium, readByte2, readInt);
return true;
case 7:
readGoAway(handler, readMedium, readByte2, readInt);
return true;
case 8:
readWindowUpdate(handler, readMedium, readByte2, readInt);
return true;
default:
this.source.skip(readMedium);
return true;
}
} catch (EOFException unused) {
return false;
}
}
public final void readHeaders(Handler handler, int i, byte b, int i2) {
if (i2 == 0) {
throw Http2.ioException("PROTOCOL_ERROR: TYPE_HEADERS streamId == 0", new Object[0]);
}
boolean z = (b & 1) != 0;
short readByte = (b & 8) != 0 ? (short) (this.source.readByte() & 255) : (short) 0;
if ((b & 32) != 0) {
readPriority(handler, i2);
i -= 5;
}
handler.headers(z, i2, -1, readHeaderBlock(lengthWithoutPadding(i, b, readByte), readByte, b, i2));
}
public final List readHeaderBlock(int i, short s, byte b, int i2) {
ContinuationSource continuationSource = this.continuation;
continuationSource.left = i;
continuationSource.length = i;
continuationSource.padding = s;
continuationSource.flags = b;
continuationSource.streamId = i2;
this.hpackReader.readHeaders();
return this.hpackReader.getAndResetHeaderList();
}
public final void readData(Handler handler, int i, byte b, int i2) {
if (i2 == 0) {
throw Http2.ioException("PROTOCOL_ERROR: TYPE_DATA streamId == 0", new Object[0]);
}
boolean z = (b & 1) != 0;
if ((b & 32) != 0) {
throw Http2.ioException("PROTOCOL_ERROR: FLAG_COMPRESSED without SETTINGS_COMPRESS_DATA", new Object[0]);
}
short readByte = (b & 8) != 0 ? (short) (this.source.readByte() & 255) : (short) 0;
handler.data(z, i2, this.source, lengthWithoutPadding(i, b, readByte));
this.source.skip(readByte);
}
public final void readPriority(Handler handler, int i, byte b, int i2) {
if (i != 5) {
throw Http2.ioException("TYPE_PRIORITY length: %d != 5", Integer.valueOf(i));
}
if (i2 == 0) {
throw Http2.ioException("TYPE_PRIORITY streamId == 0", new Object[0]);
}
readPriority(handler, i2);
}
public final void readPriority(Handler handler, int i) {
int readInt = this.source.readInt();
handler.priority(i, readInt & Integer.MAX_VALUE, (this.source.readByte() & 255) + 1, (Integer.MIN_VALUE & readInt) != 0);
}
public final void readRstStream(Handler handler, int i, byte b, int i2) {
if (i != 4) {
throw Http2.ioException("TYPE_RST_STREAM length: %d != 4", Integer.valueOf(i));
}
if (i2 == 0) {
throw Http2.ioException("TYPE_RST_STREAM streamId == 0", new Object[0]);
}
int readInt = this.source.readInt();
ErrorCode fromHttp2 = ErrorCode.fromHttp2(readInt);
if (fromHttp2 == null) {
throw Http2.ioException("TYPE_RST_STREAM unexpected error code: %d", Integer.valueOf(readInt));
}
handler.rstStream(i2, fromHttp2);
}
public final void readSettings(Handler handler, int i, byte b, int i2) {
if (i2 != 0) {
throw Http2.ioException("TYPE_SETTINGS streamId != 0", new Object[0]);
}
if ((b & 1) != 0) {
if (i != 0) {
throw Http2.ioException("FRAME_SIZE_ERROR ack frame should be empty!", new Object[0]);
}
handler.ackSettings();
return;
}
if (i % 6 != 0) {
throw Http2.ioException("TYPE_SETTINGS length %% 6 != 0: %s", Integer.valueOf(i));
}
Settings settings = new Settings();
for (int i3 = 0; i3 < i; i3 += 6) {
int readShort = this.source.readShort() & 65535;
int readInt = this.source.readInt();
if (readShort != 2) {
if (readShort == 3) {
readShort = 4;
} else if (readShort == 4) {
if (readInt < 0) {
throw Http2.ioException("PROTOCOL_ERROR SETTINGS_INITIAL_WINDOW_SIZE > 2^31 - 1", new Object[0]);
}
readShort = 7;
} else if (readShort == 5 && (readInt < 16384 || readInt > 16777215)) {
throw Http2.ioException("PROTOCOL_ERROR SETTINGS_MAX_FRAME_SIZE: %s", Integer.valueOf(readInt));
}
} else if (readInt != 0 && readInt != 1) {
throw Http2.ioException("PROTOCOL_ERROR SETTINGS_ENABLE_PUSH != 0 or 1", new Object[0]);
}
settings.set(readShort, readInt);
}
handler.settings(false, settings);
}
public final void readPushPromise(Handler handler, int i, byte b, int i2) {
if (i2 == 0) {
throw Http2.ioException("PROTOCOL_ERROR: TYPE_PUSH_PROMISE streamId == 0", new Object[0]);
}
short readByte = (b & 8) != 0 ? (short) (this.source.readByte() & 255) : (short) 0;
handler.pushPromise(i2, this.source.readInt() & Integer.MAX_VALUE, readHeaderBlock(lengthWithoutPadding(i - 4, b, readByte), readByte, b, i2));
}
public final void readPing(Handler handler, int i, byte b, int i2) {
if (i != 8) {
throw Http2.ioException("TYPE_PING length != 8: %s", Integer.valueOf(i));
}
if (i2 != 0) {
throw Http2.ioException("TYPE_PING streamId != 0", new Object[0]);
}
handler.ping((b & 1) != 0, this.source.readInt(), this.source.readInt());
}
public final void readGoAway(Handler handler, int i, byte b, int i2) {
if (i < 8) {
throw Http2.ioException("TYPE_GOAWAY length < 8: %s", Integer.valueOf(i));
}
if (i2 != 0) {
throw Http2.ioException("TYPE_GOAWAY streamId != 0", new Object[0]);
}
int readInt = this.source.readInt();
int readInt2 = this.source.readInt();
int i3 = i - 8;
ErrorCode fromHttp2 = ErrorCode.fromHttp2(readInt2);
if (fromHttp2 == null) {
throw Http2.ioException("TYPE_GOAWAY unexpected error code: %d", Integer.valueOf(readInt2));
}
ByteString byteString = ByteString.EMPTY;
if (i3 > 0) {
byteString = this.source.readByteString(i3);
}
handler.goAway(readInt, fromHttp2, byteString);
}
public final void readWindowUpdate(Handler handler, int i, byte b, int i2) {
if (i != 4) {
throw Http2.ioException("TYPE_WINDOW_UPDATE length !=4: %s", Integer.valueOf(i));
}
long readInt = this.source.readInt() & 2147483647L;
if (readInt == 0) {
throw Http2.ioException("windowSizeIncrement was 0", Long.valueOf(readInt));
}
handler.windowUpdate(i2, readInt);
}
@Override // java.io.Closeable, java.lang.AutoCloseable
public void close() {
this.source.close();
}
public static final class ContinuationSource implements Source {
public byte flags;
public int left;
public int length;
public short padding;
public final BufferedSource source;
public int streamId;
@Override // okio.Source, java.io.Closeable, java.lang.AutoCloseable
public void close() {
}
public ContinuationSource(BufferedSource bufferedSource) {
this.source = bufferedSource;
}
@Override // okio.Source
public long read(Buffer buffer, long j) {
while (true) {
int i = this.left;
if (i == 0) {
this.source.skip(this.padding);
this.padding = (short) 0;
if ((this.flags & 4) != 0) {
return -1L;
}
readContinuationHeader();
} else {
long read = this.source.read(buffer, Math.min(j, i));
if (read == -1) {
return -1L;
}
this.left = (int) (this.left - read);
return read;
}
}
}
@Override // okio.Source
public Timeout timeout() {
return this.source.timeout();
}
public final void readContinuationHeader() {
int i = this.streamId;
int readMedium = Http2Reader.readMedium(this.source);
this.left = readMedium;
this.length = readMedium;
byte readByte = (byte) (this.source.readByte() & 255);
this.flags = (byte) (this.source.readByte() & 255);
Logger logger = Http2Reader.logger;
if (logger.isLoggable(Level.FINE)) {
logger.fine(Http2.frameLog(true, this.streamId, this.length, readByte, this.flags));
}
int readInt = this.source.readInt() & Integer.MAX_VALUE;
this.streamId = readInt;
if (readByte != 9) {
throw Http2.ioException("%s != TYPE_CONTINUATION", Byte.valueOf(readByte));
}
if (readInt != i) {
throw Http2.ioException("TYPE_CONTINUATION streamId changed", new Object[0]);
}
}
}
public static int readMedium(BufferedSource bufferedSource) {
return (bufferedSource.readByte() & 255) | ((bufferedSource.readByte() & 255) << 16) | ((bufferedSource.readByte() & 255) << 8);
}
public static int lengthWithoutPadding(int i, byte b, short s) {
if ((b & 8) != 0) {
i--;
}
if (s <= i) {
return (short) (i - s);
}
throw Http2.ioException("PROTOCOL_ERROR padding %s > remaining length %s", Short.valueOf(s), Integer.valueOf(i));
}
}

View File

@@ -0,0 +1,640 @@
package okhttp3.internal.http2;
import android.support.v4.media.session.PlaybackStateCompat;
import java.io.EOFException;
import java.io.IOException;
import java.io.InterruptedIOException;
import java.net.SocketTimeoutException;
import java.util.ArrayDeque;
import java.util.Deque;
import okhttp3.Headers;
import okhttp3.internal.Util;
import okio.AsyncTimeout;
import okio.Buffer;
import okio.BufferedSource;
import okio.Sink;
import okio.Source;
import okio.Timeout;
/* loaded from: classes5.dex */
public final class Http2Stream {
public long bytesLeftInWriteWindow;
public final Http2Connection connection;
public ErrorCode errorCode;
public IOException errorException;
public boolean hasResponseHeaders;
public final Deque headersQueue;
public final int id;
public final StreamTimeout readTimeout;
public final FramingSink sink;
public final FramingSource source;
public long unacknowledgedBytesRead = 0;
public final StreamTimeout writeTimeout;
public int getId() {
return this.id;
}
public Source getSource() {
return this.source;
}
public Timeout readTimeout() {
return this.readTimeout;
}
public Timeout writeTimeout() {
return this.writeTimeout;
}
public Http2Stream(int i, Http2Connection http2Connection, boolean z, boolean z2, Headers headers) {
ArrayDeque arrayDeque = new ArrayDeque();
this.headersQueue = arrayDeque;
this.readTimeout = new StreamTimeout();
this.writeTimeout = new StreamTimeout();
if (http2Connection == null) {
throw new NullPointerException("connection == null");
}
this.id = i;
this.connection = http2Connection;
this.bytesLeftInWriteWindow = http2Connection.peerSettings.getInitialWindowSize();
FramingSource framingSource = new FramingSource(http2Connection.okHttpSettings.getInitialWindowSize());
this.source = framingSource;
FramingSink framingSink = new FramingSink();
this.sink = framingSink;
framingSource.finished = z2;
framingSink.finished = z;
if (headers != null) {
arrayDeque.add(headers);
}
if (isLocallyInitiated() && headers != null) {
throw new IllegalStateException("locally-initiated streams shouldn't have headers yet");
}
if (!isLocallyInitiated() && headers == null) {
throw new IllegalStateException("remotely-initiated streams should have headers");
}
}
public synchronized boolean isOpen() {
try {
if (this.errorCode != null) {
return false;
}
FramingSource framingSource = this.source;
if (!framingSource.finished) {
if (framingSource.closed) {
}
return true;
}
FramingSink framingSink = this.sink;
if (framingSink.finished || framingSink.closed) {
if (this.hasResponseHeaders) {
return false;
}
}
return true;
} catch (Throwable th) {
throw th;
}
}
public boolean isLocallyInitiated() {
return this.connection.client == ((this.id & 1) == 1);
}
public synchronized Headers takeHeaders() {
this.readTimeout.enter();
while (this.headersQueue.isEmpty() && this.errorCode == null) {
try {
waitForIo();
} catch (Throwable th) {
this.readTimeout.exitAndThrowIfTimedOut();
throw th;
}
}
this.readTimeout.exitAndThrowIfTimedOut();
if (this.headersQueue.isEmpty()) {
IOException iOException = this.errorException;
if (iOException != null) {
throw iOException;
}
throw new StreamResetException(this.errorCode);
}
return (Headers) this.headersQueue.removeFirst();
}
public Sink getSink() {
synchronized (this) {
try {
if (!this.hasResponseHeaders && !isLocallyInitiated()) {
throw new IllegalStateException("reply before requesting the sink");
}
} catch (Throwable th) {
throw th;
}
}
return this.sink;
}
public void close(ErrorCode errorCode, IOException iOException) {
if (closeInternal(errorCode, iOException)) {
this.connection.writeSynReset(this.id, errorCode);
}
}
public void closeLater(ErrorCode errorCode) {
if (closeInternal(errorCode, null)) {
this.connection.writeSynResetLater(this.id, errorCode);
}
}
public final boolean closeInternal(ErrorCode errorCode, IOException iOException) {
synchronized (this) {
try {
if (this.errorCode != null) {
return false;
}
if (this.source.finished && this.sink.finished) {
return false;
}
this.errorCode = errorCode;
this.errorException = iOException;
notifyAll();
this.connection.removeStream(this.id);
return true;
} catch (Throwable th) {
throw th;
}
}
}
public void receiveData(BufferedSource bufferedSource, int i) {
this.source.receive(bufferedSource, i);
}
/* JADX WARN: Removed duplicated region for block: B:9:0x001a A[Catch: all -> 0x000f, TryCatch #0 {all -> 0x000f, blocks: (B:3:0x0001, B:7:0x0009, B:9:0x001a, B:10:0x001e, B:11:0x0025, B:18:0x0011), top: B:2:0x0001 }] */
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct add '--show-bad-code' argument
*/
public void receiveHeaders(okhttp3.Headers r3, boolean r4) {
/*
r2 = this;
monitor-enter(r2)
boolean r0 = r2.hasResponseHeaders // Catch: java.lang.Throwable -> Lf
r1 = 1
if (r0 == 0) goto L11
if (r4 != 0) goto L9
goto L11
L9:
okhttp3.internal.http2.Http2Stream$FramingSource r0 = r2.source // Catch: java.lang.Throwable -> Lf
okhttp3.internal.http2.Http2Stream.FramingSource.access$202(r0, r3) // Catch: java.lang.Throwable -> Lf
goto L18
Lf:
r3 = move-exception
goto L30
L11:
r2.hasResponseHeaders = r1 // Catch: java.lang.Throwable -> Lf
java.util.Deque r0 = r2.headersQueue // Catch: java.lang.Throwable -> Lf
r0.add(r3) // Catch: java.lang.Throwable -> Lf
L18:
if (r4 == 0) goto L1e
okhttp3.internal.http2.Http2Stream$FramingSource r3 = r2.source // Catch: java.lang.Throwable -> Lf
r3.finished = r1 // Catch: java.lang.Throwable -> Lf
L1e:
boolean r3 = r2.isOpen() // Catch: java.lang.Throwable -> Lf
r2.notifyAll() // Catch: java.lang.Throwable -> Lf
monitor-exit(r2) // Catch: java.lang.Throwable -> Lf
if (r3 != 0) goto L2f
okhttp3.internal.http2.Http2Connection r3 = r2.connection
int r4 = r2.id
r3.removeStream(r4)
L2f:
return
L30:
monitor-exit(r2) // Catch: java.lang.Throwable -> Lf
throw r3
*/
throw new UnsupportedOperationException("Method not decompiled: okhttp3.internal.http2.Http2Stream.receiveHeaders(okhttp3.Headers, boolean):void");
}
public synchronized void receiveRstStream(ErrorCode errorCode) {
if (this.errorCode == null) {
this.errorCode = errorCode;
notifyAll();
}
}
public final class FramingSource implements Source {
public boolean closed;
public boolean finished;
public final long maxByteCount;
public Headers trailers;
public final Buffer receiveBuffer = new Buffer();
public final Buffer readBuffer = new Buffer();
public FramingSource(long j) {
this.maxByteCount = j;
}
/* JADX WARN: Code restructure failed: missing block: B:25:0x0085, code lost:
r12 = -1;
*/
/* JADX WARN: Removed duplicated region for block: B:30:0x0092 */
/* JADX WARN: Removed duplicated region for block: B:33:0x0096 */
@Override // okio.Source
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct add '--show-bad-code' argument
*/
public long read(okio.Buffer r12, long r13) {
/*
r11 = this;
r0 = 0
int r2 = (r13 > r0 ? 1 : (r13 == r0 ? 0 : -1))
if (r2 < 0) goto Lac
L6:
okhttp3.internal.http2.Http2Stream r2 = okhttp3.internal.http2.Http2Stream.this
monitor-enter(r2)
okhttp3.internal.http2.Http2Stream r3 = okhttp3.internal.http2.Http2Stream.this // Catch: java.lang.Throwable -> L83
okhttp3.internal.http2.Http2Stream$StreamTimeout r3 = r3.readTimeout // Catch: java.lang.Throwable -> L83
r3.enter() // Catch: java.lang.Throwable -> L83
okhttp3.internal.http2.Http2Stream r3 = okhttp3.internal.http2.Http2Stream.this // Catch: java.lang.Throwable -> L25
okhttp3.internal.http2.ErrorCode r4 = r3.errorCode // Catch: java.lang.Throwable -> L25
if (r4 == 0) goto L28
java.io.IOException r3 = r3.errorException // Catch: java.lang.Throwable -> L25
if (r3 == 0) goto L1b
goto L29
L1b:
okhttp3.internal.http2.StreamResetException r3 = new okhttp3.internal.http2.StreamResetException // Catch: java.lang.Throwable -> L25
okhttp3.internal.http2.Http2Stream r4 = okhttp3.internal.http2.Http2Stream.this // Catch: java.lang.Throwable -> L25
okhttp3.internal.http2.ErrorCode r4 = r4.errorCode // Catch: java.lang.Throwable -> L25
r3.<init>(r4) // Catch: java.lang.Throwable -> L25
goto L29
L25:
r12 = move-exception
goto La2
L28:
r3 = 0
L29:
boolean r4 = r11.closed // Catch: java.lang.Throwable -> L25
if (r4 != 0) goto L9a
okio.Buffer r4 = r11.readBuffer // Catch: java.lang.Throwable -> L25
long r4 = r4.size() // Catch: java.lang.Throwable -> L25
int r4 = (r4 > r0 ? 1 : (r4 == r0 ? 0 : -1))
r5 = -1
if (r4 <= 0) goto L6f
okio.Buffer r4 = r11.readBuffer // Catch: java.lang.Throwable -> L25
long r7 = r4.size() // Catch: java.lang.Throwable -> L25
long r13 = java.lang.Math.min(r13, r7) // Catch: java.lang.Throwable -> L25
long r12 = r4.read(r12, r13) // Catch: java.lang.Throwable -> L25
okhttp3.internal.http2.Http2Stream r14 = okhttp3.internal.http2.Http2Stream.this // Catch: java.lang.Throwable -> L25
long r7 = r14.unacknowledgedBytesRead // Catch: java.lang.Throwable -> L25
long r7 = r7 + r12
r14.unacknowledgedBytesRead = r7 // Catch: java.lang.Throwable -> L25
if (r3 != 0) goto L86
okhttp3.internal.http2.Http2Connection r14 = r14.connection // Catch: java.lang.Throwable -> L25
okhttp3.internal.http2.Settings r14 = r14.okHttpSettings // Catch: java.lang.Throwable -> L25
int r14 = r14.getInitialWindowSize() // Catch: java.lang.Throwable -> L25
int r14 = r14 / 2
long r9 = (long) r14 // Catch: java.lang.Throwable -> L25
int r14 = (r7 > r9 ? 1 : (r7 == r9 ? 0 : -1))
if (r14 < 0) goto L86
okhttp3.internal.http2.Http2Stream r14 = okhttp3.internal.http2.Http2Stream.this // Catch: java.lang.Throwable -> L25
okhttp3.internal.http2.Http2Connection r4 = r14.connection // Catch: java.lang.Throwable -> L25
int r7 = r14.id // Catch: java.lang.Throwable -> L25
long r8 = r14.unacknowledgedBytesRead // Catch: java.lang.Throwable -> L25
r4.writeWindowUpdateLater(r7, r8) // Catch: java.lang.Throwable -> L25
okhttp3.internal.http2.Http2Stream r14 = okhttp3.internal.http2.Http2Stream.this // Catch: java.lang.Throwable -> L25
r14.unacknowledgedBytesRead = r0 // Catch: java.lang.Throwable -> L25
goto L86
L6f:
boolean r4 = r11.finished // Catch: java.lang.Throwable -> L25
if (r4 != 0) goto L85
if (r3 != 0) goto L85
okhttp3.internal.http2.Http2Stream r3 = okhttp3.internal.http2.Http2Stream.this // Catch: java.lang.Throwable -> L25
r3.waitForIo() // Catch: java.lang.Throwable -> L25
okhttp3.internal.http2.Http2Stream r3 = okhttp3.internal.http2.Http2Stream.this // Catch: java.lang.Throwable -> L83
okhttp3.internal.http2.Http2Stream$StreamTimeout r3 = r3.readTimeout // Catch: java.lang.Throwable -> L83
r3.exitAndThrowIfTimedOut() // Catch: java.lang.Throwable -> L83
monitor-exit(r2) // Catch: java.lang.Throwable -> L83
goto L6
L83:
r12 = move-exception
goto Laa
L85:
r12 = r5
L86:
okhttp3.internal.http2.Http2Stream r14 = okhttp3.internal.http2.Http2Stream.this // Catch: java.lang.Throwable -> L83
okhttp3.internal.http2.Http2Stream$StreamTimeout r14 = r14.readTimeout // Catch: java.lang.Throwable -> L83
r14.exitAndThrowIfTimedOut() // Catch: java.lang.Throwable -> L83
monitor-exit(r2) // Catch: java.lang.Throwable -> L83
int r14 = (r12 > r5 ? 1 : (r12 == r5 ? 0 : -1))
if (r14 == 0) goto L96
r11.updateConnectionFlowControl(r12)
return r12
L96:
if (r3 != 0) goto L99
return r5
L99:
throw r3
L9a:
java.io.IOException r12 = new java.io.IOException // Catch: java.lang.Throwable -> L25
java.lang.String r13 = "stream closed"
r12.<init>(r13) // Catch: java.lang.Throwable -> L25
throw r12 // Catch: java.lang.Throwable -> L25
La2:
okhttp3.internal.http2.Http2Stream r13 = okhttp3.internal.http2.Http2Stream.this // Catch: java.lang.Throwable -> L83
okhttp3.internal.http2.Http2Stream$StreamTimeout r13 = r13.readTimeout // Catch: java.lang.Throwable -> L83
r13.exitAndThrowIfTimedOut() // Catch: java.lang.Throwable -> L83
throw r12 // Catch: java.lang.Throwable -> L83
Laa:
monitor-exit(r2) // Catch: java.lang.Throwable -> L83
throw r12
Lac:
java.lang.IllegalArgumentException r12 = new java.lang.IllegalArgumentException
java.lang.StringBuilder r0 = new java.lang.StringBuilder
r0.<init>()
java.lang.String r1 = "byteCount < 0: "
r0.append(r1)
r0.append(r13)
java.lang.String r13 = r0.toString()
r12.<init>(r13)
throw r12
*/
throw new UnsupportedOperationException("Method not decompiled: okhttp3.internal.http2.Http2Stream.FramingSource.read(okio.Buffer, long):long");
}
public final void updateConnectionFlowControl(long j) {
Http2Stream.this.connection.updateConnectionFlowControl(j);
}
public void receive(BufferedSource bufferedSource, long j) {
boolean z;
boolean z2;
long j2;
while (j > 0) {
synchronized (Http2Stream.this) {
z = this.finished;
z2 = this.readBuffer.size() + j > this.maxByteCount;
}
if (z2) {
bufferedSource.skip(j);
Http2Stream.this.closeLater(ErrorCode.FLOW_CONTROL_ERROR);
return;
}
if (z) {
bufferedSource.skip(j);
return;
}
long read = bufferedSource.read(this.receiveBuffer, j);
if (read == -1) {
throw new EOFException();
}
j -= read;
synchronized (Http2Stream.this) {
try {
if (this.closed) {
j2 = this.receiveBuffer.size();
this.receiveBuffer.clear();
} else {
boolean z3 = this.readBuffer.size() == 0;
this.readBuffer.writeAll(this.receiveBuffer);
if (z3) {
Http2Stream.this.notifyAll();
}
j2 = 0;
}
} finally {
}
}
if (j2 > 0) {
updateConnectionFlowControl(j2);
}
}
}
@Override // okio.Source
public Timeout timeout() {
return Http2Stream.this.readTimeout;
}
@Override // okio.Source, java.io.Closeable, java.lang.AutoCloseable
public void close() {
long size;
synchronized (Http2Stream.this) {
this.closed = true;
size = this.readBuffer.size();
this.readBuffer.clear();
Http2Stream.this.notifyAll();
}
if (size > 0) {
updateConnectionFlowControl(size);
}
Http2Stream.this.cancelStreamIfNecessary();
}
}
public void cancelStreamIfNecessary() {
boolean z;
boolean isOpen;
synchronized (this) {
try {
FramingSource framingSource = this.source;
if (!framingSource.finished && framingSource.closed) {
FramingSink framingSink = this.sink;
if (!framingSink.finished) {
if (framingSink.closed) {
}
}
z = true;
isOpen = isOpen();
}
z = false;
isOpen = isOpen();
} catch (Throwable th) {
throw th;
}
}
if (z) {
close(ErrorCode.CANCEL, null);
} else {
if (isOpen) {
return;
}
this.connection.removeStream(this.id);
}
}
public final class FramingSink implements Sink {
public boolean closed;
public boolean finished;
public final Buffer sendBuffer = new Buffer();
public Headers trailers;
public FramingSink() {
}
@Override // okio.Sink
public void write(Buffer buffer, long j) {
this.sendBuffer.write(buffer, j);
while (this.sendBuffer.size() >= PlaybackStateCompat.ACTION_PREPARE) {
emitFrame(false);
}
}
public final void emitFrame(boolean z) {
Http2Stream http2Stream;
long min;
Http2Stream http2Stream2;
boolean z2;
synchronized (Http2Stream.this) {
Http2Stream.this.writeTimeout.enter();
while (true) {
try {
http2Stream = Http2Stream.this;
if (http2Stream.bytesLeftInWriteWindow > 0 || this.finished || this.closed || http2Stream.errorCode != null) {
break;
} else {
http2Stream.waitForIo();
}
} finally {
Http2Stream.this.writeTimeout.exitAndThrowIfTimedOut();
}
}
http2Stream.writeTimeout.exitAndThrowIfTimedOut();
Http2Stream.this.checkOutNotClosed();
min = Math.min(Http2Stream.this.bytesLeftInWriteWindow, this.sendBuffer.size());
http2Stream2 = Http2Stream.this;
http2Stream2.bytesLeftInWriteWindow -= min;
}
http2Stream2.writeTimeout.enter();
if (z) {
try {
if (min == this.sendBuffer.size()) {
z2 = true;
boolean z3 = z2;
Http2Stream http2Stream3 = Http2Stream.this;
http2Stream3.connection.writeData(http2Stream3.id, z3, this.sendBuffer, min);
}
} catch (Throwable th) {
throw th;
}
}
z2 = false;
boolean z32 = z2;
Http2Stream http2Stream32 = Http2Stream.this;
http2Stream32.connection.writeData(http2Stream32.id, z32, this.sendBuffer, min);
}
@Override // okio.Sink, java.io.Flushable
public void flush() {
synchronized (Http2Stream.this) {
Http2Stream.this.checkOutNotClosed();
}
while (this.sendBuffer.size() > 0) {
emitFrame(false);
Http2Stream.this.connection.flush();
}
}
@Override // okio.Sink
public Timeout timeout() {
return Http2Stream.this.writeTimeout;
}
@Override // okio.Sink, java.io.Closeable, java.lang.AutoCloseable
public void close() {
synchronized (Http2Stream.this) {
try {
if (this.closed) {
return;
}
if (!Http2Stream.this.sink.finished) {
boolean z = this.sendBuffer.size() > 0;
if (this.trailers != null) {
while (this.sendBuffer.size() > 0) {
emitFrame(false);
}
Http2Stream http2Stream = Http2Stream.this;
http2Stream.connection.writeHeaders(http2Stream.id, true, Util.toHeaderBlock(this.trailers));
} else if (z) {
while (this.sendBuffer.size() > 0) {
emitFrame(true);
}
} else {
Http2Stream http2Stream2 = Http2Stream.this;
http2Stream2.connection.writeData(http2Stream2.id, true, null, 0L);
}
}
synchronized (Http2Stream.this) {
this.closed = true;
}
Http2Stream.this.connection.flush();
Http2Stream.this.cancelStreamIfNecessary();
} catch (Throwable th) {
throw th;
}
}
}
}
public void addBytesToWriteWindow(long j) {
this.bytesLeftInWriteWindow += j;
if (j > 0) {
notifyAll();
}
}
public void checkOutNotClosed() {
FramingSink framingSink = this.sink;
if (framingSink.closed) {
throw new IOException("stream closed");
}
if (framingSink.finished) {
throw new IOException("stream finished");
}
if (this.errorCode != null) {
IOException iOException = this.errorException;
if (iOException == null) {
throw new StreamResetException(this.errorCode);
}
}
}
public void waitForIo() {
try {
wait();
} catch (InterruptedException unused) {
Thread.currentThread().interrupt();
throw new InterruptedIOException();
}
}
public class StreamTimeout extends AsyncTimeout {
public StreamTimeout() {
}
@Override // okio.AsyncTimeout
public void timedOut() {
Http2Stream.this.closeLater(ErrorCode.CANCEL);
Http2Stream.this.connection.sendDegradedPingLater();
}
@Override // okio.AsyncTimeout
public IOException newTimeoutException(IOException iOException) {
SocketTimeoutException socketTimeoutException = new SocketTimeoutException("timeout");
if (iOException != null) {
socketTimeoutException.initCause(iOException);
}
return socketTimeoutException;
}
public void exitAndThrowIfTimedOut() {
if (exit()) {
throw newTimeoutException(null);
}
}
}
}

View File

@@ -0,0 +1,240 @@
package okhttp3.internal.http2;
import csdk.gluads.Consts;
import java.io.Closeable;
import java.io.IOException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import okhttp3.internal.Util;
import okhttp3.internal.http2.Hpack;
import okio.Buffer;
import okio.BufferedSink;
/* loaded from: classes5.dex */
public final class Http2Writer implements Closeable {
public static final Logger logger = Logger.getLogger(Http2.class.getName());
public final boolean client;
public boolean closed;
public final Buffer hpackBuffer;
public final Hpack.Writer hpackWriter;
public int maxFrameSize;
public final BufferedSink sink;
public int maxDataLength() {
return this.maxFrameSize;
}
public Http2Writer(BufferedSink bufferedSink, boolean z) {
this.sink = bufferedSink;
this.client = z;
Buffer buffer = new Buffer();
this.hpackBuffer = buffer;
this.hpackWriter = new Hpack.Writer(buffer);
this.maxFrameSize = 16384;
}
public synchronized void connectionPreface() {
try {
if (this.closed) {
throw new IOException(Consts.PLACEMENT_STATUS_CLOSED);
}
if (this.client) {
Logger logger2 = logger;
if (logger2.isLoggable(Level.FINE)) {
logger2.fine(Util.format(">> CONNECTION %s", Http2.CONNECTION_PREFACE.hex()));
}
this.sink.write(Http2.CONNECTION_PREFACE.toByteArray());
this.sink.flush();
}
} catch (Throwable th) {
throw th;
}
}
public synchronized void applyAndAckSettings(Settings settings) {
try {
if (this.closed) {
throw new IOException(Consts.PLACEMENT_STATUS_CLOSED);
}
this.maxFrameSize = settings.getMaxFrameSize(this.maxFrameSize);
if (settings.getHeaderTableSize() != -1) {
this.hpackWriter.setHeaderTableSizeSetting(settings.getHeaderTableSize());
}
frameHeader(0, 0, (byte) 4, (byte) 1);
this.sink.flush();
} catch (Throwable th) {
throw th;
}
}
public synchronized void pushPromise(int i, int i2, List list) {
if (this.closed) {
throw new IOException(Consts.PLACEMENT_STATUS_CLOSED);
}
this.hpackWriter.writeHeaders(list);
long size = this.hpackBuffer.size();
int min = (int) Math.min(this.maxFrameSize - 4, size);
long j = min;
frameHeader(i, min + 4, (byte) 5, size == j ? (byte) 4 : (byte) 0);
this.sink.writeInt(i2 & Integer.MAX_VALUE);
this.sink.write(this.hpackBuffer, j);
if (size > j) {
writeContinuationFrames(i, size - j);
}
}
public synchronized void flush() {
if (this.closed) {
throw new IOException(Consts.PLACEMENT_STATUS_CLOSED);
}
this.sink.flush();
}
public synchronized void rstStream(int i, ErrorCode errorCode) {
if (this.closed) {
throw new IOException(Consts.PLACEMENT_STATUS_CLOSED);
}
if (errorCode.httpCode == -1) {
throw new IllegalArgumentException();
}
frameHeader(i, 4, (byte) 3, (byte) 0);
this.sink.writeInt(errorCode.httpCode);
this.sink.flush();
}
public synchronized void data(boolean z, int i, Buffer buffer, int i2) {
if (this.closed) {
throw new IOException(Consts.PLACEMENT_STATUS_CLOSED);
}
dataFrame(i, z ? (byte) 1 : (byte) 0, buffer, i2);
}
public void dataFrame(int i, byte b, Buffer buffer, int i2) {
frameHeader(i, i2, (byte) 0, b);
if (i2 > 0) {
this.sink.write(buffer, i2);
}
}
public synchronized void settings(Settings settings) {
try {
if (this.closed) {
throw new IOException(Consts.PLACEMENT_STATUS_CLOSED);
}
int i = 0;
frameHeader(0, settings.size() * 6, (byte) 4, (byte) 0);
while (i < 10) {
if (settings.isSet(i)) {
this.sink.writeShort(i == 4 ? 3 : i == 7 ? 4 : i);
this.sink.writeInt(settings.get(i));
}
i++;
}
this.sink.flush();
} catch (Throwable th) {
throw th;
}
}
public synchronized void ping(boolean z, int i, int i2) {
if (this.closed) {
throw new IOException(Consts.PLACEMENT_STATUS_CLOSED);
}
frameHeader(0, 8, (byte) 6, z ? (byte) 1 : (byte) 0);
this.sink.writeInt(i);
this.sink.writeInt(i2);
this.sink.flush();
}
public synchronized void goAway(int i, ErrorCode errorCode, byte[] bArr) {
try {
if (this.closed) {
throw new IOException(Consts.PLACEMENT_STATUS_CLOSED);
}
if (errorCode.httpCode == -1) {
throw Http2.illegalArgument("errorCode.httpCode == -1", new Object[0]);
}
frameHeader(0, bArr.length + 8, (byte) 7, (byte) 0);
this.sink.writeInt(i);
this.sink.writeInt(errorCode.httpCode);
if (bArr.length > 0) {
this.sink.write(bArr);
}
this.sink.flush();
} catch (Throwable th) {
throw th;
}
}
public synchronized void windowUpdate(int i, long j) {
if (this.closed) {
throw new IOException(Consts.PLACEMENT_STATUS_CLOSED);
}
if (j == 0 || j > 2147483647L) {
throw Http2.illegalArgument("windowSizeIncrement == 0 || windowSizeIncrement > 0x7fffffffL: %s", Long.valueOf(j));
}
frameHeader(i, 4, (byte) 8, (byte) 0);
this.sink.writeInt((int) j);
this.sink.flush();
}
public void frameHeader(int i, int i2, byte b, byte b2) {
Logger logger2 = logger;
if (logger2.isLoggable(Level.FINE)) {
logger2.fine(Http2.frameLog(false, i, i2, b, b2));
}
int i3 = this.maxFrameSize;
if (i2 > i3) {
throw Http2.illegalArgument("FRAME_SIZE_ERROR length > %d: %d", Integer.valueOf(i3), Integer.valueOf(i2));
}
if ((Integer.MIN_VALUE & i) != 0) {
throw Http2.illegalArgument("reserved bit set: %s", Integer.valueOf(i));
}
writeMedium(this.sink, i2);
this.sink.writeByte(b & 255);
this.sink.writeByte(b2 & 255);
this.sink.writeInt(i & Integer.MAX_VALUE);
}
@Override // java.io.Closeable, java.lang.AutoCloseable
public synchronized void close() {
this.closed = true;
this.sink.close();
}
public static void writeMedium(BufferedSink bufferedSink, int i) {
bufferedSink.writeByte((i >>> 16) & 255);
bufferedSink.writeByte((i >>> 8) & 255);
bufferedSink.writeByte(i & 255);
}
public final void writeContinuationFrames(int i, long j) {
while (j > 0) {
int min = (int) Math.min(this.maxFrameSize, j);
long j2 = min;
j -= j2;
frameHeader(i, min, (byte) 9, j == 0 ? (byte) 4 : (byte) 0);
this.sink.write(this.hpackBuffer, j2);
}
}
public synchronized void headers(boolean z, int i, List list) {
if (this.closed) {
throw new IOException(Consts.PLACEMENT_STATUS_CLOSED);
}
this.hpackWriter.writeHeaders(list);
long size = this.hpackBuffer.size();
int min = (int) Math.min(this.maxFrameSize, size);
long j = min;
byte b = size == j ? (byte) 4 : (byte) 0;
if (z) {
b = (byte) (b | 1);
}
frameHeader(i, min, (byte) 1, b);
this.sink.write(this.hpackBuffer, j);
if (size > j) {
writeContinuationFrames(i, size - j);
}
}
}

View File

@@ -0,0 +1,136 @@
package okhttp3.internal.http2;
import androidx.core.view.PointerIconCompat;
import com.applovin.exoplayer2.common.base.Ascii;
import com.vungle.ads.internal.signals.SignalKey;
import java.io.ByteArrayOutputStream;
import okio.BufferedSink;
import okio.ByteString;
/* loaded from: classes5.dex */
public class Huffman {
public static final int[] CODES = {8184, 8388568, 268435426, 268435427, 268435428, 268435429, 268435430, 268435431, 268435432, 16777194, 1073741820, 268435433, 268435434, 1073741821, 268435435, 268435436, 268435437, 268435438, 268435439, 268435440, 268435441, 268435442, 1073741822, 268435443, 268435444, 268435445, 268435446, 268435447, 268435448, 268435449, 268435450, 268435451, 20, 1016, PointerIconCompat.TYPE_TOP_LEFT_DIAGONAL_DOUBLE_ARROW, 4090, 8185, 21, 248, 2042, 1018, 1019, 249, 2043, 250, 22, 23, 24, 0, 1, 2, 25, 26, 27, 28, 29, 30, 31, 92, 251, 32764, 32, 4091, 1020, 8186, 33, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, SignalKey.EVENT_ID, 108, 109, 110, 111, 112, 113, 114, 252, 115, 253, 8187, 524272, 8188, 16380, 34, 32765, 3, 35, 4, 36, 5, 37, 38, 39, 6, 116, 117, 40, 41, 42, 7, 43, 118, 44, 8, 9, 45, 119, 120, 121, 122, 123, 32766, 2044, 16381, 8189, 268435452, 1048550, 4194258, 1048551, 1048552, 4194259, 4194260, 4194261, 8388569, 4194262, 8388570, 8388571, 8388572, 8388573, 8388574, 16777195, 8388575, 16777196, 16777197, 4194263, 8388576, 16777198, 8388577, 8388578, 8388579, 8388580, 2097116, 4194264, 8388581, 4194265, 8388582, 8388583, 16777199, 4194266, 2097117, 1048553, 4194267, 4194268, 8388584, 8388585, 2097118, 8388586, 4194269, 4194270, 16777200, 2097119, 4194271, 8388587, 8388588, 2097120, 2097121, 4194272, 2097122, 8388589, 4194273, 8388590, 8388591, 1048554, 4194274, 4194275, 4194276, 8388592, 4194277, 4194278, 8388593, 67108832, 67108833, 1048555, 524273, 4194279, 8388594, 4194280, 33554412, 67108834, 67108835, 67108836, 134217694, 134217695, 67108837, 16777201, 33554413, 524274, 2097123, 67108838, 134217696, 134217697, 67108839, 134217698, 16777202, 2097124, 2097125, 67108840, 67108841, 268435453, 134217699, 134217700, 134217701, 1048556, 16777203, 1048557, 2097126, 4194281, 2097127, 2097128, 8388595, 4194282, 4194283, 33554414, 33554415, 16777204, 16777205, 67108842, 8388596, 67108843, 134217702, 67108844, 67108845, 134217703, 134217704, 134217705, 134217706, 134217707, 268435454, 134217708, 134217709, 134217710, 134217711, 134217712, 67108846};
public static final byte[] CODE_LENGTHS = {Ascii.CR, Ascii.ETB, Ascii.FS, Ascii.FS, Ascii.FS, Ascii.FS, Ascii.FS, Ascii.FS, Ascii.FS, Ascii.CAN, Ascii.RS, Ascii.FS, Ascii.FS, Ascii.RS, Ascii.FS, Ascii.FS, Ascii.FS, Ascii.FS, Ascii.FS, Ascii.FS, Ascii.FS, Ascii.FS, Ascii.RS, Ascii.FS, Ascii.FS, Ascii.FS, Ascii.FS, Ascii.FS, Ascii.FS, Ascii.FS, Ascii.FS, Ascii.FS, 6, 10, 10, Ascii.FF, Ascii.CR, 6, 8, Ascii.VT, 10, 10, 8, Ascii.VT, 8, 6, 6, 6, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 7, 8, Ascii.SI, 6, Ascii.FF, 10, Ascii.CR, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 7, 8, Ascii.CR, 19, Ascii.CR, Ascii.SO, 6, Ascii.SI, 5, 6, 5, 6, 5, 6, 6, 6, 5, 7, 7, 6, 6, 6, 5, 6, 7, 6, 5, 5, 6, 7, 7, 7, 7, 7, Ascii.SI, Ascii.VT, Ascii.SO, Ascii.CR, Ascii.FS, Ascii.DC4, Ascii.SYN, Ascii.DC4, Ascii.DC4, Ascii.SYN, Ascii.SYN, Ascii.SYN, Ascii.ETB, Ascii.SYN, Ascii.ETB, Ascii.ETB, Ascii.ETB, Ascii.ETB, Ascii.ETB, Ascii.CAN, Ascii.ETB, Ascii.CAN, Ascii.CAN, Ascii.SYN, Ascii.ETB, Ascii.CAN, Ascii.ETB, Ascii.ETB, Ascii.ETB, Ascii.ETB, Ascii.NAK, Ascii.SYN, Ascii.ETB, Ascii.SYN, Ascii.ETB, Ascii.ETB, Ascii.CAN, Ascii.SYN, Ascii.NAK, Ascii.DC4, Ascii.SYN, Ascii.SYN, Ascii.ETB, Ascii.ETB, Ascii.NAK, Ascii.ETB, Ascii.SYN, Ascii.SYN, Ascii.CAN, Ascii.NAK, Ascii.SYN, Ascii.ETB, Ascii.ETB, Ascii.NAK, Ascii.NAK, Ascii.SYN, Ascii.NAK, Ascii.ETB, Ascii.SYN, Ascii.ETB, Ascii.ETB, Ascii.DC4, Ascii.SYN, Ascii.SYN, Ascii.SYN, Ascii.ETB, Ascii.SYN, Ascii.SYN, Ascii.ETB, Ascii.SUB, Ascii.SUB, Ascii.DC4, 19, Ascii.SYN, Ascii.ETB, Ascii.SYN, Ascii.EM, Ascii.SUB, Ascii.SUB, Ascii.SUB, Ascii.ESC, Ascii.ESC, Ascii.SUB, Ascii.CAN, Ascii.EM, 19, Ascii.NAK, Ascii.SUB, Ascii.ESC, Ascii.ESC, Ascii.SUB, Ascii.ESC, Ascii.CAN, Ascii.NAK, Ascii.NAK, Ascii.SUB, Ascii.SUB, Ascii.FS, Ascii.ESC, Ascii.ESC, Ascii.ESC, Ascii.DC4, Ascii.CAN, Ascii.DC4, Ascii.NAK, Ascii.SYN, Ascii.NAK, Ascii.NAK, Ascii.ETB, Ascii.SYN, Ascii.SYN, Ascii.EM, Ascii.EM, Ascii.CAN, Ascii.CAN, Ascii.SUB, Ascii.ETB, Ascii.SUB, Ascii.ESC, Ascii.SUB, Ascii.SUB, Ascii.ESC, Ascii.ESC, Ascii.ESC, Ascii.ESC, Ascii.ESC, Ascii.FS, Ascii.ESC, Ascii.ESC, Ascii.ESC, Ascii.ESC, Ascii.ESC, Ascii.SUB};
public static final Huffman INSTANCE = new Huffman();
public final Node root = new Node();
public static Huffman get() {
return INSTANCE;
}
public Huffman() {
buildTree();
}
public void encode(ByteString byteString, BufferedSink bufferedSink) {
long j = 0;
int i = 0;
for (int i2 = 0; i2 < byteString.size(); i2++) {
int i3 = byteString.getByte(i2) & 255;
int i4 = CODES[i3];
byte b = CODE_LENGTHS[i3];
j = (j << b) | i4;
i += b;
while (i >= 8) {
i -= 8;
bufferedSink.writeByte((int) (j >> i));
}
}
if (i > 0) {
bufferedSink.writeByte((int) ((j << (8 - i)) | (255 >>> i)));
}
}
public int encodedLength(ByteString byteString) {
long j = 0;
for (int i = 0; i < byteString.size(); i++) {
j += CODE_LENGTHS[byteString.getByte(i) & 255];
}
return (int) ((j + 7) >> 3);
}
public byte[] decode(byte[] bArr) {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
Node node = this.root;
int i = 0;
int i2 = 0;
for (byte b : bArr) {
i = (i << 8) | (b & 255);
i2 += 8;
while (i2 >= 8) {
node = node.children[(i >>> (i2 - 8)) & 255];
if (node.children == null) {
byteArrayOutputStream.write(node.symbol);
i2 -= node.terminalBits;
node = this.root;
} else {
i2 -= 8;
}
}
}
while (i2 > 0) {
Node node2 = node.children[(i << (8 - i2)) & 255];
if (node2.children != null || node2.terminalBits > i2) {
break;
}
byteArrayOutputStream.write(node2.symbol);
i2 -= node2.terminalBits;
node = this.root;
}
return byteArrayOutputStream.toByteArray();
}
public final void buildTree() {
int i = 0;
while (true) {
byte[] bArr = CODE_LENGTHS;
if (i >= bArr.length) {
return;
}
addCode(i, CODES[i], bArr[i]);
i++;
}
}
public final void addCode(int i, int i2, byte b) {
Node node = new Node(i, b);
Node node2 = this.root;
while (b > 8) {
b = (byte) (b - 8);
int i3 = (i2 >>> b) & 255;
Node[] nodeArr = node2.children;
if (nodeArr == null) {
throw new IllegalStateException("invalid dictionary: prefix not unique");
}
if (nodeArr[i3] == null) {
nodeArr[i3] = new Node();
}
node2 = node2.children[i3];
}
int i4 = 8 - b;
int i5 = (i2 << i4) & 255;
int i6 = 1 << i4;
for (int i7 = i5; i7 < i5 + i6; i7++) {
node2.children[i7] = node;
}
}
public static final class Node {
public final Node[] children;
public final int symbol;
public final int terminalBits;
public Node() {
this.children = new Node[256];
this.symbol = 0;
this.terminalBits = 0;
}
public Node(int i, int i2) {
this.children = null;
this.symbol = i;
int i3 = i2 & 7;
this.terminalBits = i3 == 0 ? 8 : i3;
}
}
}

View File

@@ -0,0 +1,37 @@
package okhttp3.internal.http2;
import java.util.List;
import okio.BufferedSource;
/* loaded from: classes5.dex */
public interface PushObserver {
public static final PushObserver CANCEL = new PushObserver() { // from class: okhttp3.internal.http2.PushObserver.1
@Override // okhttp3.internal.http2.PushObserver
public boolean onHeaders(int i, List list, boolean z) {
return true;
}
@Override // okhttp3.internal.http2.PushObserver
public boolean onRequest(int i, List list) {
return true;
}
@Override // okhttp3.internal.http2.PushObserver
public void onReset(int i, ErrorCode errorCode) {
}
@Override // okhttp3.internal.http2.PushObserver
public boolean onData(int i, BufferedSource bufferedSource, int i2, boolean z) {
bufferedSource.skip(i2);
return true;
}
};
boolean onData(int i, BufferedSource bufferedSource, int i2, boolean z);
boolean onHeaders(int i, List list, boolean z);
boolean onRequest(int i, List list);
void onReset(int i, ErrorCode errorCode);
}

View File

@@ -0,0 +1,65 @@
package okhttp3.internal.http2;
import androidx.core.internal.view.SupportMenu;
import java.util.Arrays;
/* loaded from: classes5.dex */
public final class Settings {
public int set;
public final int[] values = new int[10];
public boolean isSet(int i) {
return ((1 << i) & this.set) != 0;
}
public void clear() {
this.set = 0;
Arrays.fill(this.values, 0);
}
public Settings set(int i, int i2) {
if (i >= 0) {
int[] iArr = this.values;
if (i < iArr.length) {
this.set = (1 << i) | this.set;
iArr[i] = i2;
}
}
return this;
}
public int get(int i) {
return this.values[i];
}
public int size() {
return Integer.bitCount(this.set);
}
public int getHeaderTableSize() {
if ((this.set & 2) != 0) {
return this.values[1];
}
return -1;
}
public int getMaxConcurrentStreams(int i) {
return (this.set & 16) != 0 ? this.values[4] : i;
}
public int getMaxFrameSize(int i) {
return (this.set & 32) != 0 ? this.values[5] : i;
}
public int getInitialWindowSize() {
return (this.set & 128) != 0 ? this.values[7] : SupportMenu.USER_MASK;
}
public void merge(Settings settings) {
for (int i = 0; i < 10; i++) {
if (settings.isSet(i)) {
set(i, settings.get(i));
}
}
}
}

View File

@@ -0,0 +1,13 @@
package okhttp3.internal.http2;
import java.io.IOException;
/* loaded from: classes5.dex */
public final class StreamResetException extends IOException {
public final ErrorCode errorCode;
public StreamResetException(ErrorCode errorCode) {
super("stream was reset: " + errorCode);
this.errorCode = errorCode;
}
}