From: David ‘Bombe’ Roden Date: Thu, 19 Mar 2009 20:28:18 +0000 (+0100) Subject: Add modifyPeer(). X-Git-Tag: v0.1.1~86 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=d649abb6cc777878323c0e21ee665e88934d3873;p=jFCPlib.git Add modifyPeer(). --- diff --git a/src/net/pterodactylus/fcp/highlevel/FcpClient.java b/src/net/pterodactylus/fcp/highlevel/FcpClient.java index 88bc13f..5a3ec09 100644 --- a/src/net/pterodactylus/fcp/highlevel/FcpClient.java +++ b/src/net/pterodactylus/fcp/highlevel/FcpClient.java @@ -35,6 +35,7 @@ import net.pterodactylus.fcp.FcpAdapter; import net.pterodactylus.fcp.FcpConnection; import net.pterodactylus.fcp.FcpListener; import net.pterodactylus.fcp.ListPeers; +import net.pterodactylus.fcp.ModifyPeer; import net.pterodactylus.fcp.NodeHello; import net.pterodactylus.fcp.NodeRef; import net.pterodactylus.fcp.Peer; @@ -335,6 +336,49 @@ public class FcpClient { } /** + * Modifies the given peer. + * + * @param peer + * The peer to modify + * @param allowLocalAddresses + * true to allow local address, false + * to not allow local address, null to not change + * the setting + * @param disabled + * true to disable the peer, false to + * enable the peer, null to not change the setting + * @param listenOnly + * true to enable “listen only” for the peer, + * false to disable it, null to not + * change it + * @throws IOException + * if an I/O error occurs + * @throws FcpException + * if an FCP error occurs + */ + public void modifyPeer(Peer peer, Boolean allowLocalAddresses, Boolean disabled, Boolean listenOnly) throws IOException, FcpException { + ExtendedFcpAdapter fcpListener = new ExtendedFcpAdapter() { + + /** + * {@inheritDoc} + */ + @Override + public void receivedPeer(FcpConnection fcpConnection, Peer peer) { + completionLatch.countDown(); + } + }; + fcpConnection.addFcpListener(fcpListener); + try { + fcpConnection.sendMessage(new ModifyPeer(peer.getIdentity(), allowLocalAddresses, disabled, listenOnly)); + } finally { + fcpConnection.removeFcpListener(fcpListener); + } + if (fcpListener.getFcpException() != null) { + throw fcpListener.getFcpException(); + } + } + + /** * Implementation of an {@link FcpListener} that can store an * {@link FcpException} and wait for the arrival of a certain command. *