Changeset 178

Show
Ignore:
Timestamp:
03/01/06 11:10:13 (2 years ago)
Author:
dsandler
Message:

Remove deprecated DistPastryNodeFactory. According to jeffh, we should
just use SocketPastryNodeFactory, because there aren't any others.
Besides, by not using the socket factory directly, we aren't passing the
user's selected IP address in there, causing it to bind to something at random
(whatever InetAddress.getLocalHost() returns, in fact).

Now we should be passing the behind-the-NAT address to the right places, and
the publicly-detected IP address to the right places. (crosses fingers)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • feedtree/trunk/src/net/feedtree/core/client/Client.java

    r174 r178  
    1010 
    1111import rice.pastry.PastryNode; 
    12 import rice.pastry.dist.DistPastryNodeFactory; 
    13 import rice.pastry.socket.SocketPastryNode; 
     12import rice.pastry.socket.*; 
    1413import rice.pastry.standard.*; 
    1514import rice.pastry.commonapi.PastryIdFactory; 
     
    2726    public static final boolean ANYCAST_STOP = false; 
    2827     
    29     public static int           PASTRY_PROTOCOL = DistPastryNodeFactory.PROTOCOL_SOCKET; 
    30      
    31     protected static InetSocketAddress g_localNodeAddress = null; 
     28    protected static InetSocketAddress g_publicNodeAddress = null; 
    3229    protected static Environment    g_pastryEnv = new Environment(); 
    3330 
    3431    public static InetSocketAddress getLocalNodeAddress() {  
    35         return g_localNodeAddress;  
     32        return g_publicNodeAddress;  
    3633    } 
    3734 
     
    257254                "Starting FeedTree client"); 
    258255         
    259         DistPastryNodeFactory factory = null; 
    260          
    261         try { 
    262             factory = DistPastryNodeFactory.getFactory( 
    263                 new RandomNodeIdFactory(g_pastryEnv),  
    264                 PASTRY_PROTOCOL,  
    265                 port, 
    266                 g_pastryEnv); 
    267         } catch (IOException exc) { 
    268             Logger.global.severe("error: couldn't create node factory; bailing"); 
    269             status.notifyStatus(ClientStatus.STATUS_FATAL_ERROR,  
    270                     "Error loading Pastry network code"); 
    271              
    272             return null; 
    273         } 
     256        SocketPastryNodeFactory factory = null; 
    274257 
    275258        int attempts = 5; 
     
    306289                    status.notifyStatus(ClientStatus.STATUS_STARTING, 
    307290                            "Detecting public IP address"); 
    308                                 
     291                     
    309292                    InetAddress natAddr = NAT.findNatAddress( 
    310293                            localHost, port, bootSocketList, g_pastryEnv); 
    311                     g_localNodeAddress = null; 
     294                    g_publicNodeAddress = null; 
    312295                    if (natAddr != null) 
    313                         g_localNodeAddress = new InetSocketAddress(natAddr, port); 
     296                        g_publicNodeAddress = new InetSocketAddress(natAddr, port); 
     297         
     298                    try { 
     299 
     300                        // Construct the node factory given the *local* 
     301                        // address to bind to (this allows us to select among 
     302                        // multiple network interfaces on the client).  Note 
     303                        // that we're not yet using the (detected) external 
     304                        // IP; that comes later. 
     305                        factory = new SocketPastryNodeFactory( 
     306                            new RandomNodeIdFactory(g_pastryEnv), 
     307                            natAddr, port, g_pastryEnv); 
     308 
     309                    } catch (IOException exc) { 
     310                        Logger.global.severe("error: couldn't create node factory; bailing"); 
     311                        status.notifyStatus(ClientStatus.STATUS_FATAL_ERROR,  
     312                                "Error loading Pastry network code"); 
     313                         
     314                        return null; 
     315                    } 
    314316                 
    315317                    Logger.global.fine("[Contacting bootstrap host " 
     
    318320                    status.notifyStatus(ClientStatus.STATUS_STARTING, 
    319321                            "Contacting bootstrap host"); 
    320                                  
     322                         
     323                    // Finally: construct the Pastry node, given the  
     324                    // address to "claim" in the ring (our external IP) 
    321325                    node = factory.newNode( 
    322326                        factory.getNodeHandle(bootSocketList[0]), 
    323                         g_localNodeAddress); 
     327                        g_publicNodeAddress); 
     328 
    324329                } catch (java.net.BindException exc) { 
    325330                    Logger.global.severe("error: couldn't bind to requested address (already in use?)");