All Implemented Interfaces:
Serializable, DataStructure
Direct Known Subclasses:
Lease2, MetaLease

public class Leaseextends DataStructureImpl
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: Hash identifying the router hosting the tunnel
  • Tunnel ID: TunnelId identifying specific tunnel on gateway
  • End Time: long timestamp 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:

  • LeaseSet - Container for multiple leases
  • Lease2 - Enhanced version with 4-byte timestamps
  • MetaLease - References other LeaseSets instead of tunnels
  • TunnelId - Tunnel identifier on gateway router
See Also:
  • Field Details

    • _gateway

      protected Hash _gateway
      Gateway router hash.
    • _tunnelId

      protected TunnelId _tunnelId
      Tunnel identifier on the gateway.
    • _end

      protected long _end
      Lease expiration time in milliseconds since epoch.
  • Constructor Details

    • Lease

      public Lease()
      Required for deserialization.
  • Method Details

    • getGateway

      public Hash getGateway()
      Retrieve the router at which the destination can be contacted.
      Returns:
      identity of the router acting as a gateway
    • setGateway

      public void setGateway(Hash ident)
      Configure the router at which the destination can be contacted.
      Parameters:
      ident - router acting as the gateway
    • getTunnelId

      public TunnelId getTunnelId()
      Tunnel on the gateway to communicate with.
      Returns:
      the tunnel on the gateway, or null if none is set
    • setTunnelId

      public void setTunnelId(TunnelId id)
      Configure the tunnel on the gateway to communicate with.
      Parameters:
      id - the tunnel on the gateway to communicate with; null clears it
    • getEndDate

      public Date getEndDate()
      Convenience wrapper, prefer getEndTime() for new code.
      Returns:
      when the lease expires, as a Date
    • setEndDate

      public void setEndDate(Date date)
      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

      public void readBytes(InputStream in) throws DataFormatException, IOException
      Reads the lease from an input stream.
      Parameters:
      in - stream to read from
      Throws:
      DataFormatException - if the data is improperly formatted
      IOException - if there was a problem reading the stream
    • writeBytes

      public void writeBytes(OutputStream out) throws DataFormatException, IOException
      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 written
      IOException - if there was a problem writing to the stream
    • equals

      public boolean equals(Object object)
      Compares this Lease with another object for equality.
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Hash code based on end time, gateway, and tunnel ID.
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Returns a string representation of this Lease.
      Overrides:
      toString in class Object