コード例 #1
0
ファイル: RelayUtils.java プロジェクト: thirdy/TomP2P
 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
ファイル: Replication.java プロジェクト: narayana1208/TomP2P
 /**
  * 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
ファイル: Utils2.java プロジェクト: narayana1208/TomP2P
 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
ファイル: Replication.java プロジェクト: narayana1208/TomP2P
 /**
  * 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
ファイル: Replication.java プロジェクト: narayana1208/TomP2P
 /**
  * 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();
 }