net.vattp.data
Class RecvThread

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--net.vattp.data.RecvThread
All Implemented Interfaces:
Runnable

class RecvThread
extends Thread


Field Summary
private static int HASH_BLOCK_SIZE
           
private static int HEADER_INT_LENGTH
           
private static int HEADER_INVALID
           
private static int HEADER_VLEN_HMAC
           
private static int HEADER_VLEN_SHA1
           
private  int myBufferLength
           
private  boolean myChangeProtocolIsOk
           
private  DataPath myDataPath
           
private  byte[] myHeader
           
private  InputStream myInputStream
           
private  boolean myIsAggragating
           
private  boolean myIsCompressingMsgLengths
           
private  boolean myIsDoingHMAC
           
private  boolean myIsDoingMac
           
private  boolean myIsStandardCBC
           
private  byte[] myMAC
           
private  byte[] myMACKey
           
private  Vector myMessagesToPass
           
private  byte[] mySequence
           
private  MessageDigest mySHA1
           
private  boolean myTerminateFlag
           
private  long myTotalTime
           
private  MsgTransformer myTransform
           
private  Vat myVat
          The vat we will synchronize with when calling the DataPath
private static int NOTIFY_EVERY
          Notify DataPath every NOTIFY_EVERY bytes of receive progress
private static int[] theHeaderLengths
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
RecvThread(InputStream inputStream, DataPath connection, String remoteAddr, Vat vat)
          Construct a new RecvThread.
 
Method Summary
private  void callDataPath(DataCommThunk thunk)
          Call a method in our VatTPMgr
(package private)  void changeProtocol(AuthSecrets protocolParms)
          Change the authorization protocol being used to receive messages on the connection.
private  byte[] computeMAC(Vector messages)
           
private  void fillArray(byte[] b, int off, int len)
           
(package private)  byte[] getSequence()
          Get the current message sequence number
private  void increment(byte[] value)
           
private static boolean isEqual(byte[] a, byte[] b)
          isEqual - Compare two byte arrays.
private  byte[] md5Hash(int pad, byte[] data, MessageDigest md5)
          Calculate the MD5 hash of some data with a specific padding.
private  void readAndProcessMessage()
          Process input data.
private static void replicate(byte[] a, byte v)
          replicate - Copy a single byte to all elements of a byte array.
 void run()
          The actual connection receive thread -- the asynchronous part.
private  MessageDigest setSHA1(AuthSecrets macParms)
           
(package private)  void shutdown()
          Shutdown this thread.
private  void traceDebugMsg(byte[] msg, int off, int len, String note)
           
private  void traceErrorMsg(byte[] msg, int off, int len, String note)
           
private static void xor(byte[] a, byte[] b)
          xor - Exclusive OR two byte arrays.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

HEADER_INVALID

private static final int HEADER_INVALID

HEADER_INT_LENGTH

private static final int HEADER_INT_LENGTH

HEADER_VLEN_SHA1

private static final int HEADER_VLEN_SHA1

HEADER_VLEN_HMAC

private static final int HEADER_VLEN_HMAC

theHeaderLengths

private static final int[] theHeaderLengths

NOTIFY_EVERY

private static final int NOTIFY_EVERY
Notify DataPath every NOTIFY_EVERY bytes of receive progress


myInputStream

private final InputStream myInputStream

myDataPath

private DataPath myDataPath

myTerminateFlag

private boolean myTerminateFlag

myBufferLength

private int myBufferLength

myVat

private final Vat myVat
The vat we will synchronize with when calling the DataPath


myHeader

private byte[] myHeader

myChangeProtocolIsOk

private boolean myChangeProtocolIsOk

myIsAggragating

private boolean myIsAggragating

myMessagesToPass

private final Vector myMessagesToPass

myTransform

private MsgTransformer myTransform

myIsStandardCBC

private boolean myIsStandardCBC

HASH_BLOCK_SIZE

private static final int HASH_BLOCK_SIZE

myIsDoingMac

private boolean myIsDoingMac

myIsDoingHMAC

private boolean myIsDoingHMAC

myMACKey

private byte[] myMACKey

mySHA1

private MessageDigest mySHA1

myMAC

private byte[] myMAC

mySequence

private byte[] mySequence

myIsCompressingMsgLengths

private boolean myIsCompressingMsgLengths

myTotalTime

private long myTotalTime
Constructor Detail

RecvThread

public RecvThread(InputStream inputStream,
                  DataPath connection,
                  String remoteAddr,
                  Vat vat)
Construct a new RecvThread.

Parameters:
inputStream - stream to read data from.
connection - a RawConnection to send problem reports to.
Method Detail

callDataPath

private void callDataPath(DataCommThunk thunk)
Call a method in our VatTPMgr

Parameters:
thunk - a Thunk that will perform the call. The thunk will be called after the Vat lock is obtained.

changeProtocol

void changeProtocol(AuthSecrets protocolParms)
Change the authorization protocol being used to receive messages on the connection. This routine must be called when the RecvThread is synchronized with the Vat thread. This assertion is checked by setting myChangeProtocolIsOk just before calling into the Vat with a new incoming message and resetting it when the call returns. This routine will throw an Assertion failure if that boolean is not true.

Parameters:
protocolParms - is the parameter bundle for the protocol suite to use. This routine must, of course, support the selected suite.

computeMAC

private byte[] computeMAC(Vector messages)
                   throws IOException
IOException

fillArray

private void fillArray(byte[] b,
                       int off,
                       int len)
                throws IOException
IOException

getSequence

byte[] getSequence()
Get the current message sequence number


increment

private void increment(byte[] value)

isEqual

private static boolean isEqual(byte[] a,
                               byte[] b)
isEqual - Compare two byte arrays.

Parameters:
a - is the first input array.
b - is the second input array.
Returns:
is true if the two arrays contain all the same bytes, else false.

xor

private static void xor(byte[] a,
                        byte[] b)
xor - Exclusive OR two byte arrays.

Parameters:
a - is the input and output array.
b - is the array which is XORed with a.

replicate

private static void replicate(byte[] a,
                              byte v)
replicate - Copy a single byte to all elements of a byte array.

Parameters:
a - is the byte array.
v - is the byte to be replicated.

md5Hash

private byte[] md5Hash(int pad,
                       byte[] data,
                       MessageDigest md5)
Calculate the MD5 hash of some data with a specific padding.

The padding allows different values to be obtained from the same data by varing the padding value. We use it to get the different authentication values from the same Diffie Hellman shared secret.

Parameters:
pad - The int (treated as a byte) to be used to pad the MD5 calculation.
data - The data to be hashed.
md5 - The message digest object to be used.
Returns:
A byte array representing the hash.

readAndProcessMessage

private void readAndProcessMessage()
                            throws IOException
Process input data.

IOException

run

public void run()
The actual connection receive thread -- the asynchronous part.

Specified by:
run in interface Runnable
Overrides:
run in class Thread
See Also:
java.lang.Thread#start(), java.lang.Thread#stop(), java.lang.Thread#Thread(java.lang.ThreadGroup, java.lang.Runnable, java.lang.String), java.lang.Runnable#run()

setSHA1

private MessageDigest setSHA1(AuthSecrets macParms)

shutdown

void shutdown()
Shutdown this thread. The thread doesn't actually exit until the read unblocks.


traceDebugMsg

private void traceDebugMsg(byte[] msg,
                           int off,
                           int len,
                           String note)

traceErrorMsg

private void traceErrorMsg(byte[] msg,
                           int off,
                           int len,
                           String note)


comments?