Search in sources :

Example 1 with NodeInfoMessage

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);
        }
    }
}
Also used : ChannelMessageReceivedEvent(me.matoosh.undernet.event.channel.message.ChannelMessageReceivedEvent) NetworkIdentity(me.matoosh.undernet.identity.NetworkIdentity) ChannelCreatedEvent(me.matoosh.undernet.event.channel.ChannelCreatedEvent) NodeInfoMessage(me.matoosh.undernet.p2p.router.data.message.NodeInfoMessage)

Example 2 with NodeInfoMessage

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)));
}
Also used : NetworkMessage(me.matoosh.undernet.p2p.router.data.message.NetworkMessage) NodeInfoMessage(me.matoosh.undernet.p2p.router.data.message.NodeInfoMessage)

Aggregations

NodeInfoMessage (me.matoosh.undernet.p2p.router.data.message.NodeInfoMessage)2 ChannelCreatedEvent (me.matoosh.undernet.event.channel.ChannelCreatedEvent)1 ChannelMessageReceivedEvent (me.matoosh.undernet.event.channel.message.ChannelMessageReceivedEvent)1 NetworkIdentity (me.matoosh.undernet.identity.NetworkIdentity)1 NetworkMessage (me.matoosh.undernet.p2p.router.data.message.NetworkMessage)1