- All Known Implementing Classes:
AbuseReason, AbuseSeverity, Certificate, DatabaseEntry, DataStructureImpl, DateAndFlags, DeliveryInstructions, Destination, EncryptedBuildRecord, EncryptedLeaseSet, GarlicClove, Hash, Hash384, Hash512, InfoHash, KeyCertificate, KeysAndCert, Lease, Lease2, LeaseSet, LeaseSet2, LocalHash, MetaLease, MetaLeaseSet, NextSessionKey, NID, NodeInfo, Payload, Peer, PrivateKey, PublicKey, RouterAddress, RouterIdentity, RouterInfo, RSASigningPrivateCrtKey, SendMessageOptions, SessionConfig, SessionKey, SessionKeyAndNonce, SHA1Hash, ShortEncryptedBuildRecord, Signature, SigningPrivateKey, SigningPublicKey, SimpleDataStructure, TokenKey, VerifiedDestination
public interface DataStructure
Base interface defining standard binary representation for I2P data structures.
DataStructure provides the foundation for all I2P protocol data:
- Binary Protocol: Defines exact bit-level representation
- Serialization: Standard methods for reading/writing to streams
- Network Compatibility: Ensures consistent data encoding
- Validation: Built-in integrity and format checking
Core Operations:
readBytes(InputStream)- Deserialize from binary streamwriteBytes(OutputStream)- Serialize to binary stream- Format Compliance: Follows I2P data structure specification
- Error Handling: Proper exception reporting for invalid data
Integrity Protection:
- Immutable After Initialization: Prevents modification after deserialization
- IllegalStateException: Thrown when modification is attempted
- NetDb Protection: Safeguards network database from corruption
- Message Safety: Protects I2NP messages during transmission
Usage Throughout I2P:
- I2NP Messages: All protocol messages implement DataStructure
- NetDb Entries: RouterInfo and LeaseSet storage format
- I2CP Protocol: Client-router communication data
- Cryptography: Keys, signatures, and certificates
- Routing: Tunnel IDs, leases, and routing information
Implementation Guidelines:
- Do Not Reuse: Create new instances for each data element
- Thread Safety: Protection is not guaranteed to be thread-safe
- Corruption Prevention: Multiple protection layers but not foolproof
- Direct Modification: Avoid modifying internal byte[] arrays
Security Considerations:
- Input Validation: Always validate deserialized data
- Bounds Checking: Prevent buffer overflows and underflows
- Exception Handling: Properly handle DataFormatException
- Memory Safety: Be cautious with direct byte array access
Performance Aspects:
- Efficient Serialization: Optimized for network transmission
- Minimal Overhead: Compact binary representation
- Fast Validation: Quick integrity and format checking
- Memory Management: Careful allocation and cleanup
Common Implementations:
DataStructureImpl- Base class with common functionalitySimpleDataStructure- Fixed-size byte array structuresDatabaseEntry- NetDb-storable objects with signatures- All I2P protocol message classes
Method Summary
All MethodsModifier and TypeMethodDescriptionCalculate the SHA256 value of this object (useful for a few scenarios).voidfromBase64(String data) Load the structure from the provided base64 string.voidfromByteArray(byte[] data) Loads structure from the data providedvoidreadBytes(InputStream in) Load up the current object with data from the given stream.toBase64()Render the structure into modified base 64 notation.byte[]Convert the structure to a byte array.voidwriteBytes(OutputStream out) Write out the data structure to the stream, using the format defined in the I2P data structure specification.
Method Details
readBytes
Load up the current object with data from the given stream. Data loaded this way must match the I2P data structure specification.Warning - many classes will throw IllegalStateException if data is already set.
- Parameters:
in- stream to read from- Throws:
DataFormatException- if the data is improperly formattedIOException- if there was a problem reading the stream
writeBytes
Write out the data structure to the stream, using the format defined in the I2P data structure specification.- Parameters:
out- stream to write to- Throws:
DataFormatException- if the data was incomplete or not yet ready to be writtenIOException- if there was a problem writing to the stream
toBase64
fromBase64
Load the structure from the provided base64 string.Warning - many classes will throw IllegalStateException if data is already set. Warning - many classes will throw IllegalArgumentException if data is the wrong size.
- Parameters:
data- base64 encoded string to load from- Throws:
DataFormatException- if the data format is invalid
toByteArray
byte[] toByteArray()Convert the structure to a byte array.- Returns:
- may be null if data is not set
fromByteArray
Loads structure from the data providedWarning - many classes will throw IllegalStateException if data is already set. Warning - many classes will throw IllegalArgumentException if data is the wrong size.
- Parameters:
data- byte array to load from- Throws:
DataFormatException- if the data format is invalid
calculateHash
Hash calculateHash()Calculate the SHA256 value of this object (useful for a few scenarios).- Returns:
- SHA256 hash, or null if there were problems (data format or io errors)