|
26 | 26 |
|
27 | 27 | import java.io.IOException;
|
28 | 28 | import java.net.InetAddress;
|
29 |
| -import java.net.NetworkInterface; |
30 | 29 | import java.net.SocketException;
|
31 | 30 | import java.net.URI;
|
32 | 31 | import java.net.URISyntaxException;
|
33 | 32 | import java.nio.channels.CompletionHandler;
|
34 | 33 | import java.security.NoSuchAlgorithmException;
|
35 |
| -import java.util.Enumeration; |
36 | 34 | import java.util.UUID;
|
37 | 35 |
|
38 | 36 | import diskCacheV111.util.CacheException;
|
@@ -279,54 +277,18 @@ private void sendAddressToDoor(HttpMover mover, int port, UUID uuid)
|
279 | 277 | private URI getUri(HttpProtocolInfo protocolInfo, int port, UUID uuid)
|
280 | 278 | throws SocketException, CacheException, URISyntaxException
|
281 | 279 | {
|
282 |
| - URI targetURI = null; |
283 | 280 | String path = protocolInfo.getPath();
|
284 | 281 | if (!path.startsWith("/")) {
|
285 | 282 | path = "/" + path;
|
286 | 283 | }
|
287 |
| - // try to pick the ip address with corresponds to the |
288 |
| - // hostname (which is hopefully visible to the world) |
289 | 284 | InetAddress localIP =
|
290 | 285 | NetworkUtils.getLocalAddress(protocolInfo.getSocketAddress().getAddress());
|
291 |
| - |
292 |
| - if (localIP != null && !localIP.isLoopbackAddress()) { |
293 |
| - // the ip we got from the hostname is at least not |
294 |
| - // 127.0.01 and from the IP4-family |
295 |
| - targetURI = new URI(PROTOCOL_HTTP, |
296 |
| - null, |
297 |
| - localIP.getCanonicalHostName(), |
298 |
| - port, |
299 |
| - path, |
300 |
| - UUID_QUERY_PARAM + QUERY_PARAM_ASSIGN + uuid.toString(), |
301 |
| - null); |
302 |
| - } else { |
303 |
| - // let's loop through the network interfaces |
304 |
| - Enumeration<NetworkInterface> ifList = NetworkInterface.getNetworkInterfaces(); |
305 |
| - while (ifList.hasMoreElements()) { |
306 |
| - NetworkInterface netif = ifList.nextElement(); |
307 |
| - Enumeration<InetAddress> ips = netif.getInetAddresses(); |
308 |
| - while (ips.hasMoreElements()) { |
309 |
| - InetAddress addr = ips.nextElement(); |
310 |
| - // check again each ip from each interface. |
311 |
| - // WARNING: multiple ip addresses in case of |
312 |
| - // multiple ifs could be selected, we can't |
313 |
| - // determine the "correct" one |
314 |
| - if (!addr.isLoopbackAddress()) { |
315 |
| - targetURI = new URI(PROTOCOL_HTTP, |
316 |
| - null, |
317 |
| - localIP.getCanonicalHostName(), |
318 |
| - port, |
319 |
| - path, |
320 |
| - UUID_QUERY_PARAM + QUERY_PARAM_ASSIGN + uuid.toString(), |
321 |
| - null); |
322 |
| - } |
323 |
| - } |
324 |
| - } |
325 |
| - if (targetURI == null) { |
326 |
| - throw new CacheException("Error: Cannot determine my ip " + |
327 |
| - "address. Aborting transfer"); |
328 |
| - } |
329 |
| - } |
330 |
| - return targetURI; |
| 286 | + return new URI(PROTOCOL_HTTP, |
| 287 | + null, |
| 288 | + localIP.getCanonicalHostName(), |
| 289 | + port, |
| 290 | + path, |
| 291 | + UUID_QUERY_PARAM + QUERY_PARAM_ASSIGN + uuid.toString(), |
| 292 | + null); |
331 | 293 | }
|
332 | 294 | }
|
0 commit comments