Plugin API

From Freenet Wiki

Jump to: navigation, search

Work in progress please help to update.

Getting started

We'll start by examining the HelloWorld plugin. The source of this plugin can be found lower on this page.

A plugin is created by implementing various FredPlugin* interfaces. The most important ones are listed here. But more can be found in freenet.pluginmanager.

For the HelloWorldPlugin only FredPlugin is implemented. The FredPlugin interface takes care that runPlugin() is be called when the plugin gets loaded and terminate() will be called when it is removed or when the node shuts down.

The first thing you want to do when your runPlugin() gets called is saving your PluginRespirator. The PluginRespirator is your starting point in communicating with the node.

Then we'll print the heartbeat to System.err and wait 1 second as long as the boolean goon is true. This message ends up in wrapper.log in the directory of your node. On linux you can watch the messages with "tail -F /directory/of/node/wrapper.log".

When the node shuts down or your plugin gets unloaded terminate is called(). As we don't want to do any stuff after being asked to terminate we kill the loop by making goon false.

This is all that's needed to create a basic plugin. The whole source:

 package plugins.HelloWorld;
 
 import freenet.pluginmanager.FredPlugin;
 import freenet.pluginmanager.PluginRespirator;
 
 public class HelloWorld implements FredPlugin {
 
   public void terminate () {
     goon = false;
   }
 
   public void runPlugin (PluginRespirator pr) {
     this.pr = pr;
       
     while(goon) {
       System.err.println("Heartbeat from HelloWorld-plugin: " + (new Date()));
       try {
         Thread.sleep(1000);
       } catch (InterruptedException e) {
         // Who cares?
       }
   }
 
 }

Fetching

You must

 HighLevelSimpleClient hlsc = pr.getHLSimpleClient();

Watch for the FetchException from that function, it can mean that the redirect was encountered, simple test

 if(e.newURI != null)

will tell you if the Exception is an actual error.

Inserting

(coming soon)

See also

Personal tools