current state
authorDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Tue, 15 Apr 2008 17:16:46 +0000 (17:16 +0000)
committerDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Tue, 15 Apr 2008 17:16:46 +0000 (17:16 +0000)
git-svn-id: http://trooper/svn/projects/jFCPlib/branch/high-level-client@824 c3eda9e8-030b-0410-8277-bc7414b0a119

src/net/pterodactylus/fcp/highlevel/HighLevelClient.java
src/net/pterodactylus/fcp/highlevel/PeerListResult.java [new file with mode: 0644]

index 741726f..48399da 100644 (file)
@@ -42,6 +42,7 @@ import net.pterodactylus.fcp.FinishedCompression;
 import net.pterodactylus.fcp.GenerateSSK;
 import net.pterodactylus.fcp.GetFailed;
 import net.pterodactylus.fcp.IdentifierCollision;
+import net.pterodactylus.fcp.ListPeers;
 import net.pterodactylus.fcp.NodeData;
 import net.pterodactylus.fcp.NodeHello;
 import net.pterodactylus.fcp.Peer;
@@ -100,6 +101,9 @@ public class HighLevelClient {
        /** Mapping from request identifiers to callbacks. */
        private Map<String, HighLevelCallback<KeyGenerationResult>> keyGenerationCallbacks = Collections.synchronizedMap(new HashMap<String, HighLevelCallback<KeyGenerationResult>>());
 
+       /** Mapping from request identifier to peer list callbacks. */
+       private Map<String, HighLevelCallback<PeerListResult>> peerListCallbacks = Collections.synchronizedMap(new HashMap<String, HighLevelCallback<PeerListResult>>());
+
        /**
         * Creates a new high-level client that connects to a node on
         * <code>localhost</code>.
@@ -209,6 +213,22 @@ public class HighLevelClient {
        }
 
        /**
+        * Gets a list of all peers from the node.
+        * 
+        * @return A callback with the peer list
+        * @throws IOException
+        *             if an I/O error occurs with the node
+        */
+       public HighLevelCallback<PeerListResult> getPeers() throws IOException {
+               String identifier = generateIdentifier("listPeers");
+               ListPeers listPeers = new ListPeers(identifier, true, true);
+               HighLevelCallback<PeerListResult> peerListCallback = new HighLevelCallback<PeerListResult>();
+               peerListCallbacks.put(identifier, peerListCallback);
+               fcpConnection.sendMessage(listPeers);
+               return peerListCallback;
+       }
+
+       /**
         * Generates an identifier for the given function.
         * 
         * @param function
@@ -344,7 +364,18 @@ public class HighLevelClient {
                 * @see net.pterodactylus.fcp.FcpListener#receivedPeer(net.pterodactylus.fcp.FcpConnection,
                 *      net.pterodactylus.fcp.Peer)
                 */
+               @SuppressWarnings("synthetic-access")
                public void receivedPeer(FcpConnection fcpConnection, Peer peer) {
+                       if (fcpConnection != HighLevelClient.this.fcpConnection) {
+                               return;
+                       }
+                       String identifier = peer.getIdentifier();
+                       HighLevelCallback<PeerListResult> peerListCallback = peerListCallbacks.get(identifier);
+                       PeerListResult peerListResult = peerListCallback.getIntermediaryResult();
+                       if (peerListResult == null) {
+                               peerListResult = new PeerListResult();
+                               peerListCallback.setResult(peerListResult, false);
+                       }
                }
 
                /**
diff --git a/src/net/pterodactylus/fcp/highlevel/PeerListResult.java b/src/net/pterodactylus/fcp/highlevel/PeerListResult.java
new file mode 100644 (file)
index 0000000..ca2b264
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * jFCPlib-high-level-client - PeerListResult.java -
+ * Copyright © 2008 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+package net.pterodactylus.fcp.highlevel;
+
+/**
+ * The result of a {@link HighLevelClient#getPeers()} operation.
+ * 
+ * @author David ‘Bombe’ Roden &lt;bombe@freenetproject.org&gt;
+ * @version $Id$
+ */
+public class PeerListResult extends HighLevelResult {
+
+}