Пример #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();
      }
    }
  }
Пример #2
0
 private BitSet getInterestingBlocks(BlockMask remote) throws IOException {
   if (T.t) {
     T.ass(fd != null, "Need a FD for this call to work");
   }
   BitSet interestingBlocks = new BitSet();
   BlockMask myBm = manager.getCore().getFileManager().getBlockMask(fd.getRootHash());
   if (myBm != null) {
     interestingBlocks.or(myBm);
   }
   interestingBlocks.flip(0, fd.getNumberOfBlocks());
   interestingBlocks.and(remote);
   return interestingBlocks;
 }
Пример #3
0
 public static Download createFrom(ObjectInputStream in, DownloadManager m) throws IOException {
   try {
     Hash h = new Hash();
     int r = in.read(h.array());
     String fn = in.readUTF();
     ArrayList<Integer> guids = (ArrayList<Integer>) in.readObject();
     if (T.t) {
       T.ass(r == h.array().length, "Incorrect length when deserializing download");
     }
     BlockStorage bs = BlockStorage.getById(m.getCore(), in.readInt());
     Download d = new Download(m, h, bs, fn, guids);
     d.fd = d.manager.getCore().getFileManager().getFd(h);
     return d;
   } catch (ClassNotFoundException e) {
     throw new IOException("Could not find class while deserializing: " + e);
   }
 }