jist.runtime
Class ProxyPoint

java.lang.Object
  extended by jist.runtime.ProxyPoint

public class ProxyPoint
extends java.lang.Object

Firewall and NAT-busting functionality for JiST (and any RMI client). Basic idea is to avoid any incoming connections. All parties make outgoing connections to the central ProxyPoint, and the ProxyPoint connects people up and marshalls information back and forth. None of this is very efficient, but it works well enough to hooks up scores of clients to scores of servers all over the world! In other words, it's one big hack that does the job.

Since:
JIST1.0
Version:
$Id: ProxyPoint.java,v 1.11 2004/04/06 16:07:43 barr Exp $
Author:
Rimon Barr <barr+jist@cs.cornell.edu>

Nested Class Summary
static class ProxyPoint.ProxyAcceptSocket
          A Socket on the server-side that operates via the ProxyPoint proxy.
static class ProxyPoint.ProxyClientSocket
          A Socket on the client-side that operates via the ProxyPoint proxy.
static class ProxyPoint.ProxyServerSocket
          A ServerSocket that operates via the ProxyPoint proxy.
static class ProxyPoint.ProxySocketFactory
          An RMI socket factory that returns proxied sockets.
static class ProxyPoint.StreamPump
          A Runnable object that pumps from an InputStream to an OutputStream.
 
Field Summary
static byte COMMAND_CONNECT
          proxy server command constant.
static byte COMMAND_CONNECTED
          proxy server command constant.
static byte COMMAND_INVALID
          proxy server command constant.
static byte COMMAND_LISTEN
          proxy server command constant.
static byte COMMAND_NOOP
          proxy server command constant.
static boolean DEBUG
          whether to show some output.
private  java.util.Hashtable listen
          listen sockets: SocketAddress -- Socket.
static int PROXY_PORT
          default proxy server port.
private  java.net.ServerSocket ss
          proxy server listen socket.
 
Constructor Summary
ProxyPoint(int port)
          Create a new ProxyPoint server object.
 
Method Summary
 void accept()
          Block for and process a single incoming connection.
private  int getUnusedPort(java.net.InetAddress addr)
          Return an unused proxied port number for given address.
static void main(java.lang.String[] args)
          Entry point to start a proxy point server.
static void pumpSocket(java.net.Socket s1, java.net.Socket s2)
          Pump data between two sockets in both directions, and close both if one fails.
static java.net.InetAddress readInetAddress(java.io.ObjectInputStream is)
          Read and parse IP address from input stream.
static void setRmiProxy(java.net.InetAddress host, int port)
          Set global RMI proxy factory to proxy sockets to given proxy server.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROXY_PORT

public static final int PROXY_PORT
default proxy server port.

See Also:
Constant Field Values

COMMAND_INVALID

public static final byte COMMAND_INVALID
proxy server command constant.

See Also:
Constant Field Values

COMMAND_NOOP

public static final byte COMMAND_NOOP
proxy server command constant.

See Also:
Constant Field Values

COMMAND_LISTEN

public static final byte COMMAND_LISTEN
proxy server command constant.

See Also:
Constant Field Values

COMMAND_CONNECT

public static final byte COMMAND_CONNECT
proxy server command constant.

See Also:
Constant Field Values

COMMAND_CONNECTED

public static final byte COMMAND_CONNECTED
proxy server command constant.

See Also:
Constant Field Values

DEBUG

public static final boolean DEBUG
whether to show some output.

See Also:
Constant Field Values

ss

private java.net.ServerSocket ss
proxy server listen socket.


listen

private java.util.Hashtable listen
listen sockets: SocketAddress -- Socket.

Constructor Detail

ProxyPoint

public ProxyPoint(int port)
           throws java.io.IOException
Create a new ProxyPoint server object.

Parameters:
port - port for incoming connections
Throws:
java.io.IOException - when i/o fails
Method Detail

setRmiProxy

public static void setRmiProxy(java.net.InetAddress host,
                               int port)
                        throws java.io.IOException
Set global RMI proxy factory to proxy sockets to given proxy server. This methods tests the server first with a quick "ping" connection, and then sets the socket factory.

Parameters:
host - proxy server host
port - proxy server port
Throws:
java.io.IOException - when i/o fails

pumpSocket

public static void pumpSocket(java.net.Socket s1,
                              java.net.Socket s2)
                       throws java.io.IOException
Pump data between two sockets in both directions, and close both if one fails. This method is not particularly efficient... it creates three threads to deal with the work, rather than performing selects, and non-blocking i/o.

Parameters:
s1 - first socket to pump
s2 - second socket to pump
Throws:
java.io.IOException - when i/o fails (before pumping begins)

readInetAddress

public static java.net.InetAddress readInetAddress(java.io.ObjectInputStream is)
                                            throws java.io.IOException
Read and parse IP address from input stream.

Parameters:
is - input stream to read
Returns:
IP address read
Throws:
java.io.IOException - when i/o fails

getUnusedPort

private int getUnusedPort(java.net.InetAddress addr)
Return an unused proxied port number for given address.

Parameters:
addr - machine requesting unused port
Returns:
unused proxied port at given address

accept

public void accept()
Block for and process a single incoming connection.


main

public static void main(java.lang.String[] args)
Entry point to start a proxy point server.

Parameters:
args - command-line parameters