Example #1
0
  public void fileDescriptorReceived(DownloadConnection source, FileDescriptor fd)
      throws IOException {
    if (this.fd != null) {
      if (T.t) {
        T.info("Already has FD. Ignore the new one and start download for this connection.");
      }
      if (T.t) {
        T.ass(source.readyToStartDownload(), "Not ready to start download?");
      }
      if (needsMoreDownloadConnections()) {
        source.startDownloadingBlock();
      }
      return;
    }
    if (T.t) {
      T.debug("Received file descriptor " + fd);
    }

    this.fd = fd;
    setState(State.DOWNLOADING);

    ArrayList<DownloadConnection> al = new ArrayList<DownloadConnection>();
    for (DownloadConnection c : connections.values()) {
      al.add(c);
    }
    for (DownloadConnection c : al) {
      if (c.readyToStartDownload() && needsMoreDownloadConnections()) {
        c.startDownloadingBlock();
      }
    }
  }
Example #2
0
 public void abortAndRemovePerfmanently() throws IOException {
   for (DownloadConnection c : connections.values()) {
     if (c.isConnected()) {
       c.sendGracefulClose();
     }
   }
   storage.removePermanently(root);
 }
Example #3
0
 public boolean isDownloadingFd() {
   for (DownloadConnection c : connections.values()) {
     if (c.isDownloadingFd()) {
       return true;
     }
   }
   return false;
 }
Example #4
0
 private Connection getConnectionByGUID(int srcGuid) {
   for (DownloadConnection c : connections.values()) {
     if (c.getRemoteUserGUID() == srcGuid) {
       return c;
     }
   }
   return null;
 }
Example #5
0
 public void connectionEstablished(DownloadConnection downloadConnection) {
   connections.put(downloadConnection.getRemoteFriend(), downloadConnection);
   if (T.t) {
     T.trace(
         "Connection established: " + downloadConnection + " connections: " + connections.size());
   }
 }
Example #6
0
 public void removeConnection(DownloadConnection downloadConnection) throws IOException {
   connections.remove(downloadConnection.getRemoteFriend());
   if (connections.size() == 0 && isComplete()) {
     if (T.t) {
       T.info("Download is complete");
     }
     manager.downloadComplete(this);
   }
 }
Example #7
0
 public void addConnection(DownloadConnection con) {
   connections.put(con.getRemoteFriend(), con);
 }