Skip to content

Commit

Permalink
backported fix for cross-talking( https://jira.jboss.org/jira/browse/…
Browse files Browse the repository at this point in the history
  • Loading branch information
belaban committed Sep 18, 2008
1 parent 0190f20 commit 2fb438b
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 10 deletions.
20 changes: 17 additions & 3 deletions src/org/jgroups/protocols/UDP.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
* input buffer overflow, consider setting this property to true.
* </ul>
* @author Bela Ban
* @version $Id: UDP.java,v 1.156.2.9 2008/06/02 05:59:49 belaban Exp $
* @version $Id: UDP.java,v 1.156.2.10 2008/09/18 16:19:31 belaban Exp $
*/
public class UDP extends TP implements Runnable {

Expand All @@ -57,6 +57,12 @@ public class UDP extends TP implements Runnable {
*/
private static final BoundedList<Integer> last_ports_used=new BoundedList<Integer>(100);

private static final boolean is_linux; // are we running on Linux ?

static {
is_linux=Util.checkForLinux();
}

/** IP multicast socket for <em>sending</em> and <em>receiving</em> multicast packets */
MulticastSocket mcast_sock=null;

Expand Down Expand Up @@ -477,9 +483,17 @@ private void createSockets() throws Exception {
// 3. Create socket for receiving IP multicast packets
if(ip_mcast) {
// 3a. Create mcast receiver socket
mcast_sock=new MulticastSocket(mcast_port);
mcast_sock.setTimeToLive(ip_ttl);
tmp_addr=InetAddress.getByName(mcast_addr_name);

// https://jira.jboss.org/jira/browse/JGRP-777 - this doesn't work on MacOS, and we don't have
// cross talking on Windows anyway, so we just do it for Linux. (How about Solaris ?)
if(is_linux)
mcast_sock=Util.createMulticastSocket(tmp_addr, mcast_port, log);
else
mcast_sock=new MulticastSocket(mcast_port);

mcast_sock.setTimeToLive(ip_ttl);

mcast_addr=new IpAddress(tmp_addr, mcast_port);
if(tos > 0) {
try {
Expand Down
58 changes: 51 additions & 7 deletions src/org/jgroups/util/Util.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.jgroups.util;

import org.apache.commons.logging.LogFactory;
import org.apache.commons.logging.Log;
import org.jgroups.*;
import org.jgroups.auth.AuthToken;
import org.jgroups.conf.ClassConfigurator;
Expand Down Expand Up @@ -28,7 +29,7 @@
/**
* Collection of various utility routines that can not be assigned to other classes.
* @author Bela Ban
* @version $Id: Util.java,v 1.137.2.5 2008/07/22 08:03:53 belaban Exp $
* @version $Id: Util.java,v 1.137.2.6 2008/09/18 16:19:30 belaban Exp $
*/
public class Util {

Expand Down Expand Up @@ -2034,6 +2035,42 @@ public static DatagramSocket createDatagramSocket(InetAddress addr, int port) th
}


public static MulticastSocket createMulticastSocket(int port) throws IOException {
return createMulticastSocket(null, port, null);
}

public static MulticastSocket createMulticastSocket(InetAddress mcast_addr, int port, Log log) throws IOException {
if(mcast_addr != null && !mcast_addr.isMulticastAddress()) {
if(log != null && log.isWarnEnabled())
log.warn("mcast_addr (" + mcast_addr + ") is not a multicast address, will be ignored");
return new MulticastSocket(port);
}

SocketAddress saddr=new InetSocketAddress(mcast_addr, port);
MulticastSocket retval=null;

try {
retval=new MulticastSocket(saddr);
}
catch(IOException ex) {
if(log != null && log.isWarnEnabled()) {
StringBuilder sb=new StringBuilder();
String type=mcast_addr != null ? mcast_addr instanceof Inet4Address? "IPv4" : "IPv6" : "n/a";
sb.append("could not bind to " + mcast_addr + " (" + type + " address)");
sb.append("; make sure your mcast_addr is of the same type as the IP stack (IPv4 or IPv6).");
sb.append("\nWill ignore mcast_addr, but this may lead to cross talking " +
"(see http://www.jboss.com/wiki/Edit.jsp?page=CrossTalking for details). ");
sb.append("\nException was: " + ex);
log.warn(sb);
}
}
if(retval == null)
retval=new MulticastSocket(port);
return retval;
}



/**
* Returns the address of the interface to use defined by bind_addr and bind_interface
* @param props
Expand Down Expand Up @@ -2092,18 +2129,25 @@ else if(addr.getHostAddress().trim().equalsIgnoreCase(bind_addr)) {


public static boolean checkForLinux() {
String os=System.getProperty("os.name");
return os != null && os.toLowerCase().startsWith("linux");
return checkForPresence("os.name", "linux");
}

public static boolean checkForSolaris() {
String os=System.getProperty("os.name");
return os != null && os.toLowerCase().startsWith("sun");
return checkForPresence("os.name", "sun");
}

public static boolean checkForWindows() {
String os=System.getProperty("os.name");
return os != null && os.toLowerCase().startsWith("win");
return checkForPresence("os.name", "win");
}

private static boolean checkForPresence(String key, String value) {
try {
String tmp=System.getProperty(key);
return tmp != null && tmp.trim().toLowerCase().startsWith(value);
}
catch(Throwable t) {
return false;
}
}

public static void prompt(String s) {
Expand Down

0 comments on commit 2fb438b

Please sign in to comment.