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 |
bagSizeVerified() |
NavigableSet<PeerAddress> |
closePeers(int atLeast)
Returns close peers to the peer itself.
|
NavigableSet<PeerAddress> |
closePeers(Number160 id,
int atLeast)
Returns close peer from the set to a given key.
|
static NavigableSet<PeerAddress> |
closePeers(Number160 self,
Number160 other,
int atLeast,
List<Map<Number160,PeerStatistic>> peerMap) |
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.
|
Comparator<PeerAddress> |
createComparator()
Creates an XOR comparator based on this peer ID.
|
static Comparator<PeerAddress> |
createComparator(Number160 id)
Create the Kademlia distance comparator.
|
static Comparator<Number160> |
createComparator2(Number160 id) |
PeerAddress |
find(Number160 peerId) |
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)
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)
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)
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 suchpublic boolean peerFailed(PeerAddress remotePeer, PeerException peerException)
peerFailed in interface PeerStatusListenerremotePeer - The node that should be removedforce - A flag that removes a peer immediately.public boolean contains(PeerAddress peerAddress)
peerAddress - The peer address to checkpublic boolean containsOverflow(PeerAddress peerAddress)
peerAddress - The peer address to checkpublic NavigableSet<PeerAddress> closePeers(int atLeast)
atLeast - The number we want to find at leastpublic NavigableSet<PeerAddress> 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<PeerAddress> closePeers(Number160 self, Number160 other, int atLeast, List<Map<Number160,PeerStatistic>> peerMap)
public Comparator<PeerAddress> createComparator()
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 Comparator<PeerAddress> createComparator(Number160 id)
id - The id of this peerpublic static Comparator<Number160> createComparator2(Number160 id)
public static PeerStatistic updateExistingVerifiedPeerAddress(Map<Number160,PeerStatistic> tmp, PeerAddress peerAddress, boolean firstHand)
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 peerpublic int bagSizeVerified()
public int bagSizeOverflow()
public PeerAddress find(Number160 peerId)
Copyright © 2014. All rights reserved.