org.tron.p2p.connection.socket.MessageHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of libp2p Show documentation
Show all versions of libp2p Show documentation
libp2p is a p2p network SDK implemented in java language.
The newest version!
package org.tron.p2p.connection.socket;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.tron.p2p.connection.Channel;
import org.tron.p2p.connection.ChannelManager;
import org.tron.p2p.connection.business.upgrade.UpgradeController;
import org.tron.p2p.connection.message.base.P2pDisconnectMessage;
import org.tron.p2p.connection.message.detect.StatusMessage;
import org.tron.p2p.exception.P2pException;
import org.tron.p2p.protos.Connect.DisconnectReason;
import org.tron.p2p.utils.ByteArray;
@Slf4j(topic = "net")
public class MessageHandler extends ByteToMessageDecoder {
private final Channel channel;
public MessageHandler(Channel channel) {
this.channel = channel;
}
@Override
public void handlerAdded(ChannelHandlerContext ctx) {
}
@Override
public void channelActive(ChannelHandlerContext ctx) {
log.debug("Channel active, {}", ctx.channel().remoteAddress());
channel.setChannelHandlerContext(ctx);
if (channel.isActive()) {
if (channel.isDiscoveryMode()) {
channel.send(new StatusMessage());
} else {
ChannelManager.getHandshakeService().startHandshake(channel);
}
}
}
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf buffer, List
© 2015 - 2024 Weber Informatics LLC | Privacy Policy