Search in sources :

Example 1 with TopicVerifyMessage

use of org.fisco.bcos.channel.dto.TopicVerifyMessage in project web3sdk by FISCO-BCOS.

the class Service method sendResponse2Node.

private void sendResponse2Node(ChannelHandlerContext ctx, TopicVerifyMessage message) {
    try {
        Message response = new Message();
        response.setSeq(message.getSeq());
        response.setResult(0);
        response.setType((short) ChannelMessageType.REQUEST_TOPICCERT.getType());
        response.setData("".getBytes());
        ByteBuf out = ctx.alloc().buffer();
        response.writeHeader(out);
        response.writeExtra(out);
        ctx.writeAndFlush(out);
        logger.info("response seq:{} length:{}", response.getSeq(), out.readableBytes());
    } catch (Exception e) {
        logger.error("response seq:{} send error", message.getSeq());
    }
}
Also used : BcosMessage(org.fisco.bcos.channel.dto.BcosMessage) Message(org.fisco.bcos.channel.handler.Message) TopicVerifyMessage(org.fisco.bcos.channel.dto.TopicVerifyMessage) ByteBuf(io.netty.buffer.ByteBuf) KeyStoreException(java.security.KeyStoreException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) InvalidKeySpecException(java.security.spec.InvalidKeySpecException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) TransactionException(org.fisco.bcos.web3j.protocol.exceptions.TransactionException) NoSuchProviderException(java.security.NoSuchProviderException)

Example 2 with TopicVerifyMessage

use of org.fisco.bcos.channel.dto.TopicVerifyMessage in project web3sdk by FISCO-BCOS.

the class ConnectionCallback method onMessage.

@Override
public void onMessage(ChannelHandlerContext ctx, ByteBuf message) {
    try {
        Message msg = new Message();
        try {
            msg.readHeader(message);
        } catch (Exception e) {
            String host = ((SocketChannel) ctx.channel()).remoteAddress().getAddress().getHostAddress();
            Integer port = ((SocketChannel) ctx.channel()).remoteAddress().getPort();
            logger.error(" Maybe p2p port is used to channel connection, please check the configuration, peer {}:{}", host, port);
            throw new RuntimeException(e.getCause());
        }
        logger.trace("onMessage, seq:{}, type: {}, result: {}", msg.getSeq(), msg.getType(), msg.getResult());
        if (msg.getType() == ChannelMessageType.AMOP_REQUEST.getType() || msg.getType() == ChannelMessageType.AMOP_RESPONSE.getType() || msg.getType() == ChannelMessageType.AMOP_MULBROADCAST.getType()) {
            ChannelMessage2 channelMessage = new ChannelMessage2(msg);
            channelMessage.readExtra(message);
            channelService.onReceiveChannelMessage2(ctx, channelMessage);
        } else if (msg.getType() == ChannelMessageType.CHANNEL_RPC_REQUEST.getType()) {
            BcosMessage fiscoMessage = new BcosMessage(msg);
            fiscoMessage.readExtra(message);
            channelService.onReceiveEthereumMessage(ctx, fiscoMessage);
        } else if (msg.getType() == ChannelMessageType.CLIENT_HEARTBEAT.getType()) {
            msg.readExtra(message);
            channelService.onReceiveHeartbeat(ctx, msg);
        } else if (msg.getType() == ChannelMessageType.CLIENT_HANDSHAKE.getType()) {
            BcosMessage fiscoMessage = new BcosMessage(msg);
            fiscoMessage.readExtra(message);
            channelService.onReceiveEthereumMessage(ctx, fiscoMessage);
        } else if (msg.getType() == ChannelMessageType.CLIENT_REGISTER_EVENT_LOG.getType()) {
            ChannelMessage2 channelMessage = new ChannelMessage2(msg);
            channelMessage.readExtra(message);
            channelService.onReceiveRegisterEventResponse(ctx, channelMessage);
        } else if (msg.getType() == ChannelMessageType.TRANSACTION_NOTIFY.getType()) {
            BcosMessage fiscoMessage = new BcosMessage(msg);
            fiscoMessage.readExtra(message);
            channelService.onReceiveTransactionMessage(ctx, fiscoMessage);
        } else if (msg.getType() == ChannelMessageType.BLOCK_NOTIFY.getType()) {
            // new block notify
            ChannelMessage2 channelMessage = new ChannelMessage2(msg);
            channelMessage.readExtra(message);
            channelService.onReceiveBlockNotify(ctx, channelMessage);
        } else if (msg.getType() == ChannelMessageType.EVENT_LOG_PUSH.getType()) {
            BcosMessage bcosMessage = new BcosMessage(msg);
            bcosMessage.readExtra(message);
            channelService.onReceiveEventLogPush(ctx, bcosMessage);
        } else if (msg.getType() == ChannelMessageType.REQUEST_TOPICCERT.getType()) {
            logger.info("get generate rand value request data");
            TopicVerifyMessage channelMessage = new TopicVerifyMessage(msg);
            channelMessage.readExtra(message);
            try {
                channelService.checkTopicVerify(ctx, channelMessage);
            } catch (IOException e) {
                logger.error("on receive channel failed");
            }
        } else {
            logger.error("unknown message type:{}", msg.getType());
        }
    } finally {
        message.release();
    }
}
Also used : BigInteger(java.math.BigInteger) SocketChannel(io.netty.channel.socket.SocketChannel) BcosMessage(org.fisco.bcos.channel.dto.BcosMessage) ChannelMessage2(org.fisco.bcos.channel.dto.ChannelMessage2) BcosMessage(org.fisco.bcos.channel.dto.BcosMessage) TopicVerifyMessage(org.fisco.bcos.channel.dto.TopicVerifyMessage) IOException(java.io.IOException) MessageDecodingException(org.fisco.bcos.web3j.protocol.exceptions.MessageDecodingException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) TopicVerifyMessage(org.fisco.bcos.channel.dto.TopicVerifyMessage)

Aggregations

JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 IOException (java.io.IOException)2 BcosMessage (org.fisco.bcos.channel.dto.BcosMessage)2 TopicVerifyMessage (org.fisco.bcos.channel.dto.TopicVerifyMessage)2 ByteBuf (io.netty.buffer.ByteBuf)1 SocketChannel (io.netty.channel.socket.SocketChannel)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 BigInteger (java.math.BigInteger)1 KeyStoreException (java.security.KeyStoreException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 NoSuchProviderException (java.security.NoSuchProviderException)1 CertificateException (java.security.cert.CertificateException)1 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)1 ChannelMessage2 (org.fisco.bcos.channel.dto.ChannelMessage2)1 Message (org.fisco.bcos.channel.handler.Message)1 MessageDecodingException (org.fisco.bcos.web3j.protocol.exceptions.MessageDecodingException)1 TransactionException (org.fisco.bcos.web3j.protocol.exceptions.TransactionException)1