Package net.tomp2p.message

Examples of net.tomp2p.message.Buffer


   
    PeerAddress receiver = UtilsNAT.createAddress();
    message.recipient(receiver);
    message.recipientSocket(receiver.createSocketTCP());
   
    Buffer encoded = RelayUtils.encodeMessage(message, signature);
    Message decoded = RelayUtils.decodeMessage(encoded, message.recipientSocket(), message.senderSocket(), signature);
    Assert.assertEquals(message.peerSocketAddresses().size(), decoded.peerSocketAddresses().size());
  }
View Full Code Here


  }
 
  @Test
  public void testEncodeDecodeString() {
    String test = "dummy";
    Buffer encoded = RelayUtils.encodeString(test);
    String decoded = RelayUtils.decodeString(encoded);
    Assert.assertEquals(test, decoded);
  }
View Full Code Here

   *
   * @param bufferResponse
   * @param futureDone
   */
  public void handleBufferResponse(Message bufferResponse, FutureDone<Void> futureDone) {
    Buffer buffer = bufferResponse.buffer(0);
    if (buffer != null) {
      // decompose the large buffer into a buffer for each message
      List<Message> bufferedMessages = RelayUtils.decomposeCompositeBuffer(buffer.buffer(), bufferResponse.recipientSocket(),
          bufferResponse.senderSocket(), peer.connectionBean().channelServer().channelServerConfiguration().signatureFactory());
      LOG.debug("Received {} buffered messages", bufferedMessages.size());
      for (Message bufferedMessage : bufferedMessages) {
          processMessage(bufferedMessage);
      }
View Full Code Here

          InetSocketAddress recipientSocket = message.senderSocket();
          if (recipientSocket == null) {
            recipientSocket = message.sender().createSocketTCP();
          }

          Buffer buffer = future.responseMessage().buffer(0);
          Message responseFromUnreachablePeer = RelayUtils.decodeMessage(buffer, recipientSocket, senderSocket, connectionBean().channelServer().channelServerConfiguration().signatureFactory());
          responseFromUnreachablePeer.restoreContentReferences();
          futureDone.done(responseFromUnreachablePeer);
        } else {
          futureDone.failed("Could not forward message over TCP channel");
View Full Code Here

    ByteBuf buffer = Unpooled.buffer();
    for (Message msg : messages) {
      try {
        msg.restoreContentReferences();
        msg.restoreBuffers();
        Buffer encoded = encodeMessage(msg, signatureFactory);

        buffer.writeInt(encoded.length());
        buffer.writeBytes(encoded.buffer());
      } catch (Exception e) {
        LOG.error("Cannot encode the buffered message. Skip it.", e);
      }
    }
    return buffer;
View Full Code Here

    while (messageBuffer.readableBytes() > 0) {
      int size = messageBuffer.readInt();
      ByteBuf message = messageBuffer.readBytes(size);
     
      try {
        Message decodedMessage = decodeRelayedMessage(new Buffer(message), recipient, sender, signatureFactory);
        messages.add(decodedMessage);
      } catch (Exception e) {
        LOG.error("Cannot decode buffered message. Skip it.", e);
      }
    }
View Full Code Here

   */
  public static Buffer encodeMessage(Message message, SignatureFactory signatureFactory) throws InvalidKeyException, SignatureException, IOException {
    Encoder e = new Encoder(signatureFactory);
    AlternativeCompositeByteBuf buf = AlternativeCompositeByteBuf.compBuffer();
    e.write(buf, message, message.receivedSignature());
    return new Buffer(buf);
  }
View Full Code Here

        return null;
      }
      encoder.flush(byteBuffer);
    }
    ByteBuf wrappedBuffer = Unpooled.wrappedBuffer(byteBuffer);
    return new Buffer(wrappedBuffer);
  }
View Full Code Here

      sender = PeerSocketAddress.createSocketTCP(peerSocketAddresses.iterator().next());
        } else {
          sender = new InetSocketAddress(0);
        }
       
        Buffer requestBuffer = message.buffer(0);
        Message realMessage = RelayUtils.decodeRelayedMessage(requestBuffer, message.recipientSocket(), sender, signatureFactory());
        realMessage.restoreContentReferences();

        LOG.debug("Received message from relay peer: {}", realMessage);
       
View Full Code Here

                    System.err.println("reply 2 ? " + complete);
                    ByteBuf replyBuffer = Unpooled.buffer(50);
                    replyBuffer.writerIndex(50);
                    if (complete) {
                        replyComplete.incrementAndGet();
                        return new Buffer(replyBuffer, 100);
                    } else {
                        replyNotComplete.incrementAndGet();
                        return new Buffer(replyBuffer, 100);
                    }
                }
            });

            FutureChannelCreator fcc = sender.connectionBean().reservation().create(0, 1);
            fcc.awaitUninterruptibly();
            cc = fcc.channelCreator();

            SendDirectBuilder sendDirectBuilder = new SendDirectBuilder(sender, (PeerAddress) null);
            sendDirectBuilder.streaming();
            sendDirectBuilder.idleTCPSeconds(Integer.MAX_VALUE);

            byte[] me = new byte[50];
            Buffer b = new Buffer(Unpooled.compositeBuffer(), 100);
            b.addComponent(Unpooled.wrappedBuffer(me));
            if (!wait) {
                ByteBuf replyBuffer = Unpooled.buffer(50);
                replyBuffer.writerIndex(50);
                b.addComponent(replyBuffer);
            }
            sendDirectBuilder.buffer(b);
            sendDirectBuilder.progressListener(new ProgressListener() {
                @Override
                public void progress(final Message interMediateMessage) {
                    if (interMediateMessage.isDone()) {
                        progressComplete.incrementAndGet();
                        System.err.println("progress 1 ? done");
                    } else {
                        progressNotComplete.incrementAndGet();
                        System.err.println("progress 1 ? not done");
                    }
                }
            });

            FutureResponse fr = sender.directDataRPC().send(recv1.peerAddress(), sendDirectBuilder, cc);
            if (wait) {
                Thread.sleep(500);
                ByteBuf replyBuffer = Unpooled.buffer(50);
                replyBuffer.writerIndex(50);
                b.addComponent(replyBuffer);
            }
            fr.progress();
            System.err.println("progres");
            // we are not done yet!
View Full Code Here

TOP

Related Classes of net.tomp2p.message.Buffer

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.