java.lang.Object
net.i2p.data.DataStructureImpl
net.i2p.data.DatabaseEntry
net.i2p.data.router.RouterInfo
- All Implemented Interfaces:
Serializable, DataStructure
Defines the data that a router either publishes to the global routing table or provides to trusted peers.
For efficiency, the methods and structures here are now unsynchronized. Initialize the RI with readBytes(InputStream), or call the setters and then sign() in a single thread. Don't change it after that.
To ensure integrity of the RouterInfo, methods that change an element of the RouterInfo will throw an IllegalStateException after the RouterInfo is signed.
- See Also:
Field Summary
Modifier and TypeFieldDescriptionprivate final List<RouterAddress> Save addresses in the order received so the signature works.private byte[]Cached serialized byte form.private intCached hash code.private booleanWhether the hash code has been initialized.private RouterIdentityThis router's identity (router key + certificate).private booleanWhether this router info is valid.private final PropertiesConfig properties for this router info.May be null to save memory, no longer final.private longLast published time in ms since epoch.private booleanWhether to cache the byte and string versions of this router info.private booleanWhether the signature has been verified.static final StringPublic string of chars which serve as bandwidth capacity markers NOTE: individual chars defined in Router.java.private static final booleanMaybe we should check if we are floodfill? If we do bring this back, don't do on ARM or Android.static final charCapability flag for hidden.static final StringPublic string of chars which serve as bandwidth congestion markers NOTE: individual chars defined in Router.java.private final I2PAppContextRouter context.private final LogClass logger.private static final intMost addresses one router info may carry.private static final intMost introducers a floodfill will return.static final intAll legit RIs are currently under 2KB.static final StringProperty key for capabilities.static final StringProperty key for network id.Fields inherited from class 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_RECORDModifier and TypeFieldDescriptionprotected SignatureCryptographic signature.static final intEncrypted LeaseSet 2 type.static final intLeaseSet (v1) type.static final intLeaseSet 2 type.static final intMeta LeaseSet 2 type.static final intRouter info type.static final intService list type.static final intService record type.Constructor Summary
ConstructorsConstructorDescriptionConstructor with default address list and options properties.RouterInfo(RouterInfo old) Used only by Router and PublishLocalRouterInfoJob.Method Summary
Modifier and TypeMethodDescriptionprivate voidActually validate the signature.booleanCompare the published time, signature, identity, addresses, options, and peers for equality.intReturn the number of router addresses.Retrieve the set of RouterAddress structures at which this router can be contacted.Return a string representation of this node's bandwidth tier, or "Unknown".protected byte[]getBytes()Write out the raw payload of the routerInfo, excluding the signature.What special capabilities this router offers.Return a string representation of this node's congestion cap, or "Unknown".longgetDate()Return the date.Retrieve the identity of the router represented.Return the keysAndCert.intWhich network this router info is a part of, configured through the property PROP_NETWORK_ID.Return the value of a single option.Retrieve a set of options or statistics that the router can expose.Retrieve a set of options or statistics that the router can expose.getPeers()Retrieve a set of SHA-256 hashes of RouterIdentities from routers this router can be reached through.longRetrieve the timestamp on which the info was published, essentially a version number for the RouterInfo.getTargetAddress(String transportStyle) Pull the first workable target address for the given transport.getTargetAddresses(String transportStyle) For multiple addresses per-transport (IPv4 or IPv6).getTargetAddresses(String transportStyle1, String transportStyle2) For multiple addresses per-transport (IPv4 or IPv6) Return addresses matching either of two styles.intgetType()Return the type.For convenience, the same as getOption("router.version"), but returns "0" if unset.inthashCode()Hash code based on the identity and published time.booleanisCurrent(long maxAgeMs) Determine whether the router was published recently (within the given age milliseconds).booleanisHidden()Is this a hidden node?booleanisValid()Determine whether this router info is authorized with a valid signature.voidreadBytes(InputStream in) This does NOT validate the signature.voidreadBytes(InputStream in, boolean verifySig) If verifySig is true, this validates the signature while reading in, and throws a DataFormatException if the sig is invalid.voidsetAddresses(Collection<RouterAddress> addresses) Specify a set of RouterAddress structures at which this router can be contacted.voidsetIdentity(RouterIdentity ident) Configure the identity of the router represented.voidsetOptions(Properties options) Configure a set of options or statistics that the router can expose.voidSpecify a set of SHA-256 hashes of RouterIdentities from routers this router can be reached through.voidsetPublished(long published) Date on which it was published, in milliseconds since Midnight GMT on Jan 01, 1970.toString()String form for debugging, showing all router info fields.booleanReturn true if the signature is valid, asisValid()does.voidwriteBytes(OutputStream out) This does NOT validate the signature.private voidWrite out the raw payload of the routerInfo, excluding the signature.Methods inherited from class DatabaseEntry
getHash, getReceivedAsPublished, getReceivedAsReply, getReceivedBy, getRoutingKey, getSignature, getSigningPublicKey, isLeaseSet, isLeaseSet, isRouterInfo, setReceivedAsPublished, setReceivedAsReply, setReceivedBy, setSignature, sign, validateRoutingKeyModifier and TypeMethodDescriptiongetHash()A common interface to the Hash of the two subclasses.booleanIf true, we received this LeaseSet by a remote peer publishing it to us, rather than by searching for it ourselves or locally creating it.booleanIf true, we received this LeaseSet by searching for it Default false.The Hash of the local client that received this LS, null if the router or unknown.Routing key for the structure using the current modifier in the RoutingKeyGenerator.Retrieve the proof that the identity stands behind the info here.protected SigningPublicKeyIdentical to getDestination().DatabaseEntry.getSigningPublicKey()in LeaseSet, and getIdentity().getSigningPublicKey() in RouterInfo.booleanConvenience method, is the type any variant of leaseset?static booleanisLeaseSet(int type) Convenience method, is the type any variant of leaseset?booleanConvenience method, is the type any variant of router info?voidMarks this entry as received via published mode.voidMarks this entry as received via reply.voidsetReceivedBy(Hash receivedBy) Local client that received this entry.voidsetSignature(Signature signature) Configure the proof that the entity stands behind the info here.voidsign(SigningPrivateKey key) Sign the structure using the supplied signing key.booleanValidates the routing key for this entry.Methods inherited from class DataStructureImpl
calculateHash, fromBase64, fromByteArray, read, toBase64, toByteArrayModifier and TypeMethodDescriptionCalculate the SHA256 value of this object (useful for a few scenarios).voidfromBase64(String data) Load the structure from the provided base64 string.voidfromByteArray(byte[] data) Loads structure from the data providedprotected intread(InputStream in, byte[] target) Repeated reads until buffer is full or IOException is thrown.toBase64()Render the structure into modified base 64 notation.byte[]Convert the structure to a byte array.
Field Details
ctx
Router context.log
Class logger._identity
This router's identity (router key + certificate)._published
private volatile long _publishedLast published time in ms since epoch._addresses
Save addresses in the order received so the signature works._peers
_options
Config properties for this router info._validated
private volatile boolean _validatedWhether the signature has been verified._isValid
private volatile boolean _isValidWhether this router info is valid._byteified
private volatile byte[] _byteifiedCached serialized byte form._hashCode
private volatile int _hashCodeCached hash code._hashCodeInitialized
private volatile boolean _hashCodeInitializedWhether the hash code has been initialized._shouldCache
private volatile boolean _shouldCacheWhether to cache the byte and string versions of this router info.CACHE_ALL
private static final boolean CACHE_ALLMaybe we should check if we are floodfill? If we do bring this back, don't do on ARM or Android. The disabled initializer below uses the max memory.- See Also:
PROP_NETWORK_ID
Property key for network id.- See Also:
PROP_CAPABILITIES
Property key for capabilities.- See Also:
CAPABILITY_HIDDEN
MAX_ADDRESSES
private static final int MAX_ADDRESSESMost addresses one router info may carry.- See Also:
MAX_INTRODUCERS
private static final int MAX_INTRODUCERSMost introducers a floodfill will return.- See Also:
MAX_UNCOMPRESSED_SIZE
public static final int MAX_UNCOMPRESSED_SIZEAll legit RIs are currently under 2KB. May need to be adjusted if we add a huge new enctype or sigtype. Enforced in DatabaseStoreMessage, the transports, and reseed.- See Also:
BW_CAPABILITY_CHARS
Public string of chars which serve as bandwidth capacity markers NOTE: individual chars defined in Router.java.- See Also:
CONGESTION_CAPABILITY_CHARS
Public string of chars which serve as bandwidth congestion markers NOTE: individual chars defined in Router.java.- See Also:
Constructor Details
RouterInfo
public RouterInfo()Constructor with default address list and options properties.RouterInfo
Used only by Router and PublishLocalRouterInfoJob. Copies ONLY the identity and peers. Does not copy published, addresses, options, or signature.- Parameters:
old- the RouterInfo to copy the identity and peer set from
Method Details
getDate
public long getDate()Return the date.- Specified by:
getDatein classDatabaseEntry- Returns:
- the date this entry takes effect, in milliseconds since the epoch: the expiration of the earliest lease for a LeaseSet, the publication time for a RouterInfo
getKeysAndCert
Return the keysAndCert.- Specified by:
getKeysAndCertin classDatabaseEntry- Returns:
- KAC or null
getType
public int getType()Return the type.- Specified by:
getTypein classDatabaseEntry- Returns:
- KEY_TYPE_ROUTERINFO or KEY_TYPE_LEASESET or LS2 types
getIdentity
Retrieve the identity of the router represented.- Returns:
- the RouterIdentity holding the public key and certificate
setIdentity
Configure the identity of the router represented.- Parameters:
ident- the RouterIdentity whose public key and certificate describe this router- Throws:
IllegalStateException- if RouterInfo is already signed
getPublished
public long getPublished()Retrieve the timestamp on which the info was published, essentially a version number for the RouterInfo. This should be used to expire old RouterInfo structures.- Returns:
- the publication date in milliseconds since the epoch
setPublished
public void setPublished(long published) Date on which it was published, in milliseconds since Midnight GMT on Jan 01, 1970.- Parameters:
published- the publication time in milliseconds since the epoch- Throws:
IllegalStateException- if RouterInfo is already signed
getAddressCount
public int getAddressCount()Return the number of router addresses. More efficient thangetAddresses().size().- Returns:
- the address count
getAddresses
Retrieve the set of RouterAddress structures at which this router can be contacted.- Returns:
- unmodifiable view, non-null
setAddresses
Specify a set of RouterAddress structures at which this router can be contacted.- Parameters:
addresses- may be null- Throws:
IllegalStateException- if RouterInfo is already signed or addresses previously setIllegalArgumentException- if too many addresses
getPeers
setPeers
Specify a set of SHA-256 hashes of RouterIdentities from routers this router can be reached through. Obsolete — peer set is typically empty.- Parameters:
peers- SHA-256 hashes of the peers this router can be reached through; null or empty clears the set- Throws:
IllegalStateException- if RouterInfo is already signed
getOptions
Retrieve a set of options or statistics that the router can expose. PrefergetOptionsMap()for an unmodifiable view.- Returns:
- sorted, non-null, NOT a copy, do not modify!!!
getOptionsMap
getOption
getVersion
For convenience, the same as getOption("router.version"), but returns "0" if unset.- Returns:
- non-null, "0" if unknown.
setOptions
Configure a set of options or statistics that the router can expose. Makes a copy.Warning, clears all capabilities.
- Parameters:
options- if null, clears current options- Throws:
IllegalStateException- if RouterInfo is already signed
getBytes
Write out the raw payload of the routerInfo, excluding the signature. This caches the data in memory if possible.- Specified by:
getBytesin classDatabaseEntry- Returns:
- the serialized payload excluding the signature
- Throws:
DataFormatException- if the data is somehow b0rked (missing props, etc)
writeDataBytes
Write out the raw payload of the routerInfo, excluding the signature. This caches the data in memory if possible.- Parameters:
out- the stream to write to- Throws:
DataFormatException- if the data is somehow b0rked (missing props, etc)IOException- if writing to the stream fails
isValid
public boolean isValid()Determine whether this router info is authorized with a valid signature.- Returns:
- true if the signature verifies, false otherwise
verifySignature
public boolean verifySignature()Return true if the signature is valid, asisValid()does.- Overrides:
verifySignaturein classDatabaseEntry- Returns:
- true if the entry carries a signature that verifies over its own data
getNetworkId
public int getNetworkId()Which network this router info is a part of, configured through the property PROP_NETWORK_ID.- Returns:
- -1 if unknown
getCapabilities
What special capabilities this router offers.- Returns:
- non-null, empty string if none
isHidden
public boolean isHidden()Is this a hidden node?- Returns:
- true if either 'H' is in the capabilities, or router identity contains a hidden cert.
getBandwidthTier
Return a string representation of this node's bandwidth tier, or "Unknown".- Returns:
- the bandwidth tier
getCongestionCap
Return a string representation of this node's congestion cap, or "Unknown".- Returns:
- the congestion cap
isCurrent
public boolean isCurrent(long maxAgeMs) Determine whether the router was published recently (within the given age milliseconds). The age should be large enough to take into consideration any clock fudge factor, so values such as 1 or 2 hours are probably reasonable.- Parameters:
maxAgeMs- milliseconds between the current time and publish date to check- Returns:
- true if it was published recently, false otherwise
getTargetAddress
Pull the first workable target address for the given transport. Use to check for any address. For all addresses, usegetTargetAddresses(String), which you probably want if you care about IPv6.- Parameters:
transportStyle- the transport style to match, e.g. NTCP2 or SSU2- Returns:
- the target address, or null if this router advertises none for that style
getTargetAddresses
For multiple addresses per-transport (IPv4 or IPv6).- Parameters:
transportStyle- the transport style to match, e.g. NTCP2 or SSU2- Returns:
- a mutable list of the advertised addresses in that style, never null
getTargetAddresses
For multiple addresses per-transport (IPv4 or IPv6) Return addresses matching either of two styles.- Parameters:
transportStyle1- the first transport style to match, e.g. NTCP2transportStyle2- the second transport style to match, e.g. SSU2- Returns:
- a mutable list of the advertised addresses in either style, never null
doValidate
private void doValidate()Actually validate the signature.readBytes
This does NOT validate the signature.- Parameters:
in- stream to read from- Throws:
IllegalStateException- if RouterInfo was already read inDataFormatException- if the data is improperly formattedIOException- if there was a problem reading the stream
readBytes
If verifySig is true, this validates the signature while reading in, and throws a DataFormatException if the sig is invalid. This is faster than reserializing to validate later.- Parameters:
in- the stream to read the RouterInfo fromverifySig- if true, validate the signature as the bytes are read- Throws:
DataFormatException- if the data cannot be parsed, or if verifySig is true and the signature does not validateIllegalStateException- if RouterInfo was already read inIOException- if the stream cannot be read
writeBytes
This does NOT validate the signature.- 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
equals
hashCode
toString