- All Implemented Interfaces:
Serializable, Cloneable, Iterable<String>, Collection<String>, Set<String>
Provides IP address masking functionality to detect routers with matching IP addresses or belonging to the same network family. Used for network topology analysis and peer relationship identification in distributed hash table operations.
Supports configurable masking levels (1-4 bytes) and includes both communication system records and network database addresses for comprehensive matching. Optimized for efficiency with local lookup operations to avoid deadlocks.
As of 0.9.24, returned set includes netdb family as well as IP-based matches for broader detection capabilities.
- See Also:
Constructor Summary
ConstructorsConstructorDescriptionCreate an empty set.MaskedIPSet(int initialCapacity) Masked IP set with a given initial capacity.MaskedIPSet(RouterContext ctx, Hash peer, int mask) The Set of IPs for this peer, with a given mask.MaskedIPSet(RouterContext ctx, Hash peer, RouterInfo pinfo, int mask) The Set of IPs for this peer, with a given mask.MaskedIPSet(RouterContext ctx, RouterInfo pinfo, int mask) The Set of IPs for this peer, with a given mask.Method Summary
Modifier and TypeMethodDescriptionbooleancontainsAny(Set<String> b) Does this contain any of the elements in b?private static RouterInfolookupRILocally(RouterContext ctx, Hash peer) This gets the peer from the netdb without validation, for efficiency and to avoid deadlocks.static StringmaskedIPKey(byte[] ip, int mask) Generate an arbitrary unique value for this ip/mask (mask = 1-4).Methods inherited from class HashSet
add, clear, clone, contains, isEmpty, iterator, newHashSet, remove, size, spliterator, toArray, toArrayMethods inherited from class AbstractSet
equals, hashCode, removeAllMethods inherited from class AbstractCollection
addAll, containsAll, retainAll, toStringMethods inherited from interface Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface Set
addAll, containsAll, retainAll
Constructor Details
MaskedIPSet
public MaskedIPSet()Create an empty set.MaskedIPSet
public MaskedIPSet(int initialCapacity) Masked IP set with a given initial capacity.- Parameters:
initialCapacity- the initial capacity
MaskedIPSet
The Set of IPs for this peer, with a given mask. Includes the comm system's record of the IP, and all netDb addresses.As of 0.9.24, returned set will include netdb family as well.
This gets the peer from the netdb without validation, for efficiency and to avoid deadlocks. Peers are presumed to be validated elsewhere.
- Parameters:
ctx- router context used to look up the peer in the netdb and comm systempeer- non-nullmask- is 1-4 (number of bytes to match)
MaskedIPSet
The Set of IPs for this peer, with a given mask. Includes the comm system's record of the IP, and all netDb addresses.As of 0.9.24, returned set will include netdb family as well.
- Parameters:
ctx- router context used to look up the peer in the netdb and comm systempinfo- may be nullmask- is 1-4 (number of bytes to match)
MaskedIPSet
The Set of IPs for this peer, with a given mask. Includes the comm system's record of the IP, and all netDb addresses.As of 0.9.24, returned set will include netdb family as well.
- Parameters:
ctx- router context supplying the peer's recorded comm system IPpeer- the peer's router hash, used for the comm system lookuppinfo- may be nullmask- is 1-4 (number of bytes to match)
Method Details
lookupRILocally
This gets the peer from the netdb without validation, for efficiency and to avoid deadlocks.- Parameters:
ctx- the context holding the NetDb to searchpeer- the peer hash to look up- Returns:
- the peer's RouterInfo, or null if the NetDb holds no RouterInfo for it
maskedIPKey
Generate an arbitrary unique value for this ip/mask (mask = 1-4). If IPv6, double the mask value.Format: a family-delimiting leading char, '.' for IPv4 or ':' for IPv6, and the IPv6 form also doubles the matched byte count; then two '0'-offset hex nibbles per matched byte — the fake hex range
0123456789:;<=>?. Equal keys mean "same masked subnet".Public as of 0.9.71+ so callers that build keys without building a set share this format. A peer's fingerprints are compared against keys claimed by other peers, so two different formats silently never match and the diversity gate stops rejecting anything.
- Parameters:
ip- an IPv4 (4-byte) or IPv6 (16-byte) addressmask- 1-4, the number of leading bytes to match- Returns:
- the fingerprint key
containsAny