Package net.i2p.data.router
Class RouterInfo
java.lang.Object
net.i2p.data.DataStructureImpl
net.i2p.data.DatabaseEntry
net.i2p.data.router.RouterInfo
- All Implemented Interfaces:
Serializable,DataStructure
public class RouterInfo extends DatabaseEntry
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(), 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.
- Since:
- 0.9.16 moved from net.i2p.data
- Author:
- jrandom
- See Also:
- Serialized Form
-
Field Summary
Fields Modifier and Type Field Description static StringBW_CAPABILITY_CHARSPublic string of chars which serve as bandwidth capacity markers NOTE: individual chars defined in Router.javastatic charCAPABILITY_HIDDENstatic StringPROP_CAPABILITIESstatic StringPROP_NETWORK_IDFields 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 Constructor Description RouterInfo()RouterInfo(RouterInfo old)Used only by Router and PublishLocalRouterInfoJob. -
Method Summary
Modifier and Type Method Description booleanequals(Object object)intgetAddressCount()Return the number of router addresses.Collection<RouterAddress>getAddresses()Retrieve the set of RouterAddress structures at which this router can be contacted.StringgetBandwidthTier()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.StringgetCapabilities()what special capabilities this router offerslonggetDate()A common interface to the timestamp of the two subclasses.RouterIdentitygetIdentity()Retrieve the identity of the router representedKeysAndCertgetKeysAndCert()Get the keys and the cert Identical to getDestination() in LeaseSet, and getIdentity() in RouterInfo.intgetNetworkId()which network is this routerInfo a part of.StringgetOption(String opt)PropertiesgetOptions()Deprecated.use getOptionsMap()Map<Object,Object>getOptionsMap()Retrieve a set of options or statistics that the router can expose.Set<Hash>getPeers()Deprecated.Implemented here but unused elsewherelonggetPublished()Retrieve the timestamp on which the info was published, essentially a version number for the RouterInfo.RouterAddressgetTargetAddress(String transportStyle)Pull the first workable target address for the given transport.List<RouterAddress>getTargetAddresses(String transportStyle)For multiple addresses per-transport (IPv4 or IPv6)List<RouterAddress>getTargetAddresses(String transportStyle1, String transportStyle2)For multiple addresses per-transport (IPv4 or IPv6) Return addresses matching either of two stylesintgetType()Get the type of the data structure.StringgetVersion()For convenience, the same as getOption("router.version"), but returns "0" if unset.inthashCode()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 signaturestatic voidmain(String[] args)Print out routerinfos from files specified on the command line.voidreadBytes(InputStream in)This does NOT validate the signaturevoidreadBytes(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 representedvoidsetOptions(Properties options)Configure a set of options or statistics that the router can expose.voidsetPeers(Set<Hash> peers)Deprecated.Implemented here but unused elsewherevoidsetPublished(long published)Date on which it was published, in milliseconds since Midnight GMT on Jan 01, 1970StringtoString()booleanverifySignature()Same as isValid()voidwriteBytes(OutputStream out)This does NOT validate the signatureMethods inherited from class net.i2p.data.DatabaseEntry
getHash, getRoutingKey, getSignature, getSigningPublicKey, isLeaseSet, isLeaseSet, setSignature, sign, validateRoutingKeyMethods inherited from class net.i2p.data.DataStructureImpl
calculateHash, fromBase64, fromByteArray, read, toBase64, toByteArray
-
Field Details
-
PROP_NETWORK_ID
- See Also:
- Constant Field Values
-
PROP_CAPABILITIES
- See Also:
- Constant Field Values
-
CAPABILITY_HIDDEN
public static final char CAPABILITY_HIDDEN- See Also:
- Constant Field Values
-
BW_CAPABILITY_CHARS
Public string of chars which serve as bandwidth capacity markers NOTE: individual chars defined in Router.java- See Also:
- Constant Field Values
-
-
Constructor Details
-
RouterInfo
public RouterInfo() -
RouterInfo
Used only by Router and PublishLocalRouterInfoJob. Copies ONLY the identity and peers. Does not copy published, addresses, options, or signature.
-
-
Method Details
-
getDate
public long getDate()Description copied from class:DatabaseEntryA common interface to the timestamp of the two subclasses. Identical to getEarliestLeaseData() in LeaseSet, and getPublished() in RouterInfo. Note that for a LeaseSet this will be in the future, and for a RouterInfo it will be in the past. Either way, it's a timestamp.- Specified by:
getDatein classDatabaseEntry
-
getKeysAndCert
Description copied from class:DatabaseEntryGet the keys and the cert Identical to getDestination() in LeaseSet, and getIdentity() in RouterInfo.- Specified by:
getKeysAndCertin classDatabaseEntry- Returns:
- KAC or null
-
getType
public int getType()Description copied from class:DatabaseEntryGet the type of the data structure. This should be faster than instanceof.- Specified by:
getTypein classDatabaseEntry- Returns:
- KEY_TYPE_ROUTERINFO or KEY_TYPE_LEASESET or LS2 types
-
getIdentity
Retrieve the identity of the router represented -
setIdentity
Configure the identity of the router represented- 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. -
setPublished
public void setPublished(long published)Date on which it was published, in milliseconds since Midnight GMT on Jan 01, 1970- Throws:
IllegalStateException- if RouterInfo is already signed
-
getAddressCount
public int getAddressCount()Return the number of router addresses. More efficient than getAddresses().size()- Since:
- 0.9.27
-
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
Deprecated.Implemented here but unused elsewhereRetrieve a set of SHA-256 hashes of RouterIdentities from routers this router can be reached through. -
setPeers
Deprecated.Implemented here but unused elsewhereSpecify a set of SHA-256 hashes of RouterIdentities from routers this router can be reached through.- Throws:
IllegalStateException- if RouterInfo is already signed
-
getOptions
Deprecated.use getOptionsMap()Retrieve a set of options or statistics that the router can expose.- Returns:
- sorted, non-null, NOT a copy, do not modify!!!
-
getOptionsMap
Retrieve a set of options or statistics that the router can expose.- Returns:
- an unmodifiable view, non-null, sorted
- Since:
- 0.8.13
-
getOption
-
getVersion
For convenience, the same as getOption("router.version"), but returns "0" if unset.- Returns:
- non-null, "0" if unknown.
- Since:
- 0.9.18
-
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 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:
- null on error ???????????????????????
- Throws:
DataFormatException- if the data is somehow b0rked (missing props, etc)
-
isValid
public boolean isValid()Determine whether this router info is authorized with a valid signature -
verifySignature
public boolean verifySignature()Same as isValid()- Overrides:
verifySignaturein classDatabaseEntry- Returns:
- valid
- Since:
- 0.9
-
getNetworkId
public int getNetworkId()which network is this routerInfo 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 capbilities, or router identity contains a hidden cert.
-
getBandwidthTier
Return a string representation of this node's bandwidth tier, or "Unknown" -
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, use getTargetAddresses(), which you probably want if you care about IPv6. -
getTargetAddresses
For multiple addresses per-transport (IPv4 or IPv6)- Returns:
- non-null
- Since:
- 0.7.11
-
getTargetAddresses
For multiple addresses per-transport (IPv4 or IPv6) Return addresses matching either of two styles- Returns:
- non-null
- Since:
- 0.9.35
-
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.- Throws:
IllegalStateException- if RouterInfo was already read inDataFormatExceptionIOException- Since:
- 0.9
-
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
public int hashCode() -
toString
-
main
Print out routerinfos from files specified on the command line. Exits 1 if any RI is invalid, fails signature, etc.- Since:
- 0.8
-