Package net.i2p.data
Class LeaseSet2
java.lang.Object
net.i2p.data.DataStructureImpl
net.i2p.data.DatabaseEntry
net.i2p.data.LeaseSet
net.i2p.data.LeaseSet2
- All Implemented Interfaces:
Serializable,DataStructure
- Direct Known Subclasses:
EncryptedLeaseSet,MetaLeaseSet
See proposal 123
- Since:
- 0.9.38
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected longprotected intprotected Signatureprotected Propertiesprotected longprotected longprotected SigningPublicKeyFields inherited from class net.i2p.data.LeaseSet
_byteified, _checked, _destination, _encryptionKey, _lastExpiration, _leases, _receivedAsPublished, _signingKey, MAX_LEASESFields inherited from class net.i2p.data.DatabaseEntry
_signature, KEY_TYPE_ENCRYPTED_LS2, KEY_TYPE_LEASESET, KEY_TYPE_LS2, KEY_TYPE_META_LS2, KEY_TYPE_ROUTERINFO, KEY_TYPE_SERVICE_LIST, KEY_TYPE_SERVICE_RECORD -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd an encryption key.voidvoidencrypt(SessionKey key) Encrypt the gateway and tunnel ID of each lease, leaving the expire dates unchanged.booleanThe orignal blinded hash, where this came from.protected byte[]getBytes()without sig!If more than one key, return the first supported one.getEncryptionKey(Set<EncType> supported) If more than one key, return the first supported one.This returns all the keys.longPublished expiration, as received.longPublished timestamp, as received.booleanIf true, we received this LeaseSet by a remote peer publishing it to us, AND the unpublished flag is not set.longAbsolute time, not time from now.intgetType()Get the type of the data structure.inthashCode()the destination has enough randomness in it to use it by itself for speedbooleanSet if the unencrypted LS, when published, will be blinded/encryptedbooleanisCurrent(long fudge) Determine whether the leaseset is currently valid, at least within a given fudge factor.booleanbooleanstatic SignatureofflineSign(long expires, SigningPublicKey transientSPK, SigningPrivateKey priv) Generate a Signature to pass to setOfflineSignature()voidreadBytes(InputStream in) This does NOT validate the signatureprotected voidprotected voidvoidsetBlindedHash(Hash bh) Set this on creation if knownvoidSet if the unencrypted LS, when published, will be blinded/encryptedbooleansetOfflineSignature(long expires, SigningPublicKey transientSPK, Signature offlineSig) Destination must be previously set.voidsetOptions(Properties options) Configure a set of options or statistics that the router can expose.voidThe revocation key.voidvoidsign(SigningPrivateKey key) Sign the structure using the supplied signing key.intsize()Number of bytes, NOT including signaturetoString()booleanprotected booleanbooleanVerify with the SPK in the dest for online sigs.protected voidwriteBody(OutputStream out) Without sig.voidwriteBytes(OutputStream out) Including sig.protected voidWithout sig.protected voidwriteHeader(OutputStream out) protected voidMethods inherited from class net.i2p.data.LeaseSet
getDate, getDestination, getEarliestLeaseDate, getKeysAndCert, getLatestLeaseDate, getLease, getLeaseCount, getReceivedAsReply, getReceivedBy, getSigningKey, setDestination, setEncryptionKey, setReceivedAsPublished, setReceivedAsReply, setReceivedBy, verifySignatureMethods inherited from class net.i2p.data.DatabaseEntry
getHash, getRoutingKey, getSignature, getSigningPublicKey, isLeaseSet, isLeaseSet, setSignature, validateRoutingKeyMethods inherited from class net.i2p.data.DataStructureImpl
calculateHash, fromBase64, fromByteArray, read, toBase64, toByteArray
-
Field Details
-
_flags
protected int _flags -
_published
protected long _published -
_expires
protected long _expires -
_transientExpires
protected long _transientExpires -
_transientSigningPublicKey
-
_offlineSignature
-
_options
-
-
Constructor Details
-
LeaseSet2
public LeaseSet2()
-
-
Method Details
-
getPublished
public long getPublished()Published timestamp, as received. Different than getDate() or getEarliestLeaseDate(), which are the earliest lease expiration.- Returns:
- in ms, with 1 second resolution
- Since:
- 0.9.39
-
getExpires
public long getExpires()Published expiration, as received. May be different than getLatestLeaseDate(), which is the latest lease expiration.- Returns:
- in ms, with 1 second resolution
- Since:
- 0.9.39
-
isUnpublished
public boolean isUnpublished() -
setUnpublished
public void setUnpublished()- Throws:
IllegalStateException- if already signed
-
isBlindedWhenPublished
public boolean isBlindedWhenPublished()Set if the unencrypted LS, when published, will be blinded/encrypted- Since:
- 0.9.42
-
setBlindedWhenPublished
public void setBlindedWhenPublished()Set if the unencrypted LS, when published, will be blinded/encrypted- Throws:
IllegalStateException- if already signed- Since:
- 0.9.42
-
getReceivedAsPublished
public boolean getReceivedAsPublished()If true, we received this LeaseSet by a remote peer publishing it to us, AND the unpublished flag is not set. Default false.- Overrides:
getReceivedAsPublishedin classLeaseSet- Since:
- 0.9.39 overridden
-
getOption
-
getEncryptionKey
If more than one key, return the first supported one. If none supported, return the first one.- Overrides:
getEncryptionKeyin classLeaseSet- Since:
- 0.9.39 overridden
-
getEncryptionKey
If more than one key, return the first supported one. If none supported, return null.- Overrides:
getEncryptionKeyin classLeaseSet- Parameters:
supported- what return types are allowed- Returns:
- first supported key or null
- Since:
- 0.9.44
-
addEncryptionKey
Add an encryption key. Encryption keys should be added in order of server preference, most-preferred first. -
getEncryptionKeys
This returns all the keys. getEncryptionKey() returns the first one. Encryption keys should be in order of server preference, most-preferred first. Client behavior should be to select the first key with a supported encryption type. Clients may use other selection algorithms based on encryption support, relative performance, and other factors.- Returns:
- not a copy, do not modify, null if none
-
setOptions
Configure a set of options or statistics that the router can expose. Makes a copy. Warning, clears all capabilities, must be called BEFORE addCapability().- Parameters:
options- if null, clears current options- Throws:
IllegalStateException- if LeaseSet2 is already signed
-
isOffline
public boolean isOffline() -
getTransientSigningKey
- Returns:
- transient public key or null if not offline signed
-
getTransientExpiration
public long getTransientExpiration()Absolute time, not time from now.- Returns:
- transient expiration time or 0 if not offline signed
- Since:
- 0.9.48
-
setOfflineSignature
public boolean setOfflineSignature(long expires, SigningPublicKey transientSPK, Signature offlineSig) Destination must be previously set.- Parameters:
expires- absolute mstransientSPK- the key that will sign the leasesetofflineSig- the signature by the spk in the destination- Returns:
- success, false if verify failed or expired
- Throws:
IllegalStateException- if already signed
-
offlineSign
public static Signature offlineSign(long expires, SigningPublicKey transientSPK, SigningPrivateKey priv) Generate a Signature to pass to setOfflineSignature()- Parameters:
expires- absolute mstransientSPK- the key that will sign the leasesetpriv- the private signing key for the destination- Returns:
- null on error
-
verifyOfflineSignature
public boolean verifyOfflineSignature() -
verifyOfflineSignature
-
setBlindedHash
Set this on creation if known -
getBlindedHash
The orignal blinded hash, where this came from.- Returns:
- null if unknown or not previously blinded
-
getType
public int getType()Description copied from class:DatabaseEntryGet the type of the data structure. This should be faster than instanceof. -
setSigningKey
The revocation key. Overridden to do nothing, as we're using the _signingKey field for the blinded key in Enc LS2.- Overrides:
setSigningKeyin classLeaseSet- Since:
- 0.9.39
-
isCurrent
public boolean isCurrent(long fudge) Determine whether the leaseset is currently valid, at least within a given fudge factor. Overridden to use the expiration time instead of the last expiration. -
getBytes
protected byte[] getBytes()without sig! -
readBytes
This does NOT validate the signature- Specified by:
readBytesin interfaceDataStructure- Overrides:
readBytesin classLeaseSet- Parameters:
in- stream to read from- Throws:
IllegalStateException- if called more than once or Destination already setDataFormatException- if the data is improperly formattedIOException- if there was a problem reading the stream
-
writeBytes
Including sig. This does NOT validate the signature- Specified by:
writeBytesin interfaceDataStructure- Overrides:
writeBytesin classLeaseSet- 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
-
writeBytesWithoutSig
Without sig. This does NOT validate the signature- Throws:
DataFormatExceptionIOException
-
writeBody
Without sig. This does NOT validate the signature- Throws:
DataFormatExceptionIOException
-
readHeader
- Throws:
DataFormatExceptionIOException
-
writeHeader
- Throws:
DataFormatExceptionIOException
-
readOfflineBytes
- Throws:
DataFormatExceptionIOException
-
writeOfflineBytes
- Throws:
DataFormatExceptionIOException
-
size
public int size()Number of bytes, NOT including signature -
addLease
- Overrides:
addLeasein classLeaseSet- Parameters:
lease- must be a Lease2- Throws:
IllegalArgumentException- if not a Lease2
-
sign
Sign the structure using the supplied signing key. Overridden because LS2 sigs cover the type byte.- Overrides:
signin classDatabaseEntry- Throws:
IllegalStateException- if already signedDataFormatException
-
verifySignature
public boolean verifySignature()Verify with the SPK in the dest for online sigs. Verify with the SPK in the offline sig section for offline sigs.- Overrides:
verifySignaturein classLeaseSet- Returns:
- valid
-
equals
-
hashCode
public int hashCode()the destination has enough randomness in it to use it by itself for speed -
toString
-
encrypt
Description copied from class:LeaseSetEncrypt the gateway and tunnel ID of each lease, leaving the expire dates unchanged. This adds an extra dummy lease, because AES data must be padded to 16 bytes. The fact that it is encrypted is not stored anywhere. Must be called after all the leases are in place, but before sign().
-