java.lang.Object
net.i2p.data.DataStructureImpl
net.i2p.data.Lease
net.i2p.data.Lease2
- All Implemented Interfaces:
Serializable, DataStructure
Implementation of Lease2 as specified in Proposal 123: New NetDb Entries.
Lease2 extends the original Lease format with enhanced timestamp resolution:
- Uses 4-byte timestamps instead of 8-byte for space efficiency
- Timestamps have 1-second resolution (stored as seconds since epoch)
- Fixed length of 40 bytes for consistent serialization
- Designed for use with
LeaseSet2and its variants
Structure:
- Gateway: 32-byte Hash of the gateway router
- Tunnel ID: 4-byte tunnel identifier
- End Time: 4-byte timestamp (seconds since epoch)
Key Differences from Lease:
- Timestamp resolution: 4 bytes vs 8 bytes in original Lease
- Time representation: Seconds vs milliseconds
- Fixed total length: 40 bytes
- Optimized for LeaseSet2 serialization format
Usage:
- Used within LeaseSet2, MetaLeaseSet, and EncryptedLeaseSet
- Provides more compact representation for large numbers of leases
- Maintains compatibility with existing tunnel infrastructure
Implementation Status: PRELIMINARY - Subject to change as the proposal evolves.
- See Also:
Field Summary
FieldsConstructor Summary
ConstructorsMethod Summary
All MethodsModifier and TypeMethodDescriptionbooleanCompares this Lease with another object for equality.inthashCode()Hash code based on end time, gateway, and tunnel ID.voidreadBytes(InputStream in) Reads the lease from an input stream.voidwriteBytes(OutputStream out) Writes the lease to an output stream.Methods inherited from class Lease
getEndDate, getEndTime, getGateway, getTunnelId, isExpired, isExpired, setEndDate, setEndDate, setGateway, setTunnelId, toStringModifier and TypeMethodDescriptionConvenience wrapper, preferLease.getEndTime()for new code.longGets the lease end time.Retrieve the router at which the destination can be contacted.Tunnel on the gateway to communicate with.booleanTrue if the lease has expired.booleanisExpired(long fudgeFactor) Fudge factor in milliseconds for clock skew.voidsetEndDate(long date) Sets the lease end date.voidsetEndDate(Date date) Convenience wrapper, prefer the long overload for new code.voidsetGateway(Hash ident) Configure the router at which the destination can be contacted.voidsetTunnelId(TunnelId id) Configure the tunnel on the gateway to communicate with.toString()Returns a string representation of this Lease.Methods inherited from class DataStructureImpl
calculateHash, fromBase64, fromByteArray, read, toBase64, toByteArrayModifier 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.byte[]Convert the structure to a byte array.
Field Details
LENGTH
Constructor Details
Lease2
public Lease2()Constructor. An empty lease; the gateway, tunnel id and end date are filled in byreadBytes(InputStream)or by the LeaseSet that owns it.
Method Details
readBytes
Description copied from class:LeaseReads the lease from an input stream.- Specified by:
readBytesin interfaceDataStructure- Overrides:
readBytesin classLease- Parameters:
in- stream to read from- Throws:
DataFormatException- if the data is improperly formattedIOException- if there was a problem reading the stream
writeBytes
Description copied from class:LeaseWrites the lease to an output stream.- Specified by:
writeBytesin interfaceDataStructure- Overrides:
writeBytesin classLease- 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
equals
hashCode