}
/**
+ * Notifies all listeners that an “PersistentPutDir” message was received.
+ *
+ * @param persistentPutDir
+ * The “PersistentPutDir” message
+ */
+ private void fireReceivedPersistentPutDir(PersistentPutDir persistentPutDir) {
+ for (FcpListener fcpListener: fcpListeners) {
+ fcpListener.receivedPersistentPutDir(this, persistentPutDir);
+ }
+ }
+
+ /**
+ * Notifies all listeners that a “PersistentRequestRemoved” message was
+ * received.
+ *
+ * @param persistentRequestRemoved
+ * The “PersistentRequestRemoved” message
+ */
+ private void fireReceivedPersistentRequestRemoved(PersistentRequestRemoved persistentRequestRemoved) {
+ for (FcpListener fcpListener: fcpListeners) {
+ fcpListener.receivedPersistentRequestRemoved(this, persistentRequestRemoved);
+ }
+ }
+
+ /**
+ * Notifies all listeners that a “SubscribedUSKUpdate” message was received.
+ *
+ * @param subscribedUSKUpdate
+ * The “SubscribedUSKUpdate” message
+ */
+ private void fireReceivedSubscribedUSKUpdate(SubscribedUSKUpdate subscribedUSKUpdate) {
+ for (FcpListener fcpListener: fcpListeners) {
+ fcpListener.receivedSubscribedUSKUpdate(this, subscribedUSKUpdate);
+ }
+ }
+
+ /**
+ * Notifies all listeners that a “PluginInfo” message was received.
+ *
+ * @param pluginInfo
+ * The “PluginInfo” message
+ */
+ private void fireReceivedPluginInfo(PluginInfo pluginInfo) {
+ for (FcpListener fcpListener: fcpListeners) {
+ fcpListener.receivedPluginInfo(this, pluginInfo);
+ }
+ }
+
+ /**
+ * Notifies all listeners that an “FCPPluginReply” message was received.
+ *
+ * @param fcpPluginReply
+ * The “FCPPluginReply” message
+ */
+ private void fireReceivedFCPPluginReply(FCPPluginReply fcpPluginReply) {
+ for (FcpListener fcpListener: fcpListeners) {
+ fcpListener.receivedFCPPluginReply(this, fcpPluginReply);
+ }
+ }
+
+ /**
* Notifies all listeners that a “ProtocolError” message was received.
*
* @param protocolError
fireReceivedPersistentGet(new PersistentGet(fcpMessage));
} else if ("PersistentPut".equals(messageName)) {
fireReceivedPersistentPut(new PersistentPut(fcpMessage));
+ } else if ("PersistentPutDir".equals(messageName)) {
+ fireReceivedPersistentPutDir(new PersistentPutDir(fcpMessage));
} else if ("URIGenerated".equals(messageName)) {
fireReceivedURIGenerated(new URIGenerated(fcpMessage));
} else if ("EndListPersistentRequests".equals(messageName)) {
fireReceivedPutFailed(new PutFailed(fcpMessage));
} else if ("DataFound".equals(messageName)) {
fireReceivedDataFound(new DataFound(fcpMessage));
+ } else if ("SubscribedUSKUpdate".equals(messageName)) {
+ fireReceivedSubscribedUSKUpdate(new SubscribedUSKUpdate(fcpMessage));
} else if ("IdentifierCollision".equals(messageName)) {
fireReceivedIdentifierCollision(new IdentifierCollision(fcpMessage));
} else if ("AllData".equals(messageName)) {
- long dataLength;
- try {
- dataLength = Long.valueOf(fcpMessage.getField("DataLength"));
- } catch (NumberFormatException nfe1) {
- dataLength = -1;
- }
- LimitedInputStream payloadInputStream = new LimitedInputStream(remoteInputStream, dataLength);
+ LimitedInputStream payloadInputStream = getInputStream(FcpUtils.safeParseLong(fcpMessage.getField("DataLength")));
fireReceivedAllData(new AllData(fcpMessage, payloadInputStream));
try {
payloadInputStream.consume();
} catch (IOException ioe1) {
- /* FIXME - what now? */
/* well, ignore. when the connection handler fails, all fails. */
}
} else if ("EndListPeerNotes".equals(messageName)) {
fireReceivedSSKKeypair(new SSKKeypair(fcpMessage));
} else if ("PeerRemoved".equals(messageName)) {
fireReceivedPeerRemoved(new PeerRemoved(fcpMessage));
+ } else if ("PersistentRequestRemoved".equals(messageName)) {
+ fireReceivedPersistentRequestRemoved(new PersistentRequestRemoved(fcpMessage));
} else if ("UnknownPeerNoteType".equals(messageName)) {
fireReceivedUnknownPeerNoteType(new UnknownPeerNoteType(fcpMessage));
} else if ("UnknownNodeIdentifier".equals(messageName)) {
fireReceivedUnknownNodeIdentifier(new UnknownNodeIdentifier(fcpMessage));
+ } else if ("FCPPluginReply".equals(messageName)) {
+ LimitedInputStream payloadInputStream = getInputStream(FcpUtils.safeParseLong(fcpMessage.getField("DataLength")));
+ fireReceivedFCPPluginReply(new FCPPluginReply(fcpMessage, payloadInputStream));
+ try {
+ payloadInputStream.consume();
+ } catch (IOException ioe1) {
+ /* ignore. */
+ }
+ } else if ("PluginInfo".equals(messageName)) {
+ fireReceivedPluginInfo(new PluginInfo(fcpMessage));
} else if ("NodeData".equals(messageName)) {
fireReceivedNodeData(new NodeData(fcpMessage));
} else if ("TestDDAReply".equals(messageName)) {
incomingMessageStatistics.put(name, oldValue + 1);
}
+ /**
+ * Returns a limited input stream from the node’s input stream.
+ *
+ * @param dataLength
+ * The length of the stream
+ * @return The limited input stream
+ */
+ private LimitedInputStream getInputStream(long dataLength) {
+ if (dataLength <= 0) {
+ return new LimitedInputStream(null, 0);
+ }
+ return new LimitedInputStream(remoteInputStream, dataLength);
+ }
+
}