Example #1
0
  public void runPlugin(PluginRespirator pr) {
    node = pr.getNode();
    nodeRefHelper = new NodeRefHelper(node);

    // Add the bridge node reference in the resources as a friend
    PeerAdditionReturnCodes addBridgeResult = addFriendBridge();
    if (addBridgeResult == PeerAdditionReturnCodes.ALREADY_IN_REFERENCE
        || addBridgeResult == PeerAdditionReturnCodes.OK) {
      Logger.normal(this, "Successfully added the node in bridgeref.txt resource file as friend.");
    } else {
      // Bridge node could not be added as a friend, the plugin will terminate and unload
      Logger.error(
          this, "Error while adding Bridge node as a friend, will terminate Backbone plugin...");
      terminate();
    }

    nodeInterface = new NodeInterface(pr.getNode(), pr);

    /* Set a random next message number in order to avoid dropping freemails at the bridge,
     * because of their message number being processed before. This is obligatory since
     * we are using the same Freemail address with multiple backbone nodes, for reaching
     * the bridge.
     */
    if (!nodeInterface.setRandomNextMsgNumber(backboneFreemail, bridgeFreemail)) {
      Logger.error(
          this,
          "Could not set a random nextMessageNumber. Freemails will most probably be dropped at the bridge");
      terminate();
    }

    /* Schedule a thread in order to Send a Freemail to the bridge node with the own node reference.
     * First attempt will be in a minute from plugin initialization, and if it fails, there will be
     * other attempts every 2 minutes till the Freemail is sent. For every failed attempt, we keep
     * an error-level entry in the log.
     */
    scheduledExecutorService = Executors.newScheduledThreadPool(1);
    scheduleSend =
        scheduledExecutorService.scheduleWithFixedDelay(new RefSender(), 2, 1, TimeUnit.MINUTES);
  }