Search in sources :

Example 6 with Node

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();
}
Also used : Node(me.matoosh.undernet.p2p.node.Node) NetworkConfig(me.matoosh.undernet.p2p.config.NetworkConfig) SecureRandom(java.security.SecureRandom) Router(me.matoosh.undernet.p2p.router.Router)

Example 7 with Node

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));
}
Also used : Node(me.matoosh.undernet.p2p.node.Node) ChannelCreatedEvent(me.matoosh.undernet.event.channel.ChannelCreatedEvent)

Example 8 with Node

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

Node (me.matoosh.undernet.p2p.node.Node)8 ChannelClosedEvent (me.matoosh.undernet.event.channel.ChannelClosedEvent)2 ChannelCreatedEvent (me.matoosh.undernet.event.channel.ChannelCreatedEvent)2 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)1 SecureRandom (java.security.SecureRandom)1 ArrayList (java.util.ArrayList)1 ClientExceptionEvent (me.matoosh.undernet.event.client.ClientExceptionEvent)1 ClientStatusEvent (me.matoosh.undernet.event.client.ClientStatusEvent)1 ResourceFinalStopEvent (me.matoosh.undernet.event.resource.push.ResourceFinalStopEvent)1 ResourcePushSentEvent (me.matoosh.undernet.event.resource.push.ResourcePushSentEvent)1 NetworkConfig (me.matoosh.undernet.p2p.config.NetworkConfig)1 Router (me.matoosh.undernet.p2p.router.Router)1 NetworkMessage (me.matoosh.undernet.p2p.router.data.message.NetworkMessage)1