Пример #1
0
  private void x_startTorrent() {
    boolean ok = _util.connect();
    if (!ok) fatal("Unable to connect to I2P");
    if (coordinator == null) {
      I2PServerSocket serversocket = _util.getServerSocket();
      if (serversocket == null) fatal("Unable to listen for I2P connections");
      else {
        Destination d = serversocket.getManager().getSession().getMyDestination();
        if (_log.shouldLog(Log.INFO))
          _log.info(
              "Listening on I2P destination "
                  + d.toBase64()
                  + " / "
                  + d.calculateHash().toBase64());
      }
      if (_log.shouldLog(Log.INFO))
        _log.info("Starting PeerCoordinator, ConnectionAcceptor, and TrackerClient");
      activity = "Collecting pieces";
      coordinator = new PeerCoordinator(_util, id, infoHash, meta, storage, this, this);
      coordinator.setUploaded(savedUploaded);
      if (_peerCoordinatorSet != null) {
        // multitorrent
        _peerCoordinatorSet.add(coordinator);
      } else {
        // single torrent
        acceptor = new ConnectionAcceptor(_util, new PeerAcceptor(coordinator));
      }
      // TODO pass saved closest DHT nodes to the tracker? or direct to the coordinator?
      trackerclient = new TrackerClient(_util, meta, additionalTrackerURL, coordinator, this);
    }
    // ensure acceptor is running when in multitorrent
    if (_peerCoordinatorSet != null && acceptor != null) {
      acceptor.startAccepting();
    }

    stopped = false;
    if (coordinator.halted()) {
      coordinator.restart();
      if (_peerCoordinatorSet != null) _peerCoordinatorSet.add(coordinator);
    }
    if (!trackerclient.started()) {
      trackerclient.start();
    } else if (trackerclient.halted()) {
      if (storage != null) {
        try {
          storage.reopen();
        } catch (IOException ioe) {
          try {
            storage.close();
          } catch (IOException ioee) {
            ioee.printStackTrace();
          }
          fatal("Could not reopen storage", ioe);
        }
      }
      trackerclient.start();
    } else {
      if (_log.shouldLog(Log.INFO)) _log.info("NOT starting TrackerClient???");
    }
  }
Пример #2
0
 public boolean overUpBWLimit() {
   if (_peerCoordinatorSet == null) return false;
   long total = 0;
   for (PeerCoordinator c : _peerCoordinatorSet) {
     if (!c.halted()) total += c.getCurrentUploadRate();
   }
   long limit = 1024l * _util.getMaxUpBW();
   if (_log.shouldLog(Log.INFO)) _log.info("Total up bw: " + total + " Limit: " + limit);
   return total > limit;
 }
Пример #3
0
 public boolean overUploadLimit(int uploaders) {
   if (_peerCoordinatorSet == null || uploaders <= 0) return false;
   int totalUploaders = 0;
   for (PeerCoordinator c : _peerCoordinatorSet) {
     if (!c.halted()) totalUploaders += c.uploaders;
   }
   int limit = _util.getMaxUploaders();
   if (_log.shouldLog(Log.DEBUG))
     _log.debug("Total uploaders: " + totalUploaders + " Limit: " + limit);
   return totalUploaders > limit;
 }