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;
/**
}
/**
+ * @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)
*/
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;
/**
* Notifies listeners that a “Peer” message was received.
*
+ * @see FcpListener#receivedPeer(FcpConnection, Peer)
* @param peer
* The “Peer” message
*/
/**
* Notifies all listeners that an “EndListPeers” message was received.
*
+ * @see FcpListener#receivedEndListPeers(FcpConnection, EndListPeers)
* @param endListPeers
* The “EndListPeers” message
*/
}
/**
+ * 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)
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)) {
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;
/**
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!
--- /dev/null
+/**
+ * © 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);
+ }
+
+}
--- /dev/null
+/**
+ * © 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);
+ }
+
+}
--- /dev/null
+/**
+ * © 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"));
+ }
+
+}