net.vattp.data
Class VatTPMgr

java.lang.Object
  |
  +--net.vattp.data.VatTPMgr

public class VatTPMgr
extends Object

Untamed: Manage the connections between this vat and other vats.

The VatTPMgr acts as the focal point for managing the TCP connections from a particular vat. It uses the public/private key pair for the vat, which defines the vat's identity.

The important method(s) are getConnection(...) which returns a VatTPConnection to a remote vat, and addNewConnectionReactor which lets the higher layers connect themselves to connections which have completed the startup protocol.

Author:
Bill Frantz, Mark S. Miller

Field Summary
(package private) static int LIVES_CONTINUE
           
(package private) static int LIVES_DUP
           
(package private) static int LIVES_NOTIFY
           
private  Hashtable myDieingConnections
          Connections which have been told to shut down (until they have gone).
private  Hashtable myIdentifiedConnections
          The connections which haven't completed the start up protocol.
private  KeyPair myIdentityKeys
           
private  ListenThread[] myListenThreads
          The threads which are listening for incoming connections
private  String myLocalVatID
          The vatID of the local vat.
private  NetConfig myNetConfig
           
private  NewConnectionReactor myReactor
          The object to notify about newly available connections
private  Hashtable myRunningDataConnections
          The running DataConnections.
private  Hashtable mySuspendedConnections
          The connections which are suspended.
private  Hashtable mySuspendingConnections
          The connections in the process of suspending.
private  Hashtable myUnidentifiedConnections
          The unidentified connections which haven't completed the start up protocol.
private  Vat myVat
          Connection to the E run queue
private  VatLocationLookup myVLS
          VLS registrations that we maintain
 
Constructor Summary
  VatTPMgr(KeyPair identityKeys, NetConfig netConfig)
          Enabled: Make a VatTPMgr listening on the specified ports.
private VatTPMgr(KeyPair identityKeys, NetConfig netConfig, Vat vat)
          Make a VatTPMgr.
 
Method Summary
 void addNewConnectionReactor(NewConnectionReactor reactor)
          Enabled: Register an object to notice a new connection which has successfully completed the startup protocol.
(package private)  void connectionSuspended(VatTPConnection conn, String vatID)
          Register that this connection is suspended
(package private)  void connectionSuspending(VatTPConnection conn, String vatID)
          Register that this connection is suspending
(package private)  void connectToSelf(DataPath path)
          Notify the connectToVatAt caller that he has tried to connect to self.
 Ref connectToVatAt(String ipPort)
          Enabled: Make an authenticated connection to a vat given an IP:port address.
 void connectToVatAt(String ipPort, Resolver res)
          Enabled: Make an authenticated connection to a vat given an IP:port address.
(package private)  void deathNotification(VatTPConnection conn)
          Mark the death of a connection.
(package private)  void enterHospice(VatTPConnection conn, String vatID)
          Register that this connection is dying
private static ConstList expandPath(NetAddr netAddr)
          Return the subset of a searchPath for directly connecting to netAddr.
private  VatTPConnection findDataConnection(String vatID)
          Find an existing VatTPConnection object that can or will be able to be used for data transfer.
 VatTPConnection getConnection(String vatID, ConstList searchList)
          Enabled: Return a VatTPConnection to the remote vat given its vatID and search path.
 NetConfig getNetConfig()
          Enabled: Returns the VatTP configuration parameters as they exist after allocating a listen port.
private  void listState(Enumeration enum, StringBuffer buf)
          List the current DataPaths/DataConnections in a enumeration.
private  int moveIdentifiedPath(DataPath path, String remoteVatID, boolean isIncoming)
          Move a path from the unidentified list to the identified but not connected path list.
(package private)  int newConnectionIdentified(DataPath path, String remoteVatID, String localVatID, boolean isIncoming)
          Register a DataPath for an connection where the remote vat has been identified
(package private)  void newInboundSocket(Socket socket)
          Receive a new inbound socket from the ListenThread.
(package private)  void noticeProblem(Throwable error)
          Learn of a problem with the ListenThread.
 VatTPConnection optConnection(String vatID)
          Enabled: Like getConnection((vatID, searchList), but if there isn't a working live one, will return null rather than creating one.
private  VatTPConnection removeDataConnection(String vatID)
          Remove an existing VatTPConnection object that can or will be able to be used for data transfer (That is, one that is not dying or dead) from the hash table which holds it and return it.
private  String removeDieing(VatTPConnection dc)
          Remove an entry from myDieingConnections
private  VatTPConnection removeIdentified(String regID)
          Remove an entry from myIdentifiedConnections
private  VatTPConnection removeSuspended(String regID)
          Remove an entry from mySuspendedConnections
private  VatTPConnection removeSuspending(String regID)
          Remove an entry from mySuspendingConnections
private  Object removeUnidentified(DataPath path)
          Remove an entry from myUnidentifiedConnections
 ConstList searchPath()
          Enabled: Return the search path to our own vat.
 void setVatLocationLookup(VatLocationLookup vls)
          Enabled: Set the object which will respond to vat location queries on our listen port.
(package private)  void startupSuccessful(VatTPConnection connection, String remoteVatID, boolean isResuming)
          Inform the world that a new conection is ready to pass data.
 String toString()
          Suppressed: Convert the state of the world to a string and print it.
(package private)  void unidentifiedConnectionDied(DataPath path, String msg, Throwable problem)
          Note that a DataPath for an connection has died before the vat at the other end was identified.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

myIdentityKeys

private final KeyPair myIdentityKeys

myLocalVatID

private final String myLocalVatID
The vatID of the local vat. The hash of this end's public key.


myNetConfig

private final NetConfig myNetConfig

myVLS

private VatLocationLookup myVLS
VLS registrations that we maintain


myVat

private final Vat myVat
Connection to the E run queue


myListenThreads

private final ListenThread[] myListenThreads
The threads which are listening for incoming connections


myReactor

private NewConnectionReactor myReactor
The object to notify about newly available connections


myUnidentifiedConnections

private Hashtable myUnidentifiedConnections
The unidentified connections which haven't completed the start up protocol. The key is the DataPath object. The value is the DataPath object if this entry is for an incoming connections, or the Resolver if the path was created for a connectToVatAt connection.


myIdentifiedConnections

private Hashtable myIdentifiedConnections
The connections which haven't completed the start up protocol. The key is the vatID. The value is the VatTPConnection object.


myRunningDataConnections

private final Hashtable myRunningDataConnections
The running DataConnections. The key is vatID, the value is the VatTPConnection object.


mySuspendingConnections

private Hashtable mySuspendingConnections
The connections in the process of suspending. The key is vatID, the value is the VatTPConnection object.


mySuspendedConnections

private Hashtable mySuspendedConnections
The connections which are suspended. The key is vatID, the value is the VatTPConnection object.


myDieingConnections

private Hashtable myDieingConnections
Connections which have been told to shut down (until they have gone). The key is the VatTPConnection object and the value is the vatID.


LIVES_CONTINUE

static final int LIVES_CONTINUE

LIVES_DUP

static final int LIVES_DUP

LIVES_NOTIFY

static final int LIVES_NOTIFY
Constructor Detail

VatTPMgr

public VatTPMgr(KeyPair identityKeys,
                NetConfig netConfig)
         throws UnknownHostException,
                IOException
Enabled: Make a VatTPMgr listening on the specified ports.

Each VatTPMgr made will have a different ID. The VatTPMgr is associated with one vat.

This constructor gets the Vat for that vat via the static method Vat.getCurrentVat(). The rest of the VatTP system gets access to that Vat by having the reference explicitly passed during construction. Therefore, if it is necessary to have a VatTP system work with a different Vat, the constructor which accepts the Vat as a specific parameter should be used.

Parameters:
identityKeys - is the KeyPair which defines the identity of this vat.
netConfig - holds the configuration parameters for configuring how we interact with the network.

VatTPMgr

private VatTPMgr(KeyPair identityKeys,
                 NetConfig netConfig,
                 Vat vat)
          throws UnknownHostException,
                 IOException
Make a VatTPMgr.

Each VatTPMgr made will have a different ID. The VatTPMgr is associated with one vat.

Parameters:
identityKeys - is the KeyPair which defines the identity of this vat.
netConfig - holds the configuration parameters for configuring how we interact with the network.
vat - is the Vat to use to synchronize the connections.
Method Detail

expandPath

private static ConstList expandPath(NetAddr netAddr)
                             throws UnknownHostException
Return the subset of a searchPath for directly connecting to netAddr.

This does various kinds of DNS lookup to convert netAddr to an externally addressable form

UnknownHostException

connectionSuspended

void connectionSuspended(VatTPConnection conn,
                         String vatID)
Register that this connection is suspended

Parameters:
conn - The data connection which is suspended.
vatID - The vatID of the remote end.

connectionSuspending

void connectionSuspending(VatTPConnection conn,
                          String vatID)
Register that this connection is suspending

Parameters:
conn - The data connection which is suspending.
vatID - The vatID of the remote end.

connectToSelf

void connectToSelf(DataPath path)
Notify the connectToVatAt caller that he has tried to connect to self.

Parameters:
path - is the DataPath object trying the connection.

connectToVatAt

public Ref connectToVatAt(String ipPort)
Enabled: Make an authenticated connection to a vat given an IP:port address.

Parameters:
ipPort - is the IP address and port to connect to separated by a colon. For example "groucho.communities.com:1670".
Returns:
A promise for the resulting VatTPConnection

connectToVatAt

public void connectToVatAt(String ipPort,
                           Resolver res)
Enabled: Make an authenticated connection to a vat given an IP:port address.

Parameters:
ipPort - The IP address and port to connect to, separated by a colon. For example "groucho.communities.com:1670".
res - The object that will be notified when the connection is completed or if the attempt to connect fails.

deathNotification

void deathNotification(VatTPConnection conn)
Mark the death of a connection. Remove it from all tables so it can be garbage collected.

Parameters:
conn - The data connection which has shut down.

enterHospice

void enterHospice(VatTPConnection conn,
                  String vatID)
Register that this connection is dying

Parameters:
conn - The data connection which is shutting down.
vatID - The vatID of the remote end.

findDataConnection

private VatTPConnection findDataConnection(String vatID)
Find an existing VatTPConnection object that can or will be able to be used for data transfer. (That is, one that is not dying or dead.)

Parameters:
vatID - is the vatID of the remote vat.
Returns:
an existing VatTPConnection object or null if there are none.

getConnection

public VatTPConnection getConnection(String vatID,
                                     ConstList searchList)
Enabled: Return a VatTPConnection to the remote vat given its vatID and search path.

Parameters:
vatID - is the vatID for the remote vat wanted. The process of setting up the physical connection will verify that the vatID is indeed the hash of the public key of the remote vat, and that the other end of the connection holds the associated private key.
searchList - is a list of Strings each of which is the IP address and port number of a place to look for the remote vat. The IP address can be a DNS name or a dot repsentation of the 32 bit IP number. Most commonly, the Strings will be the location of the Vat Location Servers (VLSs) with which the remote vat is believed to register. It may be useful under special circumstances to include the actual address where the remote vat may be listening in the list.
Returns:
a VatTPConnection object to the remote vat or null. This is either an existing VatTPConnection object or a newly created one. If the VatTPConnection object is newly created, then it has been asked to initiate the connection startup protocol. This method returns null if the request is to connect the vat to itself.

optConnection

public VatTPConnection optConnection(String vatID)
Enabled: Like getConnection((vatID, searchList), but if there isn't a working live one, will return null rather than creating one.


listState

private void listState(Enumeration enum,
                       StringBuffer buf)
List the current DataPaths/DataConnections in a enumeration.

Parameters:
enum - is the Enumeration to list. The elements produced should be either DataConnections or DataPaths.
buf - is a StringBuffer to fill with the list.

moveIdentifiedPath

private int moveIdentifiedPath(DataPath path,
                               String remoteVatID,
                               boolean isIncoming)
                        throws IOException
Move a path from the unidentified list to the identified but not connected path list. This also handles forwarding to the promise returned by connectToVatAt for that type of connection.

Parameters:
path - is the DataPath object which has been identified.
remoteVatID - is the identified remote vat's vatID.
isIncoming - says whether this is an incoming connection (true) or an outgoing connection (false).
Returns:
LIVES_CONTINUE - Continue setting up this connection
LIVES_DUP - This connection is a duplicate, discard it.
LIVES_NOTIFY - Notify the other end of a duplicate connection. The other end must decide which connection to keep.
IOException

newConnectionIdentified

int newConnectionIdentified(DataPath path,
                            String remoteVatID,
                            String localVatID,
                            boolean isIncoming)
                      throws IOException
Register a DataPath for an connection where the remote vat has been identified

Parameters:
path - the new DataPath
remoteVatID - is the vat ID of the remote vat.
localVatID - is the vat ID of this vat.
isIncoming - is true if this is an inbound connection, false if it is an outbound connection.
Returns:
LIVES_CONTINUE - Continue setting up this connection
LIVES_DUP - This connection is a duplicate, discard it.
LIVES_NOTIFY - Notify the other end of a duplicate connection. The other end must decide which connection to keep.
IOException

newInboundSocket

void newInboundSocket(Socket socket)
Receive a new inbound socket from the ListenThread.

Parameters:
socket - is the new inbound socket object, just as received by the listen operation.

noticeProblem

void noticeProblem(Throwable error)
Learn of a problem with the ListenThread.

Parameters:
error - the Throwable which represents the error.

addNewConnectionReactor

public void addNewConnectionReactor(NewConnectionReactor reactor)
                             throws IOException
Enabled: Register an object to notice a new connection which has successfully completed the startup protocol. This object is expected to connect up MsgHandlers for all the messages processed by higher layers in the protocol. Note that a maximum of one NewConnectionReactor may be registered.

This notification is for all DataConnections, whether the connection was initiated from this end or from the other end.

Parameters:
reactor - is an object which implements NewConnectionReactor.
Throws:
IOException - is thrown if there is already a reactor registered.

removeDataConnection

private VatTPConnection removeDataConnection(String vatID)
Remove an existing VatTPConnection object that can or will be able to be used for data transfer (That is, one that is not dying or dead) from the hash table which holds it and return it.

Parameters:
vatID - is the vatID of the remote vat.
Returns:
an existing VatTPConnection object or null if there are none.

removeDieing

private String removeDieing(VatTPConnection dc)
Remove an entry from myDieingConnections


removeIdentified

private VatTPConnection removeIdentified(String regID)
Remove an entry from myIdentifiedConnections

Parameters:
regID - is the VatID to remove.

removeSuspended

private VatTPConnection removeSuspended(String regID)
Remove an entry from mySuspendedConnections

Parameters:
regID - is the VatID to remove.

removeSuspending

private VatTPConnection removeSuspending(String regID)
Remove an entry from mySuspendingConnections

Parameters:
regID - is the VatID to remove.

removeUnidentified

private Object removeUnidentified(DataPath path)
Remove an entry from myUnidentifiedConnections


getNetConfig

public NetConfig getNetConfig()
Enabled: Returns the VatTP configuration parameters as they exist after allocating a listen port.


searchPath

public ConstList searchPath()
Enabled: Return the search path to our own vat.


setVatLocationLookup

public void setVatLocationLookup(VatLocationLookup vls)
Enabled: Set the object which will respond to vat location queries on our listen port.

Parameters:
vls - The VLS object

startupSuccessful

void startupSuccessful(VatTPConnection connection,
                       String remoteVatID,
                       boolean isResuming)
Inform the world that a new conection is ready to pass data. This method is called by VatTPConnection after the start up protocol has successfully completed.

Parameters:
connection - The VatTPConnection which is now in RUNNING state.
remoteVatID - is the vatID of the remote vat.
isResuming - is true if this connection is resuming, false if it is starting.

toString

public String toString()
Suppressed: Convert the state of the world to a string and print it.

Overrides:
toString in class Object
Returns:
is a String which descirbes this VatTPMgr and the state of all the connections it is managing.

unidentifiedConnectionDied

void unidentifiedConnectionDied(DataPath path,
                                String msg,
                                Throwable problem)
Note that a DataPath for an connection has died before the vat at the other end was identified.

Parameters:
path - is the DataPath object whose connection has died.


comments?