net.i2p.data
Class DatabaseEntry

java.lang.Object
  extended by net.i2p.data.DataStructureImpl
      extended by net.i2p.data.DatabaseEntry
All Implemented Interfaces:
DataStructure
Direct Known Subclasses:
LeaseSet, RouterInfo

public abstract class DatabaseEntry
extends DataStructureImpl

Base implementation of common methods for the two data structures that are stored in the netDb, i.e. LeaseSet and RouterInfo. Implemented in 0.8.2 and retrofitted over LeaseSet and RouterInfo. This consolidates some common code and makes it easier to implement the NetDB and I2NP without doing instanceof all over the place. DatabaseEntries have a SHA256 hash, a routing key, a timestamp, and signatures.

Since:
0.8.2
Author:
zzz

Field Summary
protected  Hash _currentRoutingKey
           
protected  byte[] _routingKeyGenMod
           
protected  Signature _signature
           
static int KEY_TYPE_LEASESET
           
static int KEY_TYPE_ROUTERINFO
          these are the same as in i2np's DatabaseStoreMessage
 
Constructor Summary
DatabaseEntry()
           
 
Method Summary
protected abstract  byte[] getBytes()
          Returns the raw payload data, excluding the signature, to be signed by sign().
abstract  long getDate()
          A common interface to the timestamp of the two subclasses.
 Hash getHash()
          A common interface to the Hash of the two subclasses.
protected abstract  KeysAndCert getKeysAndCert()
          Get the keys and the cert Identical to getDestination() in LeaseSet, and getIdentity() in RouterInfo.
 Hash getRoutingKey()
          Get the routing key for the structure using the current modifier in the RoutingKeyGenerator.
 Signature getSignature()
          Retrieve the proof that the identity stands behind the info here
protected  SigningPublicKey getSigningPublicKey()
          Identical to getDestination().getSigningPublicKey() in LeaseSet, and getIdentity().getSigningPublicKey() in RouterInfo.
abstract  int getType()
          Get the type of the data structure.
 void setRoutingKey(Hash key)
           
 void setSignature(Signature signature)
          Configure the proof that the entity stands behind the info here
 void sign(SigningPrivateKey key)
          Sign the structure using the supplied signing key
 boolean validateRoutingKey()
           
protected  boolean verifySignature()
          This is the same as isValid() in RouterInfo or verifySignature() in LeaseSet.
 
Methods inherited from class net.i2p.data.DataStructureImpl
calculateHash, fromBase64, fromByteArray, read, toBase64, toByteArray
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.i2p.data.DataStructure
readBytes, writeBytes
 

Field Detail

KEY_TYPE_ROUTERINFO

public static final int KEY_TYPE_ROUTERINFO
these are the same as in i2np's DatabaseStoreMessage

See Also:
Constant Field Values

KEY_TYPE_LEASESET

public static final int KEY_TYPE_LEASESET
See Also:
Constant Field Values

_signature

protected volatile Signature _signature

_currentRoutingKey

protected volatile Hash _currentRoutingKey

_routingKeyGenMod

protected volatile byte[] _routingKeyGenMod
Constructor Detail

DatabaseEntry

public DatabaseEntry()
Method Detail

getDate

public abstract long getDate()
A common interface to the timestamp of the two subclasses. Identical to getEarliestLeaseData() in LeaseSet, and getPublished() in RouterInfo. Note that for a LeaseSet this will be in the future, and for a RouterInfo it will be in the past. Either way, it's a timestamp.

Since:
0.8.2

getKeysAndCert

protected abstract KeysAndCert getKeysAndCert()
Get the keys and the cert Identical to getDestination() in LeaseSet, and getIdentity() in RouterInfo.

Returns:
KAC or null
Since:
0.8.2

getHash

public Hash getHash()
A common interface to the Hash of the two subclasses. Identical to getDestination().calculateHash() in LeaseSet, and getIdentity().getHash() in RouterInfo.

Returns:
Hash or null
Since:
0.8.2

getType

public abstract int getType()
Get the type of the data structure. This should be faster than instanceof.

Returns:
KEY_TYPE_ROUTERINFO or KEY_TYPE_LEASESET
Since:
0.8.2

getBytes

protected abstract byte[] getBytes()
                            throws DataFormatException
Returns the raw payload data, excluding the signature, to be signed by sign(). FIXME RouterInfo throws DFE and LeaseSet returns null

Returns:
null on error ???????????????????????
Throws:
DataFormatException

getRoutingKey

public Hash getRoutingKey()
Get the routing key for the structure using the current modifier in the RoutingKeyGenerator. This only calculates a new one when necessary though (if the generator's key modifier changes)


setRoutingKey

public void setRoutingKey(Hash key)

validateRoutingKey

public boolean validateRoutingKey()

getSignature

public Signature getSignature()
Retrieve the proof that the identity stands behind the info here


setSignature

public void setSignature(Signature signature)
Configure the proof that the entity stands behind the info here


sign

public void sign(SigningPrivateKey key)
          throws DataFormatException
Sign the structure using the supplied signing key

Throws:
DataFormatException

getSigningPublicKey

protected SigningPublicKey getSigningPublicKey()
Identical to getDestination().getSigningPublicKey() in LeaseSet, and getIdentity().getSigningPublicKey() in RouterInfo.

Returns:
SPK or null
Since:
0.8.2

verifySignature

protected boolean verifySignature()
This is the same as isValid() in RouterInfo or verifySignature() in LeaseSet.

Returns:
valid