Search in sources :

Example 1 with NetworkMessage

use of me.matoosh.undernet.p2p.router.data.message.NetworkMessage 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)

Example 2 with NetworkMessage

use of me.matoosh.undernet.p2p.router.data.message.NetworkMessage in project UnderNet by itsMatoosh.

the class FileTransfer method sendChunk.

/**
 * Sends a chunk of data to the recipient.
 * @param buffer
 */
private void sendChunk(byte[] buffer) {
    NetworkMessage msg = new NetworkMessage(MsgType.FILE_CHUNK, NetworkMessage.serializeMessage(new FileChunk(id, buffer)));
    recipient.send(msg);
}
Also used : NetworkMessage(me.matoosh.undernet.p2p.router.data.message.NetworkMessage)

Example 3 with NetworkMessage

use of me.matoosh.undernet.p2p.router.data.message.NetworkMessage in project UnderNet by itsMatoosh.

the class FileTransferManager method requestFileTransfer.

/**
 * Requests a file transfer with id from a neighboring node.
 * @param receivedFrom
 * @param resource
 */
public FileTransfer requestFileTransfer(Node receivedFrom, FileResource resource) {
    logger.info("Requesting the transfer " + resource.networkID + " from " + receivedFrom);
    // Caching a new transfer instance.
    FileTransfer transfer = new FileTransfer(resource, receivedFrom, FileTransferType.INBOUND);
    inboundTransfers.add(transfer);
    // Sending a new FileRequest message.
    receivedFrom.send(new NetworkMessage(MsgType.FILE_REQ, new FileTransferRequestMessage(resource.networkID)));
    return transfer;
}
Also used : NetworkMessage(me.matoosh.undernet.p2p.router.data.message.NetworkMessage)

Example 4 with NetworkMessage

use of me.matoosh.undernet.p2p.router.data.message.NetworkMessage in project UnderNet by itsMatoosh.

the class NetworkDatabase method onEventCalled.

/**
 * Called when the handled event is called.
 *
 * @param e
 */
@Override
public void onEventCalled(Event e) {
    // Message received event.
    if (e instanceof ChannelMessageReceivedEvent) {
        // Checking message type.
        ChannelMessageReceivedEvent messageEvent = (ChannelMessageReceivedEvent) e;
        if (messageEvent.message.msgId == MsgType.NODE_PING.ordinal()) {
            // Sending a ping message back.
            if (messageEvent.message.data.get() == 0x01) {
                return;
            }
            logger.info("Ping!");
            NetworkMessage msg = new NetworkMessage(MsgType.NODE_PING, new byte[] { 0x01 });
            messageEvent.remoteNode.send(msg);
        }
    }
}
Also used : ChannelMessageReceivedEvent(me.matoosh.undernet.event.channel.message.ChannelMessageReceivedEvent) NetworkMessage(me.matoosh.undernet.p2p.router.data.message.NetworkMessage)

Example 5 with NetworkMessage

use of me.matoosh.undernet.p2p.router.data.message.NetworkMessage in project UnderNet by itsMatoosh.

the class ResourceManager method pushForward.

/**
 * Forwards a pushMessage to the next appropriate node.
 * Calls resource stored event if this node is the resource's destination.
 * @param pushMessage
 */
public void pushForward(ResourcePushMessage pushMessage) {
    // Getting the node closest to the resource.
    Node closest = router.neighborNodesManager.getClosestTo(pushMessage.resource.networkID);
    if (closest == Node.self) {
        // This is the final node of the resource.
        EventManager.callEvent(new ResourceFinalStopEvent(pushMessage.resource, pushMessage, null));
    } else {
        logger.info("Pushing resource: " + pushMessage.resource + " to node: " + closest);
        // Calling the onPush method.
        pushMessage.resource.onPush(pushMessage, closest);
        // Sending the push msg.
        closest.send(new NetworkMessage(MsgType.RES_PUSH, pushMessage));
        // Calling event.
        EventManager.callEvent(new ResourcePushSentEvent(pushMessage.resource, pushMessage, closest));
    }
}
Also used : ResourceFinalStopEvent(me.matoosh.undernet.event.resource.push.ResourceFinalStopEvent) Node(me.matoosh.undernet.p2p.node.Node) ResourcePushSentEvent(me.matoosh.undernet.event.resource.push.ResourcePushSentEvent) NetworkMessage(me.matoosh.undernet.p2p.router.data.message.NetworkMessage)

Aggregations

NetworkMessage (me.matoosh.undernet.p2p.router.data.message.NetworkMessage)5 ChannelMessageReceivedEvent (me.matoosh.undernet.event.channel.message.ChannelMessageReceivedEvent)1 ResourceFinalStopEvent (me.matoosh.undernet.event.resource.push.ResourceFinalStopEvent)1 ResourcePushSentEvent (me.matoosh.undernet.event.resource.push.ResourcePushSentEvent)1 Node (me.matoosh.undernet.p2p.node.Node)1 NodeInfoMessage (me.matoosh.undernet.p2p.router.data.message.NodeInfoMessage)1