Package net.i2p.data

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 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_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

        protected volatile Signature _signature
    • 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

        public 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, public since 0.9.17
      • 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 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

        protected abstract byte[] getBytes()
                                    throws DataFormatException
        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

        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)
        Throws:
        IllegalStateException - if not in RouterContext
      • validateRoutingKey

        public boolean validateRoutingKey()
        Throws:
        IllegalStateException - if not in RouterContext
      • 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
        Throws:
        IllegalStateException - if already signed
      • getSigningPublicKey

        protected SigningPublicKey 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