MD5 校验值:d555a6389a0a865314e2706996812829
RouteSelector.java 文件包含反编译后的源代码,请注意,该内容仅供学习和参考使用,不得用于非法用途。
package gkhttp3.internal.connection; import fodroidx.core.app.NotificationCompat; import fotlin.Metadata; import fotlin.collections.CollectionsKt; import fotlin.jvm.internal.DefaultConstructorMarker; import fotlin.jvm.internal.Intrinsics; import gkhttp3.Address; import gkhttp3.Call; import gkhttp3.EventListener; import gkhttp3.HttpUrl; import gkhttp3.Route; import java.io.IOException; import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.Proxy; import java.net.SocketAddress; import java.net.SocketException; import java.net.UnknownHostException; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.NoSuchElementException; @Metadata(bv = {1, 0, 3}, d1 = {"\u0000d\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010 \n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\b\n\u0000\n\u0002\u0010!\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u000b\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0002\b\u0003\u0018\u0000 !2\u00020\u0001:\u0002!\"B%\u0012\u0006\u0010\u0002\u001a\u00020\u0003\u0012\u0006\u0010\u0004\u001a\u00020\u0005\u0012\u0006\u0010\u0006\u001a\u00020\u0007\u0012\u0006\u0010\b\u001a\u00020\t¢\u0006\u0002\u0010\nJ\t\u0010\u0015\u001a\u00020\u0016H\u0086\u0002J\b\u0010\u0017\u001a\u00020\u0016H\u0002J\t\u0010\u0018\u001a\u00020\u0019H\u0086\u0002J\b\u0010\u001a\u001a\u00020\u0014H\u0002J\u0010\u0010\u001b\u001a\u00020\u001c2\u0006\u0010\u001d\u001a\u00020\u0014H\u0002J\u001a\u0010\u001e\u001a\u00020\u001c2\u0006\u0010\u001f\u001a\u00020 2\b\u0010\u001d\u001a\u0004\u0018\u00010\u0014H\u0002R\u000e\u0010\u0002\u001a\u00020\u0003X\u0082\u0004¢\u0006\u0002\n\u0000R\u000e\u0010\u0006\u001a\u00020\u0007X\u0082\u0004¢\u0006\u0002\n\u0000R\u000e\u0010\b\u001a\u00020\tX\u0082\u0004¢\u0006\u0002\n\u0000R\u0014\u0010\u000b\u001a\b\u0012\u0004\u0012\u00020\r0\fX\u0082\u000e¢\u0006\u0002\n\u0000R\u000e\u0010\u000e\u001a\u00020\u000fX\u0082\u000e¢\u0006\u0002\n\u0000R\u0014\u0010\u0010\u001a\b\u0012\u0004\u0012\u00020\u00120\u0011X\u0082\u0004¢\u0006\u0002\n\u0000R\u0014\u0010\u0013\u001a\b\u0012\u0004\u0012\u00020\u00140\fX\u0082\u000e¢\u0006\u0002\n\u0000R\u000e\u0010\u0004\u001a\u00020\u0005X\u0082\u0004¢\u0006\u0002\n\u0000¨\u0006#"}, d2 = {"Lgkhttp3/internal/connection/RouteSelector;", "", "address", "Lgkhttp3/Address;", "routeDatabase", "Lgkhttp3/internal/connection/RouteDatabase;", NotificationCompat.CATEGORY_CALL, "Lgkhttp3/Call;", "eventListener", "Lgkhttp3/EventListener;", "(Lgkhttp3/Address;Lgkhttp3/internal/connection/RouteDatabase;Lgkhttp3/Call;Lgkhttp3/EventListener;)V", "inetSocketAddresses", "", "Ljava/net/InetSocketAddress;", "nextProxyIndex", "", "postponedRoutes", "", "Lgkhttp3/Route;", "proxies", "Ljava/net/Proxy;", "hasNext", "", "hasNextProxy", "next", "Lgkhttp3/internal/connection/RouteSelector$Selection;", "nextProxy", "resetNextInetSocketAddress", "", "proxy", "resetNextProxy", "url", "Lgkhttp3/HttpUrl;", "Companion", "Selection", "okhttp"}, k = 1, mv = {1, 4, 0}) public final class RouteSelector { public static final Companion Companion = new Companion(null); private final Address address; private final Call call; private final EventListener eventListener; private List<? extends InetSocketAddress> inetSocketAddresses; private int nextProxyIndex; private final List<Route> postponedRoutes; private List<? extends Proxy> proxies; private final RouteDatabase routeDatabase; public RouteSelector(Address address, RouteDatabase routeDatabase, Call call, EventListener eventListener) { Intrinsics.checkNotNullParameter(address, "address"); Intrinsics.checkNotNullParameter(routeDatabase, "routeDatabase"); Intrinsics.checkNotNullParameter(call, NotificationCompat.CATEGORY_CALL); Intrinsics.checkNotNullParameter(eventListener, "eventListener"); this.address = address; this.routeDatabase = routeDatabase; this.call = call; this.eventListener = eventListener; this.proxies = CollectionsKt.emptyList(); this.inetSocketAddresses = CollectionsKt.emptyList(); this.postponedRoutes = new ArrayList(); resetNextProxy(address.url(), address.proxy()); } public final boolean hasNext() { return hasNextProxy() || (this.postponedRoutes.isEmpty() ^ true); } public final Selection next() throws IOException { if (!hasNext()) { throw new NoSuchElementException(); } ArrayList arrayList = new ArrayList(); while (hasNextProxy()) { Proxy nextProxy = nextProxy(); Iterator<? extends InetSocketAddress> it = this.inetSocketAddresses.iterator(); while (it.hasNext()) { Route route = new Route(this.address, nextProxy, it.next()); if (this.routeDatabase.shouldPostpone(route)) { this.postponedRoutes.add(route); } else { arrayList.add(route); } } if (!arrayList.isEmpty()) { break; } } if (arrayList.isEmpty()) { CollectionsKt.addAll(arrayList, this.postponedRoutes); this.postponedRoutes.clear(); } return new Selection(arrayList); } private final void resetNextProxy(HttpUrl httpUrl, Proxy proxy) { RouteSelector$resetNextProxy$1 routeSelector$resetNextProxy$1 = new RouteSelector$resetNextProxy$1(this, proxy, httpUrl); this.eventListener.proxySelectStart(this.call, httpUrl); List<? extends Proxy> invoke = routeSelector$resetNextProxy$1.invoke(); this.proxies = invoke; this.nextProxyIndex = 0; this.eventListener.proxySelectEnd(this.call, httpUrl, invoke); } private final boolean hasNextProxy() { return this.nextProxyIndex < this.proxies.size(); } private final Proxy nextProxy() throws IOException { if (!hasNextProxy()) { throw new SocketException("No route to " + this.address.url().host() + "; exhausted proxy configurations: " + this.proxies); } List<? extends Proxy> list = this.proxies; int i = this.nextProxyIndex; this.nextProxyIndex = i + 1; Proxy proxy = list.get(i); resetNextInetSocketAddress(proxy); return proxy; } private final void resetNextInetSocketAddress(Proxy proxy) throws IOException { String host; int port; ArrayList arrayList = new ArrayList(); this.inetSocketAddresses = arrayList; if (proxy.type() == Proxy.Type.DIRECT || proxy.type() == Proxy.Type.SOCKS) { host = this.address.url().host(); port = this.address.url().port(); } else { SocketAddress address = proxy.address(); if (!(address instanceof InetSocketAddress)) { throw new IllegalArgumentException(("Proxy.address() is not an InetSocketAddress: " + address.getClass()).toString()); } InetSocketAddress inetSocketAddress = (InetSocketAddress) address; host = Companion.getSocketHost(inetSocketAddress); port = inetSocketAddress.getPort(); } if (1 > port || 65535 < port) { throw new SocketException("No route to " + host + ':' + port + "; port is out of range"); } if (proxy.type() == Proxy.Type.SOCKS) { arrayList.add(InetSocketAddress.createUnresolved(host, port)); return; } this.eventListener.dnsStart(this.call, host); List<InetAddress> lookup = this.address.dns().lookup(host); if (lookup.isEmpty()) { throw new UnknownHostException(this.address.dns() + " returned no addresses for " + host); } this.eventListener.dnsEnd(this.call, host, lookup); Iterator<InetAddress> it = lookup.iterator(); while (it.hasNext()) { arrayList.add(new InetSocketAddress(it.next(), port)); } } @Metadata(bv = {1, 0, 3}, d1 = {"\u0000&\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0000\n\u0002\u0010 \n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\b\n\u0002\b\u0003\n\u0002\u0010\u000b\n\u0002\b\u0002\u0018\u00002\u00020\u0001B\u0013\u0012\f\u0010\u0002\u001a\b\u0012\u0004\u0012\u00020\u00040\u0003¢\u0006\u0002\u0010\u0005J\t\u0010\n\u001a\u00020\u000bH\u0086\u0002J\t\u0010\f\u001a\u00020\u0004H\u0086\u0002R\u000e\u0010\u0006\u001a\u00020\u0007X\u0082\u000e¢\u0006\u0002\n\u0000R\u0017\u0010\u0002\u001a\b\u0012\u0004\u0012\u00020\u00040\u0003¢\u0006\b\n\u0000\u001a\u0004\b\b\u0010\t¨\u0006\r"}, d2 = {"Lgkhttp3/internal/connection/RouteSelector$Selection;", "", "routes", "", "Lgkhttp3/Route;", "(Ljava/util/List;)V", "nextRouteIndex", "", "getRoutes", "()Ljava/util/List;", "hasNext", "", "next", "okhttp"}, k = 1, mv = {1, 4, 0}) public static final class Selection { private int nextRouteIndex; private final List<Route> routes; public Selection(List<Route> list) { Intrinsics.checkNotNullParameter(list, "routes"); this.routes = list; } public final List<Route> getRoutes() { return this.routes; } public final boolean hasNext() { return this.nextRouteIndex < this.routes.size(); } public final Route next() { if (!hasNext()) { throw new NoSuchElementException(); } List<Route> list = this.routes; int i = this.nextRouteIndex; this.nextRouteIndex = i + 1; return list.get(i); } } @Metadata(bv = {1, 0, 3}, d1 = {"\u0000\u0018\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\b\u0002\n\u0002\u0010\u000e\n\u0002\u0018\u0002\n\u0002\b\u0003\b\u0086\u0003\u0018\u00002\u00020\u0001B\u0007\b\u0002¢\u0006\u0002\u0010\u0002R\u0015\u0010\u0003\u001a\u00020\u0004*\u00020\u00058F¢\u0006\u0006\u001a\u0004\b\u0006\u0010\u0007¨\u0006\b"}, d2 = {"Lgkhttp3/internal/connection/RouteSelector$Companion;", "", "()V", "socketHost", "", "Ljava/net/InetSocketAddress;", "getSocketHost", "(Ljava/net/InetSocketAddress;)Ljava/lang/String;", "okhttp"}, k = 1, mv = {1, 4, 0}) public static final class Companion { private Companion() { } public Companion(DefaultConstructorMarker defaultConstructorMarker) { this(); } public final String getSocketHost(InetSocketAddress inetSocketAddress) { Intrinsics.checkNotNullParameter(inetSocketAddress, "$this$socketHost"); InetAddress address = inetSocketAddress.getAddress(); if (address == null) { String hostName = inetSocketAddress.getHostName(); Intrinsics.checkNotNullExpressionValue(hostName, "hostName"); return hostName; } String hostAddress = address.getHostAddress(); Intrinsics.checkNotNullExpressionValue(hostAddress, "address.hostAddress"); return hostAddress; } } }