use of me.matoosh.undernet.p2p.node.Node in project UnderNet by itsMatoosh.
the class UnderNet method setup.
/**
* Sets up UnderNet.
*/
public static void setup(FileManager fileManager, ConfigurationProvider configProvider) {
// Writing the init message.
writeInitMessage();
// Setting the secure random generator.
secureRandom = new SecureRandom();
// Setting the file manager.
UnderNet.fileManager = fileManager;
// Setting the config provider.
UnderNet.configProvider = configProvider;
networkConfig = configProvider.bind("network", NetworkConfig.class);
// Loading up the node cache.
EntryNodeCache.registerEvents();
EntryNodeCache.load();
// Setting up the self node.
Node.self = new Node();
// Setting up the router.
router = new Router();
router.setup();
}
use of me.matoosh.undernet.p2p.node.Node in project UnderNet by itsMatoosh.
the class ClientNetworkMessageHandler method channelActive.
/**
* Calls {@link ChannelHandlerContext#fireChannelActive()} to forward
* to the next {@link ChannelInboundHandler} in the {@link ChannelPipeline}.
* <p>
* Sub-classes may override this method to change behavior.
*
* @param ctx
*/
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
// Adding the channel to the client list.
client.channels.add(ctx.channel());
// Adding a node object to the connection.
Node serverNode = new Node();
// Setting the node's address.
serverNode.address = ctx.channel().remoteAddress();
serverNode.channel = ctx.channel();
ctx.channel().attr(ATTRIBUTE_KEY_SERVER_NODE).set(serverNode);
// Adding the server node to the connected nodes list.
client.router.connectedNodes.add(serverNode);
// Calling the channel created event.
EventManager.callEvent(new ChannelCreatedEvent(ctx.channel(), false));
}
use of me.matoosh.undernet.p2p.node.Node 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