java.lang.Object
net.i2p.data.DataStructureImpl
net.i2p.data.KeysAndCert
net.i2p.data.Destination
- All Implemented Interfaces:
Serializable, DataStructure
- Direct Known Subclasses:
VerifiedDestination
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 Summary
FieldsModifier and TypeFieldDescriptionprivate static final Map<SigningPublicKey, Destination> Destinations by signing key.private StringCached b64.private static final intNumber of destinations cached, sized from free memory.private static final intLargest destination cache allowed.private static final intSmallest destination cache allowed.Fields inherited from class KeysAndCert
_certificate, _paddingBlocks, _publicKey, _signingKeyModifier and TypeFieldDescriptionprotected CertificateCertificate specifying key types and metadata.protected intIf compressed, the padding size / 32, else 0.protected PublicKeyPublic encryption key.protected SigningPublicKeyPublic signing key.Constructor Summary
ModifierConstructorDescriptionEmpty destination with no data set.Alternative constructor which takes a base64 string representation.privateDestination(PublicKey pk, SigningPublicKey sk, Certificate c, byte[] padding) Creates a destination from its components.Method Summary
Modifier and TypeMethodDescriptionstatic voidClear the cache.static Destinationcreate(InputStream in) Pull from cache or return new.booleanCompares this Destination for equality with another object.inthashCode()Hash code of this destination.intsize()Serialized size of this destination.toBase32()For convenience.toBase64()Cache it.intwriteBytes(byte[] target, int offset) Deprecated, used only by Packet.java in streaming.Methods inherited from class KeysAndCert
calculateHash, combinePadding, getCertificate, getEncType, getHash, getPadding, getPublicKey, getSigningPublicKey, getSigType, isCompressible, readBytes, setCertificate, setPadding, setPublicKey, setSigningPublicKey, toString, writeBytes, writePaddingBytesModifier and TypeMethodDescriptionThrows IllegalStateException if keys and cert are not initialized, as of 0.9.12.protected static byte[]combinePadding(byte[] pad1, byte[] pad2) Combines two padding arrays.Certificate for this identity.Encryption type from the certificate.getHash()Throws IllegalStateException if keys and cert are not initialized, as of 0.9.12.byte[]Padding bytes for key alignment.Valid for RouterIdentities.Signing public key for this identity.Signature type from the certificate.booleanIs there compressible padding?voidreadBytes(InputStream in) Reads the keys and certificate from an input stream.voidsetCertificate(Certificate cert) Certificate to set.voidsetPadding(byte[] padding) Padding bytes to set.voidsetPublicKey(PublicKey key) Public key to set.voidSigning public key to set.toString()Returns a string representation of this KeysAndCert.voidwriteBytes(OutputStream out) Writes the keys and certificate to an output stream.protected intwritePaddingBytes(byte[] target, int off) ForDestination.writeBytes().Methods inherited from class DataStructureImpl
fromBase64, fromByteArray, read, toByteArrayModifier and TypeMethodDescriptionvoidfromBase64(String data) Load the structure from the provided base64 string.voidfromByteArray(byte[] data) Loads structure from the data providedprotected intread(InputStream in, byte[] target) Repeated reads until buffer is full or IOException is thrown.byte[]Convert the structure to a byte array.
Field Details
_cachedB64
Cached b64.CACHE_SIZE
private static final int CACHE_SIZENumber of destinations cached, sized from free memory.MIN_CACHE_SIZE
private static final int MIN_CACHE_SIZESmallest destination cache allowed.- See Also:
MAX_CACHE_SIZE
private static final int MAX_CACHE_SIZELargest destination cache allowed.- See Also:
_cache
Destinations by signing key.
Constructor Details
Destination
public Destination()Empty destination with no data set.Destination
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
Creates a destination from its components.- Parameters:
pk- the encryption public keysk- the signing public keyc- the certificate type, usually nullpadding- the lease key padding
Method Details
create
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 invalidIOException- 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 destinationoffset- the offset to start writing- Returns:
- the written length (NOT the new offset)
size
public int size()Serialized size of this destination. Must matchwriteBytes(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
Cache it. Useful in I2PTunnelHTTPServer where it is added to the headers.- Specified by:
toBase64in interfaceDataStructure- Overrides:
toBase64in classDataStructureImpl- Returns:
- null on error
toBase32
clearCache
public static void clearCache()Clear the cache.equals
Compares this Destination for equality with another object.- Overrides:
equalsin classKeysAndCert
hashCode
public int hashCode()Hash code of this destination.- Overrides:
hashCodein classKeysAndCert- Returns:
- the signing key's hash code, or 0 if there is none