add ListPeerNote command and replies
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 9 Apr 2008 12:12:01 +0000 (12:12 +0000)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 9 Apr 2008 12:12:01 +0000 (12:12 +0000)
git-svn-id: http://trooper/svn/projects/jSite/trunk@664 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/message/EndListPeerNotes.java [new file with mode: 0644]
src/net/pterodactylus/util/fcp/message/ListPeerNotes.java [new file with mode: 0644]
src/net/pterodactylus/util/fcp/message/PeerNote.java [new file with mode: 0644]

index d867b91..74d7967 100644 (file)
@@ -4,9 +4,11 @@
 package net.pterodactylus.util.fcp;
 
 import net.pterodactylus.util.fcp.message.CloseConnectionDuplicateClientName;
+import net.pterodactylus.util.fcp.message.EndListPeerNotes;
 import net.pterodactylus.util.fcp.message.EndListPeers;
 import net.pterodactylus.util.fcp.message.NodeHello;
 import net.pterodactylus.util.fcp.message.Peer;
+import net.pterodactylus.util.fcp.message.PeerNote;
 import net.pterodactylus.util.fcp.message.SSKKeypair;
 
 /**
@@ -58,6 +60,22 @@ public class FcpAdapter implements FcpListener {
        }
 
        /**
+        * @see net.pterodactylus.util.fcp.FcpListener#receviedPeerNote(net.pterodactylus.util.fcp.FcpConnection,
+        *      net.pterodactylus.util.fcp.message.PeerNote)
+        */
+       public void receviedPeerNote(FcpConnection fcpConnection, PeerNote peerNote) {
+               /* empty. */
+       }
+
+       /**
+        * @see net.pterodactylus.util.fcp.FcpListener#receivedEndListPeerNotes(net.pterodactylus.util.fcp.FcpConnection,
+        *      net.pterodactylus.util.fcp.message.EndListPeerNotes)
+        */
+       public void receivedEndListPeerNotes(FcpConnection fcpConnection, EndListPeerNotes endListPeerNotes) {
+               /* empty. */
+       }
+
+       /**
         * @see net.pterodactylus.util.fcp.FcpListener#receivedMessage(net.pterodactylus.util.fcp.FcpConnection,
         *      net.pterodactylus.util.fcp.FcpMessage)
         */
index 6d4ca97..a8b6024 100644 (file)
@@ -29,9 +29,11 @@ import java.util.ArrayList;
 import java.util.List;
 
 import net.pterodactylus.util.fcp.message.CloseConnectionDuplicateClientName;
+import net.pterodactylus.util.fcp.message.EndListPeerNotes;
 import net.pterodactylus.util.fcp.message.EndListPeers;
 import net.pterodactylus.util.fcp.message.NodeHello;
 import net.pterodactylus.util.fcp.message.Peer;
+import net.pterodactylus.util.fcp.message.PeerNote;
 import net.pterodactylus.util.fcp.message.SSKKeypair;
 import net.pterodactylus.util.io.Closer;
 
@@ -188,6 +190,7 @@ public class FcpConnection {
        /**
         * Notifies listeners that a “Peer” message was received.
         * 
+        * @see FcpListener#receivedPeer(FcpConnection, Peer)
         * @param peer
         *            The “Peer” message
         */
@@ -200,6 +203,7 @@ public class FcpConnection {
        /**
         * Notifies all listeners that an “EndListPeers” message was received.
         * 
+        * @see FcpListener#receivedEndListPeers(FcpConnection, EndListPeers)
         * @param endListPeers
         *            The “EndListPeers” message
         */
@@ -210,6 +214,32 @@ public class FcpConnection {
        }
 
        /**
+        * Notifies all listeners that a “PeerNote” message was received.
+        * 
+        * @see FcpListener#receviedPeerNote(FcpConnection, PeerNote)
+        * @param peerNote
+        */
+       private void fireReceivedPeerNote(PeerNote peerNote) {
+               for (FcpListener fcpListener: fcpListeners) {
+                       fcpListener.receviedPeerNote(this, peerNote);
+               }
+       }
+
+       /**
+        * Notifies all listeners that an “EndListPeerNotes” message was received.
+        * 
+        * @see FcpListener#receivedEndListPeerNotes(FcpConnection,
+        *      EndListPeerNotes)
+        * @param endListPeerNotes
+        *            The “EndListPeerNotes” message
+        */
+       private void fireReceivedEndListPeerNotes(EndListPeerNotes endListPeerNotes) {
+               for (FcpListener fcpListener: fcpListeners) {
+                       fcpListener.receivedEndListPeerNotes(this, endListPeerNotes);
+               }
+       }
+
+       /**
         * Notifies all registered listeners that a message has been received.
         * 
         * @see FcpListener#receivedMessage(FcpConnection, FcpMessage)
@@ -285,6 +315,10 @@ public class FcpConnection {
                String messageName = fcpMessage.getName();
                if ("Peer".equals(messageName)) {
                        fireReceivedPeer(new Peer(fcpMessage));
+               } else if ("PeerNote".equals(messageName)) {
+                       fireReceivedPeerNote(new PeerNote(fcpMessage));
+               } else if ("EndListPeerNotes".equals(messageName)) {
+                       fireReceivedEndListPeerNotes(new EndListPeerNotes(fcpMessage));
                } else if ("EndListPeers".equals(messageName)) {
                        fireReceivedEndListPeers(new EndListPeers(fcpMessage));
                } else if ("SSKKeypair".equals(messageName)) {
index 23ea9ff..c949d48 100644 (file)
@@ -22,9 +22,11 @@ package net.pterodactylus.util.fcp;
 import java.util.EventListener;
 
 import net.pterodactylus.util.fcp.message.CloseConnectionDuplicateClientName;
+import net.pterodactylus.util.fcp.message.EndListPeerNotes;
 import net.pterodactylus.util.fcp.message.EndListPeers;
 import net.pterodactylus.util.fcp.message.NodeHello;
 import net.pterodactylus.util.fcp.message.Peer;
+import net.pterodactylus.util.fcp.message.PeerNote;
 import net.pterodactylus.util.fcp.message.SSKKeypair;
 
 /**
@@ -87,6 +89,26 @@ public interface FcpListener extends EventListener {
        public void receivedEndListPeers(FcpConnection fcpConnection, EndListPeers endListPeers);
 
        /**
+        * Notifies a listener that a “PeerNote” message was received.
+        * 
+        * @param fcpConnection
+        *            The connection that received the message
+        * @param peerNote
+        *            The “PeerNote” message
+        */
+       public void receviedPeerNote(FcpConnection fcpConnection, PeerNote peerNote);
+
+       /**
+        * Notifies a listener that an “EndListPeerNotes” message was received.
+        * 
+        * @param fcpConnection
+        *            The connection that received the message
+        * @param endListPeerNotes
+        *            The “EndListPeerNotes” message
+        */
+       public void receivedEndListPeerNotes(FcpConnection fcpConnection, EndListPeerNotes endListPeerNotes);
+
+       /**
         * 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/message/EndListPeerNotes.java b/src/net/pterodactylus/util/fcp/message/EndListPeerNotes.java
new file mode 100644 (file)
index 0000000..5efa7b2
--- /dev/null
@@ -0,0 +1,27 @@
+/**
+ * © 2008 INA Service GmbH
+ */
+package net.pterodactylus.util.fcp.message;
+
+import net.pterodactylus.util.fcp.FcpMessage;
+
+/**
+ * The “EndListPeerNotes” message signals the end of a list of “PeerNote”
+ * messages.
+ * 
+ * @author <a href="mailto:dr@ina-germany.de">David Roden</a>
+ * @version $Id$
+ */
+public class EndListPeerNotes extends BaseMessage {
+
+       /**
+        * Creates a new “EndListPeerNotes” message that wraps the received message.
+        * 
+        * @param fcpMessage
+        *            The received message
+        */
+       public EndListPeerNotes(FcpMessage fcpMessage) {
+               super(fcpMessage);
+       }
+
+}
diff --git a/src/net/pterodactylus/util/fcp/message/ListPeerNotes.java b/src/net/pterodactylus/util/fcp/message/ListPeerNotes.java
new file mode 100644 (file)
index 0000000..2d5641b
--- /dev/null
@@ -0,0 +1,29 @@
+/**
+ * © 2008 INA Service GmbH
+ */
+package net.pterodactylus.util.fcp.message;
+
+import net.pterodactylus.util.fcp.FcpMessage;
+
+/**
+ * A “ListPeerNodes” request tells the node to list all notes that have been
+ * entered for a node. Note that notes are only supported for darknet nodes.
+ * 
+ * @author <a href="mailto:dr@ina-germany.de">David Roden</a>
+ * @version $Id$
+ */
+public class ListPeerNotes extends FcpMessage {
+
+       /**
+        * Creates a new “ListPeerNotes” request that lists all notes of the
+        * specified node.
+        * 
+        * @param nodeIdentifier
+        *            The identifier of the node
+        */
+       public ListPeerNotes(String nodeIdentifier) {
+               super("ListPeerNotes");
+               setField("NodeIdentifier", nodeIdentifier);
+       }
+
+}
diff --git a/src/net/pterodactylus/util/fcp/message/PeerNote.java b/src/net/pterodactylus/util/fcp/message/PeerNote.java
new file mode 100644 (file)
index 0000000..cd8b157
--- /dev/null
@@ -0,0 +1,52 @@
+/**
+ * © 2008 INA Service GmbH
+ */
+package net.pterodactylus.util.fcp.message;
+
+import net.pterodactylus.util.fcp.FcpMessage;
+
+/**
+ * The “PeerNote” message contains a private note that has been entered for a
+ * darknet peer.
+ * 
+ * @author <a href="mailto:dr@ina-germany.de">David Roden</a>
+ * @version $Id$
+ */
+public class PeerNote extends BaseMessage {
+
+       /** The type for base64 encoded peer notes. */
+       public static final int NOTE_TYPE_BASE64 = 1;
+
+       /**
+        * Creates a “PeerNote” message that wraps the recevied message.
+        * 
+        * @param receivedMessage
+        *            The received message
+        */
+       public PeerNote(FcpMessage receivedMessage) {
+               super(receivedMessage);
+       }
+
+       /**
+        * Returns the note text in whatever format is specified by
+        * {@link #getPeerNoteType()}.
+        * 
+        * @return The note text
+        */
+       public String getNoteText() {
+               return getField("NoteText");
+       }
+
+       /**
+        * Returns the type of the peer note. The type <code>1</code> means that
+        * the text of the note is base64-encoded.
+        * 
+        * @return The type of the peer note
+        * @throws NumberFormatException
+        *             if the field can not be parsed
+        */
+       public int getPeerNoteType() throws NumberFormatException {
+               return Integer.valueOf(getField("PeerNoteType"));
+       }
+
+}