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.
Do not reuse objects. Many of the setters and other methods contain checks to prevent altering a DatabaseEntry after it is signed. This protects the netdb, messages that contain DatabaseEntries, and the object itself from simple causes of corruption, by throwing IllegalStateExceptions. These checks are not necessarily thread-safe, and are not guaranteed to catch all possible means of corruption. Beware of other avenues of corruption, such as directly modifying data stored in byte[] objects.
Modifier and Type | Field and Description |
---|---|
protected Hash |
_currentRoutingKey |
protected long |
_routingKeyGenMod |
protected Signature |
_signature |
static int |
KEY_TYPE_LEASESET |
static int |
KEY_TYPE_ROUTERINFO
these are the same as in i2np's DatabaseStoreMessage
|
Constructor and Description |
---|
DatabaseEntry() |
Modifier and Type | Method and Description |
---|---|
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.
|
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 |
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.
|
calculateHash, fromBase64, fromByteArray, read, toBase64, toByteArray
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
readBytes, writeBytes
public static final int KEY_TYPE_ROUTERINFO
public static final int KEY_TYPE_LEASESET
protected volatile Signature _signature
protected volatile Hash _currentRoutingKey
protected volatile long _routingKeyGenMod
public abstract long getDate()
public abstract KeysAndCert getKeysAndCert()
public Hash getHash()
public abstract int getType()
protected abstract byte[] getBytes() throws DataFormatException
DataFormatException
public Hash getRoutingKey()
IllegalStateException
- if not in RouterContextpublic boolean validateRoutingKey()
IllegalStateException
- if not in RouterContextpublic Signature getSignature()
public void setSignature(Signature signature)
IllegalStateException
- if already signedpublic void sign(SigningPrivateKey key) throws DataFormatException
IllegalStateException
- if already signedDataFormatException
protected SigningPublicKey getSigningPublicKey()
protected boolean verifySignature()