private void limitKnownPeers(int limit){
  if (peerList.size() < limit)   return;
  int knownPeers=0;
  Peer oldestPeer=null;
  long oldestDate=System.currentTimeMillis();
  for (  Peer peer : peerList) {
    if (peer.hasReceivedData()) {
      knownPeers++;
      if (peer.getCreationTime() < oldestDate) {
        oldestDate=peer.getCreationTime();
        oldestPeer=peer;
      }
    }
  }
  if (knownPeers > limit) {
    peerList.remove(oldestPeer);
  }
  if (knownPeers - 1 > limit) {
    limitKnownPeers(limit);
  }
}

private void limitKnownPeers ( int limit ) { if ( peerList . size ( ) < limit ) return ; int knownPeers = 0 ; Peer oldestPeer = null ; long oldestDate = System . currentTimeMillis ( ) ; for ( Peer peer : peerList ) { if ( peer . hasReceivedData ( ) ) { knownPeers ++ ; if ( peer . getCreationTime ( ) < oldestDate ) { oldestDate = peer . getCreationTime ( ) ; oldestPeer = peer ; } } } if ( knownPeers > limit ) { peerList . remove ( oldestPeer ) ; } if ( knownPeers - 1 > limit ) { limitKnownPeers ( limit ) ; } }
limit the amount of known peers by deleting the oldest peers .
