Using and Authoring Plugins

Kadence plugins are a simple way to package additional features. A plugin is just a function that receives an instance of KademliaNode. This function can then apply any decorations desired.

Included Plugins

Example: "Howdy, Neighbor" Plugin

/**
 * Example "howdy, neighbor" plugin
 * @function
 * @param {KademliaNode} node
 */
module.exports = function(node) {

  const { identity } = node;

  /**
   * Respond to HOWDY messages
   */
  node.use('HOWDY', (req, res) => {
    res.send(['howdy, neighbor']);
  });

  /**
   * Say howdy to our nearest neighbor
   */
  node.sayHowdy = function(callback) {
    let neighbor = [
      ...node.router.getClosestContactsToKey(identity).entries()
    ].shift();
    
    node.send('HOWDY', ['howdy, neighbor'], neighbor, callback);
  };

};