From 1c2b138872a5388fbe25f7e3b6ad33ae79742db5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 25 Mar 2009 00:36:36 +0100 Subject: [PATCH] Add convenience methods to get darknet, opennet, and seed peers only. --- src/net/pterodactylus/fcp/highlevel/FcpClient.java | 72 ++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/src/net/pterodactylus/fcp/highlevel/FcpClient.java b/src/net/pterodactylus/fcp/highlevel/FcpClient.java index 4af4426..bcbc21d 100644 --- a/src/net/pterodactylus/fcp/highlevel/FcpClient.java +++ b/src/net/pterodactylus/fcp/highlevel/FcpClient.java @@ -254,6 +254,78 @@ public class FcpClient { } /** + * Returns all darknet peers. + * + * @param withMetadata + * true to include peer metadata + * @param withVolatile + * true to include volatile peer data + * @return A set containing the node’s darknet peers + * @throws IOException + * if an I/O error occurs + * @throws FcpException + * if an FCP error occurs + */ + public Collection getDarknetPeers(boolean withMetadata, boolean withVolatile) throws IOException, FcpException { + Collection allPeers = getPeers(withMetadata, withVolatile); + Collection darknetPeers = new HashSet(); + for (Peer peer : allPeers) { + if (!peer.isOpennet() && !peer.isSeed()) { + darknetPeers.add(peer); + } + } + return darknetPeers; + } + + /** + * Returns all opennet peers. + * + * @param withMetadata + * true to include peer metadata + * @param withVolatile + * true to include volatile peer data + * @return A set containing the node’s opennet peers + * @throws IOException + * if an I/O error occurs + * @throws FcpException + * if an FCP error occurs + */ + public Collection getOpennetPeers(boolean withMetadata, boolean withVolatile) throws IOException, FcpException { + Collection allPeers = getPeers(withMetadata, withVolatile); + Collection opennetPeers = new HashSet(); + for (Peer peer : allPeers) { + if (peer.isOpennet() && !peer.isSeed()) { + opennetPeers.add(peer); + } + } + return opennetPeers; + } + + /** + * Returns all seed peers. + * + * @param withMetadata + * true to include peer metadata + * @param withVolatile + * true to include volatile peer data + * @return A set containing the node’s seed peers + * @throws IOException + * if an I/O error occurs + * @throws FcpException + * if an FCP error occurs + */ + public Collection getSeedPeers(boolean withMetadata, boolean withVolatile) throws IOException, FcpException { + Collection allPeers = getPeers(withMetadata, withVolatile); + Collection seedPeers = new HashSet(); + for (Peer peer : allPeers) { + if (peer.isSeed()) { + seedPeers.add(peer); + } + } + return seedPeers; + } + + /** * Adds the given peer to the node. * * @param peer -- 2.7.4