JSAMP hub and localhost hostname

Mark Taylor m.b.taylor at bristol.ac.uk
Tue Dec 2 01:37:32 PST 2008


On Tue, 2 Dec 2008, boch at vizir.u-strasbg.fr wrote:

> Hi Mark,
>
> I've been testing and playing with (J)SAMP the last days, and I had the 
> following problem :
>
> - let's pretend I am connected to a wireless network whose DHCP server gives 
> me hcp-131-176-166-130.esac.esa.int as hostname
>
> - if I launch a JSAMP hub, the lockfile will have the following line :
> samp.hub.xmlrpc.url=http://dhcp-131-176-166-130.esac.esa.int:55823/
>
> - now, if I disconnect from this network, and startup Aladin, it won't be 
> able to connect to the hub because it won't be able to resolve the XML-RPC 
> URL hostname.
>
> So, my question is : wouldn't it be safer to use the IP address instead of 
> the hostname ?
>
> Subsidiary question : I noticed that sometimes, the Java method 
> InetAddress.getLocalHost() throws an UnknownHostException (I use this method 
> to set the callback URL of Aladin). In such a case, how safe is it to 
> consider 127.0.0.1 to be the localhost IP address ?
> Though I am not a network expert at all, I feel this would do the right thing 
> most of the time. Any opinion on that ?

Thomas,

good questions, not all of which I have good answers to. 
I'm bouncing this onto the apps-samp list in case others have thoughts
or benefit from the discussion.

First, this is an issue that we've come up against before in 
AstroGrid in relation to the AG PLASTIC hub and the VODesktop/AR
XML-RPC server.  The consensus seems to be that there is no best 
way to do it - any single approach will fail under some network
setups (see the followup bugzilla tickets in the snippet below).
With that in mind, I've tried to cover all bases in JSAMP
by making this configurable.  When JSAMP writes the hostname into
the hub lockfile, it uses the SampUtils.getLocalhost() utility method,
whose javadocs and source currently read like this:

     public static final String LOCALHOST_PROP = "samp.localhost";
     ...

     /**
      * Returns a string denoting the local host to be used for communicating
      * local server endpoints and so on.
      *
      * <p>This is normally obtained by calling
      * <pre>
      *    java.net.InetAddress.getLocalHost().getCanonicalHostName()
      * </pre>
      * but this behaviour can be overridden by setting the
      * {@link #LOCALHOST_PROP} system property to the string which should
      * be returned instead.  Sometimes local network issues make it
      * advantageous to use some non-standard string such as "127.0.0.1".
      * See, for instance, AstroGrid bugzilla tickets
      * <a href="http://www.astrogrid.org/bugzilla/show_bug.cgi?id=1799"
      *    >1799</a>,
      * <a href="http://www.astrogrid.org/bugzilla/show_bug.cgi?id=2151"
      *    >2151</a>.
      *
      * @return  local host name
      */
     public static String getLocalhost() {
         String hostname = System.getProperty( LOCALHOST_PROP, "" );
         if ( hostname.length() == 0 ) {
             try {
                 hostname = InetAddress.getLocalHost().getCanonicalHostName();
             }
             catch ( UnknownHostException e ) {
                 hostname = "127.0.0.1";
             }
         }
         return hostname;
     }

So, if you understand the problem you can fix it by running the hub
with the system property samp.localhost=131.176.166.130 or whatever
you reckon will work.

This is a good start, but the trouble is people who don't understand
the problem (=most users) won't know what's up or how to fix it. 
So there might be improvements to be made in advertising this 
functionality or in choosing a safer default.  Ideas from anyone who, 
after reading the bugzilla tickets referenced above, thinks they might 
have a contribution, are welcome.

Mark

-- 
Mark Taylor   Astronomical Programmer   Physics, Bristol University, UK
m.b.taylor at bris.ac.uk +44-117-928-8776 http://www.star.bris.ac.uk/~mbt/



More information about the apps-samp mailing list