java.lang.Object
net.i2p.data.DataStructureImpl
net.i2p.data.Lease
- All Implemented Interfaces:
Serializable, DataStructure
Authorization grant proving a router/tunnel may receive messages for a destination.
Lease represents the fundamental routing authorization in I2P:
- Authorization: Proves specific router can receive messages
- Time-Bound: Valid only for specified time period
- Destination-Specific: Authorizes service for particular destination
- Tunnel Endpoint: Identifies specific tunnel on gateway router
Key Components:
- Gateway:
Hashidentifying the router hosting the tunnel - Tunnel ID:
TunnelIdidentifying specific tunnel on gateway - End Time:
longtimestamp when lease expires
Authorization Model:
- Proof of Authority: Destination authorizes specific router
- Time Limitation: Authorization expires after set duration
- Tunnel Specificity: Authorizes particular tunnel, not all tunnels
- Renewable: Leases can be refreshed before expiration
Usage in LeaseSet:
- Multiple Leases: Destinations typically have several concurrent leases
- Load Balancing: Multiple leases distribute message load
- Redundancy: Backup tunnels if primary becomes unavailable
- Mobility: Leases updated as destination moves between routers
Network Operations:
- Message Routing: Routers use leases to forward messages
- Tunnel Selection: Senders choose from available leases
- Expiration Handling: Leases removed when they expire
- LeaseSet Publication: Leases published to network database
Security Considerations:
- Verification: Verify lease authenticity via LeaseSet signature
- Expiration: Ensure leases are still valid before use
- Gateway Trust: Verify gateway router is trusted
- Tunnel Security: Ensure tunnel endpoint is secure
Performance Aspects:
- Efficient Lookup: Hash-based gateway identification
- Quick Expiration: Timestamp comparison for validity checks
- Compact Storage: Minimal data structure for network transmission
- Fast Comparison: Optimized
equals(Object)and hashCode() methods
Related Structures:
- See Also:
Field Summary
Constructor Summary
ConstructorsMethod Summary
All MethodsModifier and TypeMethodDescriptionbooleanCompares this Lease with another object for equality.Convenience wrapper, prefergetEndTime()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.inthashCode()Hash code based on end time, gateway, and tunnel ID.booleanTrue if the lease has expired.booleanisExpired(long fudgeFactor) Fudge factor in milliseconds for clock skew.voidreadBytes(InputStream in) Reads the lease from an input stream.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.voidwriteBytes(OutputStream out) Writes the lease to an output stream.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
_gateway
Gateway router hash._tunnelId
Tunnel identifier on the gateway._end
protected long _endLease expiration time in milliseconds since epoch.
Constructor Details
Lease
public Lease()Required for deserialization.
Method Details
getGateway
Retrieve the router at which the destination can be contacted.- Returns:
- identity of the router acting as a gateway
setGateway
Configure the router at which the destination can be contacted.- Parameters:
ident- router acting as the gateway
getTunnelId
Tunnel on the gateway to communicate with.- Returns:
- the tunnel on the gateway, or null if none is set
setTunnelId
Configure the tunnel on the gateway to communicate with.- Parameters:
id- the tunnel on the gateway to communicate with; null clears it
getEndDate
Convenience wrapper, prefergetEndTime()for new code.- Returns:
- when the lease expires, as a Date
setEndDate
Convenience wrapper, prefer the long overload for new code.- Parameters:
date- when the lease expires; converted to the millisecond value stored in the lease
getEndTime
public long getEndTime()Gets the lease end time.- Returns:
- the end time
setEndDate
public void setEndDate(long date) Sets the lease end date.- Parameters:
date- end time in milliseconds since the epoch, replacing any prior value
isExpired
public boolean isExpired()True if the lease has expired.- Returns:
- true if the lease has expired
isExpired
public boolean isExpired(long fudgeFactor) Fudge factor in milliseconds for clock skew.- Parameters:
fudgeFactor- fudge factor in milliseconds for clock skew- Returns:
- true if the lease has expired
readBytes
Reads the lease from an input stream.- 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.- 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