From ef6f61426f249d09ec15735a0c6eab23ffc86f80 Mon Sep 17 00:00:00 2001 From: akwizgran <akwizgran@users.sourceforge.net> Date: Tue, 8 Nov 2011 13:14:23 +0000 Subject: [PATCH] Removed calls to supportsMulticast() for Java 1.5 compatibility. --- .../plugins/bluetooth/AbstractListener.java | 2 +- .../briar/plugins/socket/LanSocketPlugin.java | 42 ++----------------- .../plugins/socket/SimpleSocketPlugin.java | 12 +++--- 3 files changed, 11 insertions(+), 45 deletions(-) diff --git a/components/net/sf/briar/plugins/bluetooth/AbstractListener.java b/components/net/sf/briar/plugins/bluetooth/AbstractListener.java index e367d51874..8a0815dd44 100644 --- a/components/net/sf/briar/plugins/bluetooth/AbstractListener.java +++ b/components/net/sf/briar/plugins/bluetooth/AbstractListener.java @@ -53,7 +53,7 @@ abstract class AbstractListener implements DiscoveryListener { protected void findNestedClassIds(Object o, Collection<String> ids) { o = getDataElementValue(o); - if(o instanceof Enumeration) { + if(o instanceof Enumeration<?>) { for(Object o1 : Collections.list((Enumeration<?>) o)) { findNestedClassIds(o1, ids); } diff --git a/components/net/sf/briar/plugins/socket/LanSocketPlugin.java b/components/net/sf/briar/plugins/socket/LanSocketPlugin.java index 15c5cdd623..4cd0d9efbd 100644 --- a/components/net/sf/briar/plugins/socket/LanSocketPlugin.java +++ b/components/net/sf/briar/plugins/socket/LanSocketPlugin.java @@ -5,14 +5,10 @@ import java.net.DatagramPacket; import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.MulticastSocket; -import java.net.NetworkInterface; import java.net.ServerSocket; import java.net.Socket; import java.net.SocketTimeoutException; import java.net.UnknownHostException; -import java.util.Collections; -import java.util.Enumeration; -import java.util.List; import java.util.Random; import java.util.concurrent.Executor; import java.util.logging.Level; @@ -45,7 +41,7 @@ public class LanSocketPlugin extends SimpleSocketPlugin { // Bind a multicast socket for receiving packets MulticastSocket ms = null; try { - InetAddress iface = chooseMulticastInterface(); + InetAddress iface = chooseInterface(true); ms = new MulticastSocket(mcast.getPort()); ms.setInterface(iface); ms.joinGroup(mcast.getAddress()); @@ -135,38 +131,6 @@ public class LanSocketPlugin extends SimpleSocketPlugin { return b; } - private InetAddress chooseMulticastInterface() throws IOException { - // Try to find a LAN interface that supports multicast - List<NetworkInterface> ifaces = - Collections.list(NetworkInterface.getNetworkInterfaces()); - for(NetworkInterface iface : ifaces) { - if(iface.supportsMulticast()) { - Enumeration<InetAddress> addrs = iface.getInetAddresses(); - for(InetAddress addr : Collections.list(addrs)) { - if(addr.isLinkLocalAddress() || addr.isSiteLocalAddress()) { - if(LOG.isLoggable(Level.INFO)) - LOG.info("Preferring " + addr.getHostAddress()); - return addr; - } - } - } - } - // Settle for a WAN interface that supports multicast - for(NetworkInterface iface : ifaces) { - if(iface.supportsMulticast()) { - Enumeration<InetAddress> addrs = iface.getInetAddresses(); - for(InetAddress addr : Collections.list(addrs)) { - if(!addr.isLoopbackAddress()) { - if(LOG.isLoggable(Level.INFO)) - LOG.info("Accepting " + addr.getHostAddress()); - return addr; - } - } - } - } - throw new IOException("No suitable interfaces for multicast"); - } - private int parsePacket(byte[] b, int off, int len) { if(len != 2) return 0; return ByteUtils.readUint16(b, off); @@ -179,7 +143,7 @@ public class LanSocketPlugin extends SimpleSocketPlugin { // Bind a TCP socket for receiving connections ServerSocket ss = null; try { - InetAddress iface = chooseTcpInterface(true); + InetAddress iface = chooseInterface(true); ss = new ServerSocket(); ss.bind(new InetSocketAddress(iface, 0)); } catch(IOException e) { @@ -197,7 +161,7 @@ public class LanSocketPlugin extends SimpleSocketPlugin { // Bind a multicast socket for sending packets MulticastSocket ms = null; try { - InetAddress iface = chooseMulticastInterface(); + InetAddress iface = chooseInterface(true); ms = new MulticastSocket(); ms.setInterface(iface); } catch(IOException e) { diff --git a/components/net/sf/briar/plugins/socket/SimpleSocketPlugin.java b/components/net/sf/briar/plugins/socket/SimpleSocketPlugin.java index 1c0c2d55ef..84a273c562 100644 --- a/components/net/sf/briar/plugins/socket/SimpleSocketPlugin.java +++ b/components/net/sf/briar/plugins/socket/SimpleSocketPlugin.java @@ -65,7 +65,7 @@ class SimpleSocketPlugin extends SocketPlugin { SocketAddress addr = createSocketAddress(callback.getLocalProperties()); if(addr == null) { try { - return new InetSocketAddress(chooseTcpInterface(false), 0); + return new InetSocketAddress(chooseInterface(false), 0); } catch(IOException e) { if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.getMessage()); } @@ -73,7 +73,7 @@ class SimpleSocketPlugin extends SocketPlugin { return addr; } - protected InetAddress chooseTcpInterface(boolean lan) throws IOException { + protected InetAddress chooseInterface(boolean lan) throws IOException { List<NetworkInterface> ifaces = Collections.list(NetworkInterface.getNetworkInterfaces()); // Try to find an interface of the preferred type (LAN or WAN) @@ -84,7 +84,8 @@ class SimpleSocketPlugin extends SocketPlugin { boolean site = addr.isSiteLocalAddress(); if(lan == (link || site)) { if(LOG.isLoggable(Level.INFO)) - LOG.info("Preferring " + addr.getHostAddress()); + LOG.info("Choosing interface " + + addr.getHostAddress()); return addr; } } @@ -95,12 +96,13 @@ class SimpleSocketPlugin extends SocketPlugin { for(InetAddress addr : Collections.list(iface.getInetAddresses())) { if(!addr.isLoopbackAddress()) { if(LOG.isLoggable(Level.INFO)) - LOG.info("Accepting " + addr.getHostAddress()); + LOG.info("Accepting interface " + + addr.getHostAddress()); return addr; } } } - throw new IOException("No suitable interfaces for TCP"); + throw new IOException("No suitable interfaces"); } @Override -- GitLab