Ejemplo n.º 1
0
    public int compare(Object a, Object b) {
      RemoteFileDesc pongA = (RemoteFileDesc) a;
      RemoteFileDesc pongB = (RemoteFileDesc) b;

      // Multicasts are best
      if (pongA.isReplyToMulticast() != pongB.isReplyToMulticast()) {
        if (pongA.isReplyToMulticast()) return -1;
        else return 1;
      }

      // HeadPongs with highest number of free slots get the highest priority
      if (pongA.getQueueStatus() > pongB.getQueueStatus()) return 1;
      else if (pongA.getQueueStatus() < pongB.getQueueStatus()) return -1;

      // Within the same queue rank, firewalled hosts get priority
      if (pongA.needsPush() != pongB.needsPush()) {
        if (pongA.needsPush()) return -1;
        else return 1;
      }

      // Within the same queue/fwall, partial hosts get priority
      if (pongA.isPartialSource() != pongB.isPartialSource()) {
        if (pongA.isPartialSource()) return -1;
        else return 1;
      }

      // the two pongs seem completely the same
      return pongA.hashCode() - pongB.hashCode();
    }
Ejemplo n.º 2
0
  private boolean addInternal(RemoteFileDesc host) {
    // initialize the sha1 if we don't have one
    if (sha1 == null) {
      if (host.getSHA1Urn() != null) sha1 = host.getSHA1Urn();
      else //  BUGFIX:  We can't discard sources w/out a SHA1 when we dont' have
        //  a SHA1 for the download, or else it won't be possible to download a
        //  file from a query hit without a SHA1, if we can received UDP pings
        return testedLocations.add(host); // we can't do anything yet
    }

    // do not allow duplicate hosts
    if (running && knowsAboutHost(host)) return false;

    if (LOG.isDebugEnabled()) LOG.debug("adding new host " + host + " " + host.getPushAddr());

    boolean ret = false;

    // don't bother ranking multicasts
    if (host.isReplyToMulticast()) ret = verifiedHosts.add(host);
    else ret = newHosts.add(host); // rank

    // make sure that if we were stopped, we return true
    ret = ret | !running;

    // initialize the guid if we don't have one
    if (myGUID == null && meshHandler != null) {
      myGUID = new GUID(GUID.makeGuid());
      RouterService.getMessageRouter().registerMessageListener(myGUID.bytes(), this);
    }

    return ret;
  }
Ejemplo n.º 3
0
 public boolean isReplyToMulticast() {
   return remoteFileDesc.isReplyToMulticast();
 }