RouteSelector.java
6.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
package com.squareup.okhttp.internal.http;
import com.squareup.okhttp.Address;
import com.squareup.okhttp.Dns;
import com.squareup.okhttp.HttpUrl;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.Route;
import com.squareup.okhttp.internal.Internal;
import com.squareup.okhttp.internal.RouteDatabase;
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.Proxy.Type;
import java.net.ProxySelector;
import java.net.SocketException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.NoSuchElementException;
public final class RouteSelector
{
private final Address address;
private final OkHttpClient client;
private List<InetSocketAddress> inetSocketAddresses = Collections.emptyList();
private InetSocketAddress lastInetSocketAddress;
private Proxy lastProxy;
private int nextInetSocketAddressIndex;
private int nextProxyIndex;
private final List<Route> postponedRoutes = new ArrayList();
private List<Proxy> proxies = Collections.emptyList();
private final RouteDatabase routeDatabase;
private final HttpUrl url;
private RouteSelector(Address paramAddress, HttpUrl paramHttpUrl, OkHttpClient paramOkHttpClient)
{
this.address = paramAddress;
this.url = paramHttpUrl;
this.client = paramOkHttpClient;
this.routeDatabase = Internal.instance.routeDatabase(paramOkHttpClient);
resetNextProxy(paramHttpUrl, paramAddress.getProxy());
}
public static RouteSelector get(Address paramAddress, Request paramRequest, OkHttpClient paramOkHttpClient)
throws IOException
{
return new RouteSelector(paramAddress, paramRequest.httpUrl(), paramOkHttpClient);
}
static String getHostString(InetSocketAddress paramInetSocketAddress)
{
InetAddress localInetAddress = paramInetSocketAddress.getAddress();
if (localInetAddress == null) {
return paramInetSocketAddress.getHostName();
}
return localInetAddress.getHostAddress();
}
private boolean hasNextInetSocketAddress()
{
return this.nextInetSocketAddressIndex < this.inetSocketAddresses.size();
}
private boolean hasNextPostponed()
{
return !this.postponedRoutes.isEmpty();
}
private boolean hasNextProxy()
{
return this.nextProxyIndex < this.proxies.size();
}
private InetSocketAddress nextInetSocketAddress()
throws IOException
{
if (!hasNextInetSocketAddress()) {
throw new SocketException("No route to " + this.address.getUriHost() + "; exhausted inet socket addresses: " + this.inetSocketAddresses);
}
List localList = this.inetSocketAddresses;
int i = this.nextInetSocketAddressIndex;
this.nextInetSocketAddressIndex = (i + 1);
return (InetSocketAddress)localList.get(i);
}
private Route nextPostponed()
{
return (Route)this.postponedRoutes.remove(0);
}
private Proxy nextProxy()
throws IOException
{
if (!hasNextProxy()) {
throw new SocketException("No route to " + this.address.getUriHost() + "; exhausted proxy configurations: " + this.proxies);
}
Object localObject = this.proxies;
int i = this.nextProxyIndex;
this.nextProxyIndex = (i + 1);
localObject = (Proxy)((List)localObject).get(i);
resetNextInetSocketAddress((Proxy)localObject);
return (Proxy)localObject;
}
private void resetNextInetSocketAddress(Proxy paramProxy)
throws IOException
{
this.inetSocketAddresses = new ArrayList();
if ((paramProxy.type() == Proxy.Type.DIRECT) || (paramProxy.type() == Proxy.Type.SOCKS)) {
paramProxy = this.address.getUriHost();
}
Object localObject;
for (int i = this.address.getUriPort(); (i <= 0) || (i > 65535); i = ((InetSocketAddress)localObject).getPort())
{
throw new SocketException("No route to " + paramProxy + ":" + i + "; port is out of range");
paramProxy = paramProxy.address();
if (!(paramProxy instanceof InetSocketAddress)) {
throw new IllegalArgumentException("Proxy.address() is not an InetSocketAddress: " + paramProxy.getClass());
}
localObject = (InetSocketAddress)paramProxy;
paramProxy = getHostString((InetSocketAddress)localObject);
}
paramProxy = this.address.getDns().lookup(paramProxy);
int k = paramProxy.size();
int j = 0;
while (j < k)
{
localObject = (InetAddress)paramProxy.get(j);
this.inetSocketAddresses.add(new InetSocketAddress((InetAddress)localObject, i));
j += 1;
}
this.nextInetSocketAddressIndex = 0;
}
private void resetNextProxy(HttpUrl paramHttpUrl, Proxy paramProxy)
{
if (paramProxy != null) {
this.proxies = Collections.singletonList(paramProxy);
}
for (;;)
{
this.nextProxyIndex = 0;
return;
this.proxies = new ArrayList();
paramHttpUrl = this.client.getProxySelector().select(paramHttpUrl.uri());
if (paramHttpUrl != null) {
this.proxies.addAll(paramHttpUrl);
}
this.proxies.removeAll(Collections.singleton(Proxy.NO_PROXY));
this.proxies.add(Proxy.NO_PROXY);
}
}
public final void connectFailed(Route paramRoute, IOException paramIOException)
{
if ((paramRoute.getProxy().type() != Proxy.Type.DIRECT) && (this.address.getProxySelector() != null)) {
this.address.getProxySelector().connectFailed(this.url.uri(), paramRoute.getProxy().address(), paramIOException);
}
this.routeDatabase.failed(paramRoute);
}
public final boolean hasNext()
{
return (hasNextInetSocketAddress()) || (hasNextProxy()) || (hasNextPostponed());
}
public final Route next()
throws IOException
{
for (;;)
{
Object localObject;
if (!hasNextInetSocketAddress()) {
if (!hasNextProxy())
{
if (!hasNextPostponed()) {
throw new NoSuchElementException();
}
localObject = nextPostponed();
}
}
Route localRoute;
do
{
return (Route)localObject;
this.lastProxy = nextProxy();
this.lastInetSocketAddress = nextInetSocketAddress();
localRoute = new Route(this.address, this.lastProxy, this.lastInetSocketAddress);
localObject = localRoute;
} while (!this.routeDatabase.shouldPostpone(localRoute));
this.postponedRoutes.add(localRoute);
}
}
}
/* Location: /home/merong/decompile/hackery-dex2jar.jar!/com/squareup/okhttp/internal/http/RouteSelector.class
* Java compiler version: 6 (50.0)
* JD-Core Version: 0.7.1
*/