java.lang.Object
net.i2p.router.transport.udp.UDPAddress
Parses and caches the host, port, introducer list, MTU, and key data from a RouterAddress for the SSU and SSU2 transport styles.
Field Summary
Modifier and TypeFieldDescriptionprivate final StringThe host name or literal address.private InetAddressThe resolved host address.private static final Map<String, InetAddress> Textual IP to InetAddress, becauseInetAddress.getByName(String)is slow.private final InetAddress[]The resolved introducer addresses.private final long[]When the introducers expire.private final Hash[]The introducer hashes.private final String[]The introducer host names.private final byte[]Our introduction key.private final byte[][]The introducer keys.private final int[]The introducer ports.private final long[]The introducer tags.private final booleanTrue if the address supports IPv4, both flags if both.private final booleanTrue if the address supports IPv6.private final intThe MTU of the address.private final intThe UDP port.static final char'C'.static final char'B'.(package private) static final intMaximum number of introducers per address.static final StringProperty key for capabilities.static final StringConfig key for SSU host.private static final String[]Config keys of the introducer expirations.static final StringIntroduction expiration prefix.private static final String[]Config keys of the introducer hashes.static final StringIntroduction hash prefix for SSU2.private static final String[]Config keys of the introducer hosts.static final StringIntroducer host.private static final String[]Config keys of the introducer keys.static final StringIntroduction key.static final StringIntroducer key.private static final String[]Config keys of the introducer ports.static final StringIntroducer port.(package private) static final String[]Introducer tag property names indexed by position.static final StringIntroducer tag.static final StringProperty key for MTU.static final StringConfig key for SSU port.Constructor Summary
ConstructorsMethod Summary
Modifier and TypeMethodDescription(package private) static voidClear cache.private static InetAddressCaching version ofgetByName(host), which is slow.getHost()Host string from the router address.(package private) InetAddressThe InetAddress for the router address's host, looked up on first use.(package private) intHow many introducers this address carries.(package private) longgetIntroducerExpiration(int i) Expiration for the given introducer.(package private) HashgetIntroducerHash(int i) Introducer hash for the given introducer.(package private) InetAddressgetIntroducerHost(int i) The InetAddress for the introducer at index i, looked up on first use.(package private) byte[]getIntroducerKey(int i) Introducer key for the given introducer.(package private) intgetIntroducerPort(int i) Port number for the given introducer.(package private) longgetIntroducerTag(int i) Introducer tag for the given introducer.(package private) byte[]The key this address is introduced under.(package private) intgetMTU()The MTU to use for this address.intgetPort()Port number from the router address.(package private) booleanisIPv4()Whether this address is IPv4.(package private) booleanisIPv6()Whether this address is IPv6.(package private) static booleanCheck whether a property-order parse error names an introducer property beyond our cap, e.g.(package private) static booleanCheck whether a peer address declares more introducers than the spec allows.toString()String representation.
Field Details
_host
The host name or literal address._hostAddress
The resolved host address._port
private final int _portThe UDP port._introKey
private final byte[] _introKeyOur introduction key._introHosts
The introducer host names._introAddresses
The resolved introducer addresses._introPorts
private final int[] _introPortsThe introducer ports._introKeys
private final byte[][] _introKeysThe introducer keys._introTags
private final long[] _introTagsThe introducer tags._introExps
private final long[] _introExpsWhen the introducers expire._introHashes
The introducer hashes._mtu
private final int _mtuThe MTU of the address._isIPv4
private final boolean _isIPv4True if the address supports IPv4, both flags if both._isIPv6
private final boolean _isIPv6True if the address supports IPv6.PROP_PORT
PROP_HOST
PROP_INTRO_KEY
PROP_MTU
PROP_CAPACITY
Property key for capabilities.- See Also:
CAPACITY_TESTING
CAPACITY_INTRODUCER
PROP_INTRO_HOST_PREFIX
PROP_INTRO_PORT_PREFIX
PROP_INTRO_KEY_PREFIX
PROP_INTRO_TAG_PREFIX
PROP_INTRO_EXP_PREFIX
Introduction expiration prefix.- See Also:
PROP_INTRO_HASH_PREFIX
Introduction hash prefix for SSU2.- See Also:
MAX_INTRODUCERS
static final int MAX_INTRODUCERSMaximum number of introducers per address.- See Also:
PROP_INTRO_HOST
Config keys of the introducer hosts.PROP_INTRO_PORT
Config keys of the introducer ports.PROP_INTRO_IKEY
Config keys of the introducer keys.PROP_INTRO_TAG
Introducer tag property names indexed by position.PROP_INTRO_EXP
Config keys of the introducer expirations.PROP_INTRO_HASH
Config keys of the introducer hashes._inetAddressCache
Textual IP to InetAddress, becauseInetAddress.getByName(String)is slow. Copied from Addresses.java, but caching InetAddress rather than byte[].
Constructor Details
UDPAddress
Parse and cache router address data.- Parameters:
addr- the address to parse, null for an invalid address
Method Details
tooManyIntroducers
Check whether a peer address declares more introducers than the spec allows. Each introducer requires a tag property, so any tag at or beyond our cap means the peer is out of spec.- Parameters:
addr- the peer's transport address- Returns:
- true if introducer properties beyond MAX_INTRODUCERS are present
overCapIntroducerKey
Check whether a property-order parse error names an introducer property beyond our cap, e.g. "iexp10". Such a peer wrote its introducer options numerically instead of in the required sorted order, which only happens with more introducers than we support.- Parameters:
msg- the DataFormatException message- Returns:
- true if an over-cap introducer key appears in the message
getHost
Host string from the router address.- Returns:
- the host, null when the address is invalid
getHostAddress
InetAddress getHostAddress()The InetAddress for the router address's host, looked up on first use.Hostnames are not resolved; a host that is not a literal IP address gives a null address.
- Returns:
- InetAddress or null
getPort
public int getPort()Port number from the router address.- Returns:
- the port, 0 when the address is invalid
getIntroKey
byte[] getIntroKey()The key this address is introduced under.- Returns:
- shouldn't be null but will be if invalid
getIntroducerCount
int getIntroducerCount()How many introducers this address carries.- Returns:
- the introducer count, 0 when there are none
getIntroducerHost
The InetAddress for the introducer at index i, looked up on first use.Hostnames are not resolved; a host that is not a literal IP address gives a null address.
- Parameters:
i- the introducer index, from 0- Returns:
- null if invalid or for SSU2
getIntroducerPort
int getIntroducerPort(int i) Port number for the given introducer.- Parameters:
i- the introducer index, from 0- Returns:
- greater than zero or zero for SSU2
getIntroducerKey
byte[] getIntroducerKey(int i) Introducer key for the given introducer.- Parameters:
i- the introducer index, from 0- Returns:
- null if no keys or for SSU2
getIntroducerTag
long getIntroducerTag(int i) Introducer tag for the given introducer.- Parameters:
i- the introducer index, from 0- Returns:
- greater than zero
getIntroducerExpiration
long getIntroducerExpiration(int i) Expiration for the given introducer.- Parameters:
i- the introducer index, from 0- Returns:
- ms since epoch, zero if unset
getIntroducerHash
Introducer hash for the given introducer.- Parameters:
i- the introducer index, from 0- Returns:
- the introducer hash, null when unset or out of range
isIPv4
boolean isIPv4()Whether this address is IPv4.- Returns:
- true when the address is IPv4
isIPv6
boolean isIPv6()Whether this address is IPv6.- Returns:
- true when the address is IPv6
getMTU
int getMTU()The MTU to use for this address.- Returns:
- 0 if unset or invalid; rectified via
MTU.rectify(boolean, int)
toString
getByName
Caching version ofgetByName(host), which is slow. Caches numeric IPs only. As of 0.9.32, will NOT resolve hostnames.Unlike
InetAddress.getByName(String), we do NOT allow numeric IPs of the form d.d.d, d.d, or d, as these are almost certainly mistakes.- Parameters:
host- literal IPv4 or IPv6; if null or hostname, returns null- Returns:
- InetAddress or null
clearCache
static void clearCache()Clear cache.