java.lang.Object
net.i2p.data.DataStructureImpl
net.i2p.data.Lease
net.i2p.data.MetaLease
- All Implemented Interfaces:
Serializable, DataStructure
Implementation of MetaLease as specified in Proposal 123: New NetDb Entries.
MetaLease extends the Lease concept to reference other LeaseSets rather than tunnel endpoints:
- Points to another LeaseSet via its hash instead of a gateway router
- Enables advanced routing and load balancing strategies
- Includes cost and type information for selection algorithms
- Fixed length of 40 bytes for consistency with Lease2
Structure:
- LeaseSet Hash: 32-byte hash of the target LeaseSet (available via
Lease.getGateway()) - Cost: 4-byte cost value for routing decisions
- Type: 4-byte type identifier for the referenced LeaseSet
Key Differences from Lease:
- Reference: Points to LeaseSet hash, not gateway router
- TunnelId: Not supported (throws
UnsupportedOperationException) - Metadata: Includes cost and type for intelligent selection
- Usage: Used within MetaLeaseSet for indirect routing
Usage Scenarios:
- Load Balancing: Distribute traffic across multiple LeaseSets
- Geographic Routing: Select LeaseSets based on location or performance
- Fallback Strategies: Provide alternative LeaseSets for redundancy
- Service Aggregation: Combine multiple services under one destination
Selection Criteria:
- Cost: Lower values indicate preferred routes
- Type: Application-specific categorization
- Hash: Uniquely identifies the target LeaseSet
Implementation Status: PRELIMINARY - Subject to change as proposal evolves.
- See Also:
Field Summary
Constructor Summary
ConstructorsConstructorDescriptionRequired for deserialization:readBytes(InputStream)fills the inherited and own fields.Method Summary
All MethodsModifier and TypeMethodDescriptionbooleanCompares this Lease with another object for equality.intgetCost()Cost value for this lease.UnsupportedOperationException always.intgetType()Type identifier for this lease.inthashCode()Hash code based on end time, gateway, and tunnel ID.voidreadBytes(InputStream in) Reads the lease from an input stream.voidsetCost(int cost) Set the cost of this lease.voidsetTunnelId(TunnelId id) UnsupportedOperationException always.voidsetType(int type) Set the type of this lease.toString()Returns a string representation of this Lease.voidwriteBytes(OutputStream out) Writes the lease to an output stream.Methods inherited from class Lease
getEndDate, getEndTime, getGateway, isExpired, isExpired, setEndDate, setEndDate, setGatewayModifier and TypeMethodDescriptionConvenience wrapper, preferLease.getEndTime()for new code.longGets the lease end time.Retrieve the router at which the destination can be contacted.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.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
_cost
private int _costCost value for this meta lease._type
private int _typeType identifier for this meta lease.
Constructor Details
MetaLease
public MetaLease()Required for deserialization:readBytes(InputStream)fills the inherited and own fields.
Method Details
getCost
public int getCost()Cost value for this lease.- Returns:
- the cost value, a raw int with no unit of its own
setCost
public void setCost(int cost) Set the cost of this lease.- Parameters:
cost- the cost value recorded in the LeaseSet for this tunnel, stored and compared as a raw int
getType
public int getType()Type identifier for this lease.- Returns:
- the tunnel type identifier, a raw int
setType
public void setType(int type) Set the type of this lease.- Parameters:
type- the tunnel type identifier recorded in the LeaseSet, stored and compared as a raw int
getTunnelId
UnsupportedOperationException always.- Overrides:
getTunnelIdin classLease- Returns:
- the tunnel id
- Throws:
UnsupportedOperationException- always, as a meta lease has no tunnel of its own
setTunnelId
UnsupportedOperationException always.- Overrides:
setTunnelIdin classLease- Parameters:
id- the tunnel on the gateway to communicate with; null clears it- Throws:
UnsupportedOperationException- always, as a meta lease has no tunnel of its own
readBytes
Reads 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
Writes 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
toString