net.i2p.data
Class LeaseSet

java.lang.Object
  extended by net.i2p.data.DataStructureImpl
      extended by net.i2p.data.LeaseSet
All Implemented Interfaces:
DataStructure

public class LeaseSet
extends DataStructureImpl

Defines the set of leases a destination currently has.

Author:
jrandom

Constructor Summary
LeaseSet()
           
 
Method Summary
 void addLease(Lease lease)
           
 boolean equals(java.lang.Object object)
           
 Destination getDestination()
           
 long getEarliestLeaseDate()
          Retrieve the end date of the earliest lease include in this leaseSet.
 PublicKey getEncryptionKey()
           
 Lease getLease(int index)
           
 int getLeaseCount()
           
 boolean getReceivedAsPublished()
          If true, we received this LeaseSet by a remote peer publishing it to us, rather than by searching for it ourselves or locally creating it.
 Hash getRoutingKey()
          Get the routing key for the structure using the current modifier in the RoutingKeyGenerator.
 Signature getSignature()
           
 SigningPublicKey getSigningKey()
           
 int hashCode()
           
 boolean isCurrent(long fudge)
          Determine whether there are currently valid leases, at least within a given fudge factor
 void readBytes(java.io.InputStream in)
          Load up the current object with data from the given stream.
 void removeLease(int index)
           
 void removeLease(Lease lease)
           
 void setDestination(Destination dest)
           
 void setEncryptionKey(PublicKey encryptionKey)
           
 void setReceivedAsPublished(boolean received)
           
 void setRoutingKey(Hash key)
           
 void setSignature(Signature sig)
           
 void setSigningKey(SigningPublicKey key)
           
 void sign(SigningPrivateKey key)
          Sign the structure using the supplied signing key
 int size()
           
 java.lang.String toString()
           
 boolean validateRoutingKey()
           
 boolean verifySignature()
          Verify that the signature matches the lease set's destination's signing public key.
 boolean verifySignature(SigningPublicKey signingKey)
          Verify that the signature matches the lease set's destination's signing public key.
 void writeBytes(java.io.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.DataStructureImpl
calculateHash, fromBase64, fromByteArray, read, toBase64, toByteArray
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

LeaseSet

public LeaseSet()
Method Detail

getDestination

public Destination getDestination()

setDestination

public void setDestination(Destination dest)

getEncryptionKey

public PublicKey getEncryptionKey()

setEncryptionKey

public void setEncryptionKey(PublicKey encryptionKey)

getSigningKey

public SigningPublicKey getSigningKey()

setSigningKey

public void setSigningKey(SigningPublicKey key)

getReceivedAsPublished

public boolean getReceivedAsPublished()
If true, we received this LeaseSet by a remote peer publishing it to us, rather than by searching for it ourselves or locally creating it.


setReceivedAsPublished

public void setReceivedAsPublished(boolean received)

addLease

public void addLease(Lease lease)

removeLease

public void removeLease(Lease lease)

removeLease

public void removeLease(int index)

getLeaseCount

public int getLeaseCount()

getLease

public Lease getLease(int index)

getSignature

public Signature getSignature()

setSignature

public void setSignature(Signature sig)

getRoutingKey

public Hash getRoutingKey()
Get the routing key for the structure using the current modifier in the RoutingKeyGenerator. This only calculates a new one when necessary though (if the generator's key modifier changes)


setRoutingKey

public void setRoutingKey(Hash key)

validateRoutingKey

public boolean validateRoutingKey()

getEarliestLeaseDate

public long getEarliestLeaseDate()
Retrieve the end date of the earliest lease include in this leaseSet. This is the date that should be used in comparisons for leaseSet age - to determine which LeaseSet was published more recently (later earliestLeaseSetDate means it was published later)

Returns:
earliest end date of any lease in the set, or -1 if there are no leases

sign

public void sign(SigningPrivateKey key)
          throws DataFormatException
Sign the structure using the supplied signing key

Throws:
DataFormatException

verifySignature

public boolean verifySignature()
Verify that the signature matches the lease set's destination's signing public key.

Returns:
true only if the signature matches

verifySignature

public boolean verifySignature(SigningPublicKey signingKey)
Verify that the signature matches the lease set's destination's signing public key.

Returns:
true only if the signature matches

isCurrent

public boolean isCurrent(long fudge)
Determine whether there are currently valid leases, at least within a given fudge factor

Parameters:
fudge - milliseconds fudge factor to allow between the current time
Returns:
true if there are current leases, false otherwise

readBytes

public void readBytes(java.io.InputStream in)
               throws DataFormatException,
                      java.io.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.

Parameters:
in - stream to read from
Throws:
DataFormatException - if the data is improperly formatted
java.io.IOException - if there was a problem reading the stream

writeBytes

public void writeBytes(java.io.OutputStream out)
                throws DataFormatException,
                       java.io.IOException
Description copied from interface: DataStructure
Write out the data structure to the stream, using the format defined in the I2P data structure specification.

Parameters:
out - stream to write to
Throws:
DataFormatException - if the data was incomplete or not yet ready to be written
java.io.IOException - if there was a problem writing to the stream

size

public int size()

equals

public boolean equals(java.lang.Object object)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object