Пример #1
0
 public static List<Map<Number160, PeerStatistic>> unflatten(
     Collection<PeerAddress> map, PeerAddress sender) {
   PeerMapConfiguration peerMapConfiguration = new PeerMapConfiguration(sender.peerId());
   PeerMap peerMap = new PeerMap(peerMapConfiguration);
   for (PeerAddress peerAddress : map) {
     LOG.debug("found peer in unflatten for relaying, {}", peerAddress);
     peerMap.peerFound(peerAddress, null, null, null);
   }
   return peerMap.peerMapVerified();
 }
Пример #2
0
 /**
  * Constructor.
  *
  * @param replicationStorage The interface where we shore the replication responsibilities
  * @param selfAddress My address to know for what my peer is responsible
  * @param peerMap The map of my neighbors
  * @param replicationFactor The replication factor
  */
 public Replication(
     final ReplicationStorage replicationStorage,
     final PeerAddress selfAddress,
     final PeerMap peerMap,
     final int replicationFactor) {
   this.replicationStorage = replicationStorage;
   this.selfAddress = selfAddress;
   this.peerMap = peerMap;
   this.replicationFactor = replicationFactor;
   peerMap.addPeerMapChangeListener(this);
 }
Пример #3
0
 public static void routing(Number160 key, Peer[] peers, int start) {
   System.out.println("routing: searching for key " + key);
   NavigableSet<PeerAddress> pa1 = new TreeSet<PeerAddress>(PeerMap.createComparator(key));
   NavigableSet<PeerAddress> queried = new TreeSet<PeerAddress>(PeerMap.createComparator(key));
   Number160 result = Number160.ZERO;
   Number160 resultPeer = new Number160("0xd75d1a3d57841fbc9e2a3d175d6a35dc2e15b9f");
   int round = 0;
   while (!resultPeer.equals(result)) {
     System.out.println("round " + round);
     round++;
     pa1.addAll(peers[start].getPeerBean().peerMap().getAll());
     queried.add(peers[start].getPeerAddress());
     System.out.println("closest so far: " + queried.first());
     PeerAddress next = pa1.pollFirst();
     while (queried.contains(next)) {
       next = pa1.pollFirst();
     }
     result = next.getPeerId();
     start = findNr(next.getPeerId().toString(), peers);
   }
 }
Пример #4
0
 /**
  * Checks if a peeraddress is within the replication range. This means that the peer should also
  * receive a replica.
  *
  * @param locationKey The locationKey
  * @param peerAddress The peeraddress to check if its within the replication range
  * @param replicationFactor The replication factor
  * @return True if the peer is within replication range, otherwise false.
  */
 private boolean isInReplicationRange(
     final Number160 locationKey, final PeerAddress peerAddress, final int replicationFactor) {
   SortedSet<PeerAddress> tmp = peerMap.closePeers(locationKey, replicationFactor);
   return tmp.headSet(peerAddress).size() < replicationFactor;
 }
Пример #5
0
 /**
  * Returns the closest peer to a number (including myself).
  *
  * @param locationKey The locationKey
  * @return The peer that is responsible for the location key, including myself.
  */
 private PeerAddress closest(final Number160 locationKey) {
   SortedSet<PeerAddress> tmp = peerMap.closePeers(locationKey, 1);
   tmp.add(selfAddress);
   return tmp.iterator().next();
 }