Search in sources :

Example 1 with Message

use of pubsub.pb.Rpc.Message in project teku by ConsenSys.

the class MockMessageApi method getOriginalMessage.

@NotNull
@Override
public PubsubMessage getOriginalMessage() {
    Message protoMessage = Message.newBuilder().addAllTopicIDs(getTopics().stream().map(Topic::getTopic).collect(Collectors.toList())).setData(ByteString.copyFrom(getData().nioBuffer())).build();
    PreparedGossipMessage preparedMessage = new PreparedGossipMessage() {

        @Override
        public Bytes getMessageId() {
            return Bytes.wrap(Hash.sha256(protoMessage.getData().toByteArray()));
        }

        @Override
        public DecodedMessageResult getDecodedMessage() {
            final Bytes decoded = Bytes.of(protoMessage.getData().toByteArray());
            return DecodedMessageResult.successful(decoded);
        }

        @Override
        public Bytes getOriginalMessage() {
            return Bytes.wrapByteBuf(data);
        }
    };
    return new PreparedPubsubMessage(protoMessage, preparedMessage);
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) PubsubMessage(io.libp2p.pubsub.PubsubMessage) PreparedPubsubMessage(tech.pegasys.teku.networking.p2p.libp2p.gossip.PreparedPubsubMessage) Message(pubsub.pb.Rpc.Message) PreparedGossipMessage(tech.pegasys.teku.networking.p2p.gossip.PreparedGossipMessage) PreparedGossipMessage(tech.pegasys.teku.networking.p2p.gossip.PreparedGossipMessage) Topic(io.libp2p.core.pubsub.Topic) PreparedPubsubMessage(tech.pegasys.teku.networking.p2p.libp2p.gossip.PreparedPubsubMessage) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

Topic (io.libp2p.core.pubsub.Topic)1 PubsubMessage (io.libp2p.pubsub.PubsubMessage)1 Bytes (org.apache.tuweni.bytes.Bytes)1 NotNull (org.jetbrains.annotations.NotNull)1 Message (pubsub.pb.Rpc.Message)1 PreparedGossipMessage (tech.pegasys.teku.networking.p2p.gossip.PreparedGossipMessage)1 PreparedPubsubMessage (tech.pegasys.teku.networking.p2p.libp2p.gossip.PreparedPubsubMessage)1