net.tomp2p.peers
Interface PeerMap

All Known Implementing Classes:
PeerMapKadImpl

public interface PeerMap

Defines a map to store neighbor peers. The metric is defined in the implementation.

Author:
Thomas Bocek

Method Summary
 void addAddressFilter(InetAddress address)
           
 void addPeerMapChangeListener(PeerMapChangeListener peerMapChangeListener)
           
 void addPeerOfflineListener(PeerStatusListener peerListener)
           
 SortedSet<PeerAddress> closePeers(Number160 key, int number)
          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 key, Number160 key1, Number160 key2)
          Returns -1 if the first key is closer to the key, if the second is closer, then 1 is returned.
 int isCloser(Number160 key, PeerAddress nodeAddress1, PeerAddress nodeAddress2)
          Returns -1 if the first remote node is closer to the key, if the second is closer, then 1 is returned.
 boolean isPeerRemovedTemporarly(PeerAddress node)
          Checks if this peer has been removed.
 boolean peerFound(PeerAddress node, PeerAddress referer)
          Adds a neighbor to the neighbor list.
 boolean peerOffline(PeerAddress node, boolean force)
          Remove a peer from the list.
 Collection<PeerAddress> peersForMaintenance()
           
 void removePeerMapChangeListener(PeerMapChangeListener peerMapChangeListener)
           
 void removePeerOfflineListener(PeerStatusListener peerListener)
           
 Number160 self()
          Each node that has a bag has an ID itself to define what is close.
 int size()
           
 

Method Detail

self

Number160 self()
Each node that has a bag has an ID itself to define what is close. This method returns this ID.

Returns:
The id of this node

peerFound

boolean peerFound(PeerAddress node,
                  PeerAddress referer)
Adds a neighbor to the neighbor list. If the bag is full, the id zero or the same as our id, the neighbor is not added. This method is tread-safe

Parameters:
node - The node that should be added
firstHand - 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 such
Returns:
True if the neighbor could be added, otherwise false.

peerOffline

boolean peerOffline(PeerAddress node,
                    boolean force)
Remove a peer from the list. In order to not reappear, the node is put for a certain time in a cache list to keep the node removed. This method is thread-safe.

Parameters:
node - The node that should be removed
Returns:
True if the neighbor was removed and added to a cache list. False if peer has not been removed or is already in the peer removed temporarly list.

isPeerRemovedTemporarly

boolean isPeerRemovedTemporarly(PeerAddress node)
Checks if this peer has been removed. A peer that has been removed will be stored in a cache list for a certain time. This method is tread-safe

Parameters:
node - The node to check
Returns:
True if the peer has been removed recently

closePeers

SortedSet<PeerAddress> closePeers(Number160 key,
                                  int number)
Returns close peer from the set to a given key. This method is tread-safe. You can use the returned set as its a copy of the actual PeerMap and changes in the return set do not affect PeerMap.

Parameters:
key - The key that should be close to the keys in the map
number - The number we want to find at least
Returns:
A navigable set with close peers first in this set.

peersForMaintenance

Collection<PeerAddress> peersForMaintenance()

isCloser

int isCloser(Number160 key,
             PeerAddress nodeAddress1,
             PeerAddress nodeAddress2)
Returns -1 if the first remote node is closer to the key, if the second is closer, then 1 is returned. If both are equal, 0 is returned

Parameters:
key - The key to search for
nodeAddress1 - The remote node on the routing path to node close to key
nodeAddress2 - An other remote node on the routing path to node close to key
Returns:
-1 if nodeAddress1 is closer to the key than nodeAddress2, otherwise 1. 0 is returned if both are equal.

isCloser

int isCloser(Number160 key,
             Number160 key1,
             Number160 key2)
Returns -1 if the first key is closer to the key, if the second is closer, then 1 is returned. If both are equal, 0 is returned

Parameters:
key - The key to search for
key1 - The first key
key2 - The second key
Returns:
-1 if key1 is closer to key, otherwise 1. 0 is returned if both are equal.

createPeerComparator

Comparator<PeerAddress> createPeerComparator(Number160 id)
Creates a comparator that orders to peers according to their distance to the specified id.

Parameters:
id - The id that defines the metric
Returns:
The comparator to be used with the collection framework

createPeerComparator

Comparator<PeerAddress> createPeerComparator()

size

int size()

contains

boolean contains(PeerAddress peerAddress)

addPeerMapChangeListener

void addPeerMapChangeListener(PeerMapChangeListener peerMapChangeListener)

removePeerMapChangeListener

void removePeerMapChangeListener(PeerMapChangeListener peerMapChangeListener)

addPeerOfflineListener

void addPeerOfflineListener(PeerStatusListener peerListener)

removePeerOfflineListener

void removePeerOfflineListener(PeerStatusListener peerListener)

getAll

Collection<PeerAddress> getAll()
Return all addresses from the neighbor list. The collection is partially sorted.

Returns:
All neighbors

addAddressFilter

void addAddressFilter(InetAddress address)

getStatistics

Statistics getStatistics()


Copyright © 2012. All Rights Reserved.