use of io.nuls.network.entity.Node in project nuls by nuls-io.
the class ServerChannelHandler method channelRead.
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
SocketChannel channel = (SocketChannel) ctx.channel();
Node node = getNetworkService().getNode(channel.remoteAddress().getHostString());
if (node != null && node.isAlive()) {
ByteBuf buf = (ByteBuf) msg;
byte[] bytes = new byte[buf.readableBytes()];
buf.readBytes(bytes);
buf.release();
ByteBuffer buffer = ByteBuffer.allocate(bytes.length);
buffer.put(bytes);
getNetworkService().receiveMessage(buffer, node);
}
}
use of io.nuls.network.entity.Node in project nuls by nuls-io.
the class ServerChannelHandler method channelActive.
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
Log.debug("----------------------server channelActive ------------------------- ");
String channelId = ctx.channel().id().asLongText();
SocketChannel channel = (SocketChannel) ctx.channel();
NioChannelMap.add(channelId, channel);
Node node = new Node(getNetworkService().getNetworkParam(), Node.IN, channel.remoteAddress().getHostString(), channel.remoteAddress().getPort(), channelId);
node.setStatus(Node.CONNECT);
getNetworkService().addNodeToGroup(NetworkConstant.NETWORK_NODE_IN_GROUP, node);
}
use of io.nuls.network.entity.Node in project nuls by nuls-io.
the class NodeEventHandler method process.
@Override
public NetworkEventResult process(BaseEvent networkEvent, Node node) {
NodeEvent event = (NodeEvent) networkEvent;
for (Node newNode : event.getEventBody().getNodes()) {
newNode.setType(Node.OUT);
newNode.setStatus(Node.WAIT);
getNetworkService().addNodeToGroup(NetworkConstant.NETWORK_NODE_OUT_GROUP, newNode);
}
return null;
}
use of io.nuls.network.entity.Node in project nuls by nuls-io.
the class BroadcastHandler method broadcastToNode.
public BroadcastResult broadcastToNode(BaseEvent event, String nodeId, boolean asyn) {
try {
NulsMessage message = new NulsMessage(network.packetMagic(), event.serialize());
Node node = nodesManager.getNode(nodeId);
if (node == null) {
return new BroadcastResult(false, "node not found");
}
return broadcast(message, node, asyn);
} catch (IOException e) {
return new BroadcastResult(false, "event.serialize() error");
}
}
use of io.nuls.network.entity.Node in project nuls by nuls-io.
the class NodeEventBody method size.
@Override
public int size() {
int s = 0;
s += VarInt.sizeOf(nodes.size());
for (Node node : nodes) {
s += node.size();
}
return s;
}
Aggregations