Class DatabaseEntry
- All Implemented Interfaces:
Serializable
,DataStructure
- Direct Known Subclasses:
LeaseSet
,RouterInfo
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:
-
Field Summary
Modifier and TypeFieldDescriptionprotected Signature
static final int
static final int
static final int
static final int
static final int
these are the same as in i2np's DatabaseStoreMessagestatic final int
static final int
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected 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.getHash()
A common interface to the Hash of the two subclasses.abstract KeysAndCert
Get the keys and the cert Identical to getDestination() in LeaseSet, and getIdentity() in RouterInfo.Get the routing key for the structure using the current modifier in the RoutingKeyGenerator.Retrieve the proof that the identity stands behind the info hereprotected SigningPublicKey
Identical to getDestination().getSigningPublicKey() in LeaseSet, and getIdentity().getSigningPublicKey() in RouterInfo.abstract int
getType()
Get the type of the data structure.boolean
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
boolean
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 Details
-
KEY_TYPE_ROUTERINFO
public static final int KEY_TYPE_ROUTERINFOthese are the same as in i2np's DatabaseStoreMessage- See Also:
-
KEY_TYPE_LEASESET
public static final int KEY_TYPE_LEASESET- See Also:
-
KEY_TYPE_LS2
public static final int KEY_TYPE_LS2- Since:
- 0.9.38
- See Also:
-
KEY_TYPE_ENCRYPTED_LS2
public static final int KEY_TYPE_ENCRYPTED_LS2- Since:
- 0.9.38
- See Also:
-
KEY_TYPE_META_LS2
public static final int KEY_TYPE_META_LS2- Since:
- 0.9.38
- See Also:
-
KEY_TYPE_SERVICE_RECORD
public static final int KEY_TYPE_SERVICE_RECORD- Since:
- 0.9.38
- See Also:
-
KEY_TYPE_SERVICE_LIST
public static final int KEY_TYPE_SERVICE_LIST- Since:
- 0.9.38
- See Also:
-
_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 getEarliestLeaseDate() 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
-