Merge branch 'master' into next
[Sone.git] / src / main / java / net / pterodactylus / sone / freenet / wot / WebOfTrustConnector.java
index 1802f2d..a7c6524 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Sone - WebOfTrustConnector.java - Copyright © 2010 David Roden
+ * Sone - WebOfTrustConnector.java - Copyright © 2010–2012 David Roden
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -70,6 +70,16 @@ public class WebOfTrustConnector implements ConnectorListener {
        //
 
        /**
+        * Stops the web of trust connector.
+        */
+       public void stop() {
+               pluginConnector.removeConnectorListener(WOT_PLUGIN_NAME, PLUGIN_CONNECTION_IDENTIFIER, this);
+               synchronized (reply) {
+                       reply.notifyAll();
+               }
+       }
+
+       /**
         * Loads all own identities from the Web of Trust plugin.
         *
         * @return All own identity
@@ -124,7 +134,7 @@ public class WebOfTrustConnector implements ConnectorListener {
         *             if an error occured talking to the Web of Trust plugin
         */
        public Set<Identity> loadTrustedIdentities(OwnIdentity ownIdentity, String context) throws PluginException {
-               Reply reply = performRequest(SimpleFieldSetConstructor.create().put("Message", "GetIdentitiesByScore").put("TreeOwner", ownIdentity.getId()).put("Selection", "+").put("Context", (context == null) ? "" : context).get());
+               Reply reply = performRequest(SimpleFieldSetConstructor.create().put("Message", "GetIdentitiesByScore").put("Truster", ownIdentity.getId()).put("Selection", "+").put("Context", (context == null) ? "" : context).get());
                SimpleFieldSet fields = reply.getFields();
                Set<Identity> identities = new HashSet<Identity>();
                int identityCounter = -1;
@@ -230,7 +240,7 @@ public class WebOfTrustConnector implements ConnectorListener {
         *             if an error occured talking to the Web of Trust plugin
         */
        public Trust getTrust(OwnIdentity ownIdentity, Identity identity) throws PluginException {
-               Reply getTrustReply = performRequest(SimpleFieldSetConstructor.create().put("Message", "GetIdentity").put("TreeOwner", ownIdentity.getId()).put("Identity", identity.getId()).get());
+               Reply getTrustReply = performRequest(SimpleFieldSetConstructor.create().put("Message", "GetIdentity").put("Truster", ownIdentity.getId()).put("Identity", identity.getId()).get());
                String trust = getTrustReply.getFields().get("Trust");
                String score = getTrustReply.getFields().get("Score");
                String rank = getTrustReply.getFields().get("Rank");
@@ -372,16 +382,16 @@ public class WebOfTrustConnector implements ConnectorListener {
         */
        private synchronized Reply performRequest(SimpleFieldSet fields, Bucket data) throws PluginException {
                reply = new Reply();
-               logger.log(Level.FINE, "Sending FCP Request: " + fields.get("Message"));
+               logger.log(Level.FINE, String.format("Sending FCP Request: %s", fields.get("Message")));
                synchronized (reply) {
                        pluginConnector.sendRequest(WOT_PLUGIN_NAME, PLUGIN_CONNECTION_IDENTIFIER, fields, data);
                        try {
                                reply.wait();
                        } catch (InterruptedException ie1) {
-                               logger.log(Level.WARNING, "Got interrupted while waiting for reply on " + fields.get("Message") + ".", ie1);
+                               logger.log(Level.WARNING, String.format("Got interrupted while waiting for reply on %s.", fields.get("Message")), ie1);
                        }
                }
-               logger.log(Level.FINEST, "Received FCP Response for %s: %s", new Object[] { fields.get("Message"), (reply.getFields() != null) ? reply.getFields().get("Message") : null });
+               logger.log(Level.FINEST, String.format("Received FCP Response for %s: %s", fields.get("Message"), (reply.getFields() != null) ? reply.getFields().get("Message") : null));
                if ((reply.getFields() == null) || "Error".equals(reply.getFields().get("Message"))) {
                        throw new PluginException("Could not perform request for " + fields.get("Message"));
                }
@@ -398,7 +408,7 @@ public class WebOfTrustConnector implements ConnectorListener {
        @Override
        public void receivedReply(PluginConnector pluginConnector, SimpleFieldSet fields, Bucket data) {
                String messageName = fields.get("Message");
-               logger.log(Level.FINEST, "Received Reply from Plugin: " + messageName);
+               logger.log(Level.FINEST, String.format("Received Reply from Plugin: %s", messageName));
                synchronized (reply) {
                        reply.setFields(fields);
                        reply.setData(data);