Changeset 173

Show
Ignore:
Timestamp:
02/23/06 18:37:19 (2 years ago)
Author:
dsandler
Message:

Working on ticket #38: Allow the user to specify the local IP address to bind
to (in so doing, selecting the interface to bind to as well).

Command-line clients should use the {{-I}}/{{--local-ip}} flag to specify an
IP. The Publisher now has a node_local_ip property (to go along with
node_port.) The GUI app needs (but does not currently have!) a spot in
the preference dialog for the user to specify an IP.

I plan to seed this version as a nightly build to those who've had trouble,
and update the UI, before closing #38.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • feedtree/trunk/build.xml

    r166 r173  
    7272                description="compile the source " > 
    7373 
    74         <!-- Compile the java code from ${src} into ${build} --> 
    7574        <javac  
    76         srcdir="${src}" 
    77         destdir="${build}" 
    78         classpathref="project.classpath" 
    79         debuglevel="lines,vars,source" 
    80         debug="true" 
    81         > 
    82     </javac> 
     75            srcdir="${src}" 
     76            destdir="${build}" 
     77            classpathref="project.classpath" 
     78            debuglevel="lines,vars,source" 
     79            debug="true" 
     80            > 
     81            <exclude name="net/feedtree/report/*.java"/> 
     82        </javac> 
    8383    </target> 
    8484 
  • feedtree/trunk/src/net/feedtree/core/client/Client.java

    r101 r173  
    238238    } 
    239239 
    240     public static Node start_node(int port, String bootHost, int bootPort, boolean waitForReady) { 
     240    public static Node start_node( 
     241            InetAddress localHost, int port,  
     242            String bootHost, int bootPort,  
     243            boolean waitForReady)  
     244    { 
    241245        Node node = null; 
    242246 
     
    275279            attempts --; 
    276280 
    277             Logger.global.fine("[Creating new node on port " + port + "]"); 
     281            Logger.global.fine("[Creating new node on "  
     282                    + localHost + " port " + port + "]"); 
    278283             
    279284            if (bootHost != "") { 
     
    296301                                 
    297302                    InetAddress natAddr = NAT.findNatAddress( 
    298                             port, bootSocketList, pastryEnv); 
     303                            localHost, port, bootSocketList, pastryEnv); 
    299304                    g_localNodeAddress = null; 
    300305                    if (natAddr != null) 
     
    310315                        factory.getNodeHandle(bootSocketList[0]), 
    311316                        g_localNodeAddress); 
     317                } catch (java.net.BindException exc) { 
     318                    Logger.global.severe("error: couldn't bind to requested address (already in use?)"); 
     319                    status.notifyStatus(ClientStatus.STATUS_ERROR, 
     320                            "The address " + localHost.getHostAddress() + ":" 
     321                            + port + " couldn't be used.  Is the proxy already running?"); 
     322                    return null; 
    312323                } catch (java.io.StreamCorruptedException exc) { 
    313324                    Logger.global.severe("Stream corruption error while finding bootstrap.  Sleeping and trying again."); 
  • feedtree/trunk/src/net/feedtree/proxyapp/WebProxyClient.java

    r160 r173  
    13451345                "Starting up"); 
    13461346 
     1347        InetAddress myHost = null; 
     1348        try { 
     1349            myHost = InetAddress.getLocalHost(); 
     1350        } catch (UnknownHostException exc) { 
     1351            // pass ... hopefully the user will specify it 
     1352        } 
    13471353        int myPort = Client.PASTRY_PORT; 
    13481354        int bsPort = Client.PASTRY_PORT; 
     
    13641370            if (args[i].equals("--port") || args[i].equals("-p")) { 
    13651371                myPort = to_int(args[++i]); 
     1372            } else if (args[i].equals("--local-ip") || args[i].equals("-I")) { 
     1373                String hostSpec = args[++i]; 
     1374                try { 
     1375                    myHost = InetAddress.getByName(hostSpec); 
     1376                } catch (UnknownHostException exc) { 
     1377                    System.out.println("error: address could not be resolved: " + hostSpec); 
     1378                    System.exit(1); 
     1379                } 
    13661380            } else if (args[i].equals("--verbose") || args[i].equals("-v")) { 
    13671381                verbosity++; 
     
    14491463                    + "       (default: "+Client.PASTRY_PORT+")\n" 
    14501464                    + "\n" 
     1465                    + "  -I/--local-ip <address>\n" 
     1466                    + "       local IP address for FeedTree node (optional)\n" 
     1467                    + "       (use this only if you need to select among multiple network \n" 
     1468                    + "       interfaces; if behind a NAT, put your internal NAT IP here,\n" 
     1469                    + "       not your public IP)\n" 
     1470                    + "       (guessed default: "+myHost.getHostAddress()+")\n" 
     1471                    + "\n" 
    14511472                    + "  -w/--web-port <port>\n" 
    14521473                    + "       port on localhost for web-based status page\n" 
     
    15461567        } 
    15471568 
     1569        if (myHost == null) { 
     1570            System.out.println("error: could not automatically detect local host address; consider using --local-ip flag"); 
     1571            System.exit(1); 
     1572        } 
     1573 
    15481574        // Start the node 
    1549         Node node = Client.start_node(myPort, bs, bsPort, true); 
    1550  
    1551         if (node == null) { return; } 
     1575        Node node = Client.start_node(myHost, myPort, bs, bsPort, true); 
     1576 
     1577        if (node == null) { 
     1578            System.out.println("error: problem starting node (run with --max-verbose for more information)"); 
     1579            System.exit(1); 
     1580        } 
    15521581         
    15531582        Client.clientStatus().notifyStatus(ClientStatus.STATUS_STARTING, 
  • feedtree/trunk/src/net/feedtree/proxyapp/gui/AppControl.java

    r136 r173  
    55import java.util.logging.*; 
    66import java.util.prefs.*; 
     7import java.net.*; 
    78 
    89import net.feedtree.proxyapp.*; 
     
    2122 
    2223    public static final String PR_PASTRY_PORT = "port"; 
     24    public static final String PR_LOCAL_IP = "local-ip"; 
    2325    public static final String PR_BOOTSTRAP = "bootstrap"; 
    2426    public static final String PR_PUBLIC = "public"; 
     
    258260                WebProxyClient.DEFAULT_BOOTSTRAP_HOST + ":" + Client.PASTRY_PORT); 
    259261 
     262        InetAddress myHost = null; 
     263        String localIP = prefs.get(PR_LOCAL_IP, ""); 
     264        if (localIP.equals("")) { 
     265            try { 
     266                myHost = InetAddress.getLocalHost(); 
     267            } catch (UnknownHostException exc) { 
     268                Client.clientStatus().notifyStatus( 
     269                        Client.ClientStatus.STATUS_ERROR, 
     270                        "Could not detect local IP.  Please configure one in the preferences panel and re-start the proxy."); 
     271            } 
     272        } else { 
     273            try { 
     274                myHost = InetAddress.getByName(localIP); 
     275            } catch (UnknownHostException exc) { 
     276                Client.clientStatus().notifyStatus( 
     277                        Client.ClientStatus.STATUS_ERROR, 
     278                        "Could not parse local IP: " + localIP + ".  Please alter the value in the preferences panel and re-start the proxy."); 
     279            } 
     280        } 
     281         
    260282        String bs; int bsPort; 
    261283        try { 
     
    343365         
    344366        // Start the node 
    345         Node node = Client.start_node(myPort, bs, bsPort, true); 
     367        Node node = Client.start_node(myHost, myPort, bs, bsPort, true); 
    346368         
    347369        // communicate with AppGUI 
  • feedtree/trunk/src/net/feedtree/publisher/Publisher.java

    r160 r173  
    8383    public static final String PROP_HEARTBEAT_INTERVAL = "heartbeat_interval_sec"; 
    8484     
     85    /// Local hostname or IP on which to start the FeedTree node (default: auto-detected) 
     86    /// \note If your publisher host has multiple network interfaces, this 
     87    /// will allow you to control which one is used for the Pastry node 
     88    /// \note If you run behind a NAT and choose to specify this, use your 
     89    /// local address, not your public address; the public address will be 
     90    /// detected at run-time 
     91    public static final String PROP_LOCAL_IP = "node_local_ip"; 
     92 
    8593    /// Port on which to start the FeedTree node (default: 29690) 
    8694    /// \note If the Publisher runs behind a NAT, this port must be  
     
    776784        } 
    777785         
     786        InetAddress myHost = null; 
     787 
     788        String localIP = g_config.optString(PROP_LOCAL_IP,""); 
     789        if (localIP.equals("")) { 
     790            try { 
     791                myHost = InetAddress.getLocalHost(); 
     792            } catch (UnknownHostException exc) { 
     793                Logger.global.severe("error: could not automatically detect IP address; add a " + PROP_LOCAL_IP + " property to your config file"); 
     794                System.exit(1); 
     795            } 
     796        } else { 
     797            try { 
     798                myHost = InetAddress.getByName(localIP); 
     799            } catch (UnknownHostException exc) { 
     800                Logger.global.severe("error: could not parse/resolve specified IP address: " + localIP); 
     801                System.exit(1); 
     802            } 
     803        } 
     804 
     805         
    778806        int myPort = g_config.optInt(PROP_PASTRY_PORT, Client.PASTRY_PORT); 
    779807        int bsPort = g_config.optInt(PROP_BOOTSTRAP_PORT, Client.PASTRY_PORT); 
     
    849877        // Start the publisher node and application. 
    850878     
    851         Node node = Client.start_node(myPort, bs, bsPort, true); 
     879        Node node = Client.start_node(myHost, myPort, bs, bsPort, true); 
    852880         
    853881        Publisher appl = new Publisher(node, myPort, webPort, feeds, privateKey); 
  • feedtree/trunk/src/net/feedtree/util/NAT.java

    r106 r173  
    33import java.lang.*; 
    44import java.net.*; 
     5import java.io.*; 
    56import java.util.Random; 
    67import java.util.logging.*; 
     
    2930    protected static Random random = new Random(); 
    3031 
    31     public static InetAddress findNatAddress(int port, InetSocketAddress[] addresses, Environment env)  
    32             throws Exception  
     32    public static InetAddress findNatAddress( 
     33            InetAddress localHost, int port,  
     34            InetSocketAddress[] addresses, Environment env)  
     35            throws UnknownHostException, StreamCorruptedException, IOException 
    3336    { 
    34         InetAddress localHost = InetAddress.getLocalHost(); 
     37        Logger.global.info("Finding public address for IP: " + localHost.getHostAddress()); 
     38 
    3539        InetSocketAddress localSocket = new InetSocketAddress(localHost, port); 
    3640        int speedup = 4;