Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| Rice Pastry API
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

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

    java.lang.Object
      org.mpisws.p2p.transport.peerreview.history.SecureHistoryImpl

All Implemented Interfaces:
  SecureHistory

    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

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, Hash hash)` Append a new hashed entry to the log.
`void` | `close()` The destructor.
`long` | `findLastEntry(short[] types, long maxSeq)` Find the most recent entry whose type is in the specified set.
`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
`boolean` | `serializeRange(int idxFrom, int idxTo, HashPolicy hashPolicy, RandomAccessFileIOBuffer outfile)` Serialize a given range of entries, and write the result to the specified file.
`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`

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,
                           Hash 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`

### 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 boolean serializeRange(int idxFrom,
                                  int idxTo,
                                  HashPolicy hashPolicy,
                                  RandomAccessFileIOBuffer outfile)
                           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`

### 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`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| Rice Pastry API
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2001-2005 - Rice Pastry.