java.lang.Object
net.i2p.data.DataStructureImpl
net.i2p.data.i2np.GarlicClove
- All Implemented Interfaces:
Serializable, DataStructure
Contains one deliverable message encrypted to a router along with instructions and a certificate 'paying for' the delivery.
Note that certificates are always the null certificate at this time, others are unimplemented.
- See Also:
Field Summary
FieldsModifier and TypeFieldDescriptionprivate CertificateCertificate authorizing delivery (always null certificate currently).private longUnique identifier for this clove.private final I2PAppContextApplication context for logging and configuration.private longTime after which this clove expires.private DeliveryInstructionsHow and where to deliver this clove.private I2NPMessageThe message payload wrapped in this clove.private static final longPinned for serialized-form compatibility.Constructor Summary
ConstructorsConstructorDescriptionGarlicClove(I2PAppContext context) Creates an empty clove with no id until one is read or set.Method Summary
All MethodsModifier and TypeMethodDescriptionbooleanCompare all clove fields for equality.intEstimated serialized length of this clove.Certificate authorizing delivery of this clove.longUnique identifier for this clove.getData()The message payload wrapped in this clove.longTime after which this clove expires.How and where to deliver this clove.intSize of the ratchet-format clove.inthashCode()Hash code covering all clove fields.intreadBytes(byte[] source, int offset) Read the clove from a byte array.voidreadBytesRatchet(byte[] source, int offset, int len) Short format for ECIES-Ratchet, saves 22 bytes.voidsetCertificate(Certificate cert) Certificate authorizing delivery of this clove.voidsetCloveId(long id) Unique identifier for this clove.voidsetData(I2NPMessage msg) Message payload wrapped in this clove.voidsetExpiration(long exp) Time after which this clove expires.voidDelivery instructions for this clove.byte[]Serialized clove.toString()String form for debugging, showing the instructions, expiration, and data.intwriteBytesRatchet(byte[] tgt, int offset) Short format for ECIES-Ratchet, saves 22 bytes.Methods inherited from class DataStructureImpl
calculateHash, fromBase64, fromByteArray, read, toBase64Modifier 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 providedprotected intread(InputStream in, byte[] target) Repeated reads until buffer is full or IOException is thrown.toBase64()Render the structure into modified base 64 notation.Methods inherited from interface DataStructure
readBytes, writeBytesModifier and TypeMethodDescriptionvoidreadBytes(InputStream in) Load up the current object with data from the given stream.voidwriteBytes(OutputStream out) Write out the data structure to the stream, using the format defined in the I2P data structure specification.
Field Details
serialVersionUID
private static final long serialVersionUIDPinned for serialized-form compatibility.- See Also:
_context
Application context for logging and configuration._instructions
How and where to deliver this clove._msg
The message payload wrapped in this clove._cloveId
private long _cloveIdUnique identifier for this clove._expiration
private long _expirationTime after which this clove expires._certificate
Certificate authorizing delivery (always null certificate currently).
Constructor Details
GarlicClove
Creates an empty clove with no id until one is read or set.- Parameters:
context- the app context used to read messages and to log
Method Details
getInstructions
How and where to deliver this clove.- Returns:
- the delivery instructions, or null until set
setInstructions
Delivery instructions for this clove.- Parameters:
instr- the routing instructions this clove is to be delivered under
getData
The message payload wrapped in this clove.- Returns:
- the wrapped I2NP message, or null until set
setData
Message payload wrapped in this clove.- Parameters:
msg- the I2NP message this clove carries
getCloveId
public long getCloveId()Unique identifier for this clove.- Returns:
- the clove id
setCloveId
public void setCloveId(long id) Unique identifier for this clove.- Parameters:
id- the unique identifier to record for this clove
getExpiration
public long getExpiration()Time after which this clove expires.- Returns:
- the expiry time in ms since the epoch, 0 when unset
setExpiration
public void setExpiration(long exp) Time after which this clove expires.- Parameters:
exp- the time in milliseconds since the epoch after which this clove expires
getCertificate
Certificate authorizing delivery of this clove.- Returns:
- the authorizing certificate, or null when none was set
setCertificate
Certificate authorizing delivery of this clove.- Parameters:
cert- the certificate authorizing delivery of this clove
readBytes
Read the clove from a byte array.- Parameters:
source- the array holding the serialized cloveoffset- the offset into source at which the clove starts- Returns:
- the bytes consumed, from offset through the end of the certificate
- Throws:
DataFormatException- if the delivery instructions, message or certificate cannot be parsed
readBytesRatchet
Short format for ECIES-Ratchet, saves 22 bytes. NTCP2-style header, no ID, no separate expiration, no cert.- Parameters:
source- the array holding the serialized ratchet-format cloveoffset- the offset into source at which the clove startslen- the number of bytes of source that make up the clove- Throws:
DataFormatException- if the delivery instructions or message cannot be parsed
toByteArray
public byte[] toByteArray()Serialized clove.- Specified by:
toByteArrayin interfaceDataStructure- Overrides:
toByteArrayin classDataStructureImpl- Returns:
- the clove in standard (non-ratchet) format, sized by
estimateSize()
writeBytesRatchet
public int writeBytesRatchet(byte[] tgt, int offset) Short format for ECIES-Ratchet, saves 22 bytes. NTCP2-style header, no ID, no separate expiration, no cert.- Parameters:
tgt- the array the clove is written intooffset- the offset into tgt at which to start writing- Returns:
- the offset just past the ratchet-format clove
getSizeRatchet
public int getSizeRatchet()Size of the ratchet-format clove.- Returns:
- the ratchet-clove size
estimateSize
public int estimateSize()Estimated serialized length of this clove.- Returns:
- the number of bytes toByteArray will produce for this clove
equals
hashCode
toString