Rice Pastry API

org.mpisws.p2p.transport.peerreview.history
Class SecureHistoryImpl

java.lang.Object
  extended by org.mpisws.p2p.transport.peerreview.history.SecureHistoryImpl
All Implemented Interfaces:
SecureHistory, PeerReviewConstants, StatusConstants
Direct Known Subclasses:
PRInconsistent1.ForkingSecureHistory

public class SecureHistoryImpl
extends java.lang.Object
implements SecureHistory

The following class implements PeerReview's log. A log entry consists of a sequence number, a type, and a string of bytes. On disk, the log is stored as two files: An index file and a data file.

Author:
Jeff Hoye, Andreas Haeberlen

Field Summary
protected  long baseSeq
           
protected  RandomAccessFileIOBuffer dataFile
           
protected  HashProvider hashProv
           
protected  IndexEntryFactory indexFactory
           
protected  RandomAccessFileIOBuffer indexFile
           
protected  Logger logger
           
protected  long nextSeq
           
protected  long numEntries
           
protected  boolean pointerAtEnd
           
protected  boolean readOnly
           
protected  IndexEntry topEntry
           
 
Fields inherited from interface org.mpisws.p2p.transport.peerreview.PeerReviewConstants
AUTH_CACHE_INTERVAL, CERT_MISSING, CHAL_AUDIT, CHAL_SEND, DEFAULT_AUDIT_INTERVAL_MILLIS, DEFAULT_AUTH_PUSH_INTERVAL_MILLIS, DEFAULT_CHECKPOINT_INTERVAL_MILLIS, DEFAULT_LOG_DOWNLOAD_TIMEOUT, DEFAULT_TIME_TOLERANCE_MILLIS, EVT_ACK, EVT_CHECKPOINT, EVT_CHOOSE_Q, EVT_CHOOSE_RAND, EVT_INIT, EVT_MAX_RESERVED, EVT_MAX_SOCKET_EVT, EVT_MIN_SOCKET_EVT, EVT_RECV, EVT_SEND, EVT_SENDSIGN, EVT_SIGN, EVT_SOCKET_CAN_READ, EVT_SOCKET_CAN_RW, EVT_SOCKET_CAN_WRITE, EVT_SOCKET_CLOSE, EVT_SOCKET_CLOSED, EVT_SOCKET_EXCEPTION, EVT_SOCKET_OPEN_INCOMING, EVT_SOCKET_OPEN_OUTGOING, EVT_SOCKET_OPENED_OUTGOING, EVT_SOCKET_READ, EVT_SOCKET_SHUTDOWN_OUTPUT, EVT_SOCKET_WRITE, EVT_VRF, EX_TYPE_ClosedChannel, EX_TYPE_IO, EX_TYPE_Unknown, FLAG_FULL_MESSAGES_ALL, FLAG_FULL_MESSAGES_SENDER, FLAG_INCLUDE_CHECKPOINT, INVALID, INVESTIGATION_INTERVAL_MILLIS, MAINTENANCE_INTERVAL_MILLIS, MAX_ACTIVE_AUDITS, MAX_ACTIVE_INVESTIGATIONS, MAX_ENTRIES_BETWEEN_CHECKPOINTS, MAX_STATUS_INFO, MAX_WITNESSED_NODES, MSG_ACCUSATION, MSG_ACK, MSG_AUTHPUSH, MSG_AUTHREQ, MSG_AUTHRESP, MSG_CHALLENGE, MSG_RESPONSE, MSG_USERDATA, MSG_USERDGRAM, NO_CERTIFICATE, PROGRESS_INTERVAL_MILLIS, PROOF_INCONSISTENT, PROOF_NONCONFORMANT, RESP_AUDIT, RESP_SEND, SIGNATURE_BAD, SIGNATURE_OK, STATE_SEND_AUDIT, STATE_WAIT_FOR_LOG, TI_AUTH_PUSH, TI_CHECKPOINT, TI_MAINTENANCE, TI_MAKE_PROGRESS, TI_MAX_RESERVED, TI_START_AUDITS, TI_STATUS_INFO, VALID
 
Fields inherited from interface org.mpisws.p2p.transport.peerreview.StatusConstants
STATUS_EXPOSED, STATUS_SUSPECTED, STATUS_TRUSTED
 
Constructor Summary
SecureHistoryImpl(RandomAccessFileIOBuffer indexFile, RandomAccessFileIOBuffer dataFile, boolean readOnly, HashProvider hashProv, IndexEntryFactory indexFactory, Logger logger)
           
 
Method Summary
 void appendEntry(short type, boolean storeFullEntry, java.nio.ByteBuffer... entry)
          Appends a new entry to the log.
 void appendHash(short type, byte[] hash)
          Append a new hashed entry to the log.
 void appendSnippetToHistory(LogSnippet snippet)
           
 void close()
          The destructor.
 long findLastEntry(short[] types, long maxSeq)
          Find the most recent entry whose type is in the specified set.
 long findSeq(long seq)
           
 long findSeqOrHigher(long seq, boolean allowHigher)
          Look up a given sequence number, or the first sequence number that is not lower than a given number.
 long getBaseSeq()
           
 byte[] getEntry(IndexEntry ie, int maxSizeToRead)
           
 byte[] getEntry(long idx, int maxSizeToRead)
          Get the content of a log entry, specified by its record number
 long getLastSeq()
           
 long getNumEntries()
           
 HashSeq getTopLevelEntry()
          Returns the node hash and the sequence number of the most recent log entry
 LogSnippet serializeRange(long idxFrom, long idxTo, HashPolicy hashPolicy)
          Serialize a given range of entries, and write the result to the specified file.
 boolean serializeRange2(long idxFrom, long idxTo, HashPolicy hashPolicy, OutputBuffer outfile)
           
 boolean setNextSeq(long nextSeq)
          Sets the next sequence number to be used.
 IndexEntry statEntry(long idx)
          Retrieve information about a given record
 boolean upgradeHashedEntry(int idx, java.nio.ByteBuffer entry)
          If the log already contains an entry in 'hashed' form and we learn the actual contents later, this function is called.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected Logger logger

hashProv

protected HashProvider hashProv

pointerAtEnd

protected boolean pointerAtEnd

topEntry

protected IndexEntry topEntry

baseSeq

protected long baseSeq

nextSeq

protected long nextSeq

numEntries

protected long numEntries

indexFile

protected RandomAccessFileIOBuffer indexFile

dataFile

protected RandomAccessFileIOBuffer dataFile

readOnly

protected boolean readOnly

indexFactory

protected IndexEntryFactory indexFactory
Constructor Detail

SecureHistoryImpl

public SecureHistoryImpl(RandomAccessFileIOBuffer indexFile,
                         RandomAccessFileIOBuffer dataFile,
                         boolean readOnly,
                         HashProvider hashProv,
                         IndexEntryFactory indexFactory,
                         Logger logger)
                  throws java.io.IOException
Throws:
java.io.IOException
Method Detail

getBaseSeq

public long getBaseSeq()
Specified by:
getBaseSeq in interface SecureHistory

getLastSeq

public long getLastSeq()
Specified by:
getLastSeq in interface SecureHistory

getNumEntries

public long getNumEntries()
Specified by:
getNumEntries in interface SecureHistory

getTopLevelEntry

public HashSeq getTopLevelEntry()
Returns the node hash and the sequence number of the most recent log entry

Specified by:
getTopLevelEntry in interface SecureHistory

appendEntry

public void appendEntry(short type,
                        boolean storeFullEntry,
                        java.nio.ByteBuffer... entry)
                 throws java.io.IOException
Appends a new entry to the log. If 'storeFullEntry' is false, only the hash of the entry is stored. If 'header' is not NULL, the log entry is formed by concatenating 'header' and 'entry'; otherwise, only 'entry' is used.

Specified by:
appendEntry in interface SecureHistory
Throws:
java.io.IOException

appendHash

public void appendHash(short type,
                       byte[] hash)
                throws java.io.IOException
Append a new hashed entry to the log. Unlike appendEntry(), this only keeps the content type, sequence number, and hash values. No entry is made in the data file.

Specified by:
appendHash in interface SecureHistory
Throws:
java.io.IOException

setNextSeq

public boolean setNextSeq(long nextSeq)
Sets the next sequence number to be used. The PeerReview library typically uses the format , where X is a timestamp in microseconds and Y a sequence number. The sequence numbers need not be contigious (and usually aren't)

Specified by:
setNextSeq in interface SecureHistory

close

public void close()
           throws java.io.IOException
The destructor. Closes the file handles.

Specified by:
close in interface SecureHistory
Throws:
java.io.IOException

findSeq

public long findSeq(long seq)
             throws java.io.IOException
Specified by:
findSeq in interface SecureHistory
Throws:
java.io.IOException

findSeqOrHigher

public long findSeqOrHigher(long seq,
                            boolean allowHigher)
                     throws java.io.IOException
Look up a given sequence number, or the first sequence number that is not lower than a given number. The return value is the number of the corresponding record in the index file, or -1 if no matching record was found.

Specified by:
findSeqOrHigher in interface SecureHistory
Throws:
java.io.IOException

serializeRange

public LogSnippet serializeRange(long idxFrom,
                                 long idxTo,
                                 HashPolicy hashPolicy)
                          throws java.io.IOException
Serialize a given range of entries, and write the result to the specified file. This is used when we need to send a portion of our log to some other node, e.g. during an audit. The format of the serialized log segment is as follows: 1. base hash value (size depends on hash function) 2. entry type (1 byte) 3. entry size in bytes (1 byte); 0x00=entry is hashed; 0xFF=16-bit size follows 4. entry content (size as specified; omitted if entry is hashed) 5. difference to next sequence number (1 byte) 0x00: increment by one 0xFF: 64-bit sequence number follows Otherwise: Round down to nearest multiple of 1000, then add specified value times 1000 6. repeat 2-5 as often as necessary; 5 is omitted on last entry. Note that the idxFrom and idxTo arguments are record numbers, NOT sequence numbers. Use findSeqOrHigher() to get these if only sequence numbers are known.

Specified by:
serializeRange in interface SecureHistory
Throws:
java.io.IOException

serializeRange2

public boolean serializeRange2(long idxFrom,
                               long idxTo,
                               HashPolicy hashPolicy,
                               OutputBuffer outfile)
                        throws java.io.IOException
Throws:
java.io.IOException

statEntry

public IndexEntry statEntry(long idx)
                     throws java.io.IOException
Retrieve information about a given record

Specified by:
statEntry in interface SecureHistory
Parameters:
idx - the index you are interested in
Throws:
java.io.IOException

getEntry

public byte[] getEntry(long idx,
                       int maxSizeToRead)
                throws java.io.IOException
Get the content of a log entry, specified by its record number

Specified by:
getEntry in interface SecureHistory
Throws:
java.io.IOException

getEntry

public byte[] getEntry(IndexEntry ie,
                       int maxSizeToRead)
                throws java.io.IOException
Specified by:
getEntry in interface SecureHistory
Throws:
java.io.IOException

upgradeHashedEntry

public boolean upgradeHashedEntry(int idx,
                                  java.nio.ByteBuffer entry)
                           throws java.io.IOException
If the log already contains an entry in 'hashed' form and we learn the actual contents later, this function is called.

Specified by:
upgradeHashedEntry in interface SecureHistory
Throws:
java.io.IOException

findLastEntry

public long findLastEntry(short[] types,
                          long maxSeq)
                   throws java.io.IOException
Find the most recent entry whose type is in the specified set. Useful e.g. for locating the last CHECKPOINT or INIT entry.

Specified by:
findLastEntry in interface SecureHistory
Throws:
java.io.IOException

appendSnippetToHistory

public void appendSnippetToHistory(LogSnippet snippet)
                            throws java.io.IOException
Specified by:
appendSnippetToHistory in interface SecureHistory
Throws:
java.io.IOException

Rice Pastry API

Copyright © 2001-2005 - Rice Pastry.


Imprint-Dataprotection