Add getNodeInformation() method (implements GetNode request).
authorDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Sun, 19 Jul 2009 13:08:44 +0000 (15:08 +0200)
committerDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Sun, 19 Jul 2009 13:08:44 +0000 (15:08 +0200)
src/net/pterodactylus/fcp/highlevel/FcpClient.java

index 8a7a90d..4bbcded 100644 (file)
@@ -47,11 +47,13 @@ import net.pterodactylus.fcp.FcpConnection;
 import net.pterodactylus.fcp.FcpListener;
 import net.pterodactylus.fcp.GenerateSSK;
 import net.pterodactylus.fcp.GetFailed;
+import net.pterodactylus.fcp.GetNode;
 import net.pterodactylus.fcp.ListPeerNotes;
 import net.pterodactylus.fcp.ListPeers;
 import net.pterodactylus.fcp.ListPersistentRequests;
 import net.pterodactylus.fcp.ModifyPeer;
 import net.pterodactylus.fcp.ModifyPeerNote;
+import net.pterodactylus.fcp.NodeData;
 import net.pterodactylus.fcp.NodeHello;
 import net.pterodactylus.fcp.NodeRef;
 import net.pterodactylus.fcp.Peer;
@@ -886,6 +888,47 @@ public class FcpClient {
        }
 
        //
+       // NODE INFORMATION
+       //
+
+       /**
+        * Returns information about the node.
+        *
+        * @param giveOpennetRef
+        *            Whether to return the OpenNet reference
+        * @param withPrivate
+        *            Whether to return private node data
+        * @param withVolatile
+        *            Whether to return volatile node data
+        * @return Node information
+        * @throws FcpException
+        *             if an FCP error occurs
+        * @throws IOException
+        *             if an I/O error occurs
+        */
+       public NodeData getNodeInformation(final Boolean giveOpennetRef, final Boolean withPrivate, final Boolean withVolatile) throws IOException, FcpException {
+               final ObjectWrapper<NodeData> nodeDataWrapper = new ObjectWrapper<NodeData>();
+               new ExtendedFcpAdapter() {
+
+                       @Override
+                       @SuppressWarnings("synthetic-access")
+                       public void run() throws IOException {
+                               GetNode getNodeMessage = new GetNode(giveOpennetRef, withPrivate, withVolatile);
+                               fcpConnection.sendMessage(getNodeMessage);
+                       }
+
+                       /**
+                        * {@inheritDoc}
+                        */
+                       @Override
+                       public void receivedNodeData(FcpConnection fcpConnection, NodeData nodeData) {
+                               nodeDataWrapper.set(nodeData);
+                       }
+               }.execute();
+               return nodeDataWrapper.get();
+       }
+
+       //
        // PRIVATE METHODS
        //