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());
}
}
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();
}
}
Aggregations