当前位置: 首页>>代码示例>>Java>>正文


Java EthMessage类代码示例

本文整理汇总了Java中org.ethereum.net.eth.message.EthMessage的典型用法代码示例。如果您正苦于以下问题:Java EthMessage类的具体用法?Java EthMessage怎么用?Java EthMessage使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


EthMessage类属于org.ethereum.net.eth.message包,在下文中一共展示了EthMessage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: receivedMessage

import org.ethereum.net.eth.message.EthMessage; //导入依赖的package包/类
public void receivedMessage(Message msg) throws InterruptedException {

        MessageRoundtrip messageRoundtrip = requestQueue.peek();
        if (messageRoundtrip != null) {
            Message waitingMessage = messageRoundtrip.getMsg();

            if (waitingMessage instanceof PingMessage) {
                hasPing = false;
            }

            if (waitingMessage.getAnswerMessage() != null
                    && msg.getClass() == waitingMessage.getAnswerMessage()) {
                messageRoundtrip.answer();
                if (waitingMessage instanceof EthMessage) {
                    channel.getPeerStats().pong(messageRoundtrip.lastTimestamp);
                }
                logger.trace("Message round trip covered: [{}] ",
                        messageRoundtrip.getMsg().getClass());
            }
        }
    }
 
开发者ID:rsksmart,项目名称:rskj,代码行数:22,代码来源:MessageQueue.java

示例2: broadcastBlockHash

import org.ethereum.net.eth.message.EthMessage; //导入依赖的package包/类
@Nonnull
public Set<NodeID> broadcastBlockHash(@Nonnull final List<BlockIdentifier> identifiers, @Nullable final Set<NodeID> targets) {
    final Set<NodeID> res = new HashSet<>();
    final EthMessage newBlockHash = new RskMessage(config, new NewBlockHashesMessage(identifiers));

    synchronized (activePeers) {
        activePeers.values().forEach(c -> logger.trace("RSK activePeers: {}", c));

        activePeers.values().stream()
                .filter(p -> targets == null || targets.contains(new NodeID(p.getNodeId())))
                .forEach(peer -> {
                    logger.trace("RSK announce hash: {}", peer);
                    peer.sendMessage(newBlockHash);
                });
    }

    return res;
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:19,代码来源:ChannelManagerImpl.java

示例3: broadcastTransaction

import org.ethereum.net.eth.message.EthMessage; //导入依赖的package包/类
/**
 * broadcastTransaction Propagates a transaction message across active peers with exclusion of
 * the peers with an id belonging to the skip set.
 *
 * @param transaction new Transaction to be sent
 * @param skip  the set of peers to avoid sending the message.
 * @return a set containing the ids of the peers that received the transaction.
 */
@Nonnull
public Set<NodeID> broadcastTransaction(@Nonnull final Transaction transaction, @Nullable final Set<NodeID> skip) {
    Metrics.broadcastTransaction(transaction);
    List<Transaction> transactions = new ArrayList<>();
    transactions.add(transaction);

    final Set<NodeID> res = new HashSet<>();
    final EthMessage newTransactions = new RskMessage(config, new TransactionsMessage(transactions));

    synchronized (activePeers) {
        final Vector<Channel> peers = activePeers.values().stream()
                .filter(p -> skip == null || !skip.contains(new NodeID(p.getNodeId())))
                .collect(Collectors.toCollection(() -> new Vector<>()));

        for (Channel peer : peers) {
            res.add(new NodeID(peer.getNodeId()));
            peer.sendMessage(newTransactions);
        }
    }
    return res;
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:30,代码来源:ChannelManagerImpl.java

示例4: broadcastStatus

import org.ethereum.net.eth.message.EthMessage; //导入依赖的package包/类
@Override
public int broadcastStatus(Status status) {
    final EthMessage message = new RskMessage(config, new StatusMessage(status));

    int npeers = 0;

    synchronized (activePeers) {
        int peerCount = activePeers.size();
        if (peerCount > 0) {
            int numberOfPeersToSendStatusTo = getNumberOfPeersToSendStatusTo(peerCount);
            List<Channel> shuffledPeers = new ArrayList<>(activePeers.values());
            Collections.shuffle(shuffledPeers);
            for (int i = 0; i < numberOfPeersToSendStatusTo; i++) {
                shuffledPeers.get(i).sendMessage(message);
                npeers++;
            }
        }
    }
    return npeers;
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:21,代码来源:ChannelManagerImpl.java

示例5: encodeDecodeStatusMessage

import org.ethereum.net.eth.message.EthMessage; //导入依赖的package包/类
@Test
public void encodeDecodeStatusMessage() {
    Block block = BlockGenerator.getInstance().getBlock(1);
    Status status = new Status(block.getNumber(), block.getHash());
    StatusMessage message = new StatusMessage(status);
    RskMessage rskmessage = new RskMessage(ConfigHelper.CONFIG, message);

    byte[] encoded = rskmessage.getEncoded();

    Eth62MessageFactory factory = new Eth62MessageFactory(ConfigHelper.CONFIG);

    EthMessage ethmessage = (EthMessage)factory.create((byte)0x08, encoded);

    Assert.assertNotNull(ethmessage);
    Assert.assertEquals(EthMessageCodes.RSK_MESSAGE, ethmessage.getCommand());

    RskMessage result = (RskMessage)ethmessage;

    Assert.assertNotNull(result.getMessage());

    Message resultMessage = result.getMessage();

    Assert.assertEquals(MessageType.STATUS_MESSAGE, resultMessage.getMessageType());
    Assert.assertArrayEquals(block.getHash(), ((StatusMessage)resultMessage).getStatus().getBestBlockHash());
    Assert.assertEquals(block.getNumber(), ((StatusMessage)resultMessage).getStatus().getBestBlockNumber());
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:27,代码来源:RskMessageTest.java

示例6: encodeDecodeBlockMessage

import org.ethereum.net.eth.message.EthMessage; //导入依赖的package包/类
@Test
public void encodeDecodeBlockMessage() {
    Block block = BlockGenerator.getInstance().getBlock(1);
    BlockMessage message = new BlockMessage(block);
    RskMessage rskmessage = new RskMessage(ConfigHelper.CONFIG, message);

    byte[] encoded = rskmessage.getEncoded();

    Eth62MessageFactory factory = new Eth62MessageFactory(ConfigHelper.CONFIG);

    EthMessage ethmessage = (EthMessage)factory.create((byte)0x08, encoded);

    Assert.assertNotNull(ethmessage);
    Assert.assertEquals(EthMessageCodes.RSK_MESSAGE, ethmessage.getCommand());

    RskMessage result = (RskMessage)ethmessage;

    Assert.assertNotNull(result.getMessage());

    Message resultMessage = result.getMessage();

    Assert.assertEquals(MessageType.BLOCK_MESSAGE, resultMessage.getMessageType());
    Assert.assertArrayEquals(block.getHash(), ((BlockMessage)resultMessage).getBlock().getHash());
    Assert.assertArrayEquals(block.getEncoded(), ((BlockMessage)resultMessage).getBlock().getEncoded());
    Assert.assertEquals(block.getNumber(), ((BlockMessage)resultMessage).getBlock().getNumber());
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:27,代码来源:RskMessageTest.java

示例7: receivedMessage

import org.ethereum.net.eth.message.EthMessage; //导入依赖的package包/类
public void receivedMessage(Message msg) throws InterruptedException {

        ethereumListener.trace("[Recv: " + msg + "]");

        if (requestQueue.peek() != null) {
            MessageRoundtrip messageRoundtrip = requestQueue.peek();
            Message waitingMessage = messageRoundtrip.getMsg();

            if (waitingMessage instanceof PingMessage) hasPing = false;

            if (waitingMessage.getAnswerMessage() != null
                    && msg.getClass() == waitingMessage.getAnswerMessage()) {
                messageRoundtrip.answer();
                if (waitingMessage instanceof EthMessage)
                    channel.getPeerStats().pong(messageRoundtrip.lastTimestamp);
                logger.trace("Message round trip covered: [{}] ",
                        messageRoundtrip.getMsg().getClass());
            }
        }
    }
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:21,代码来源:MessageQueue.java

示例8: channelRead0

import org.ethereum.net.eth.message.EthMessage; //导入依赖的package包/类
@Override
public void channelRead0(final ChannelHandlerContext ctx, EthMessage msg) throws InterruptedException {

    super.channelRead0(ctx, msg);

    // Only commands that were added in V63, V62 are handled in child
    switch (msg.getCommand()) {
        case GET_NODE_DATA:
            processGetNodeData((GetNodeDataMessage) msg);
            break;
        case NODE_DATA:
            processNodeData((NodeDataMessage) msg);
            break;
        case GET_RECEIPTS:
            processGetReceipts((GetReceiptsMessage) msg);
            break;
        case RECEIPTS:
            processReceipts((ReceiptsMessage) msg);
            break;
        default:
            break;
    }
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:24,代码来源:Eth63.java

示例9: channelRead0

import org.ethereum.net.eth.message.EthMessage; //导入依赖的package包/类
@Override
public void channelRead0(final ChannelHandlerContext ctx, EthMessage msg) throws InterruptedException {
    logger.debug("Read message: " + msg.toString());

    if (EthMessageCodes.inRange(msg.getCommand().asByte(), version)) {
        logger.trace("EthHandler invoke: [{}]", msg.getCommand());
    }

    ethereumListener.trace(String.format("EthHandler invoke: [%s]", msg.getCommand()));

    channel.getNodeStatistics().ethInbound.add();

    msgQueue.receivedMessage(msg);
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:15,代码来源:EthHandler.java

示例10: sendMessage

import org.ethereum.net.eth.message.EthMessage; //导入依赖的package包/类
@Override
public void sendMessage(EthMessage message) {
    logger.debug("Send message: " + message.toString());

    msgQueue.sendMessage(message);
    channel.getNodeStatistics().ethOutbound.add();
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:8,代码来源:EthHandler.java

示例11: sendTransaction

import org.ethereum.net.eth.message.EthMessage; //导入依赖的package包/类
/**
 * Propagates the transactions message across active peers with exclusion of
 * 'receivedFrom' peer.
 *
 * @param tx           transactions to be sent
 * @param receivedFrom the peer which sent original message or null if
 *                     the transactions were originated by this peer
 */
public void sendTransaction(List<Transaction> tx, Channel receivedFrom) {
    tx.stream().forEach(t -> Metrics.broadcastTransaction(t));

    synchronized (activePeers) {
        TransactionsMessage txsmsg = new TransactionsMessage(tx);
        EthMessage msg = new RskMessage(config, txsmsg);
        for (Channel channel : activePeers.values()) {
            if (channel != receivedFrom) {
                channel.sendMessage(msg);
            }
        }
    }
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:22,代码来源:ChannelManagerImpl.java

示例12: sendNewBlock

import org.ethereum.net.eth.message.EthMessage; //导入依赖的package包/类
/**
 * Propagates the new block message across active peers with exclusion of
 * 'receivedFrom' peer.
 * @deprecated
 * @param block        new Block to be sent
 * @param receivedFrom the peer which sent original message or null if
 *                     the block has been mined by us
 */
@Deprecated // Use broadcastBlock
public void sendNewBlock(Block block, Channel receivedFrom) {
    EthMessage message = new RskMessage(config, new BlockMessage(block));

    synchronized (activePeers) {
        for (Channel channel : activePeers.values()) {
            if (channel != receivedFrom) {
                channel.sendMessage(message);
            }
        }
    }
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:21,代码来源:ChannelManagerImpl.java

示例13: sendMessage

import org.ethereum.net.eth.message.EthMessage; //导入依赖的package包/类
@Override
public void sendMessage(EthMessage message) {
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:4,代码来源:EthAdapter.java

示例14: sendMessage

import org.ethereum.net.eth.message.EthMessage; //导入依赖的package包/类
public void sendMessage(EthMessage message) {
    eth.sendMessage(message);
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:4,代码来源:Channel.java

示例15: encodeDecodeGetBlockMessage

import org.ethereum.net.eth.message.EthMessage; //导入依赖的package包/类
@Test
public void encodeDecodeGetBlockMessage() {
    Block block = BlockGenerator.getInstance().getBlock(1);
    GetBlockMessage message = new GetBlockMessage(block.getHash());
    RskMessage rskmessage = new RskMessage(ConfigHelper.CONFIG, message);

    byte[] encoded = rskmessage.getEncoded();

    Eth62MessageFactory factory = new Eth62MessageFactory(ConfigHelper.CONFIG);

    EthMessage ethmessage = (EthMessage)factory.create((byte)0x08, encoded);

    Assert.assertNotNull(ethmessage);
    Assert.assertEquals(EthMessageCodes.RSK_MESSAGE, ethmessage.getCommand());

    RskMessage result = (RskMessage)ethmessage;

    Assert.assertNotNull(result.getMessage());

    Message resultMessage = result.getMessage();

    Assert.assertEquals(MessageType.GET_BLOCK_MESSAGE, resultMessage.getMessageType());
    Assert.assertArrayEquals(block.getHash(), ((GetBlockMessage)resultMessage).getBlockHash());
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:25,代码来源:RskMessageTest.java


注:本文中的org.ethereum.net.eth.message.EthMessage类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。