use of me.matoosh.undernet.p2p.router.data.message.NodeInfoMessage in project UnderNet by itsMatoosh.
the class NeighborNodesManager method onEventCalled.
/**
* Called when the handled event is called.
*
* @param e
*/
@Override
public void onEventCalled(Event e) {
if (e instanceof ChannelCreatedEvent) {
// Sending node info to the connected node.
ChannelCreatedEvent channelCreatedEvent = (ChannelCreatedEvent) e;
sendNodeInfo(Node.self, channelCreatedEvent.remoteNode);
} else if (e instanceof ChannelMessageReceivedEvent) {
ChannelMessageReceivedEvent messageReceivedEvent = (ChannelMessageReceivedEvent) e;
if (messageReceivedEvent.message.msgId == MsgType.NODE_INFO.ordinal()) {
NodeInfoMessage message = (NodeInfoMessage) NetworkMessage.deserializeMessage(messageReceivedEvent.message.data.array());
// TODO: Check the generated id with the database and update.
logger.info("Received node info for " + messageReceivedEvent.remoteNode + ": " + message.networkID);
NetworkIdentity networkIdentity = new NetworkIdentity();
networkIdentity.setNetworkId(message.networkID);
messageReceivedEvent.remoteNode.setIdentity(networkIdentity);
}
}
}
use of me.matoosh.undernet.p2p.router.data.message.NodeInfoMessage in project UnderNet by itsMatoosh.
the class NeighborNodesManager method sendNodeInfo.
/**
* Sends a message info about infoFrom to infoTo.
* @param infoFrom
* @param infoTo
*/
public void sendNodeInfo(Node infoFrom, Node infoTo) {
logger.info("Sending " + infoFrom.toString() + " node info to: " + infoTo.toString());
infoTo.send(new NetworkMessage(MsgType.NODE_INFO, new NodeInfoMessage(infoFrom)));
}
Aggregations