public class PeerMap extends Object implements PeerStatusListener, Maintainable
| Constructor and Description |
|---|
PeerMap(PeerMapConfiguration peerMapConfiguration)
Creates the bag for the peers.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addPeerMapChangeListener(PeerMapChangeListener peerMapChangeListener)
Add a map change listener.
|
List<PeerAddress> |
all()
Return all addresses from the neighbor list.
|
List<PeerAddress> |
allOverflow()
Return all addresses from the overflow / non-verified list.
|
int |
bagSizeOverflow(int bag) |
int |
bagSizeVerified(int bag) |
static int |
classCloser(Number160 ln,
PeerAddress rn,
PeerAddress rn2)
Returns -1 if the first remote node is closer to the key, if the secondBITS is closer, then 1 is returned.
|
static int |
classMember(Number160 id1,
Number160 id2)
Returns the difference in terms of bit counts of two ids, minus 1.
|
NavigableSet<PeerStatistic> |
closePeers(int atLeast)
Returns close peers to the peer itself.
|
NavigableSet<PeerStatistic> |
closePeers(Number160 id,
int atLeast)
Returns close peer from the set to a given key.
|
static NavigableSet<PeerStatistic> |
closePeers(Number160 self,
Number160 other,
int atLeast,
List<Map<Number160,PeerStatistic>> peerMap,
Comparator<PeerStatistic> comparator) |
boolean |
contains(PeerAddress peerAddress)
Checks if a peer address in either in the verified map.
|
boolean |
containsOverflow(PeerAddress peerAddress)
Checks if a peer address in either in the overflow / non-verified map.
|
static Comparator<Number160> |
createComparator2(Number160 id) |
Comparator<PeerStatistic> |
createStatisticComparator(Number160 location) |
Comparator<PeerAddress> |
createXORAddressComparator()
Creates an XOR comparator based on this peer ID.
|
static Comparator<PeerAddress> |
createXORAddressComparator(Number160 location)
Create the Kademlia distance comparator.
|
static Comparator<PeerStatistic> |
createXORStatisticComparator(Number160 location) |
PeerAddress |
find(Number160 peerId) |
PeerStatistic |
getPeerStatistic(PeerAddress peerAddress)
Checks if an entry of that peerAddress is available in the verified peer map
or overflow peer map.
|
Collection<PeerStatistic> |
getPeerStatistics(Collection<PeerAddress> peerAddresses)
Takes a collection of PeerAddress and returns an equivalent collection
of PeerStatistic from the PeerMap.
|
static int |
isCloser(Number160 id,
Number160 rn,
Number160 rn2)
Returns -1 if the first key is closer to the key, if the second is closer, then 1 is returned.
|
static int |
isCloser(Number160 id,
PeerAddress rn,
PeerAddress rn2)
Returns -1 if the first remote node is closer to the key, if the second is closer, then 1 is returned.
|
static int |
isKadCloser(Number160 id,
PeerAddress rn,
PeerAddress rn2)
Returns -1 if the first remote node is closer to the key, if the secondBITS is closer, then 1 is returned.
|
boolean |
isPeerRemovedTemporarly(PeerAddress peerAddress)
Checks if a peer is in the offline map.
|
PeerStatistic |
nextForMaintenance(Collection<PeerAddress> notInterestedAddresses)
Finds the next peer that should have a maintenance check.
|
boolean |
peerFailed(PeerAddress remotePeer,
PeerException peerException)
Remove a peer from the list.
|
boolean |
peerFound(PeerAddress remotePeer,
PeerAddress referrer,
PeerConnection peerConnection,
RTT roundTripTime)
Adds a neighbor to the neighbor list.
|
List<Map<Number160,PeerStatistic>> |
peerMapOverflow() |
List<Map<Number160,PeerStatistic>> |
peerMapVerified() |
void |
removePeerMapChangeListener(PeerMapChangeListener peerMapChangeListener)
Remove a map change listener.
|
Number160 |
self()
Each node that has a bag has an ID itself to define what is close.
|
int |
size()
The number of the peers in the verified map.
|
String |
toString() |
static PeerStatistic |
updateExistingVerifiedPeerAddress(Map<Number160,PeerStatistic> tmp,
PeerAddress peerAddress,
boolean firstHand,
RTT roundTripTime)
Checks if a peer already exists in this map and if it does, it will update the entry because the peer address
(e.g.
|
public PeerMap(PeerMapConfiguration peerMapConfiguration)
peerMapConfiguration - The configuration values of this mappublic void addPeerMapChangeListener(PeerMapChangeListener peerMapChangeListener)
peerMapChangeListener - The listenerpublic void removePeerMapChangeListener(PeerMapChangeListener peerMapChangeListener)
peerMapChangeListener - The listenerpublic int size()
public Number160 self()
public boolean peerFound(PeerAddress remotePeer, PeerAddress referrer, PeerConnection peerConnection, RTT roundTripTime)
peerFound in interface PeerStatusListenerremotePeer - The node that should be addedreferrer - If we had direct contact and we know for sure that this node is online, we set firsthand to true.
Information from 3rd party peers are always second hand and treated as suchroundTripTime - A RTT object, that measured the round-trip-time related to the finding of this peer. This is
will be saved into the PeerStatisticpublic boolean peerFailed(PeerAddress remotePeer, PeerException peerException)
peerFailed in interface PeerStatusListenerremotePeer - The node that should be removedpublic boolean contains(PeerAddress peerAddress)
peerAddress - The peer address to checkpublic boolean containsOverflow(PeerAddress peerAddress)
peerAddress - The peer address to checkpublic PeerStatistic getPeerStatistic(PeerAddress peerAddress)
peerAddress - public NavigableSet<PeerStatistic> closePeers(int atLeast)
atLeast - The number we want to find at leastpublic NavigableSet<PeerStatistic> closePeers(Number160 id, int atLeast)
id - The key that should be close to the keys in the mapatLeast - The number we want to find at leastpublic static NavigableSet<PeerStatistic> closePeers(Number160 self, Number160 other, int atLeast, List<Map<Number160,PeerStatistic>> peerMap, Comparator<PeerStatistic> comparator)
public Comparator<PeerAddress> createXORAddressComparator()
public List<PeerAddress> all()
public List<Map<Number160,PeerStatistic>> peerMapVerified()
public List<Map<Number160,PeerStatistic>> peerMapOverflow()
public List<PeerAddress> allOverflow()
public boolean isPeerRemovedTemporarly(PeerAddress peerAddress)
peerAddress - The address to look forpublic PeerStatistic nextForMaintenance(Collection<PeerAddress> notInterestedAddresses)
nextForMaintenance in interface Maintainablepublic static int isCloser(Number160 id, PeerAddress rn, PeerAddress rn2)
id - The key to search forrn - The remote node on the routing path to node close to keyrn2 - An other remote node on the routing path to node close to keypublic static int isCloser(Number160 id, Number160 rn, Number160 rn2)
id - The key to search forrn - The first keyrn2 - The second keypublic static int isKadCloser(Number160 id, PeerAddress rn, PeerAddress rn2)
id - The id as a distance referencern - The peer to test if closer to the idrn2 - The other peer to test if closer to the idpublic static int classCloser(Number160 ln, PeerAddress rn, PeerAddress rn2)
ln - The locationrn - The peer to test if closer to the idrn2 - The other peer to test if closer to the idpublic static Comparator<PeerAddress> createXORAddressComparator(Number160 location)
location - The id of this peerpublic static Comparator<PeerStatistic> createXORStatisticComparator(Number160 location)
public Comparator<PeerStatistic> createStatisticComparator(Number160 location)
public Collection<PeerStatistic> getPeerStatistics(Collection<PeerAddress> peerAddresses)
peerAddresses - public static Comparator<Number160> createComparator2(Number160 id)
public static int classMember(Number160 id1, Number160 id2)
id1 - The first idid2 - The second idpublic static PeerStatistic updateExistingVerifiedPeerAddress(Map<Number160,PeerStatistic> tmp, PeerAddress peerAddress, boolean firstHand, RTT roundTripTime)
tmp - The map where the peer is suppost to bepeerAddress - The address of the peer that may have been changedfirstHand - True if this peer send and received a message from the remote peerroundTripTime - public int bagSizeVerified(int bag)
public int bagSizeOverflow(int bag)
public PeerAddress find(Number160 peerId)
Copyright © 2015. All rights reserved.