Class DatabaseEntry
- All Implemented Interfaces:
Serializable
,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.
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.
- Since:
- 0.8.2
- Author:
- zzz
- See Also:
- Serialized Form
-
Field Summary
Fields Modifier and Type Field 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 DatabaseStoreMessagestatic int
KEY_TYPE_SERVICE_LIST
static int
KEY_TYPE_SERVICE_RECORD
-
Constructor Summary
Constructors Constructor Description DatabaseEntry()
-
Method Summary
Modifier and Type Method 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 hereprotected 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 herevoid
sign(SigningPrivateKey key)
Sign the structure using the supplied signing keyboolean
validateRoutingKey()
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
-
Field Details
-
KEY_TYPE_ROUTERINFO
public static final int KEY_TYPE_ROUTERINFOthese 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
-
KEY_TYPE_LS2
public static final int KEY_TYPE_LS2- Since:
- 0.9.38
- See Also:
- Constant Field Values
-
KEY_TYPE_ENCRYPTED_LS2
public static final int KEY_TYPE_ENCRYPTED_LS2- Since:
- 0.9.38
- See Also:
- Constant Field Values
-
KEY_TYPE_META_LS2
public static final int KEY_TYPE_META_LS2- Since:
- 0.9.38
- See Also:
- Constant Field Values
-
KEY_TYPE_SERVICE_RECORD
public static final int KEY_TYPE_SERVICE_RECORD- Since:
- 0.9.38
- See Also:
- Constant Field Values
-
KEY_TYPE_SERVICE_LIST
public static final int KEY_TYPE_SERVICE_LIST- Since:
- 0.9.38
- See Also:
- Constant Field Values
-
_signature
-
-
Constructor Details
-
DatabaseEntry
public DatabaseEntry()
-
-
Method Details
-
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
Get the keys and the cert Identical to getDestination() in LeaseSet, and getIdentity() in RouterInfo.- Returns:
- KAC or null
- Since:
- 0.8.2, public since 0.9.17
-
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 or LS2 types
- Since:
- 0.8.2
-
isLeaseSet
public boolean isLeaseSet()Convenience method, is the type any variant of leaseset?- Returns:
- true for any type of LeaseSet, false for RouterInfo, false for others
- Since:
- 0.9.38
-
isLeaseSet
public static boolean isLeaseSet(int type)Convenience method, is the type any variant of leaseset?- Returns:
- true for any type of LeaseSet, false for RouterInfo, false for others
- Since:
- 0.9.38
-
getBytes
Returns the raw payload data, excluding the signature, to be signed by sign(). Most callers should use writeBytes() or toByteArray() instead. FIXME RouterInfo throws DFE and LeaseSet returns null- Returns:
- null on error ???????????????????????
- Throws:
DataFormatException
-
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)- Throws:
IllegalStateException
- if not in RouterContext
-
validateRoutingKey
public boolean validateRoutingKey()- Throws:
IllegalStateException
- if not in RouterContext
-
getSignature
Retrieve the proof that the identity stands behind the info here -
setSignature
Configure the proof that the entity stands behind the info here- Throws:
IllegalStateException
- if already signed
-
sign
Sign the structure using the supplied signing key- Throws:
IllegalStateException
- if already signedDataFormatException
-
getSigningPublicKey
Identical to getDestination().getSigningPublicKey() in LeaseSet, and getIdentity().getSigningPublicKey() in RouterInfo.- Returns:
- SPK or null
- Since:
- 0.8.2
-
verifySignature
public boolean verifySignature()This is the same as isValid() in RouterInfo or verifySignature() in LeaseSet.- Returns:
- valid
- Since:
- public since 0.9.47, was protected
-