From: David ‘Bombe’ Roden Date: Tue, 24 Mar 2009 23:36:36 +0000 (+0100) Subject: Add convenience methods to get darknet, opennet, and seed peers only. X-Git-Tag: v0.1.1~62 X-Git-Url: https://git.pterodactylus.net/?p=jFCPlib.git;a=commitdiff_plain;h=1c2b138872a5388fbe25f7e3b6ad33ae79742db5 Add convenience methods to get darknet, opennet, and seed peers only. --- 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