java.lang.Object
net.i2p.router.client.LeaseRequestState

class LeaseRequestStateextends Object
Bundle up the data points necessary when asynchronously requesting a lease from a client.
  • Field Details

    • MAX_TRANSIENT_PUBLISH_RETRIES

      static final int MAX_TRANSIENT_PUBLISH_RETRIES
      Maximum prompt re-requests after netdb publish() rejected the client's LeaseSet as expired. Bounds the retry loop when the client's clock or signer stays skewed; after the bound the timeout check resolves the request as before.
      See Also:
    • _requestedLeaseSet

      private final LeaseSet _requestedLeaseSet
      The lease set being requested.
    • _onGranted

      private final Job _onGranted
      Job run when the request succeeds.
    • _onFailed

      private final Job _onFailed
      Job run when the request fails.
    • _expiration

      private final long _expiration
      Time past which the request is abandoned.
    • _currentEarliestLeastDate

      private final long _currentEarliestLeastDate
      Earliest lease end seen so far.
    • _successful

      private volatile boolean _successful
      True once the request has succeeded.
    • _transientPublishRetries

      private int _transientPublishRetries
      Publish retries used so far.
    • _resolutionClaimed

      private boolean _resolutionClaimed
      True once the outcome has been acted on.
  • Constructor Details

    • LeaseRequestState

      public LeaseRequestState(Job onGranted, Job onFailed, long currentEarliestLeastDate, long expiration, LeaseSet requested)
      Create a new LeaseRequestState.
      Parameters:
      onGranted - job to run on success
      onFailed - job to run on failure
      currentEarliestLeastDate - absolute time, the earliest expiration in the current LS (NOT the requested one), or 0 if none
      expiration - absolute time, when the request expires (not when the LS expires)
      requested - LeaseSet with requested leases - this object must be updated to contain the signed version (as well as any changed/added/removed Leases) The LeaseSet contains Leases and destination only, it is unsigned.
  • Method Details

    • getRequested

      public LeaseSet getRequested()
      The lease set this request is for.
      Returns:
      the unsigned lease set, updated in place once it is signed
    • getOnGranted

      public Job getOnGranted()
      The job to run once the lease set is created.
      Returns:
      what to do once the lease set is created
    • getOnFailed

      public Job getOnFailed()
      The job to run if the lease set create fails or times out.
      Returns:
      what to do if the lease set create fails / times out
    • getExpiration

      public long getExpiration()
      When the request is abandoned if the client has not answered.
      Returns:
      absolute adjusted time in ms, not the lease set's own expiration
    • getCurrentEarliestLeaseDate

      public long getCurrentEarliestLeaseDate()
      The earliest lease expiration time in the current LS (NOT the requested one), or 0 if none.
      Returns:
      the earliest lease date
    • getIsSuccessful

      public boolean getIsSuccessful()
      Whether the request was successful in the time allotted.
      Returns:
      true if successful
    • setIsSuccessful

      public void setIsSuccessful(boolean is)
      Record whether the request was successful.
      Parameters:
      is - true if successful
    • claimTransientPublishRetry

      boolean claimTransientPublishRetry()
      Claim one attempt to re-request the LeaseSet after netdb publish() rejected it as expired (client clock skew or slow signing). The first MAX_TRANSIENT_PUBLISH_RETRIES callers receive true so the request is promptly re-run with freshly floored lease times. Later callers receive false so a persistently skewed client cannot loop.
      Returns:
      true if a retry attempt is available
    • claimCheckResolution

      boolean claimCheckResolution()
      Claim the single accounting resolution for this request. Exactly one resolution path (early job failure, timeout-check success, or timeout-check failure) proceeds past this claim, so onFailed fires at most once and success/timeout stats are never double-counted when several checks or a retry and a check race each other.
      Returns:
      true if the caller owns the resolution
    • toString

      public String toString()
      Overrides:
      toString in class Object