Package com.torrent4j.net.peerwire.messages

Examples of com.torrent4j.net.peerwire.messages.HandshakeMessage


    if (!(msg instanceof ChannelBuffer))
      return msg;
    final ChannelBuffer buffer = (ChannelBuffer) msg;

    if (!handshaked) {
      final HandshakeMessage message = new HandshakeMessage();
      message.read(buffer);

      return message;
    } else {
      if(buffer.readableBytes() == 0)
        return new KeepAliveMessage();
     
      final byte opcode = buffer.readByte();
      final PeerWireMessage message;
      switch (opcode) {
      case CancelMessage.MESSAGE_ID:
        message = new CancelMessage();
        break;
      case BitFieldMessage.MESSAGE_ID:
        message = new BitFieldMessage();
        break;
      case ChokeMessage.MESSAGE_ID:
        message = new ChokeMessage();
        break;
      case HaveMessage.MESSAGE_ID:
        message = new HaveMessage();
        break;
      case InterestedMessage.MESSAGE_ID:
        message = new InterestedMessage();
        break;
      case NotInterestedMessage.MESSAGE_ID:
        message = new NotInterestedMessage();
        break;
      case BlockMessage.MESSAGE_ID:
        message = new BlockMessage();
        break;
      case PortMessage.MESSAGE_ID:
        message = new PortMessage();
        break;
      case RequestMessage.MESSAGE_ID:
        message = new RequestMessage();
        break;
      case UnchokeMessage.MESSAGE_ID:
        message = new UnchokeMessage();
        break;
      default:
        return null;
      }
      message.read(buffer);
      return message;
    }
  }
View Full Code Here


    return channel.disconnect().awaitUninterruptibly().isSuccess();
  }

  @Override
  public void handshake(byte[] torrentHash, String peerID) {
    write(new HandshakeMessage(torrentHash, peerID));
  }
View Full Code Here

    try {
      final Object msg = e.getMessage();
      if (!(msg instanceof PeerWireMessage))
        return;
      if (msg instanceof HandshakeMessage) {
        final HandshakeMessage message = (HandshakeMessage) msg;

        ((PeerWireFrameDecoder) e.getChannel().getPipeline()
            .get("frame-decoder")).setHandshaked(true);
        ((PeerWireMessageDecoder) e.getChannel().getPipeline()
            .get("message-decoder")).setHandshaked(true);
View Full Code Here

TOP

Related Classes of com.torrent4j.net.peerwire.messages.HandshakeMessage

Copyright © 2018 www.massapicom. 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.