/**
* Notifies all listeners that a “PersistentGet” message was received.
*
+ * @see FcpListener#receivedPersistentGet(FcpConnection, PersistentGet)
* @param persistentGet
* The “PersistentGet” message
*/
* Notifies all listeners that a “EndListPersistentRequests” message was
* received.
*
+ * @see FcpListener#receivedEndListPersistentRequests(FcpConnection,
+ * EndListPersistentRequests)
* @param endListPersistentRequests
* The “EndListPersistentRequests” message
*/
/**
* Notifies all listeners that a “URIGenerated” message was received.
*
+ * @see FcpListener#receivedURIGenerated(FcpConnection, URIGenerated)
* @param uriGenerated
* The “URIGenerated” message
*/
/**
* Notifies all listeners that a “DataFound” message was received.
*
+ * @see FcpListener#receivedDataFound(FcpConnection, DataFound)
* @param dataFound
* The “DataFound” message
*/
/**
* Notifies all listeners that an “AllData” message was received.
*
+ * @see FcpListener#receivedAllData(FcpConnection, AllData)
* @param allData
* The “AllData” message
*/
/**
* Notifies all listeners that a “SimpleProgress” message was received.
*
+ * @see FcpListener#receivedSimpleProgress(FcpConnection, SimpleProgress)
* @param simpleProgress
* The “SimpleProgress” message
*/
/**
* Notifies all listeners that a “StartedCompression” message was received.
*
+ * @see FcpListener#receivedStartedCompression(FcpConnection,
+ * StartedCompression)
* @param startedCompression
* The “StartedCompression” message
*/
/**
* Notifies all listeners that a “FinishedCompression” message was received.
*
+ * @see FcpListener#receviedFinishedCompression(FcpConnection,
+ * FinishedCompression)
* @param finishedCompression
* The “FinishedCompression” message
*/
* Notifies all listeners that an “UnknownPeerNoteType” message was
* received.
*
+ * @see FcpListener#receivedUnknownPeerNoteType(FcpConnection,
+ * UnknownPeerNoteType)
* @param unknownPeerNoteType
* The “UnknownPeerNoteType” message
*/
* Notifies all listeners that an “UnknownNodeIdentifier” message was
* received.
*
+ * @see FcpListener#receivedUnknownNodeIdentifier(FcpConnection,
+ * UnknownNodeIdentifier)
* @param unknownNodeIdentifier
* The “UnknownNodeIdentifier” message
*/
/**
* Notifies all listeners that a “ConfigData” message was received.
*
+ * @see FcpListener#receivedConfigData(FcpConnection, ConfigData)
* @param configData
* The “ConfigData” message
*/
/**
* Notifies all listeners that a “GetFailed” message was received.
*
+ * @see FcpListener#receivedGetFailed(FcpConnection, GetFailed)
* @param getFailed
* The “GetFailed” message
*/
/**
* Notifies all listeners that a “PutFailed” message was received.
*
+ * @see FcpListener#receivedPutFailed(FcpConnection, PutFailed)
* @param putFailed
* The “PutFailed” message
*/
* Notifies all listeners that an “IdentifierCollision” message was
* received.
*
+ * @see FcpListener#receivedIdentifierCollision(FcpConnection,
+ * IdentifierCollision)
* @param identifierCollision
* The “IdentifierCollision” message
*/
/**
* Notifies all listeners that an “PersistentPutDir” message was received.
*
+ * @see FcpListener#receivedPersistentPutDir(FcpConnection,
+ * PersistentPutDir)
* @param persistentPutDir
* The “PersistentPutDir” message
*/
* Notifies all listeners that a “PersistentRequestRemoved” message was
* received.
*
+ * @see FcpListener#receivedPersistentRequestRemoved(FcpConnection,
+ * PersistentRequestRemoved)
* @param persistentRequestRemoved
* The “PersistentRequestRemoved” message
*/
/**
* Notifies all listeners that a “SubscribedUSKUpdate” message was received.
*
+ * @see FcpListener#receivedSubscribedUSKUpdate(FcpConnection,
+ * SubscribedUSKUpdate)
* @param subscribedUSKUpdate
* The “SubscribedUSKUpdate” message
*/
}
/**
+ * Notifies all listeners that a “PluginInfo” message was received.
+ *
+ * @see FcpListener#receivedPluginInfo(FcpConnection, PluginInfo)
+ * @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.
+ *
+ * @see FcpListener#receivedFCPPluginReply(FcpConnection, FCPPluginReply)
+ * @param fcpPluginReply
+ * The “FCPPluginReply” message
+ */
+ private void fireReceivedFCPPluginReply(FCPPluginReply fcpPluginReply) {
+ for (FcpListener fcpListener: fcpListeners) {
+ fcpListener.receivedFCPPluginReply(this, fcpPluginReply);
+ }
+ }
+
+ /**
+ * Notifies all listeners that a “PersistentRequestModified” message was
+ * received.
+ *
+ * @see FcpListener#receivedPersistentRequestModified(FcpConnection,
+ * PersistentRequestModified)
+ * @param persistentRequestModified
+ * The “PersistentRequestModified” message
+ */
+ private void fireReceivedPersistentRequestModified(PersistentRequestModified persistentRequestModified) {
+ for (FcpListener fcpListener: fcpListeners) {
+ fcpListener.receivedPersistentRequestModified(this, persistentRequestModified);
+ }
+ }
+
+ /**
+ * Notifies all listeners that a “PutSuccessful” message was received.
+ *
+ * @see FcpListener#receivedPutSuccessful(FcpConnection, PutSuccessful)
+ * @param putSuccessful
+ * The “PutSuccessful” message
+ */
+ private void fireReceivedPutSuccessful(PutSuccessful putSuccessful) {
+ for (FcpListener fcpListener: fcpListeners) {
+ fcpListener.receivedPutSuccessful(this, putSuccessful);
+ }
+ }
+
+ /**
+ * Notifies all listeners that a “PutFetchable” message was received.
+ *
+ * @see FcpListener#receivedPutFetchable(FcpConnection, PutFetchable)
+ * @param putFetchable
+ * The “PutFetchable” message
+ */
+ private void fireReceivedPutFetchable(PutFetchable putFetchable) {
+ for (FcpListener fcpListener: fcpListeners) {
+ fcpListener.receivedPutFetchable(this, putFetchable);
+ }
+ }
+
+ /**
* Notifies all listeners that a “ProtocolError” message was received.
*
+ * @see FcpListener#receivedProtocolError(FcpConnection, ProtocolError)
* @param protocolError
* The “ProtocolError” message
*/
}
}
+ /**
+ * Notifies all listeners that the connection to the node was closed.
+ *
+ * @see FcpListener#connectionClosed(FcpConnection)
+ */
+ private void fireConnectionClosed() {
+ for (FcpListener fcpListener: fcpListeners) {
+ fcpListener.connectionClosed(this);
+ }
+ }
+
//
// ACTIONS
//
fireReceivedFinishedCompression(new FinishedCompression(fcpMessage));
} else if ("GetFailed".equals(messageName)) {
fireReceivedGetFailed(new GetFailed(fcpMessage));
+ } else if ("PutFetchable".equals(messageName)) {
+ fireReceivedPutFetchable(new PutFetchable(fcpMessage));
+ } else if ("PutSuccessful".equals(messageName)) {
+ fireReceivedPutSuccessful(new PutSuccessful(fcpMessage));
} else if ("PutFailed".equals(messageName)) {
fireReceivedPutFailed(new PutFailed(fcpMessage));
} else if ("DataFound".equals(messageName)) {
} 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 ("PersistentRequestModified".equals(messageName)) {
+ fireReceivedPersistentRequestModified(new PersistentRequestModified(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)) {
Closer.close(remoteOutputStream);
Closer.close(remoteSocket);
connectionHandler = null;
+ fireConnectionClosed();
}
//
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);
+ }
+
}