add RemovePeer command and PeerRemoved reply
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 9 Apr 2008 14:54:05 +0000 (14:54 +0000)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 9 Apr 2008 14:54:05 +0000 (14:54 +0000)
git-svn-id: http://trooper/svn/projects/jSite/trunk@670 c3eda9e8-030b-0410-8277-bc7414b0a119

src/net/pterodactylus/util/fcp/FcpAdapter.java
src/net/pterodactylus/util/fcp/FcpConnection.java
src/net/pterodactylus/util/fcp/FcpListener.java
src/net/pterodactylus/util/fcp/PeerRemoved.java [new file with mode: 0644]
src/net/pterodactylus/util/fcp/RemovePeer.java [new file with mode: 0644]

index 69cc9f8..91e53c8 100644 (file)
@@ -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)
         */
index 32237f4..ba167d1 100644 (file)
@@ -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)) {
index aa8147b..8b2c621 100644 (file)
@@ -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 (file)
index 0000000..6902278
--- /dev/null
@@ -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 <a href="mailto:dr@ina-germany.de">David Roden</a>
+ * @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 (file)
index 0000000..9bec24e
--- /dev/null
@@ -0,0 +1,26 @@
+/**
+ * © 2008 INA Service GmbH
+ */
+package net.pterodactylus.util.fcp;
+
+/**
+ * The “RemovePeer” command removes a peer.
+ * 
+ * @author <a href="mailto:dr@ina-germany.de">David Roden</a>
+ * @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);
+       }
+
+}