edu.harvard.deas.hyperenc
Class HyperStorage

java.lang.Object
  extended by edu.harvard.deas.hyperenc.HyperStorage
Direct Known Subclasses:
BasicHyperStorage, DBHyperStorage

public abstract class HyperStorage
extends Object

Stores unreconciled pages and corresponding hash values, reconciled pages, system blocks, and encryption blocks for a single contact.

TODO describe the contained (abstract) data structures more carefully

Thread safety: Implementations of this class must be unconditionally thread-safe; concurrent access by multiple threads should be safe without the need for external synchronization.


Constructor Summary
HyperStorage()
           
 
Method Summary
abstract  int addEncBlock(byte[] block)
          Adds an encryption block.
abstract  void addRPage(byte[] page)
          Store a page that has been reconciled.
abstract  int addSysBlock(byte[][] block)
          Adds a system block.
abstract  void addUPage(int id, byte[] page, byte[] hash)
          Adds a page of randomness that has yet to be reconciled, along with its hash.
abstract  Contact getContact()
          Get the communication partner for this HyperStorage
abstract  MessageDigest getDigest()
          Gets the stored MessageDigest object for this HyperStorage.
abstract  Direction getDirection()
          The direction of communication for this HyperStorage.
abstract  byte[] getEncBlock(int id)
          Retrieve the encryption block with the given ID.
abstract  List<Integer> getEncBlockList()
          Gets a List of IDs of available encryption blocks.
abstract  PageShuffler getShuffler()
           
abstract  RandomSource getSource()
          Gets the stored RandomSource object for this HyperStorage.
abstract  byte[][] getSysBlock(int id)
          Retrieve the system block with the given ID.
abstract  List<Integer> getSysBlockList()
          Gets a List of IDs of available system blocks.
abstract  byte[] getUHash(int id)
          Retrieve hash of the unreconciled page with the given ID.
abstract  byte[] getUPage(int id)
          Retrieve the unreconciled page with the given ID.
abstract  List<Integer> getUPageList()
          Gets a List of IDs of available unreconciled pages.
abstract  int numEncBlocks()
           
abstract  int numRPages()
           
abstract  int numSysBlocks()
           
abstract  int numUPages()
           
abstract  byte[] remEncBlock(int id)
          Removes and returns encryption block with the given ID.
abstract  List<byte[]> remEncBlockList(List<Integer> idlist)
          Removes and returns all the encryption blocks with the given IDs.
abstract  byte[] remRPage()
          Removes and returns the first reconciled page from the FIFO queue.
abstract  byte[][] remSysBlock(int id)
          Removes and returns system block with the given ID.
abstract  byte[] remUPage(int id)
          Removes and returns unreconciled page with the given ID, and remove the corresponding hash.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HyperStorage

public HyperStorage()
Method Detail

addSysBlock

public abstract int addSysBlock(byte[][] block)
Adds a system block. Each system block is comprised of HyperCollector.NUM_SYSBLOCKS subblocks.

Parameters:
block - Data for block.
Returns:
ID number for block.

addEncBlock

public abstract int addEncBlock(byte[] block)
Adds an encryption block.

Parameters:
block - Data for block.
Returns:
ID number for block.

addUPage

public abstract void addUPage(int id,
                              byte[] page,
                              byte[] hash)
Adds a page of randomness that has yet to be reconciled, along with its hash.

Parameters:
id - ID number for the Page. This is the same as the ID for the block from which it was generated.
page - The unreconciled page.
hash - The hash of page.

addRPage

public abstract void addRPage(byte[] page)
Store a page that has been reconciled. The page is placed at the end of a FIFO queue, so there is no ID (unlike unreconciled pages).

Parameters:
page - The reconciled page.

getSysBlockList

public abstract List<Integer> getSysBlockList()
Gets a List of IDs of available system blocks. The list is a copy; callers are free to mutate the returned list.

Returns:
List of IDs of system blocks.

getEncBlockList

public abstract List<Integer> getEncBlockList()
Gets a List of IDs of available encryption blocks. The list is a copy; callers are free to mutate the returned list.

Returns:
List of IDs of encryption blocks.

getUPageList

public abstract List<Integer> getUPageList()
Gets a List of IDs of available unreconciled pages. The list is a copy; callers are free to mutate the returned list. The list can also be used as a List of IDs for all unreconciled page hashes, because every page has a hash stored with the same ID.

Returns:
List of IDs of unreconciled pages.

getSysBlock

public abstract byte[][] getSysBlock(int id)
Retrieve the system block with the given ID.

Parameters:
id - ID number of desired system block.
Returns:
The system block with the given ID (or null if no such block).

getEncBlock

public abstract byte[] getEncBlock(int id)
Retrieve the encryption block with the given ID.

Parameters:
id - ID number of desired encryption block.
Returns:
The encryption block with the given ID (or null if no such block).

getUPage

public abstract byte[] getUPage(int id)
Retrieve the unreconciled page with the given ID.

Parameters:
id - ID of desired page.
Returns:
The unreconciled page with the given ID (or null if no such page).

getUHash

public abstract byte[] getUHash(int id)
Retrieve hash of the unreconciled page with the given ID.

Parameters:
id - ID of desired page.
Returns:
The hash of the page with the given ID (or null if no such page).

remSysBlock

public abstract byte[][] remSysBlock(int id)
Removes and returns system block with the given ID.

Parameters:
id - ID of block.
Returns:
system block with the given ID

remEncBlock

public abstract byte[] remEncBlock(int id)
Removes and returns encryption block with the given ID.

Parameters:
id - ID of block.
Returns:
encryption block with the given ID

remEncBlockList

public abstract List<byte[]> remEncBlockList(List<Integer> idlist)
                                      throws BlockMissingException
Removes and returns all the encryption blocks with the given IDs. This is an atomic, all-or-nothing operation: if all of the specified block IDs exist in this storage, then they are all removed and returned. If any of the specified IDs is missing, no blocks are removed, and a BlockMissingException is thrown.

Parameters:
idlist - a list of integer encryption block IDs
Returns:
a list containing the encryption blocks with the corresponding IDs, in the same order in which the IDs were given
Throws:
BlockMissingException - if any of the specified IDs are missing. The IDs of the missing blocks can be accessed from the getMissingIDList method of BlockMissingException.

remUPage

public abstract byte[] remUPage(int id)
Removes and returns unreconciled page with the given ID, and remove the corresponding hash.

Parameters:
id - ID of page.
Returns:
unreconciled page with the given ID

remRPage

public abstract byte[] remRPage()
Removes and returns the first reconciled page from the FIFO queue.

Returns:
a reconciled page (or null if there are none)

numSysBlocks

public abstract int numSysBlocks()
Returns:
The number of system blocks contained in this HyperStorage.

numEncBlocks

public abstract int numEncBlocks()
Returns:
The number of encryption blocks contained in this HyperStorage.

numUPages

public abstract int numUPages()
Returns:
The number of unreconciled pages contained in this HyperStorage.

numRPages

public abstract int numRPages()
Returns:
The number of reconciled pages contained in this HyperStorage.

getContact

public abstract Contact getContact()
Get the communication partner for this HyperStorage

Returns:
the contact with whom this HyperStorage's blocks and pages are used to communicate

getDirection

public abstract Direction getDirection()
The direction of communication for this HyperStorage. If MASTER, this storage's blocks and pages are used for outgoing communication: sending messages to the partner (as given by getContact()). If SLAVE, this storage is used for incoming communication: receiving messages from the partner.

Returns:
the direction of communication for this storage

getSource

public abstract RandomSource getSource()
Gets the stored RandomSource object for this HyperStorage. This RandomSource object is used to create pages.

Returns:
The RandomSource for this HyperStorage.

getDigest

public abstract MessageDigest getDigest()
Gets the stored MessageDigest object for this HyperStorage. This MessageDigest object is a component of the hash function used to compute the hash of a page.

Returns:
The MessageDigest for this HyperStorage.

getShuffler

public abstract PageShuffler getShuffler()
Returns:
The PageShuffler for this HyperStorage.