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 Signature |
_signature |
static int |
KEY_TYPE_ENCRYPTED_LS2 |
static int |
KEY_TYPE_LEASESET |
static int |
KEY_TYPE_LS2 |
static int |
KEY_TYPE_META_LS2 |
static int |
KEY_TYPE_ROUTERINFO
these are the same as in i2np's DatabaseStoreMessage
|
static int |
KEY_TYPE_SERVICE_LIST |
static int |
KEY_TYPE_SERVICE_RECORD |
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.
|
boolean |
isLeaseSet()
Convenience method, is the type any variant of leaseset?
|
static boolean |
isLeaseSet(int type)
Convenience method, is the type any variant of leaseset?
|
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
public static final int KEY_TYPE_LS2
public static final int KEY_TYPE_ENCRYPTED_LS2
public static final int KEY_TYPE_META_LS2
public static final int KEY_TYPE_SERVICE_RECORD
public static final int KEY_TYPE_SERVICE_LIST
protected volatile Signature _signature
public abstract long getDate()
public abstract KeysAndCert getKeysAndCert()
public Hash getHash()
public abstract int getType()
public boolean isLeaseSet()
public static boolean isLeaseSet(int type)
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()