|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectnet.tomp2p.peers.PeerMapKadImpl
public class PeerMapKadImpl
This routing implementation uses is based on Kademlia. However, many changes have been applied to make it faster and more flexible. This class is partially thread-safe.
| Constructor Summary | |
|---|---|
PeerMapKadImpl(Number160 self,
int bagSize,
int cacheSize,
int cacheTimeout,
int maxFail,
int[] maintenanceTimeoutsSeconds)
Creates a bag of peers |
|
| Method Summary | |
|---|---|
void |
addAddressFilter(InetAddress address)
|
void |
addPeerMapChangeListener(PeerMapChangeListener peerMapChangeListener)
|
void |
addPeerOfflineListener(PeerOfflineListener peerListener)
|
SortedSet<PeerAddress> |
closePeers(Number160 id,
int atLeast)
Returns close peer from the set to a given key. |
boolean |
contains(PeerAddress peerAddress)
|
Comparator<PeerAddress> |
createPeerComparator()
|
Comparator<PeerAddress> |
createPeerComparator(Number160 id)
Creates a comparator that orders to peers according to their distance to the specified id. |
Collection<PeerAddress> |
getAll()
Return all addresses from the neighbor list. |
Statistics |
getStatistics()
|
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. |
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. |
boolean |
isPeerRemovedTemporarly(PeerAddress remoteNode)
Checks if this peer has been removed. |
boolean |
peerOffline(PeerAddress remotePeer,
boolean force)
Remove a peer from the list. |
boolean |
peerOnline(PeerAddress remotePeer,
PeerAddress referrer)
Adds a neighbor to the neighbor list. |
Collection<PeerAddress> |
peersForMaintenance()
|
void |
removePeerMapChangeListener(PeerMapChangeListener peerMapChangeListener)
|
void |
removePeerOfflineListener(PeerOfflineListener peerListener)
|
Number160 |
self()
Each node that has a bag has an ID itself to define what is close. |
int |
size()
The peerCount keeps track of the total number of peer in the system. |
String |
toString()
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public PeerMapKadImpl(Number160 self,
int bagSize,
int cacheSize,
int cacheTimeout,
int maxFail,
int[] maintenanceTimeoutsSeconds)
self - The id of this peerbagSize - The size of a bag. The original Kademlia suggests 20, but
we can go much lower, as we dont have a fixed limit for a bag. The
bagSize is a suggestion and if maxpeers has not been reached, the
peer is added even though it exceeds the bag limit.cacheSize - The size of the cache of removed peerscacheTimeout - The time that a removed peer will be in the cache in
milliseconds.peerMapChangeListener - Listeners that will be called if a peer is
added or removed.| Method Detail |
|---|
public void addPeerMapChangeListener(PeerMapChangeListener peerMapChangeListener)
addPeerMapChangeListener in interface PeerMappublic void removePeerMapChangeListener(PeerMapChangeListener peerMapChangeListener)
removePeerMapChangeListener in interface PeerMappublic void addPeerOfflineListener(PeerOfflineListener peerListener)
addPeerOfflineListener in interface PeerMappublic void removePeerOfflineListener(PeerOfflineListener peerListener)
removePeerOfflineListener in interface PeerMappublic Statistics getStatistics()
getStatistics in interface PeerMappublic int size()
size in interface PeerMappublic Number160 self()
PeerMap
self in interface PeerMap
public boolean peerOnline(PeerAddress remotePeer,
PeerAddress referrer)
PeerMap
peerOnline in interface PeerMapremotePeer - The node that should be added
public boolean peerOffline(PeerAddress remotePeer,
boolean force)
PeerMap
peerOffline in interface PeerMapremotePeer - The node that should be removed
public Collection<PeerAddress> peersForMaintenance()
peersForMaintenance in interface PeerMappublic boolean isPeerRemovedTemporarly(PeerAddress remoteNode)
PeerMap
isPeerRemovedTemporarly in interface PeerMapremoteNode - The node to check
public boolean contains(PeerAddress peerAddress)
contains in interface PeerMap
public SortedSet<PeerAddress> closePeers(Number160 id,
int atLeast)
PeerMap
closePeers in interface PeerMapid - The key that should be close to the keys in the mapatLeast - The number we want to find at least
public int isCloser(Number160 id,
PeerAddress rn,
PeerAddress rn2)
PeerMap
isCloser in interface PeerMapid - 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 key
public int isCloser(Number160 id,
Number160 rn,
Number160 rn2)
PeerMap
isCloser in interface PeerMapid - The key to search forrn - The first keyrn2 - The second key
public String toString()
toString in class Objectpublic Comparator<PeerAddress> createPeerComparator(Number160 id)
PeerMap
createPeerComparator in interface PeerMapid - The id that defines the metric
public Comparator<PeerAddress> createPeerComparator()
createPeerComparator in interface PeerMappublic Collection<PeerAddress> getAll()
PeerMap
getAll in interface PeerMappublic void addAddressFilter(InetAddress address)
addAddressFilter in interface PeerMap
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||