Skip to content

Commit 5f9fc31

Browse files
committed
pool: Clean up local interface resolution in HTTP transfer service
I don't see a reason for the complicated fallback in the loop - it appears that it would never be used. A similar change was recently made in the xrootd transfer service. Target: trunk Require-book: no Require-notes: no Acked-by: Paul Millar <paul.millar@desy.de> Patch: http://rb.dcache.org/r/5452/
1 parent 8739da0 commit 5f9fc31

File tree

1 file changed

+7
-45
lines changed

1 file changed

+7
-45
lines changed

modules/dcache/src/main/java/org/dcache/http/HttpTransferService.java

Lines changed: 7 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,11 @@
2626

2727
import java.io.IOException;
2828
import java.net.InetAddress;
29-
import java.net.NetworkInterface;
3029
import java.net.SocketException;
3130
import java.net.URI;
3231
import java.net.URISyntaxException;
3332
import java.nio.channels.CompletionHandler;
3433
import java.security.NoSuchAlgorithmException;
35-
import java.util.Enumeration;
3634
import java.util.UUID;
3735

3836
import diskCacheV111.util.CacheException;
@@ -279,54 +277,18 @@ private void sendAddressToDoor(HttpMover mover, int port, UUID uuid)
279277
private URI getUri(HttpProtocolInfo protocolInfo, int port, UUID uuid)
280278
throws SocketException, CacheException, URISyntaxException
281279
{
282-
URI targetURI = null;
283280
String path = protocolInfo.getPath();
284281
if (!path.startsWith("/")) {
285282
path = "/" + path;
286283
}
287-
// try to pick the ip address with corresponds to the
288-
// hostname (which is hopefully visible to the world)
289284
InetAddress localIP =
290285
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);
331293
}
332294
}

0 commit comments

Comments
 (0)