コード例 #1
0
  protected int getPeerCacheLimit() {
    synchronized (this) {
      if (activated.size() < announcers.size()) {

        return (0);
      }
    }

    if (SystemTime.getMonotonousTime() - create_time < 15 * 1000) {

      return (0);
    }

    TRTrackerAnnouncer active = getBestActive();

    if (active != null
        && provider != null
        && active.getStatus() == TRTrackerAnnouncerResponse.ST_ONLINE) {

      if (provider.getMaxNewConnectionsAllowed() > 0 && provider.getPendingConnectionCount() == 0) {

        return (5);

      } else {

        return (0);
      }
    }

    return (10);
  }
コード例 #2
0
  protected void checkActivation(boolean force) {
    synchronized (this) {
      int next_check_delay;

      if (destroyed || stopped || announcers.size() <= activated.size()) {

        return;
      }

      if (provider == null) {

        next_check_delay = ACT_CHECK_INIT_DELAY;

      } else {

        boolean activate = force;

        boolean seeding = provider.getRemaining() == 0;

        if (seeding && activated.size() > 0) {

          // when seeding we only activate on tracker fail or major lack of connections
          // as normally we rely on downloaders rotating and finding us

          int connected = provider.getConnectedConnectionCount();

          if (connected < 1) {

            activate = SystemTime.getMonotonousTime() - last_activation_time >= 60 * 1000;

            next_check_delay = ACT_CHECK_SEEDING_SHORT_DELAY;

          } else if (connected < 3) {

            next_check_delay = ACT_CHECK_SEEDING_LONG_DELAY;

          } else {

            next_check_delay = 0;
          }
        } else {

          int allowed = provider.getMaxNewConnectionsAllowed();
          int pending = provider.getPendingConnectionCount();
          int connected = provider.getConnectedConnectionCount();

          int online = 0;

          for (TRTrackerAnnouncerHelper a : activated) {

            TRTrackerAnnouncerResponse response = a.getLastResponse();

            if (response != null && response.getStatus() == TRTrackerAnnouncerResponse.ST_ONLINE) {

              online++;
            }
          }

          /*
          System.out.println(
          	"checkActivation: announcers=" + announcers.size() +
          	", active=" + activated.size() +
          	", online=" + online +
          	", allowed=" + allowed +
          	", pending=" + pending +
          	", connected=" + connected +
          	", seeding=" + seeding );
          */

          if (online == 0) {

            activate = true;

            // no trackers online, start next and recheck soon

            next_check_delay = ACT_CHECK_INIT_DELAY;

          } else {

            int potential = connected + pending;

            if (potential < 10) {

              // minimal connectivity

              activate = true;

              next_check_delay = ACT_CHECK_INIT_DELAY;

            } else if (allowed >= 5 && pending < 3 * allowed / 4) {

              // not enough to fulfill our needs

              activate = true;

              next_check_delay = ACT_CHECK_INTERIM_DELAY;

            } else {
              // things look good, recheck in a bit

              next_check_delay = ACT_CHECK_IDLE_DELAY;
            }
          }
        }

        if (activate) {

          for (TRTrackerAnnouncerHelper a : announcers) {

            if (!activated.contains(a)) {

              if (Logger.isEnabled()) {
                Logger.log(
                    new LogEvent(
                        getTorrent(), LOGID, "Activating " + getString(a.getAnnounceSets())));
              }

              activated.add(a);

              last_activation_time = SystemTime.getMonotonousTime();

              if (complete) {

                a.complete(true);

              } else {

                a.update(false);
              }

              break;
            }
          }
        }
      }

      if (next_check_delay > 0) {

        setupActivationCheck(next_check_delay);
      }
    }
  }