Search in sources :

Example 1 with NetworkIdentity

use of me.matoosh.undernet.identity.NetworkIdentity 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)

Aggregations

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