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

public class Destinationextends 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:
  • Field Details

    • _cachedB64

      private String _cachedB64
      Cached b64.
    • CACHE_SIZE

      private static final int CACHE_SIZE
      Number of destinations cached, sized from free memory.
    • MIN_CACHE_SIZE

      private static final int MIN_CACHE_SIZE
      Smallest destination cache allowed.
      See Also:
    • MAX_CACHE_SIZE

      private static final int MAX_CACHE_SIZE
      Largest destination cache allowed.
      See Also:
    • _cache

      private static final Map<SigningPublicKey, Destination> _cache
      Destinations by signing key.
  • Constructor Details

    • Destination

      public Destination()
      Empty destination with no data set.
    • 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 - if the string is invalid
    • Destination

      private Destination(PublicKey pk, SigningPublicKey sk, Certificate c, byte[] padding)
      Creates a destination from its components.
      Parameters:
      pk - the encryption public key
      sk - the signing public key
      c - the certificate type, usually null
      padding - the lease key padding
  • Method Details

    • create

      public static Destination create(InputStream in) throws DataFormatException, IOException
      Pull from cache or return new.
      Parameters:
      in - the input stream
      Returns:
      the destination read from the stream, shared with any instance already cached under the same signing key
      Throws:
      DataFormatException - if data is invalid
      IOException - if an I/O error occurs
    • writeBytes

      public int writeBytes(byte[] target, int offset)
      Deprecated, used only by Packet.java in streaming. Minimal variant of writeBytes(OutputStream) that writes a typed (XDH/PQ) destination too; the KEYSIZE_BYTES hardcode broke 32-byte key destinations with ArrayIndexOutOfBoundsException. Broken for sig types P521 and RSA before 0.9.15.
      Parameters:
      target - the buffer receiving the serialised destination
      offset - the offset to start writing
      Returns:
      the written length (NOT the new offset)
    • size

      public int size()
      Serialized size of this destination. Must match writeBytes(byte[], int); the KEYSIZE_BYTES hardcode broke 32-byte key destinations. For typed keys the wire layout is [pk data][pad1][pad2][spk data][cert], so the base is the actual public key length plus the truncated signing key length.
      Returns:
      the size in bytes
    • 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
    • toBase32

      public String toBase32()
      For convenience.
      Returns:
      "{52 chars}.b32.i2p" or null if fields not set.
    • clearCache

      public static void clearCache()
      Clear the cache.
    • equals

      public boolean equals(Object o)
      Compares this Destination for equality with another object.
      Overrides:
      equals in class KeysAndCert
    • hashCode

      public int hashCode()
      Hash code of this destination.
      Overrides:
      hashCode in class KeysAndCert
      Returns:
      the signing key's hash code, or 0 if there is none