import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicReference;
+import java.util.function.Consumer;
import static com.google.common.collect.FluentIterable.from;
import static java.util.stream.Collectors.toList;
* if an I/O error occurs
* @throws FcpException
* if an FCP error occurs
+ * @deprecated Use {@link #modifyPeer(Peer, Consumer)}
*/
+ @Deprecated
public void modifyPeer(final Peer peer, final Boolean allowLocalAddresses, final Boolean disabled, final Boolean listenOnly) throws IOException, FcpException {
+ modifyPeer(peer, modifyPeer -> {
+ if (allowLocalAddresses != null) {
+ modifyPeer.setAllowLocalAddresses(allowLocalAddresses);
+ }
+ if (disabled != null) {
+ modifyPeer.setEnabled(!disabled);
+ }
+ if (listenOnly != null) {
+ modifyPeer.setListenOnly(listenOnly);
+ }
+ });
+ }
+
+ /**
+ * Modifies the given peer.
+ *
+ * @param peer The peer to modify
+ * @param modifyPeerConsumer A lambda that modifies a {@link ModifyPeer}
+ * object to change the peer’s configuration
+ * @throws IOException if an I/O error occurs
+ * @throws FcpException if an FCP error occurs
+ */
+ public void modifyPeer(Peer peer, Consumer<ModifyPeer> modifyPeerConsumer) throws IOException, FcpException {
+ ModifyPeer modifyPeer = new ModifyPeer(createIdentifier("modify-peer"), peer.getIdentifier());
+ modifyPeerConsumer.accept(modifyPeer);
new ExtendedFcpAdapter() {
/**
@Override
@SuppressWarnings("synthetic-access")
public void run() throws IOException {
- sendMessage(new ModifyPeer(peer.getIdentity(), allowLocalAddresses, disabled, listenOnly));
+ sendMessage(modifyPeer);
}
/**
}
@Test
+ public void modifyPeerSendsCorrectMessage() throws Exception {
+ List<FcpMessage> sentMessages = new ArrayList<>();
+ FcpConnection fcpConnection = createFcpConnection(message -> {
+ if (message.getName().equals("ModifyPeer")) {
+ sentMessages.add(message);
+ return (listener, connection) -> listener.receivedPeer(connection, createPeer());
+ }
+ return FcpClientTest::doNothing;
+ });
+ try (FcpClient fcpClient = new FcpClient(fcpConnection)) {
+ fcpClient.modifyPeer(createPeer(), modifyPeer -> modifyPeer.setAllowLocalAddresses(true));
+ assertThat(sentMessages, contains(hasField("AllowLocalAddresses", equalTo("true"))));
+ }
+ }
+
+ @Test
public void generatingKeyPairSendsCorrectMessage() throws IOException, FcpException {
FcpConnection fcpConnection = createFcpConnection(message -> {
if (message.getName().equals("GenerateSSK")) {