From a238aa37f5716eb715f18a37a436d3ca792e33b0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 9 Apr 2008 14:54:05 +0000 Subject: [PATCH] add RemovePeer command and PeerRemoved reply git-svn-id: http://trooper/svn/projects/jSite/trunk@670 c3eda9e8-030b-0410-8277-bc7414b0a119 --- src/net/pterodactylus/util/fcp/FcpAdapter.java | 9 ++++- src/net/pterodactylus/util/fcp/FcpConnection.java | 15 ++++++++ src/net/pterodactylus/util/fcp/FcpListener.java | 11 +++++- src/net/pterodactylus/util/fcp/PeerRemoved.java | 42 +++++++++++++++++++++++ src/net/pterodactylus/util/fcp/RemovePeer.java | 26 ++++++++++++++ 5 files changed, 101 insertions(+), 2 deletions(-) create mode 100644 src/net/pterodactylus/util/fcp/PeerRemoved.java create mode 100644 src/net/pterodactylus/util/fcp/RemovePeer.java diff --git a/src/net/pterodactylus/util/fcp/FcpAdapter.java b/src/net/pterodactylus/util/fcp/FcpAdapter.java index 69cc9f8..91e53c8 100644 --- a/src/net/pterodactylus/util/fcp/FcpAdapter.java +++ b/src/net/pterodactylus/util/fcp/FcpAdapter.java @@ -3,7 +3,6 @@ */ package net.pterodactylus.util.fcp; - /** * Adapter for {@link FcpListener}. * @@ -69,6 +68,14 @@ public class FcpAdapter implements FcpListener { } /** + * @see net.pterodactylus.util.fcp.FcpListener#receviedPeerRemoved(net.pterodactylus.util.fcp.FcpConnection, + * net.pterodactylus.util.fcp.PeerRemoved) + */ + public void receviedPeerRemoved(FcpConnection fcpConnection, PeerRemoved peerRemoved) { + /* empty. */ + } + + /** * @see net.pterodactylus.util.fcp.FcpListener#receivedMessage(net.pterodactylus.util.fcp.FcpConnection, * net.pterodactylus.util.fcp.FcpMessage) */ diff --git a/src/net/pterodactylus/util/fcp/FcpConnection.java b/src/net/pterodactylus/util/fcp/FcpConnection.java index 32237f4..ba167d1 100644 --- a/src/net/pterodactylus/util/fcp/FcpConnection.java +++ b/src/net/pterodactylus/util/fcp/FcpConnection.java @@ -233,6 +233,19 @@ public class FcpConnection { } /** + * Notifies all listeners that a “PeerRemoved” message was received. + * + * @see FcpListener#receviedPeerRemoved(FcpConnection, PeerRemoved) + * @param peerRemoved + * The “PeerRemoved” message + */ + private void fireReceivedPeerRemoved(PeerRemoved peerRemoved) { + for (FcpListener fcpListener: fcpListeners) { + fcpListener.receviedPeerRemoved(this, peerRemoved); + } + } + + /** * Notifies all registered listeners that a message has been received. * * @see FcpListener#receivedMessage(FcpConnection, FcpMessage) @@ -316,6 +329,8 @@ public class FcpConnection { fireReceivedEndListPeers(new EndListPeers(fcpMessage)); } else if ("SSKKeypair".equals(messageName)) { fireReceivedSSKKeypair(new SSKKeypair(fcpMessage)); + } else if ("PeerRemoved".equals(messageName)) { + fireReceivedPeerRemoved(new PeerRemoved(fcpMessage)); } else if ("NodeHello".equals(messageName)) { fireReceivedNodeHello(new NodeHello(fcpMessage)); } else if ("CloseConnectionDuplicateClientName".equals(messageName)) { diff --git a/src/net/pterodactylus/util/fcp/FcpListener.java b/src/net/pterodactylus/util/fcp/FcpListener.java index aa8147b..8b2c621 100644 --- a/src/net/pterodactylus/util/fcp/FcpListener.java +++ b/src/net/pterodactylus/util/fcp/FcpListener.java @@ -21,7 +21,6 @@ package net.pterodactylus.util.fcp; import java.util.EventListener; - /** * Interface for objects that want to be notified on certain FCP events. * @@ -102,6 +101,16 @@ public interface FcpListener extends EventListener { public void receivedEndListPeerNotes(FcpConnection fcpConnection, EndListPeerNotes endListPeerNotes); /** + * Notifies a listener that a “PeerRemoved” message was received. + * + * @param fcpConnection + * The connection that received the message + * @param peerRemoved + * The “PeerRemoved” message + */ + public void receviedPeerRemoved(FcpConnection fcpConnection, PeerRemoved peerRemoved); + + /** * Notifies a listener that a message has been received. This method is only * called if {@link FcpConnection#handleMessage(FcpMessage)} does not * recognize the message. Should that ever happen, please file a bug report! diff --git a/src/net/pterodactylus/util/fcp/PeerRemoved.java b/src/net/pterodactylus/util/fcp/PeerRemoved.java new file mode 100644 index 0000000..6902278 --- /dev/null +++ b/src/net/pterodactylus/util/fcp/PeerRemoved.java @@ -0,0 +1,42 @@ +/** + * © 2008 INA Service GmbH + */ +package net.pterodactylus.util.fcp; + +/** + * A “PeerRemoved” message is sent by the node when a peer has been removed. + * + * @author David Roden + * @version $Id$ + */ +public class PeerRemoved extends BaseMessage { + + /** + * Creates a new “PeerRemoved” message that wraps the received message. + * + * @param receivedMessage + * The received message + */ + public PeerRemoved(FcpMessage receivedMessage) { + super(receivedMessage); + } + + /** + * Returns the identity of the removed peer. + * + * @return The identity of the removed peer + */ + public String getIdentity() { + return getField("Identity"); + } + + /** + * Returns the node identifier of the removed peer. + * + * @return The node identifier of the removed peer + */ + public String getNodeIdentifier() { + return getField("NodeIdentifier"); + } + +} diff --git a/src/net/pterodactylus/util/fcp/RemovePeer.java b/src/net/pterodactylus/util/fcp/RemovePeer.java new file mode 100644 index 0000000..9bec24e --- /dev/null +++ b/src/net/pterodactylus/util/fcp/RemovePeer.java @@ -0,0 +1,26 @@ +/** + * © 2008 INA Service GmbH + */ +package net.pterodactylus.util.fcp; + +/** + * The “RemovePeer” command removes a peer. + * + * @author David Roden + * @version $Id$ + */ +public class RemovePeer extends FcpMessage { + + /** + * Creates a new “RemovePeer” command that removes the given peer. + * + * @param nodeIdentifier + * The identifier of the node, i.e. its name, identity, or IP + * address and port pair + */ + public RemovePeer(String nodeIdentifier) { + super("RemovePeer"); + setField("NodeIdentifier", nodeIdentifier); + } + +} -- 2.7.4