Пример #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;
 }
Пример #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();
 }
Пример #3
0
 private int determineValue(TrackerResponse.PeerInfo node) {
   return ourId.distance(node.getPeerId());
 }
Пример #4
0
 public void addNode(TrackerResponse.PeerInfo node) {
   if (ourId.equals(node.getPeerId())) {
     return;
   }
   internalAdd(node);
 }