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)));
}
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);
}
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;
}
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);
}
}
}
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));
}
}
Aggregations