Exemple #1
0
 public void update(TrackerResponse.PeerInfo info) {
   if (!this.info.getSocketAddress().equals(info.getSocketAddress())) {
     throw new IllegalArgumentException("socket address differs");
   }
   if (!this.info.getPeerId().equals(info.getPeerId())) {
     this.info = info;
   }
   lastUpdate = timeSource.getTime();
   lastPinged = 0;
   pingAttempts = 0;
 }
Exemple #2
0
 public String averageDistancesPerBucket() {
   StringBuilder builder = new StringBuilder();
   for (Bucket bucket : buckets) {
     builder.append(bucket.toString()).append(": ");
     int distanceSum = 0;
     Collection<TrackerResponse.PeerInfo> entries = bucket.getEntries();
     for (TrackerResponse.PeerInfo node : entries) {
       distanceSum += ourId.distance(node.getPeerId());
     }
     double average = (double) distanceSum / entries.size();
     builder.append(average).append("\n");
   }
   return builder.toString();
 }
Exemple #3
0
 public synchronized void add(TrackerResponse.PeerInfo e) {
   InetSocketAddress address = e.getSocketAddress();
   if (entries.containsKey(address)) {
     RoutingTable.Bucket.Entry entry = entries.get(address);
     entry.update(e);
   } else if (canAddMore()) {
     entries.put(address, new Entry(e));
   } else {
     addEntryToWaitingList(e);
   }
 }
Exemple #4
0
 private void addEntryToWaitingList(TrackerResponse.PeerInfo peerInfo) {
   InetSocketAddress address = peerInfo.getSocketAddress();
   Entry entry = waitingEntries.get(address);
   if (entry == null) {
     if (waitingEntries.size() < waitingCapacity) {
       entry = new Entry(peerInfo);
       waitingEntries.put(address, entry);
     }
   } else {
     entry.update(peerInfo);
   }
 }
Exemple #5
0
 public void maintain() {
   long now = timeSource.getTime();
   if (lastUpdate + TIMEOUT > now) {
     return;
   }
   if (lastPinged + PING_TIMEOUT > now) {
     return;
   }
   if (pingAttempts < MAX_PING_ATTEMPTS) {
     pingAttempts++;
     totalPings++;
     lastPinged = now;
     pinger.ping(info.getSocketAddress());
   }
 }
Exemple #6
0
 private int determineValue(TrackerResponse.PeerInfo node) {
   return ourId.distance(node.getPeerId());
 }
Exemple #7
0
 public void addNode(TrackerResponse.PeerInfo node) {
   if (ourId.equals(node.getPeerId())) {
     return;
   }
   internalAdd(node);
 }