send a message to wot and see what comes back use-wot-event-notifications
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 27 Feb 2016 14:10:29 +0000 (15:10 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 27 Feb 2016 14:56:55 +0000 (15:56 +0100)
src/main/java/net/pterodactylus/sone/freenet/plugin/PluginConnector.java
src/main/java/net/pterodactylus/sone/freenet/wot/IdentityManagerImpl.java
src/main/java/net/pterodactylus/sone/freenet/wot/WebOfTrustConnector.java

index 46343a3..2e01f74 100644 (file)
 
 package net.pterodactylus.sone.freenet.plugin;
 
+import java.io.IOException;
+import java.util.logging.Logger;
+
+import net.pterodactylus.sone.freenet.SimpleFieldSetBuilder;
 import net.pterodactylus.sone.freenet.plugin.event.ReceivedReplyEvent;
 
 import com.google.common.eventbus.EventBus;
 import com.google.inject.Inject;
 import com.google.inject.Singleton;
 
+import freenet.clients.fcp.FCPPluginConnection;
+import freenet.clients.fcp.FCPPluginMessage;
+import freenet.pluginmanager.FredPluginFCPMessageHandler.ClientSideFCPMessageHandler;
 import freenet.pluginmanager.FredPluginTalker;
 import freenet.pluginmanager.PluginNotFoundException;
 import freenet.pluginmanager.PluginRespirator;
@@ -37,7 +44,9 @@ import freenet.support.api.Bucket;
  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
  */
 @Singleton
-public class PluginConnector implements FredPluginTalker {
+public class PluginConnector implements FredPluginTalker, ClientSideFCPMessageHandler {
+
+       private static final Logger logger = Logger.getLogger(PluginConnector.class.getName());
 
        /** The event bus. */
        private final EventBus eventBus;
@@ -59,9 +68,24 @@ public class PluginConnector implements FredPluginTalker {
                this.pluginRespirator = pluginRespirator;
        }
 
-       //
-       // ACTIONS
-       //
+       public void start() throws PluginException {
+               try {
+                       FCPPluginConnection pluginConnection = pluginRespirator.connectToOtherPlugin("plugins.WebOfTrust.WebOfTrust", this);
+                       logger.fine("Got PluginConnection: " + pluginConnection);
+                       SimpleFieldSet simpleFieldSet = new SimpleFieldSetBuilder().put("Message", "Subscribe").put("To", "Identities").get();
+                       pluginConnection.send(FCPPluginMessage.construct(simpleFieldSet, null));
+               } catch (PluginNotFoundException pnfe1) {
+                       throw new PluginException(pnfe1);
+               } catch (IOException ioe1) {
+                       throw new PluginException(ioe1);
+               }
+       }
+
+       @Override
+       public FCPPluginMessage handlePluginFCPMessage(FCPPluginConnection connection, FCPPluginMessage message) {
+               logger.fine("Got Reply: " + message);
+               return null;
+       }
 
        /**
         * Sends a request to the given plugin.
index 33b1ef6..9efb270 100644 (file)
@@ -127,6 +127,7 @@ public class IdentityManagerImpl extends AbstractService implements IdentityMana
                while (!shouldStop()) {
                        try {
                                Map<OwnIdentity, Collection<Identity>> currentIdentities = identityLoader.loadIdentities();
+                               webOfTrustConnector.start();
 
                                IdentityChangeEventSender identityChangeEventSender = new IdentityChangeEventSender(eventBus, oldIdentities);
                                identityChangeEventSender.detectChanges(currentIdentities);
index ca3a38c..8395e8b 100644 (file)
@@ -80,6 +80,14 @@ public class WebOfTrustConnector {
        // ACTIONS
        //
 
+       public void start() {
+               try {
+                       pluginConnector.start();
+               } catch (PluginException e) {
+                       e.printStackTrace();
+               }
+       }
+
        /**
         * Stops the web of trust connector.
         */