Search in sources :

Example 1 with StatusMessage

use of co.rsk.net.messages.StatusMessage in project rskj by rsksmart.

the class SimpleNode method sendFullStatusTo.

public void sendFullStatusTo(SimpleNode peer) {
    Status status = getFullStatus();
    peer.receiveMessageFrom(this, new StatusMessage(status));
}
Also used : StatusMessage(co.rsk.net.messages.StatusMessage)

Example 2 with StatusMessage

use of co.rsk.net.messages.StatusMessage in project rskj by rsksmart.

the class SimpleNode method sendStatusTo.

public void sendStatusTo(SimpleNode peer) {
    Block block = this.getBestBlock();
    Status status = new Status(block.getNumber(), block.getHash().getBytes());
    peer.receiveMessageFrom(this, new StatusMessage(status));
}
Also used : Block(org.ethereum.core.Block) StatusMessage(co.rsk.net.messages.StatusMessage)

Example 3 with StatusMessage

use of co.rsk.net.messages.StatusMessage in project rskj by rsksmart.

the class RskWireProtocol method sendStatus.

/**
 ***********************
 *    Message Sending    *
 ************************
 */
@Override
public void sendStatus() {
    byte protocolVersion = version.getCode();
    int networkId = config.networkId();
    BlockChainStatus blockChainStatus = this.blockchain.getStatus();
    Block bestBlock = blockChainStatus.getBestBlock();
    BlockDifficulty totalDifficulty = blockChainStatus.getTotalDifficulty();
    // Original status
    Genesis genesis = GenesisLoader.loadGenesis(config, config.genesisInfo(), config.getBlockchainConfig().getCommonConstants().getInitialNonce(), true);
    org.ethereum.net.eth.message.StatusMessage msg = new org.ethereum.net.eth.message.StatusMessage(protocolVersion, networkId, ByteUtil.bigIntegerToBytes(totalDifficulty.asBigInteger()), bestBlock.getHash().getBytes(), genesis.getHash().getBytes());
    sendMessage(msg);
    // RSK new protocol send status
    Status status = new Status(bestBlock.getNumber(), bestBlock.getHash().getBytes(), bestBlock.getParentHash().getBytes(), totalDifficulty);
    RskMessage rskmessage = new RskMessage(config, new StatusMessage(status));
    loggerNet.trace("Sending status best block {} to {}", status.getBestBlockNumber(), this.messageSender.getPeerNodeID().toString());
    sendMessage(rskmessage);
    ethState = EthState.STATUS_SENT;
}
Also used : BlockChainStatus(co.rsk.core.bc.BlockChainStatus) StatusMessage(co.rsk.net.messages.StatusMessage) BlockDifficulty(co.rsk.core.BlockDifficulty) BlockChainStatus(co.rsk.core.bc.BlockChainStatus) co.rsk.net(co.rsk.net)

Example 4 with StatusMessage

use of co.rsk.net.messages.StatusMessage in project rskj by rsksmart.

the class RskWireProtocol method channelRead0.

@Override
public void channelRead0(final ChannelHandlerContext ctx, EthMessage msg) throws InterruptedException {
    super.channelRead0(ctx, msg);
    if (this.messageRecorder != null) {
        this.messageRecorder.recordMessage(messageSender.getPeerNodeID(), msg);
    }
    if (!hasGoodReputation(ctx)) {
        ctx.disconnect();
        return;
    }
    Metrics.messageBytes(messageSender.getPeerNodeID(), msg.getEncoded().length);
    switch(msg.getCommand()) {
        case STATUS:
            processStatus((org.ethereum.net.eth.message.StatusMessage) msg, ctx);
            break;
        case RSK_MESSAGE:
            RskMessage rskmessage = (RskMessage) msg;
            Message message = rskmessage.getMessage();
            switch(message.getMessageType()) {
                case BLOCK_MESSAGE:
                    loggerNet.trace("RSK Block Message: Block {} {} from {}", ((BlockMessage) message).getBlock().getNumber(), ((BlockMessage) message).getBlock().getShortHash(), this.messageSender.getPeerNodeID());
                    syncStats.addBlocks(1);
                    break;
                case GET_BLOCK_MESSAGE:
                    loggerNet.trace("RSK Get Block Message: Block {} from {}", Hex.toHexString(((GetBlockMessage) message).getBlockHash()).substring(0, 10), this.messageSender.getPeerNodeID());
                    syncStats.getBlock();
                    break;
                case STATUS_MESSAGE:
                    loggerNet.trace("RSK Status Message: Block {} {} from {}", ((StatusMessage) message).getStatus().getBestBlockNumber(), Hex.toHexString(((StatusMessage) message).getStatus().getBestBlockHash()).substring(0, 10), this.messageSender.getPeerNodeID());
                    syncStats.addStatus();
                    break;
            }
            if (this.messageHandler != null) {
                this.messageHandler.postMessage(this.messageSender, rskmessage.getMessage());
            }
            break;
        default:
            break;
    }
}
Also used : BlockMessage(co.rsk.net.messages.BlockMessage) GetBlockMessage(co.rsk.net.messages.GetBlockMessage) StatusMessage(co.rsk.net.messages.StatusMessage) Message(co.rsk.net.messages.Message) BlockMessage(co.rsk.net.messages.BlockMessage) EthMessage(org.ethereum.net.eth.message.EthMessage) GetBlockMessage(co.rsk.net.messages.GetBlockMessage) TransactionsMessage(org.ethereum.net.eth.message.TransactionsMessage) co.rsk.net(co.rsk.net) StatusMessage(co.rsk.net.messages.StatusMessage)

Aggregations

StatusMessage (co.rsk.net.messages.StatusMessage)4 co.rsk.net (co.rsk.net)2 BlockDifficulty (co.rsk.core.BlockDifficulty)1 BlockChainStatus (co.rsk.core.bc.BlockChainStatus)1 BlockMessage (co.rsk.net.messages.BlockMessage)1 GetBlockMessage (co.rsk.net.messages.GetBlockMessage)1 Message (co.rsk.net.messages.Message)1 Block (org.ethereum.core.Block)1 EthMessage (org.ethereum.net.eth.message.EthMessage)1 TransactionsMessage (org.ethereum.net.eth.message.TransactionsMessage)1