Implement “SentFeed” response message.
authorDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Thu, 23 Jul 2009 06:43:04 +0000 (08:43 +0200)
committerDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Thu, 23 Jul 2009 06:43:04 +0000 (08:43 +0200)
src/net/pterodactylus/fcp/FcpAdapter.java
src/net/pterodactylus/fcp/FcpConnection.java
src/net/pterodactylus/fcp/FcpListener.java
src/net/pterodactylus/fcp/FcpListenerManager.java
src/net/pterodactylus/fcp/SentFeed.java [new file with mode: 0644]

index 6bb2f50..a358d4c 100644 (file)
@@ -277,6 +277,13 @@ public class FcpAdapter implements FcpListener {
        /**
         * {@inheritDoc}
         */
+       public void receivedSentFeed(FcpConnection source, SentFeed sentFeed) {
+               /* empty. */
+       }
+
+       /**
+        * {@inheritDoc}
+        */
        public void receivedBookmarkFeed(FcpConnection fcpConnection, ReceivedBookmarkFeed receivedBookmarkFeed) {
                /* empty. */
        }
index b7129b7..2f40785 100644 (file)
@@ -308,6 +308,8 @@ public class FcpConnection implements Closeable {
                        fcpListenerManager.fireReceivedNodeHello(new NodeHello(fcpMessage));
                } else if ("CloseConnectionDuplicateClientName".equals(messageName)) {
                        fcpListenerManager.fireReceivedCloseConnectionDuplicateClientName(new CloseConnectionDuplicateClientName(fcpMessage));
+               } else if ("SentFeed".equals(messageName)) {
+                       fcpListenerManager.fireSentFeed(new SentFeed(fcpMessage));
                } else if ("ReceivedBookmarkFeed".equals(messageName)) {
                        fcpListenerManager.fireReceivedBookmarkFeed(new ReceivedBookmarkFeed(fcpMessage));
                } else {
index a23b7ee..4f0c77a 100644 (file)
@@ -371,6 +371,16 @@ public interface FcpListener extends EventListener {
        public void receivedPutFetchable(FcpConnection fcpConnection, PutFetchable putFetchable);
 
        /**
+        * Notifies a listener that a feed was sent to a peer.
+        *
+        * @param source
+        *            The connection that received the message
+        * @param sentFeed
+        *            The “SentFeed” message
+        */
+       public void receivedSentFeed(FcpConnection source, SentFeed sentFeed);
+
+       /**
         * Notifies a listener that a bookmark was updated.
         *
         * @param fcpConnection
index 11509bf..4e1cce6 100644 (file)
@@ -511,6 +511,19 @@ public class FcpListenerManager extends AbstractListenerManager<FcpConnection, F
        }
 
        /**
+        * Notifies all listeners that a “SentFeed” message was received.
+        *
+        * @see FcpListener#receivedSentFeed(FcpConnection, SentFeed)
+        * @param sentFeed
+        *            The “SentFeed” message.
+        */
+       public void fireSentFeed(SentFeed sentFeed) {
+               for (FcpListener fcpListener : getListeners()) {
+                       fcpListener.receivedSentFeed(getSource(), sentFeed);
+               }
+       }
+
+       /**
         * Notifies all listeners that a “ReceivedBookmarkFeed” message was
         * received.
         *
diff --git a/src/net/pterodactylus/fcp/SentFeed.java b/src/net/pterodactylus/fcp/SentFeed.java
new file mode 100644 (file)
index 0000000..eb7ca0a
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+ * jFCPlib - SentFeed.java - Copyright © 2009 David Roden
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+package net.pterodactylus.fcp;
+
+/**
+ * The “SentFeed” message signals that a feed was successfully sent to a peer.
+ *
+ * @author David ‘Bombe’ Roden &lt;bombe@freenetproject.org&gt;
+ */
+public class SentFeed extends BaseMessage {
+
+       /**
+        * Creates a new “SentFeed” message from the given FCP message.
+        *
+        * @param fcpMessage
+        *            The FCP message containing the “SentFeed” message
+        */
+       public SentFeed(FcpMessage fcpMessage) {
+               super(fcpMessage);
+       }
+
+       /**
+        * Returns the identifier of the sent feed. The identifier of this message
+        * matches the identifier that was given when a {@link SendBookmarkFeed},
+        * {@link SendDownloadFeed}, or {@link SendTextFeed} command was created.
+        *
+        * @return The send feed’s identifier
+        */
+       public String getIdentifier() {
+               return getField("Identifier");
+       }
+
+       /**
+        * Returns the node status of the peer. The node status is definied in
+        * {@code freenet.node.PeerManager}.
+        * <p>
+        * <ol start="1">
+        * <li>Connected</li>
+        * <li>Backed off</li>
+        * <li>Version too new</li>
+        * <li>Version too old</li>
+        * <li>Disconnected</li>
+        * <li>Never connected</li>
+        * <li>Disabled</li>
+        * <li>Bursting</li>
+        * <li>Listening</li>
+        * <li>Listening only</li>
+        * <li>Clock problem</li>
+        * <li>Connection error</li>
+        * <li>Disconnecting</li>
+        * <li>Routing disabled</li>
+        * </ol>
+        *
+        * @return The node’s status
+        */
+       public int getNodeStatus() {
+               return FcpUtils.safeParseInt(getField("NodeStatus"));
+       }
+
+}