net.i2p.data

## Class Lease2

- java.lang.Object
- - net.i2p.data.DataStructureImpl
  - - net.i2p.data.Lease
    - - net.i2p.data.Lease2

- All Implemented Interfaces:
    Serializable, DataStructure

      public class Lease2
      extends Lease

  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 LeaseSet2 and 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:
    Serialized Form

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `LENGTH`

    - ### Fields inherited from class net.i2p.data.Lease

      `_end, _gateway, _tunnelId`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `Lease2()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `equals(Object object)`
    `int` | `hashCode()`
    `void` | `readBytes(InputStream in)` Load up the current object with data from the given stream.
    `void` | `writeBytes(OutputStream out)` Write out the data structure to the stream, using the format defined in the I2P data structure specification.

    - ### Methods inherited from class net.i2p.data.Lease

      `getEndTime, getGateway, getTunnelId, isExpired, isExpired, setEndDate, setGateway, setTunnelId, toString`

    - ### Methods inherited from class net.i2p.data.DataStructureImpl

      `calculateHash, fromBase64, fromByteArray, read, toBase64, toByteArray`

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### LENGTH

          public static final int LENGTH

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### Lease2

          public Lease2()

  - ### Method Detail

    - #### equals

          public boolean equals(Object object)

      Overrides:
        `equals` in class `Lease`

    - #### hashCode

          public int hashCode()

      Overrides:
        `hashCode` in class `Lease`

    - #### readBytes

          public void readBytes(InputStream in)
                         throws DataFormatException,
                                IOException

      Description copied from interface: `DataStructure`
      Load up the current object with data from the given stream. Data loaded this way must match the I2P data structure specification. Warning - many classes will throw IllegalStateException if data is already set.
      Specified by:
        `readBytes` in interface `DataStructure`
      Overrides:
        `readBytes` in class `Lease`
      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

      Description copied from interface: `DataStructure`
      Write out the data structure to the stream, using the format defined in the I2P data structure specification.
      Specified by:
        `writeBytes` in interface `DataStructure`
      Overrides:
        `writeBytes` in class `Lease`
      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