Examples of TorrentPieceBlock


Examples of com.torrent4j.model.TorrentPieceBlock

  }

  @Override
  public void blockReceived(Torrent torrent, TorrentPieceBlock block,
      TorrentPeer peer) {
    TorrentPieceBlock next = block.getNextBlock();
    if (next == null) {
      final TorrentPiece piece = strategy.getPieceSelector().selectPiece(
          peer);
      if (piece == null) {
        peer.withdrawInterest();
View Full Code Here

Examples of com.torrent4j.model.TorrentPieceBlock

      } else if (msg instanceof RequestMessage) {
        final RequestMessage message = (RequestMessage) msg;

        final TorrentPiece piece = peer.getTorrent().getPiece(
            message.pieceIndex);
        final TorrentPieceBlock block = piece.getBlock(message.begin,
            message.length);
       
        if(peer.getTorrentPeer().getState().hasUploadRequestedBlock()) {
          peer.disconnect();
          return;
        }

        peer.getTorrentPeer().getState().setUploadRequestedBlock(block);
        peer.getTorrentPeer().getState()
            .setUploadRequestedDate(new Date());

        peer.getStrategy()
            .getUploadStrategy()
            .blockRequested(peer.getTorrent(), block,
                peer.getTorrentPeer());
      } else if (msg instanceof CancelMessage) {
        final CancelMessage message = (CancelMessage) msg;

        final TorrentPiece piece = peer.getTorrent().getPiece(
            message.pieceIndex);
        final TorrentPieceBlock block = piece.getBlock(message.begin,
            message.length);

        peer.getTorrentPeer().getState().setUploadRequestedBlock(null);
        peer.getTorrentPeer().getState().setUploadRequestedDate(null);

        peer.getStrategy()
            .getUploadStrategy()
            .blockRequestCancelled(peer.getTorrent(), block,
                peer.getTorrentPeer());
      } else if (msg instanceof BlockMessage) {
        final BlockMessage message = (BlockMessage) msg;

        final TorrentPiece piece = peer.getTorrent().getPiece(
            message.pieceIndex);
        final TorrentPieceBlock block = piece.getBlock(message.begin,
            message.data.remaining());

        peer.getTorrentPeer().getState().setLastDownloadedBlock(block);
        peer.getTorrentPeer().getState()
            .setLastDownloadedBlockDate(new Date());

        peer.getTorrentPeer().getState()
            .setDownloadRequestedBlock(null);
        peer.getTorrentPeer().getState().setDownloadRequestedDate(null);

        controller.getStorage().write(piece.getTorrent(),
            block.getTorrentRange(), message.data);
        block.setDownloaded(true);
        if (piece.isDownloaded()) {
          final Hash pieceHash = controller.getStorage().checksum(
              piece);
          if (!piece.getHash().equals(pieceHash)) {
            piece.getTorrent()
                .getStrategy()
                .getDownloadStrategy()
                .pieceChecksumFailed(piece.getTorrent(), piece,
                    peer.getTorrentPeer());
          } else {
            piece.getTorrent().getCompletedPieces().addPiece(piece);
            piece.getTorrent()
                .getStrategy()
                .getDownloadStrategy()
                .pieceComplete(piece.getTorrent(), piece,
                    peer.getTorrentPeer());
          }
        } else {
          piece.getTorrent()
              .getStrategy()
              .getDownloadStrategy()
              .blockReceived(block.getTorrent(), block,
                  peer.getTorrentPeer());
        }
      } else {
        System.out.println(msg);
      }
View Full Code Here

Examples of com.torrent4j.model.TorrentPieceBlock

      } else if (msg instanceof BlockMessage) {
        final BlockMessage message = (BlockMessage) msg;

        final TorrentPiece piece = peer.getTorrent().getPiece(
            message.pieceIndex);
        final TorrentPieceBlock block = piece.getBlock(message.begin,
            message.data.remaining());

        peer.getTorrentPeer().getState().setLastUploadedBlock(block);
        peer.getTorrentPeer().getState()
            .setLastUploadedBlockDate(new Date());

        e.getFuture().addListener(new ChannelFutureListener() {
          @Override
          public void operationComplete(ChannelFuture future)
              throws Exception {
            if (!future.isSuccess())
              return;
            peer.getTorrentPeer().getState()
                .setUploadRequestedBlock(null);
            peer.getTorrentPeer().getState()
                .setUploadRequestedDate(null);
          }
        });
      } else if (msg instanceof RequestMessage) {
        final RequestMessage message = (RequestMessage) msg;

        final TorrentPiece piece = peer.getTorrent().getPiece(
            message.pieceIndex);
        final TorrentPieceBlock block = piece.getBlock(message.begin,
            message.length);

        peer.getTorrentPeer().getState()
            .setDownloadRequestedBlock(block);
        peer.getTorrentPeer().getState()
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.