You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@river.apache.org by pe...@apache.org on 2009/11/17 10:46:15 UTC

svn commit: r881217 - /incubator/river/jtsk/trunk/src/com/sun/jini/reggie/RegistrarImpl.java

Author: peter_firmstone
Date: Tue Nov 17 09:46:14 2009
New Revision: 881217

URL: http://svn.apache.org/viewvc?rev=881217&view=rev
Log:
River-71 Patch, Thankyou Sim.

Bugtraq ID 6449005

An RFE for Reggie: make it so that the ServerSocket used to
handle unicast discovery is created from a configurable ServerSocketFactory.
We've run across this when trying to run Reggie behind a firewall where a range
of ports is exposed--if there were a configurable ServerSocketFactory, then we
could specify one that allocated a ServerSocket within that range.

(I realize we could configure a fixed port number or open up the default
unicast discovery port in the firewall, but we'd like to avoid hardcoding
portnumbers into our configurations as much as possible, and also don't want to
preclude running more than one instance of Reggie on a given host.)

Modified:
    incubator/river/jtsk/trunk/src/com/sun/jini/reggie/RegistrarImpl.java

Modified: incubator/river/jtsk/trunk/src/com/sun/jini/reggie/RegistrarImpl.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/com/sun/jini/reggie/RegistrarImpl.java?rev=881217&r1=881216&r2=881217&view=diff
==============================================================================
--- incubator/river/jtsk/trunk/src/com/sun/jini/reggie/RegistrarImpl.java (original)
+++ incubator/river/jtsk/trunk/src/com/sun/jini/reggie/RegistrarImpl.java Tue Nov 17 09:46:14 2009
@@ -19,7 +19,6 @@
 
 import com.sun.jini.config.Config;
 import com.sun.jini.constants.ThrowableConstants;
-import com.sun.jini.constants.TimeConstants;
 import com.sun.jini.constants.VersionConstants;
 import com.sun.jini.discovery.ClientSubjectChecker;
 import com.sun.jini.discovery.Discovery;
@@ -82,6 +81,8 @@
 import java.util.logging.Logger;
 import java.security.PrivilegedActionException;
 import java.security.PrivilegedExceptionAction;
+import javax.net.ServerSocketFactory;
+import javax.net.SocketFactory;
 import javax.security.auth.Subject;
 import javax.security.auth.login.LoginContext;
 import javax.security.auth.login.LoginException;
@@ -189,6 +190,10 @@
     /** Shutdown callback object, or null if no callback needed */
     private LifeCycle lifeCycle;
 
+    /** Unicast socket factories */
+    private ServerSocketFactory serverSocketFactory ;
+    private SocketFactory socketFactory;
+
     /**
      * Map from ServiceID to SvcReg.  Every service is in this map under
      * its serviceID.
@@ -2044,7 +2049,7 @@
         private void attemptResponse(InetSocketAddress addr, int timeout) 
             throws Exception 
         {
-            Socket s = new Socket();
+            Socket s = socketFactory.createSocket();
             try {
                 s.connect(addr, timeout);
                 respond(s);
@@ -2451,14 +2456,14 @@
 	    setDaemon(true);
 	    if (port == 0) {
 		try {
-		    listen = new ServerSocket(Constants.discoveryPort);
+		    listen = serverSocketFactory.createServerSocket(Constants.discoveryPort);
 		} catch (IOException e) {
 		    logger.log(
 			Levels.HANDLED, "failed to bind to default port", e);
 		}
 	    }
 	    if (listen == null) {
-		listen = new ServerSocket(port);
+                listen = serverSocketFactory.createServerSocket(port);
 	    }
 	    this.port = listen.getLocalPort();
 	}
@@ -2500,7 +2505,8 @@
 	 */
 	public synchronized void interrupt() {
 	    try {
-		(new Socket(InetAddress.getLocalHost(), port)).close();
+                Socket s = socketFactory.createSocket(InetAddress.getLocalHost(), port);
+                s.close();
 	    } catch (IOException e) {
 	    }
 	    super.interrupt();
@@ -4391,6 +4397,14 @@
     {
 	this.lifeCycle = lifeCycle;
 
+
+        serverSocketFactory = (ServerSocketFactory) config.getEntry(
+		COMPONENT, "serverSocketFactory", ServerSocketFactory.class,
+		ServerSocketFactory.getDefault(), Configuration.NO_DATA);
+        socketFactory = (SocketFactory) config.getEntry(
+		COMPONENT, "socketFactory", SocketFactory.class,
+		SocketFactory.getDefault(), Configuration.NO_DATA);
+
 	/* persistence-specific initialization */
 	if (persistent) {
 	    persistenceSnapshotThreshold = Config.getIntEntry(