net.i2p.data

## Class Destination

- java.lang.Object
- - net.i2p.data.DataStructureImpl
  - - net.i2p.data.KeysAndCert
    - - net.i2p.data.Destination

- All Implemented Interfaces:
    Serializable, DataStructure
  Direct Known Subclasses:
    VerifiedDestination

      public class Destination
      extends KeysAndCert

  Defines an endpoint in the I2P network that can receive messages.

  Destination represents the fundamental addressing and identity concept in I2P:

  - Network Endpoint: Messages sent to a Destination will find it regardless of location
  - Cryptographic Identity: Contains encryption and signing keys
  - Certificate: Optional metadata about the identity
  - Addressing: Can be encoded as Base64 or Base32 (.b32.i2p)
  - Immutability: Identity becomes immutable after keys are set

  Key Components:

  - Public Encryption Key: Historically used for end-to-end encryption
  - Signing Public Key: Used for identity verification and LeaseSet signing
  - Certificate: Optional metadata (NULL, HIDDEN, SIGNED, etc.)
  - Cached Hash: SHA-256 hash for efficient identification

  Address Formats:

  - Base64: Full binary encoding for configuration files
  - Base32: Human-readable .b32.i2p addresses
  - Hash: 32-byte SHA-256 for internal identification

  Historical Changes:

  - Pre-0.6: Public key used for end-to-end encryption
  - Post-0.6: End-to-end encryption removed, LeaseSet keys used instead
  - LeaseSet Encryption: Public key first bytes used as IV (deprecated)
  - 0.9.9: Immutable after keys and certificate are set

  Usage:

  - Client Connections: Target for I2P client communications
  - Service Hosting: Identity for hosting I2P services
  - Message Routing: Destination for I2NP message delivery
  - Address Book: Entry in address books and contact lists

  Security Considerations:

  - Key Protection: Private keys must be securely stored
  - Identity Verification: Always verify signatures from destinations
  - Certificate Validation: Check certificate types and content
  - Deprecated Features: Avoid legacy encryption mechanisms

  Performance Features:

  - Caching: LRU cache for frequently used destinations
  - Lazy Computation: Base32 address computed on demand
  - Efficient Storage: Optimized memory usage and serialization
  - Fast Lookup: Hash-based identification for quick comparisons

  Immutability:

  - After 0.9.9: Keys and certificate cannot be changed after setting
  - Thread Safety: Immutable objects are inherently thread-safe
  - Corruption Prevention: Protects against accidental modification
  - Exception: Modification attempts throw `IllegalStateException`

  Migration Notes:

  - Legacy Encryption: Public key usage deprecated in favor of LeaseSet encryption
  - Modern Alternatives: Use EncryptedLeaseSet for proper encryption
  - IV Generation: LeaseSet encryption IV should not use public key bytes
  See Also:
    Serialized Form

- - ### Field Summary

    - ### Fields inherited from class net.i2p.data.KeysAndCert

      `_certificate, _paddingBlocks, _publicKey, _signingKey`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `Destination()`
    `Destination(String s)` alternative constructor which takes a base64 string representation

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static void` | `clearCache()` Clear the cache.
    `static Destination` | `create(InputStream in)` Pull from cache or return new
    `boolean` | `equals(Object o)`
    `int` | `hashCode()` the signing key has enough randomness in it to use it by itself for speed
    `int` | `size()`
    `String` | `toBase32()` For convenience.
    `String` | `toBase64()` Cache it.
    `int` | `writeBytes(byte[] target, int offset)` Deprecated, used only by Packet.java in streaming.

    - ### Methods inherited from class net.i2p.data.KeysAndCert

      `calculateHash, combinePadding, getCertificate, getEncType, getHash, getPadding, getPublicKey, getSigningPublicKey, getSigType, isCompressible, readBytes, setCertificate, setPadding, setPublicKey, setSigningPublicKey, toString, writeBytes, writePaddingBytes`

    - ### Methods inherited from class net.i2p.data.DataStructureImpl

      `fromBase64, fromByteArray, read, toByteArray`

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### Destination

          public Destination()

    - #### Destination

          public Destination(String s)
                      throws DataFormatException

      alternative constructor which takes a base64 string representation
      Parameters:
        `s` - a Base64 representation of the destination, as (eg) is used in hosts.txt
      Throws:
        `DataFormatException`

  - ### Method Detail

    - #### clearCache

          public static void clearCache()

      Clear the cache.

    - #### create

          public static Destination create(InputStream in)
                                    throws DataFormatException,
                                           IOException

      Pull from cache or return new
      Throws:
        `DataFormatException`
        `IOException`

    - #### equals

          public boolean equals(Object o)

      Overrides:
        `equals` in class `KeysAndCert`

    - #### hashCode

          public int hashCode()

      Description copied from class: `KeysAndCert`
      the signing key has enough randomness in it to use it by itself for speed
      Overrides:
        `hashCode` in class `KeysAndCert`

    - #### size

          public int size()

    - #### toBase32

          public String toBase32()

      For convenience.
      Returns:
        "{52 chars}.b32.i2p" or null if fields not set.

    - #### toBase64

          public String toBase64()

      Cache it. Useful in I2PTunnelHTTPServer where it is added to the headers
      Specified by:
        `toBase64` in interface `DataStructure`
      Overrides:
        `toBase64` in class `DataStructureImpl`
      Returns:
        null on error

    - #### writeBytes

          public int writeBytes(byte[] target,
                                int offset)

      Deprecated, used only by Packet.java in streaming. Broken for sig types P521 and RSA before 0.9.15
      Returns:
        the written length (NOT the new offset)