+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry kind="src" output="target/classes" path="src/main/java"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
- <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
- <classpathentry kind="output" path="target/classes"/>
-</classpath>
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
- <name>jFCPlib</name>
- <comment></comment>
- <projects>
- </projects>
- <buildSpec>
- <buildCommand>
- <name>org.eclipse.jdt.core.javabuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>edu.umd.cs.findbugs.plugin.eclipse.findbugsBuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.maven.ide.eclipse.maven2Builder</name>
- <arguments>
- </arguments>
- </buildCommand>
- </buildSpec>
- <natures>
- <nature>org.maven.ide.eclipse.maven2Nature</nature>
- <nature>org.eclipse.jdt.core.javanature</nature>
- <nature>edu.umd.cs.findbugs.plugin.eclipse.findbugsNature</nature>
- </natures>
-</projectDescription>
<modelVersion>4.0.0</modelVersion>
<groupId>net.pterodactylus</groupId>
<artifactId>jFCPlib</artifactId>
- <version>0.1.2.3</version>
+ <version>0.1.3</version>
<name>jFCPlib</name>
<packaging>jar</packaging>
<distributionManagement>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
- <version>3.8.2</version>
+ <version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
- <groupId>net.pterodactylus</groupId>
- <artifactId>utils</artifactId>
- <version>0.1.1</version>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-integration</artifactId>
+ <version>1.3</version>
+ </dependency>
+ <dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ <version>16.0.1</version>
</dependency>
</dependencies>
<repositories>
<configuration>
<source>1.6</source>
<target>1.6</target>
+ <encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
</execution>
</executions>
</plugin>
+ <plugin>
+ <groupId>org.jacoco</groupId>
+ <artifactId>jacoco-maven-plugin</artifactId>
+ <version>0.7.1.201405082137</version>
+ <executions>
+ <execution>
+ <id>default-prepare-agent</id>
+ <goals>
+ <goal>prepare-agent</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>default-report</id>
+ <phase>prepare-package</phase>
+ <goals>
+ <goal>report</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>default-check</id>
+ <phase/>
+ <goals>
+ <goal>check</goal>
+ </goals>
+ <configuration>
+ <rules>
+ <!-- implmentation is needed only for Maven 2 -->
+ <rule implementation="org.jacoco.maven.RuleConfiguration">
+ <element>BUNDLE</element>
+ <limits>
+ <!-- implmentation is needed only for Maven 2 -->
+ <limit implementation="org.jacoco.report.check.Limit">
+ <counter>COMPLEXITY</counter>
+ <value>COVEREDRATIO</value>
+ <minimum>0.60</minimum>
+ </limit>
+ </limits>
+ </rule>
+ </rules>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
</plugins>
</build>
</project>
/**
* The “AllData” message carries the payload of a successful {@link ClientGet}
- * request. You will only received this message if the {@link ClientGet} request
- * was started with a return type of {@link ReturnType#direct}. If you get this
- * message and decide that the data is for you, call
+ * request. You will only received this message if the {@link ClientGet}
+ * request was started with a return type of {@link ReturnType#direct}. If you
+ * get this message and decide that the data is for you, call
* {@link #getPayloadInputStream()} to get the data. If an AllData message
* passes through all registered {@link FcpListener}s without the payload being
* consumed, the payload is discarded!
*
* @author David ‘Bombe’ Roden <bombe@freenetproject.org>
*/
-public class AllData extends BaseMessage {
+public class AllData extends BaseMessage implements Identifiable {
/** The payload. */
private InputStream payloadInputStream;
*
* @return The identifier of the request
*/
+ @Override
public String getIdentifier() {
return getField("Identifier");
}
return payloadInputStream;
}
+ /**
+ * Returns the content type of the found file.
+ *
+ * @return The content type
+ */
+ public String getContentType() {
+ return getField("Metadata.ContentType");
+ }
+
}
}
/**
- * Sets the maximum size of the file to retrieve. If the file is larger than
- * this size the request will fail!
+ * Sets the maximum size of the file to retrieve. If the file is larger
+ * than this size the request will fail!
*
* @param maxSize
* The maximum size of the file to retrieve
}
/**
+ * Sets whether to filter the fetched content.
+ *
+ * @param filterData
+ * {@code true} to filter content, {@code false} otherwise
+ */
+ public void setFilterData(boolean filterData) {
+ setField("FilterData", String.valueOf(filterData));
+ }
+
+ /**
* Sets the allowed MIME types of the requested file. If the MIME type of
* the file does not match one of the given MIME types the request will
* fail!
}
/**
- * Sets the name for the temporary file. You should only call this method if
- * your return type is {@link ReturnType#disk}!
+ * Sets the name for the temporary file. You should only call this method
+ * if your return type is {@link ReturnType#disk}!
*
* @param tempFilename
* The name of the temporary file
* test your direct-disk access (see {@link TestDDARequest},
* {@link TestDDAReply}, {@link TestDDAResponse}, {@link TestDDAComplete})
* before using this option! If <code>uploadFrom</code> is
- * {@link UploadFrom#redirect}, use {@link #setTargetURI(String)} to set the
- * target URI of the redirect.
+ * {@link UploadFrom#redirect}, use {@link #setTargetURI(String)} to set
+ * the target URI of the redirect.
*
* @param uri
* The URI to insert to
}
/**
- * Determines whether the node should really insert the data or generate the
- * final CHK only.
+ * Determines whether the node should really insert the data or generate
+ * the final CHK only.
*
* @param getCHKOnly
* <code>true</code> to generate the final CHK only,
}
/**
+ * Sets whether an insert request should be forked when it is cached.
+ *
+ * @param forkOnCacheable
+ * {@code true} to fork the insert when it is cached,
+ * {@code false} otherwise
+ */
+ public void setForkOnCacheable(boolean forkOnCacheable) {
+ setField("ForkOnCacheable", String.valueOf(forkOnCacheable));
+ }
+
+ /**
+ * Sets the number of additional inserts of single blocks.
+ *
+ * @param extraInsertsSingleBlock
+ * The number of additional inserts
+ */
+ public void setExtraInsertsSingleBlock(int extraInsertsSingleBlock) {
+ setField("ExtraInsertsSingleBlock", String.valueOf(extraInsertsSingleBlock));
+ }
+
+ /**
+ * Sets the number of additional inserts of splitfile header blocks.
+ *
+ * @param extraInsertsSplitfileHeaderBlock
+ * The number of additional inserts
+ */
+ public void setExtraInsertsSplitfileHeaderBlock(int extraInsertsSplitfileHeaderBlock) {
+ setField("ExtraInsertsSplitfileHeaderBlock", String.valueOf(extraInsertsSplitfileHeaderBlock));
+ }
+
+ /**
* Determines whether this request appears on the global queue.
*
* @param global
* already been compressed.
*
* @param dontCompress
- * <code>true</code> to skip compression of the data in the node,
- * <code>false</code> to allow compression
+ * <code>true</code> to skip compression of the data in the
+ * node, <code>false</code> to allow compression
*/
public void setDontCompress(boolean dontCompress) {
setField("DontCompress", String.valueOf(dontCompress));
}
/**
- * Sets an optional client token. This client token is mentioned in progress
- * and other request-related messages and can be used to identify this
- * request.
+ * Sets an optional client token. This client token is mentioned in
+ * progress and other request-related messages and can be used to identify
+ * this request.
*
* @param clientToken
* The client token
}
/**
+ * Sets whether an insert request should be forked when it is cached.
+ *
+ * @param forkOnCacheable
+ * {@code true} to fork the insert when it is cached,
+ * {@code false} otherwise
+ */
+ public void setForkOnCacheable(boolean forkOnCacheable) {
+ setField("ForkOnCacheable", String.valueOf(forkOnCacheable));
+ }
+
+ /**
+ * Sets the number of additional inserts of single blocks.
+ *
+ * @param extraInsertsSingleBlock
+ * The number of additional inserts
+ */
+ public void setExtraInsertsSingleBlock(int extraInsertsSingleBlock) {
+ setField("ExtraInsertsSingleBlock", String.valueOf(extraInsertsSingleBlock));
+ }
+
+ /**
+ * Sets the number of additional inserts of splitfile header blocks.
+ *
+ * @param extraInsertsSplitfileHeaderBlock
+ * The number of additional inserts
+ */
+ public void setExtraInsertsSplitfileHeaderBlock(int extraInsertsSplitfileHeaderBlock) {
+ setField("ExtraInsertsSplitfileHeaderBlock", String.valueOf(extraInsertsSplitfileHeaderBlock));
+ }
+
+ /**
* Sets whether the request is on the global queue.
*
* @param global
* {@inheritDoc}
* <p>
* Do not call this method to add input streams! The input streams, if any,
- * will be taken directly from the {@link FileEntry}s and the stream you set
- * here will be overridden!
+ * will be taken directly from the {@link FileEntry}s and the stream you
+ * set here will be overridden!
*/
@Override
public void setPayloadInputStream(InputStream payloadInputStream) {
}
/**
- * Determines whether the node should really insert the data or generate the
- * final CHK only.
+ * Determines whether the node should really insert the data or generate
+ * the final CHK only.
*
* @param getCHKOnly
* <code>true</code> to generate the final CHK only,
}
/**
+ * Sets whether an insert request should be forked when it is cached.
+ *
+ * @param forkOnCacheable
+ * {@code true} to fork the insert when it is cached,
+ * {@code false} otherwise
+ */
+ public void setForkOnCacheable(boolean forkOnCacheable) {
+ setField("ForkOnCacheable", String.valueOf(forkOnCacheable));
+ }
+
+ /**
+ * Sets the number of additional inserts of single blocks.
+ *
+ * @param extraInsertsSingleBlock
+ * The number of additional inserts
+ */
+ public void setExtraInsertsSingleBlock(int extraInsertsSingleBlock) {
+ setField("ExtraInsertsSingleBlock", String.valueOf(extraInsertsSingleBlock));
+ }
+
+ /**
+ * Sets the number of additional inserts of splitfile header blocks.
+ *
+ * @param extraInsertsSplitfileHeaderBlock
+ * The number of additional inserts
+ */
+ public void setExtraInsertsSplitfileHeaderBlock(int extraInsertsSplitfileHeaderBlock) {
+ setField("ExtraInsertsSplitfileHeaderBlock", String.valueOf(extraInsertsSplitfileHeaderBlock));
+ }
+
+ /**
* Determines whether this request appears on the global queue.
*
* @param global
* already been compressed.
*
* @param dontCompress
- * <code>true</code> to skip compression of the data in the node,
- * <code>false</code> to allow compression
+ * <code>true</code> to skip compression of the data in the
+ * node, <code>false</code> to allow compression
*/
public void setDontCompress(boolean dontCompress) {
setField("DontCompress", String.valueOf(dontCompress));
}
/**
- * Sets an optional client token. This client token is mentioned in progress
- * and other request-related messages and can be used to identify this
- * request.
+ * Sets an optional client token. This client token is mentioned in
+ * progress and other request-related messages and can be used to identify
+ * this request.
*
* @param clientToken
* The client token
}
/**
- * Sets the name of the default file. The default file is shown when the key
- * is requested with an additional name.
+ * Sets the name of the default file. The default file is shown when the
+ * key is requested with an additional name.
*
* @param defaultName
* The name of the default file
import java.security.interfaces.DSAParams;
/**
- * Container for the DSA group of a peer. A DSA group consists of a base (called
- * “g”), a prime (called “p”) and a subprime (called “q”).
+ * Container for the DSA group of a peer. A DSA group consists of a base
+ * (called “g”), a prime (called “p”) and a subprime (called “q”).
*
* @see DSAParams
* @author David ‘Bombe’ Roden <bombe@freenetproject.org>
/**
* A “DataFound” message signals the client that the data requested by a
- * {@link ClientGet} operation has been found. This message does not include the
- * actual data, though.
+ * {@link ClientGet} operation has been found. This message does not include
+ * the actual data, though.
*
* @author David ‘Bombe’ Roden <bombe@freenetproject.org>
*/
-public class DataFound extends BaseMessage {
+public class DataFound extends BaseMessage implements Identifiable {
/**
* Creates a new “DataFound” message that wraps the received message.
*
* @return The identifier of the request
*/
+ @Override
public String getIdentifier() {
return getField("Identifier");
}
public class EndListPeerNotes extends BaseMessage {
/**
- * Creates a new “EndListPeerNotes” message that wraps the received message.
+ * Creates a new “EndListPeerNotes” message that wraps the received
+ * message.
*
* @param fcpMessage
* The received message
*
* @author David ‘Bombe’ Roden <bombe@freenetproject.org>
*/
-public class EndListPeers extends BaseMessage {
+public class EndListPeers extends BaseMessage implements Identifiable {
/**
* Creates a new “EndListPeers” message that wraps the received message.
*
* @return The identifier of the request
*/
+ @Override
public String getIdentifier() {
return getField("Identifier");
}
public class EndListPersistentRequests extends BaseMessage {
/**
- * Creates a new “EndListPersistentRequests” message that wraps the received
- * message.
+ * Creates a new “EndListPersistentRequests” message that wraps the
+ * received message.
*
* @param receivedMessage
* The received message
}
/**
- * Sets the identifier of the request. Though this is still optional you are
- * encouraged to include it because the plugin might reply in random order
- * to requests.
+ * Sets the identifier of the request. Though this is still optional you
+ * are encouraged to include it because the plugin might reply in random
+ * order to requests.
*
* @param identifier
* The identifier of the request
/**
* Sets the length of data of the optional payload. If you call this method
- * you also have to call {@link #setPayloadInputStream(java.io.InputStream)}
- * !
+ * you also have to call
+ * {@link #setPayloadInputStream(java.io.InputStream)} !
*
* @param dataLength
* The length of data in the payload input stream
*
* @author David ‘Bombe’ Roden <bombe@freenetproject.org>
*/
-public class FCPPluginReply extends BaseMessage {
+public class FCPPluginReply extends BaseMessage implements Identifiable {
/** The payload input stream. */
private final InputStream payloadInputStream;
*
* @return The identifier of the request
*/
+ @Override
public String getIdentifier() {
return getField("Identifier");
}
/**
* {@inheritDoc}
*/
+ @Override
public void receivedNodeHello(FcpConnection fcpConnection, NodeHello nodeHello) {
/* empty. */
}
/**
* {@inheritDoc}
*/
+ @Override
public void receivedCloseConnectionDuplicateClientName(FcpConnection fcpConnection, CloseConnectionDuplicateClientName closeConnectionDuplicateClientName) {
/* empty. */
}
/**
* {@inheritDoc}
*/
+ @Override
public void receivedSSKKeypair(FcpConnection fcpConnection, SSKKeypair sskKeypair) {
/* empty. */
}
/**
* {@inheritDoc}
*/
+ @Override
public void receivedPeer(FcpConnection fcpConnection, Peer peer) {
/* empty. */
}
/**
* {@inheritDoc}
*/
+ @Override
public void receivedEndListPeers(FcpConnection fcpConnection, EndListPeers endListPeers) {
/* empty. */
}
/**
* {@inheritDoc}
*/
+ @Override
public void receivedPeerNote(FcpConnection fcpConnection, PeerNote peerNote) {
/* empty. */
}
/**
* {@inheritDoc}
*/
+ @Override
public void receivedEndListPeerNotes(FcpConnection fcpConnection, EndListPeerNotes endListPeerNotes) {
/* empty. */
}
/**
* {@inheritDoc}
*/
+ @Override
public void receivedPeerRemoved(FcpConnection fcpConnection, PeerRemoved peerRemoved) {
/* empty. */
}
*
* @see FcpListener#receivedNodeData(FcpConnection, NodeData)
*/
+ @Override
public void receivedNodeData(FcpConnection fcpConnection, NodeData nodeData) {
/* empty. */
}
*
* @see FcpListener#receivedTestDDAReply(FcpConnection, TestDDAReply)
*/
+ @Override
public void receivedTestDDAReply(FcpConnection fcpConnection, TestDDAReply testDDAReply) {
/* empty. */
}
/**
* {@inheritDoc}
*/
+ @Override
public void receivedTestDDAComplete(FcpConnection fcpConnection, TestDDAComplete testDDAComplete) {
/* empty. */
}
/**
* {@inheritDoc}
*/
+ @Override
public void receivedPersistentGet(FcpConnection fcpConnection, PersistentGet persistentGet) {
/* empty. */
}
/**
* {@inheritDoc}
*/
+ @Override
public void receivedPersistentPut(FcpConnection fcpConnection, PersistentPut persistentPut) {
/* empty. */
}
/**
* {@inheritDoc}
*/
+ @Override
public void receivedEndListPersistentRequests(FcpConnection fcpConnection, EndListPersistentRequests endListPersistentRequests) {
/* empty. */
}
/**
* {@inheritDoc}
*/
+ @Override
public void receivedURIGenerated(FcpConnection fcpConnection, URIGenerated uriGenerated) {
/* empty. */
}
/**
* {@inheritDoc}
*/
+ @Override
public void receivedDataFound(FcpConnection fcpConnection, DataFound dataFound) {
/* empty. */
}
/**
* {@inheritDoc}
*/
+ @Override
public void receivedAllData(FcpConnection fcpConnection, AllData allData) {
/* empty. */
}
/**
* {@inheritDoc}
*/
+ @Override
public void receivedSimpleProgress(FcpConnection fcpConnection, SimpleProgress simpleProgress) {
/* empty. */
}
/**
* {@inheritDoc}
*/
+ @Override
public void receivedStartedCompression(FcpConnection fcpConnection, StartedCompression startedCompression) {
/* empty. */
}
/**
* {@inheritDoc}
*/
+ @Override
public void receivedFinishedCompression(FcpConnection fcpConnection, FinishedCompression finishedCompression) {
/* empty. */
}
/**
* {@inheritDoc}
*/
+ @Override
public void receivedUnknownPeerNoteType(FcpConnection fcpConnection, UnknownPeerNoteType unknownPeerNoteType) {
/* empty. */
}
/**
* {@inheritDoc}
*/
+ @Override
public void receivedUnknownNodeIdentifier(FcpConnection fcpConnection, UnknownNodeIdentifier unknownNodeIdentifier) {
/* empty. */
}
/**
* {@inheritDoc}
*/
+ @Override
public void receivedConfigData(FcpConnection fcpConnection, ConfigData configData) {
/* empty. */
}
/**
* {@inheritDoc}
*/
+ @Override
public void receivedGetFailed(FcpConnection fcpConnection, GetFailed getFailed) {
/* empty. */
}
/**
* {@inheritDoc}
*/
+ @Override
public void receivedPutFailed(FcpConnection fcpConnection, PutFailed putFailed) {
/* empty. */
}
/**
* {@inheritDoc}
*/
+ @Override
public void receivedIdentifierCollision(FcpConnection fcpConnection, IdentifierCollision identifierCollision) {
/* empty. */
}
/**
* {@inheritDoc}
*/
+ @Override
public void receivedPersistentPutDir(FcpConnection fcpConnection, PersistentPutDir persistentPutDir) {
/* empty. */
}
/**
* {@inheritDoc}
*/
+ @Override
public void receivedPersistentRequestRemoved(FcpConnection fcpConnection, PersistentRequestRemoved persistentRequestRemoved) {
/* empty. */
}
/**
* {@inheritDoc}
*/
+ @Override
public void receivedSubscribedUSKUpdate(FcpConnection fcpConnection, SubscribedUSKUpdate subscribedUSKUpdate) {
/* empty. */
}
/**
* {@inheritDoc}
*/
+ @Override
public void receivedPluginInfo(FcpConnection fcpConnection, PluginInfo pluginInfo) {
/* empty. */
}
/**
* {@inheritDoc}
*/
+ @Override
public void receivedFCPPluginReply(FcpConnection fcpConnection, FCPPluginReply fcpPluginReply) {
/* empty. */
}
/**
* {@inheritDoc}
*/
+ @Override
public void receivedPersistentRequestModified(FcpConnection fcpConnection, PersistentRequestModified persistentRequestModified) {
/* empty. */
}
/**
* {@inheritDoc}
*/
+ @Override
public void receivedPutSuccessful(FcpConnection fcpConnection, PutSuccessful putSuccessful) {
/* empty. */
}
/**
* {@inheritDoc}
*/
+ @Override
public void receivedPutFetchable(FcpConnection fcpConnection, PutFetchable putFetchable) {
/* empty. */
}
/**
* {@inheritDoc}
*/
+ @Override
public void receivedProtocolError(FcpConnection fcpConnection, ProtocolError protocolError) {
/* empty. */
}
/**
* {@inheritDoc}
*/
+ @Override
public void receivedSentFeed(FcpConnection source, SentFeed sentFeed) {
/* empty. */
}
/**
* {@inheritDoc}
*/
+ @Override
public void receivedBookmarkFeed(FcpConnection fcpConnection, ReceivedBookmarkFeed receivedBookmarkFeed) {
/* empty. */
}
/**
* {@inheritDoc}
*/
+ @Override
public void receivedMessage(FcpConnection fcpConnection, FcpMessage fcpMessage) {
/* empty. */
}
/**
* {@inheritDoc}
*/
+ @Override
public void connectionClosed(FcpConnection fcpConnection, Throwable throwable) {
/* empty. */
}
import java.util.Map;
import java.util.logging.Logger;
-import net.pterodactylus.util.logging.Logging;
-
/**
* An FCP connection to a Freenet node.
*
public class FcpConnection implements Closeable {
/** Logger. */
- private static final Logger logger = Logging.getLogger(FcpConnection.class.getName());
+ private static final Logger logger = Logger.getLogger(FcpConnection.class.getName());
/** The default port for FCP v2. */
public static final int DEFAULT_PORT = 9481;
}
/**
- * Closes the connection. If there is no connection to the node, this method
- * does nothing.
+ * Closes the connection. If there is no connection to the node, this
+ * method does nothing.
*/
+ @Override
public void close() {
handleDisconnect(null);
}
* Handles a disconnect from the node.
*
* @param throwable
- * The exception that caused the disconnect, or <code>null</code>
- * if there was no exception
+ * The exception that caused the disconnect, or
+ * <code>null</code> if there was no exception
*/
synchronized void handleDisconnect(Throwable throwable) {
FcpUtils.close(remoteInputStream);
}
/**
- * A wrapper around an {@link InputStream} that only supplies a limit number
- * of bytes from the underlying input stream.
+ * A wrapper around an {@link InputStream} that only supplies a limit
+ * number of bytes from the underlying input stream.
*
* @author David ‘Bombe’ Roden <bombe@freenetproject.org>
*/
import java.util.logging.Level;
import java.util.logging.Logger;
-import net.pterodactylus.util.logging.Logging;
-
/**
* Handles an FCP connection to a node.
*
class FcpConnectionHandler implements Runnable {
/** The logger. */
- private static final Logger logger = Logging.getLogger(FcpConnectionHandler.class.getName());
+ private static final Logger logger = Logger.getLogger(FcpConnectionHandler.class.getName());
/** The underlying connection. */
private final FcpConnection fcpConnection;
/**
* {@inheritDoc}
*/
+ @Override
public void run() {
FcpMessage fcpMessage = null;
Throwable throwable = null;
}
String field = line.substring(0, equalSign);
String value = line.substring(equalSign + 1);
- assert fcpMessage != null : "fcp message is null";
+ assert fcpMessage != null: "fcp message is null";
fcpMessage.setField(field, value);
} catch (IOException ioe1) {
throwable = ioe1;
public void receivedProtocolError(FcpConnection fcpConnection, ProtocolError protocolError);
/**
- * 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!
+ * 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!
*
* @param fcpConnection
* The connection that received the message
public void receivedMessage(FcpConnection fcpConnection, FcpMessage fcpMessage);
/**
- * Notifies a listener that a connection was closed. A closed connection can
- * be reestablished by calling {@link FcpConnection#connect()} on the same
- * object again.
+ * Notifies a listener that a connection was closed. A closed connection
+ * can be reestablished by calling {@link FcpConnection#connect()} on the
+ * same object again.
*
* @param fcpConnection
* The connection that was closed.
* @param throwable
- * The exception that caused the disconnect, or <code>null</code>
- * if there was no exception
+ * The exception that caused the disconnect, or
+ * <code>null</code> if there was no exception
*/
public void connectionClosed(FcpConnection fcpConnection, Throwable throwable);
package net.pterodactylus.fcp;
-import net.pterodactylus.util.event.AbstractListenerManager;
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
/**
* Manages FCP listeners and event firing.
*
* @author David ‘Bombe’ Roden <bombe@pterodactylus.net>
*/
-public class FcpListenerManager extends AbstractListenerManager<FcpConnection, FcpListener> {
+public class FcpListenerManager {
+
+ private final FcpConnection source;
+ private final List<FcpListener> listeners = new CopyOnWriteArrayList<FcpListener>();
/**
* Creates a new listener manager.
* The source FCP connection
*/
public FcpListenerManager(FcpConnection fcpConnection) {
- super(fcpConnection);
+ this.source = fcpConnection;
+ }
+
+ public void addListener(FcpListener fcpListener) {
+ listeners.add(fcpListener);
+ }
+
+ public void removeListener(FcpListener fcpListener) {
+ listeners.remove(fcpListener);
+ }
+
+ private FcpConnection getSource() {
+ return source;
+ }
+
+ private List<FcpListener> getListeners() {
+ return listeners;
}
/**
}
/**
- * Notifies all listeners that a “FinishedCompression” message was received.
+ * Notifies all listeners that a “FinishedCompression” message was
+ * received.
*
* @see FcpListener#receivedFinishedCompression(FcpConnection,
* FinishedCompression)
}
/**
- * Notifies all listeners that a “SubscribedUSKUpdate” message was received.
+ * Notifies all listeners that a “SubscribedUSKUpdate” message was
+ * received.
*
* @see FcpListener#receivedSubscribedUSKUpdate(FcpConnection,
* SubscribedUSKUpdate)
* Notifies all listeners that the connection to the node was closed.
*
* @param throwable
- * The exception that caused the disconnect, or <code>null</code>
- * if there was no exception
+ * The exception that caused the disconnect, or
+ * <code>null</code> if there was no exception
* @see FcpListener#connectionClosed(FcpConnection, Throwable)
*/
public void fireConnectionClosed(Throwable throwable) {
}
/**
- * Creates a new FCP message with the given name and the given payload input
- * stream. The payload input stream is not read until the message is sent to
- * the node using {@link FcpConnection#sendMessage(FcpMessage)}.
+ * Creates a new FCP message with the given name and the given payload
+ * input stream. The payload input stream is not read until the message is
+ * sent to the node using {@link FcpConnection#sendMessage(FcpMessage)}.
*
* @param name
* The name of the message
*
* @param field
* The name of the field to check for
- * @return <code>true</code> if the message has a field with the given name,
- * <code>false</code> otherwise
+ * @return <code>true</code> if the message has a field with the given
+ * name, <code>false</code> otherwise
*/
public boolean hasField(String field) {
return fields.containsKey(field);
/**
* {@inheritDoc}
*/
+ @Override
public Iterator<String> iterator() {
return fields.keySet().iterator();
}
* Writes this message to the given output stream. If the message has a
* payload (i.e. {@link #payloadInputStream} is not <code>null</code>) the
* payload is written to the given output stream after the message as well.
- * That means that this method can only be called once because on the second
- * invocation the payload input stream could not be read (again).
+ * That means that this method can only be called once because on the
+ * second invocation the payload input stream could not be read (again).
*
* @param outputStream
* The output stream to write the message to
}
/**
- * Tries to parse the given string into an int, returning <code>-1</code> if
- * the string can not be parsed.
+ * Tries to parse the given string into an int, returning <code>-1</code>
+ * if the string can not be parsed.
*
* @param value
* The string to parse
*
* @author David ‘Bombe’ Roden <bombe@freenetproject.org>
*/
-public class FinishedCompression extends BaseMessage {
+public class FinishedCompression extends BaseMessage implements Identifiable {
/**
* Creates a new “FinishedCompression” message that wraps the received
*
* @return The identifier of the request
*/
+ @Override
public String getIdentifier() {
return getField("Identifier");
}
}
/**
- * Sets whether the {@link ConfigData} result message shall include the long
- * descriptions.
+ * Sets whether the {@link ConfigData} result message shall include the
+ * long descriptions.
*
* @param withLongDescription
* <code>true</code> to include the long descriptions in the
}
/**
- * Sets whether the {@link ConfigData} result message shall include the data
- * types.
+ * Sets whether the {@link ConfigData} result message shall include the
+ * data types.
*
* @param withDataTypes
* <code>true</code> to include the data types in the result,
}
/**
- * Sets whether the {@link ConfigData} result message shall include the sort
- * order.
+ * Sets whether the {@link ConfigData} result message shall include the
+ * sort order.
*
* @param withSortOrder
* <code>true</code> to include the sort order in the result,
*
* @author David ‘Bombe’ Roden <bombe@freenetproject.org>
*/
-public class GetFailed extends BaseMessage {
+public class GetFailed extends BaseMessage implements Identifiable {
/**
* Creates a new “GetFailed” message that wraps the received message.
/**
* Returns the code of the error.
*
- * @return The code of the error, or <code>-1</code> if the error code could
- * not be parsed
+ * @return The code of the error, or <code>-1</code> if the error code
+ * could not be parsed
*/
public int getCode() {
return FcpUtils.safeParseInt(getField("Code"));
*
* @return The identifier of the request
*/
+ @Override
public String getIdentifier() {
return getField("Identifier");
}
}
/**
- * Returns whether the expected values (see {@link #getExpectedDataLength()}
- * and {@link #getExpectedMetadataContentType()}) have already been
- * finalized and can be trusted. If the values have not been finalized that
- * can change over time.
+ * Returns whether the expected values (see
+ * {@link #getExpectedDataLength()} and
+ * {@link #getExpectedMetadataContentType()}) have already been finalized
+ * and can be trusted. If the values have not been finalized that can
+ * change over time.
*
* @return <code>true</code> if the expected values have already been
* finalized, <code>false</code> otherwise
}
/**
- * Returns whether the request failed fatally. If a request fails fatally it
- * can never complete, even with inifinite retries.
+ * Returns whether the request failed fatally. If a request fails fatally
+ * it can never complete, even with inifinite retries.
*
* @return <code>true</code> if the request failed fatally,
* <code>false</code> otherwise
public class GetNode extends FcpMessage {
/**
- * Creates a “GetNode” command that returns the darknet noderef of the node.
+ * Creates a “GetNode” command that returns the darknet noderef of the
+ * node.
*/
public GetNode() {
this(null, null, null);
}
/**
- * Creates a “GetNode” command that returns the request noderef of the node,
- * including private and volatile data, if requested. If any of the Boolean
- * parameters are <code>null</code> the parameter is ignored and the node’s
- * default value is used.
+ * Creates a “GetNode” command that returns the request noderef of the
+ * node, including private and volatile data, if requested. If any of the
+ * Boolean parameters are <code>null</code> the parameter is ignored and
+ * the node’s default value is used.
*
* @param giveOpennetRef
* <code>true</code> to request the opennet noderef,
/**
* The “GetRequestStatus” message is used request status information about a
- * running request. It is also the only way to trigger a download of a persisted
- * completed {@link ClientGet} with a return type of {@link ReturnType#direct}.
+ * running request. It is also the only way to trigger a download of a
+ * persisted completed {@link ClientGet} with a return type of
+ * {@link ReturnType#direct}.
*
* @author David ‘Bombe’ Roden <bombe@freenetproject.org>
*/
--- /dev/null
+/*
+ * jFCPlib - Identifiable.java - Copyright © 2010 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 3 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, see <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.fcp;
+
+/**
+ * Interface for all {@link FcpMessage}s that have an “Identifier” field.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public interface Identifiable {
+
+ /**
+ * Returns the identifier of the FCP message.
+ *
+ * @return The identifier of the FCP message
+ */
+ public String getIdentifier();
+
+}
*
* @author David ‘Bombe’ Roden <bombe@freenetproject.org>
*/
-public class IdentifierCollision extends BaseMessage {
+public class IdentifierCollision extends BaseMessage implements Identifiable {
/**
* Creates a new “IdentifierCollision” message that wraps the received
*
* @return The identifier of the request
*/
+ @Override
public String getIdentifier() {
return getField("Identifier");
}
/**
* Creates a new “ListPeer” request that returns information about the node
- * specified by <code>nodeIdentifier</code>. <code>nodeIdentifier</code> can
- * be of several formats: The node’s name, its identity, or its IP address
- * and port (connection with a ‘:’).
+ * specified by <code>nodeIdentifier</code>. <code>nodeIdentifier</code>
+ * can be of several formats: The node’s name, its identity, or its IP
+ * address and port (connection with a ‘:’).
*
* @param nodeIdentifier
* The identifier of the node to get details about
}
/**
- * Creates a new “ListPeers” request that includes wanted data of the peers.
+ * Creates a new “ListPeers” request that includes wanted data of the
+ * peers.
*
* @param identifier
* The identifier of the request
* If <code>true</code> metadata of the peers is included in the
* reply
* @param withVolatile
- * if <code>true</code> volatile data of the peers is included in
- * the reply
+ * if <code>true</code> volatile data of the peers is included
+ * in the reply
*/
public ListPeers(String identifier, boolean withMetadata, boolean withVolatile) {
super("ListPeers");
public class ModifyPeer extends FcpMessage {
/**
- * Creates a new “ModifyPeer” request. All Boolean parameters may be null to
- * not influence the current setting.
+ * Creates a new “ModifyPeer” request. All Boolean parameters may be null
+ * to not influence the current setting.
*
* @param nodeIdentifier
- * The identifier of the node, i.e. name, identity, or IP address
- * and port
+ * The identifier of the node, i.e. name, identity, or IP
+ * address and port
* @param allowLocalAddresses
* Whether to allow local addresses from this node
* @param disabled
*
* @see PeerNote
* @param nodeIdentifier
- * The identifier of the node, i.e. name, identity, or IP address
- * and port
+ * The identifier of the node, i.e. name, identity, or IP
+ * address and port
* @param noteText
* The base64-encoded text
* @param peerNoteType
}
/**
- * Returns one of the volatile fields from the message. The given field name
- * is prepended with “volatile.” so if you want to get the value of the
- * field with the name “volatile.freeJavaMemory” you only need to specify
- * “freeJavaMemory”.
+ * Returns one of the volatile fields from the message. The given field
+ * name is prepended with “volatile.” so if you want to get the value of
+ * the field with the name “volatile.freeJavaMemory” you only need to
+ * specify “freeJavaMemory”.
*
* @param field
* The name of the field
}
/**
- * Returns the build of the node. This may not be a number but also a string
- * like “@custom@” in case you built the node yourself.
+ * Returns the build of the node. This may not be a number but also a
+ * string like “@custom@” in case you built the node yourself.
*
* @return The build of the node
*/
}
/**
- * Returns the build number of the node. This may not be a number but also a
- * string like “@custom@” in case you built the node yourself.
+ * Returns the build number of the node. This may not be a number but also
+ * a string like “@custom@” in case you built the node yourself.
*
* @return The build number of the node, or <code>-1</code> if the build
* number could not be determined
/**
* Returns the build number of the external library file.
*
- * @return The build number of the external library file, or <code>-1</code>
- * if the build number could not be determined
+ * @return The build number of the external library file, or
+ * <code>-1</code> if the build number could not be determined
*/
public int getExtBuildNumber() {
return FcpUtils.safeParseInt(getExtBuild());
}
/**
- * Returns the name of the node. If the node is an opennet peer, it will not
- * have a name!
+ * Returns the name of the node. If the node is an opennet peer, it will
+ * not have a name!
*
* @return The name of the node, or <code>null</code> if the node is an
* opennet peer
*
* @author David ‘Bombe’ Roden <bombe@freenetproject.org>
*/
-public class Peer extends BaseMessage {
+public class Peer extends BaseMessage implements Identifiable {
/**
* Creates a new “Peer” reply from the received message.
*
* @return The identifier of the request
*/
+ @Override
public String getIdentifier() {
return getField("Identifier");
}
}
/**
- * Returns one of the volatile fields from the message. The given field name
- * is prepended with “volatile.” so if you want to get the value of the
- * field with the name “volatile.status” you only need to specify “status”.
+ * Returns one of the volatile fields from the message. The given field
+ * name is prepended with “volatile.” so if you want to get the value of
+ * the field with the name “volatile.status” you only need to specify
+ * “status”.
*
* @param field
* The name of the field
}
/**
- * Returns one of the metadata fields from the message. The given field name
- * is prepended with “metadata.” so if you want to get the value of the
- * field with the name “metadata.timeLastRoutable” you only need to specify
- * “timeLastRoutable”.
+ * Returns one of the metadata fields from the message. The given field
+ * name is prepended with “metadata.” so if you want to get the value of
+ * the field with the name “metadata.timeLastRoutable” you only need to
+ * specify “timeLastRoutable”.
*
* @param field
* The name of the field
/**
* Returns the type of the peer note.
*
- * @return The type of the peer note, or <code>-1</code> if the type can not
- * be parsed
+ * @return The type of the peer note, or <code>-1</code> if the type can
+ * not be parsed
*/
public int getPeerNoteType() {
return FcpUtils.safeParseInt(getField("PeerNoteType"));
/**
* The “PersistentGet” message is sent to the client to inform it about a
- * persistent download, either in the client-local queue or in the global queue.
+ * persistent download, either in the client-local queue or in the global
+ * queue.
*
* @author David ‘Bombe’ Roden <bombe@freenetproject.org>
*/
-public class PersistentGet extends BaseMessage {
+public class PersistentGet extends BaseMessage implements Identifiable {
/**
* Creates a new “PersistentGet” message that wraps the received message.
*
* @return The identifier of the request
*/
+ @Override
public String getIdentifier() {
return getField("Identifier");
}
/**
* Returns the persistence of the request.
*
- * @return The persistence of the request, or {@link Persistence#unknown} if
- * the persistence could not be parsed
+ * @return The persistence of the request, or {@link Persistence#unknown}
+ * if the persistence could not be parsed
*/
public Persistence getPersistence() {
try {
/**
* Returns the maximum number of retries for a failed block.
*
- * @return The maximum number of retries for a failed block, <code>-1</code>
- * for endless retries, <code>-2</code> if the number could not be
- * parsed
+ * @return The maximum number of retries for a failed block,
+ * <code>-1</code> for endless retries, <code>-2</code> if the
+ * number could not be parsed
*/
public int getMaxRetries() {
return FcpUtils.safeParseInt(getField("MaxRetries"), -2);
*
* @author David ‘Bombe’ Roden <bombe@freenetproject.org>
*/
-public class PersistentPut extends BaseMessage {
+public class PersistentPut extends BaseMessage implements Identifiable {
/**
* Creates a new “PersistentPut” message that wraps the received message.
*
* @return The identifier of the request
*/
+ @Override
public String getIdentifier() {
return getField("Identifier");
}
*
* @author David ‘Bombe’ Roden <bombe@freenetproject.org>
*/
-public class PersistentPutDir extends BaseMessage {
+public class PersistentPutDir extends BaseMessage implements Identifiable {
/**
- * Creates a new “PersistentPutDir” message that wraps the received message.
+ * Creates a new “PersistentPutDir” message that wraps the received
+ * message.
*
* @param receivedMessage
* The received message
*
* @return The identifier of the request
*/
+ @Override
public String getIdentifier() {
return getField("Identifier");
}
*
* @author David ‘Bombe’ Roden <bombe@freenetproject.org>
*/
-public class PersistentRequestModified extends BaseMessage {
+public class PersistentRequestModified extends BaseMessage implements Identifiable {
/**
- * Creates a new “PersistentRequestModified” message that wraps the received
- * message.
+ * Creates a new “PersistentRequestModified” message that wraps the
+ * received message.
*
* @param receivedMessage
* The received message
*
* @return The identifier of the request
*/
+ @Override
public String getIdentifier() {
return getField("Identifier");
}
*
* @author David ‘Bombe’ Roden <bombe@freenetproject.org>
*/
-public class PersistentRequestRemoved extends BaseMessage {
+public class PersistentRequestRemoved extends BaseMessage implements Identifiable {
/**
* Creates a new “PersistentRequestRemoved” message that wraps the received
*
* @return The identifier of the request
*/
+ @Override
public String getIdentifier() {
return getField("Identifier");
}
* Returns whether the request was removed from the global queue.
*
* @return <code>true</code> if the request was removed from the global
- * queue, <code>false</code> if it was removed from the client-local
- * queue
+ * queue, <code>false</code> if it was removed from the
+ * client-local queue
*/
public boolean isGlobal() {
return Boolean.valueOf(getField("Global"));
*
* @author David ‘Bombe’ Roden <bombe@freenetproject.org>
*/
-public class PluginInfo extends BaseMessage {
+public class PluginInfo extends BaseMessage implements Identifiable {
/**
* Creates a new “PluginInfo” message that wraps the received message.
*
* @return The identifier of the request
*/
+ @Override
public String getIdentifier() {
return getField("Identifier");
}
/**
* Returns the error code.
*
- * @return The error code, or <code>-1</code> if the error code could not be
- * parsed
+ * @return The error code, or <code>-1</code> if the error code could not
+ * be parsed
*/
public int getCode() {
return FcpUtils.safeParseInt(getField("Code"));
*
* @author David ‘Bombe’ Roden <bombe@freenetproject.org>
*/
-public class PutFailed extends BaseMessage {
+public class PutFailed extends BaseMessage implements Identifiable {
/**
* Creates a new “PutFailed” message that wraps the received message.
/**
* Returns the code of the error.
*
- * @return The code of the error, or <code>-1</code> if the error code could
- * not be parsed
+ * @return The code of the error, or <code>-1</code> if the error code
+ * could not be parsed
*/
public int getCode() {
return FcpUtils.safeParseInt(getField("Code"));
*
* @return The identifier of the request
*/
+ @Override
public String getIdentifier() {
return getField("Identifier");
}
}
/**
- * Returns whether the request failed fatally. If a request fails fatally it
- * can never complete, even with inifinite retries.
+ * Returns whether the request failed fatally. If a request fails fatally
+ * it can never complete, even with inifinite retries.
*
* @return <code>true</code> if the request failed fatally,
* <code>false</code> otherwise
*
* @author David ‘Bombe’ Roden <bombe@freenetproject.org>
*/
-public class PutFetchable extends BaseMessage {
+public class PutFetchable extends BaseMessage implements Identifiable {
/**
* Creates a new “PutFetchable” message that wraps the received message.
*
* @return The identifier of the request
*/
+ @Override
public String getIdentifier() {
return getField("Identifier");
}
*
* @author David ‘Bombe’ Roden <bombe@freenetproject.org>
*/
-public class PutSuccessful extends BaseMessage {
+public class PutSuccessful extends BaseMessage implements Identifiable {
/**
* Creates a new “PutSuccessful” message that wraps the received message.
*
* @return The identifier of the request
*/
+ @Override
public String getIdentifier() {
return getField("Identifier");
}
/**
* Returns whether the bookmark has an active link image.
*
- * @return {@code true} if the bookmark has an active link image, {@code
- * false} otherwise
+ * @return {@code true} if the bookmark has an active link image,
+ * {@code false} otherwise
*/
public boolean hasActiveLink() {
return Boolean.parseBoolean(getField("HasAnActiveLink"));
}
/**
- * Returns the description of the bookmark. Note that the description may be
- * {@code null} and if it is not, it is base64-encoded!
+ * Returns the description of the bookmark. Note that the description may
+ * be {@code null} and if it is not, it is base64-encoded!
*
* @return The bookmark’s description, or {@code null} if the bookmark has
* no description
*
* @author David ‘Bombe’ Roden <bombe@freenetproject.org>
*/
-public class SSKKeypair extends BaseMessage {
+public class SSKKeypair extends BaseMessage implements Identifiable {
/**
* Creates a new “SSKKeypair” message that wraps the received message.
*
* @return The identifier of the request
*/
+ @Override
public String getIdentifier() {
return getField("Identifier");
}
* @param description
* The description of the bookmark (may be {@code null})
* @param hasActiveLink
- * {@code true} if the bookmark has an activelink image, {@code
- * false} otherwise
+ * {@code true} if the bookmark has an activelink image,
+ * {@code false} otherwise
*/
public SendBookmarkFeed(String identifier, String nodeIdentifier, String name, String uri, String description, boolean hasActiveLink) {
super("SendBookmarkFeed", identifier, nodeIdentifier);
*
* @author David ‘Bombe’ Roden <bombe@freenetproject.org>
*/
-public class SentFeed extends BaseMessage {
+public class SentFeed extends BaseMessage implements Identifiable {
/**
* Creates a new “SentFeed” message from the given FCP message.
*
* @return The send feed’s identifier
*/
+ @Override
public String getIdentifier() {
return getField("Identifier");
}
*
* @author David ‘Bombe’ Roden <bombe@freenetproject.org>
*/
-public class SimpleProgress extends BaseMessage {
+public class SimpleProgress extends BaseMessage implements Identifiable {
/**
* Creates a new “SimpleProgress” message that wraps the received message.
*
* @return The identifier of the request
*/
+ @Override
public String getIdentifier() {
return getField("Identifier");
}
*
* @author David ‘Bombe’ Roden <bombe@freenetproject.org>
*/
-public class StartedCompression extends BaseMessage {
+public class StartedCompression extends BaseMessage implements Identifiable {
/**
* Creates a new “StartedCompression” message that wraps the received
*
* @return The identifier of the request
*/
+ @Override
public String getIdentifier() {
return getField("Identifier");
}
package net.pterodactylus.fcp;
/**
- * A “SubscribedUSKUpdate” message is sent each time a new edition of a USK that
- * was previously subscribed to with {@link SubscribeUSK} was found. Note that
- * if the new edition that was found is several editions ahead of the currently
- * last known edition, you will received a SubscribedUSKUpdate for each edition
- * inbetween as welL!
+ * A “SubscribedUSKUpdate” message is sent each time a new edition of a USK
+ * that was previously subscribed to with {@link SubscribeUSK} was found. Note
+ * that if the new edition that was found is several editions ahead of the
+ * currently last known edition, you will received a SubscribedUSKUpdate for
+ * each edition inbetween as welL!
*
* @author David ‘Bombe’ Roden <bombe@freenetproject.org>
*/
-public class SubscribedUSKUpdate extends BaseMessage {
+public class SubscribedUSKUpdate extends BaseMessage implements Identifiable {
/**
* Creates a new “SubscribedUSKUpdate” message that wraps the received
*
* @return The identifier of the subscription
*/
+ @Override
public String getIdentifier() {
return getField("Identifier");
}
* The “TestDDAReply” is sent as a response to {@link TestDDARequest}. If you
* specified that you wanted to read files from that directory
* {@link #getReadFilename()} will give you a filename. Similarly, if you
- * specified that you want to write in the directory {@link #getWriteFilename()}
- * will give you a filename to write {@link #getContentToWrite()} to.
+ * specified that you want to write in the directory
+ * {@link #getWriteFilename()} will give you a filename to write
+ * {@link #getContentToWrite()} to.
*
* @author David ‘Bombe’ Roden <bombe@freenetproject.org>
*/
* @param directory
* The directory you want to access files in
* @param wantReadDirectory
- * <code>true</code> if you want to read files from the directory
+ * <code>true</code> if you want to read files from the
+ * directory
* @param wantWriteDirectory
* <code>true</code> if you want to write files to the directory
*/
/**
* A “TestDDAResponse” is sent to let the node know that either created a file
* with the content from {@link TestDDAReply#getContentToWrite()} or that you
- * read the content of the file given by {@link TestDDAReply#getReadFilename()}.
+ * read the content of the file given by {@link TestDDAReply#getReadFilename()}
+ * .
*
* @author David ‘Bombe’ Roden <bombe@freenetproject.org>
*/
public class TestDDAResponse extends FcpMessage {
/**
- * Creates a new “TestDDAResponse” message that signals that you created the
- * file given by {@link TestDDAReply#getWriteFilename()} and wrote the
+ * Creates a new “TestDDAResponse” message that signals that you created
+ * the file given by {@link TestDDAReply#getWriteFilename()} and wrote the
* contents given by {@link TestDDAReply#getContentToWrite()} to it.
*
* @param directory
}
/**
- * Creates a new “TestDDAResponse” message that signals that you created the
- * file given by {@link TestDDAReply#getWriteFilename()} with the contents
- * given by {@link TestDDAReply#getContentToWrite()} to it (when you
- * specified that you want to write to the directory) and/or that you read
- * the file given by {@link TestDDAReply#getReadFilename()} (when you
+ * Creates a new “TestDDAResponse” message that signals that you created
+ * the file given by {@link TestDDAReply#getWriteFilename()} with the
+ * contents given by {@link TestDDAReply#getContentToWrite()} to it (when
+ * you specified that you want to write to the directory) and/or that you
+ * read the file given by {@link TestDDAReply#getReadFilename()} (when you
* specified you wanted to read the directory).
*
* @param directory
package net.pterodactylus.fcp;
/**
- * The “URIGenerated” message signals the client that an URI was generated for a
- * {@link ClientPut} (or {@link ClientPutDiskDir} or {@link ClientPutComplexDir}
- * ) request.
+ * The “URIGenerated” message signals the client that an URI was generated for
+ * a {@link ClientPut} (or {@link ClientPutDiskDir} or
+ * {@link ClientPutComplexDir} ) request.
*
* @author David ‘Bombe’ Roden <bombe@freenetproject.org>
*/
-public class URIGenerated extends BaseMessage {
+public class URIGenerated extends BaseMessage implements Identifiable {
/**
* Creates a new “URIGenerated” message that wraps the received message.
*
* @return The identifier of the request
*/
+ @Override
public String getIdentifier() {
return getField("Identifier");
}
}
/**
- * Returns whether the request that generated the URI is on the global queue
- * or on the client-local queue.
+ * Returns whether the request that generated the URI is on the global
+ * queue or on the client-local queue.
*
* @return <code>true</code> if the request is on the global queue,
* <code>false</code> if it is on the client-local queue
/**
* Convenicence class for verbosity handling. This might come in handy with the
- * {@link ClientPut} and {@link ClientGet} requests. The verbosity is a bit-mask
- * that can be composed of several bits. {@link #PROGRESS} and
+ * {@link ClientPut} and {@link ClientGet} requests. The verbosity is a
+ * bit-mask that can be composed of several bits. {@link #PROGRESS} and
* {@link #COMPRESSION} are single bits in that mask and can be combined into a
* new verbosity using {@link #add(Verbosity)}.
*
*
* @param s
* The string to parse
- * @return The parsed verbosity, or {@link #NONE} if the string could not be
- * parsed
+ * @return The parsed verbosity, or {@link #NONE} if the string could not
+ * be parsed
*/
public static Verbosity valueOf(String s) {
try {
/**
* Creates a new Version from the given string. The string consists of the
- * four required fields node name, tree version, protocol version, and build
- * number, separated by a comma.
+ * four required fields node name, tree version, protocol version, and
+ * build number, separated by a comma.
*
* @param version
* The version string
package net.pterodactylus.fcp.highlevel;
+import static com.google.common.collect.FluentIterable.from;
+
+import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.net.InetAddress;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
-import java.util.Set;
import java.util.Map.Entry;
+import java.util.Set;
import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.atomic.AtomicReference;
import net.pterodactylus.fcp.AddPeer;
+import net.pterodactylus.fcp.AllData;
+import net.pterodactylus.fcp.ClientGet;
import net.pterodactylus.fcp.ClientHello;
import net.pterodactylus.fcp.CloseConnectionDuplicateClientName;
import net.pterodactylus.fcp.DataFound;
import net.pterodactylus.fcp.SSKKeypair;
import net.pterodactylus.fcp.SimpleProgress;
import net.pterodactylus.fcp.WatchGlobal;
-import net.pterodactylus.util.filter.Filter;
-import net.pterodactylus.util.filter.Filters;
-import net.pterodactylus.util.thread.ObjectWrapper;
+
+import com.google.common.base.Predicate;
/**
* High-level FCP client that hides the details of the underlying FCP
*
* @author David ‘Bombe’ Roden <bombe@freenetproject.org>
*/
-public class FcpClient {
+public class FcpClient implements Closeable {
/** Object used for synchronization. */
private final Object syncObject = new Object();
/** Listener management. */
private final FcpClientListenerManager fcpClientListenerManager = new FcpClientListenerManager(this);
- /** The name of this client. */
- private final String name;
-
/** The underlying FCP connection. */
private final FcpConnection fcpConnection;
/** Whether the client is currently connected. */
private volatile boolean connected;
+ /** The listener for “connection closed” events. */
+ private FcpListener connectionClosedListener;
+
/**
* Creates an FCP client with the given name.
*
- * @param name
- * The name of the FCP client
* @throws UnknownHostException
* if the hostname “localhost” is unknown
*/
- public FcpClient(String name) throws UnknownHostException {
- this(name, "localhost");
+ public FcpClient() throws UnknownHostException {
+ this("localhost");
}
/**
* Creates an FCP client.
*
- * @param name
- * The name of the FCP client
* @param hostname
* The hostname of the Freenet node
* @throws UnknownHostException
* if the given hostname can not be resolved
*/
- public FcpClient(String name, String hostname) throws UnknownHostException {
- this(name, hostname, FcpConnection.DEFAULT_PORT);
+ public FcpClient(String hostname) throws UnknownHostException {
+ this(hostname, FcpConnection.DEFAULT_PORT);
}
/**
* Creates an FCP client.
*
- * @param name
- * The name of the FCP client
* @param hostname
* The hostname of the Freenet node
* @param port
* @throws UnknownHostException
* if the given hostname can not be resolved
*/
- public FcpClient(String name, String hostname, int port) throws UnknownHostException {
- this(name, InetAddress.getByName(hostname), port);
+ public FcpClient(String hostname, int port) throws UnknownHostException {
+ this(InetAddress.getByName(hostname), port);
}
/**
* Creates an FCP client.
*
- * @param name
- * The name of the FCP client
* @param host
* The host address of the Freenet node
*/
- public FcpClient(String name, InetAddress host) {
- this(name, host, FcpConnection.DEFAULT_PORT);
+ public FcpClient(InetAddress host) {
+ this(host, FcpConnection.DEFAULT_PORT);
}
/**
* Creates an FCP client.
*
- * @param name
- * The name of the FCP client
* @param host
* The host address of the Freenet node
* @param port
* The Freenet node’s FCP port
*/
- public FcpClient(String name, InetAddress host, int port) {
- this.name = name;
- fcpConnection = new FcpConnection(host, port);
- fcpConnection.addFcpListener(new FcpAdapter() {
+ public FcpClient(InetAddress host, int port) {
+ this(new FcpConnection(host, port), false);
+ }
+
+ /**
+ * Creates a new high-level FCP client that will use the given connection.
+ * This constructor will assume that the FCP connection is already
+ * connected.
+ *
+ * @param fcpConnection
+ * The FCP connection to use
+ */
+ public FcpClient(FcpConnection fcpConnection) {
+ this(fcpConnection, true);
+ }
+
+ /**
+ * Creates a new high-level FCP client that will use the given connection.
+ *
+ * @param fcpConnection
+ * The FCP connection to use
+ * @param connected
+ * The initial status of the FCP connection
+ */
+ public FcpClient(FcpConnection fcpConnection, boolean connected) {
+ this.fcpConnection = fcpConnection;
+ this.connected = connected;
+ connectionClosedListener = new FcpAdapter() {
/**
* {@inheritDoc}
@Override
@SuppressWarnings("synthetic-access")
public void connectionClosed(FcpConnection fcpConnection, Throwable throwable) {
- connected = false;
+ FcpClient.this.connected = false;
fcpClientListenerManager.fireFcpClientDisconnected();
}
- });
+ };
+ fcpConnection.addFcpListener(connectionClosedListener);
}
//
/**
* Connects the FCP client.
*
+ * @param name
+ * The name of the client
* @throws IOException
* if an I/O error occurs
* @throws FcpException
* if an FCP error occurs
*/
- public void connect() throws IOException, FcpException {
+ public void connect(final String name) throws IOException, FcpException {
checkConnected(false);
connected = true;
new ExtendedFcpAdapter() {
}
/**
+ * Returns the file with the given URI. The retrieved data will be run
+ * through Freenet’s content filter.
+ *
+ * @param uri
+ * The URI to get
+ * @return The result of the get request
+ * @throws IOException
+ * if an I/O error occurs
+ * @throws FcpException
+ * if an FCP error occurs
+ */
+ public GetResult getURI(final String uri) throws IOException, FcpException {
+ return getURI(uri, true);
+ }
+
+ /**
+ * Returns the file with the given URI.
+ *
+ * @param uri
+ * The URI to get
+ * @param filterData
+ * {@code true} to filter the retrieved data, {@code false}
+ * otherwise
+ * @return The result of the get request
+ * @throws IOException
+ * if an I/O error occurs
+ * @throws FcpException
+ * if an FCP error occurs
+ */
+ public GetResult getURI(final String uri, final boolean filterData) throws IOException, FcpException {
+ checkConnected(true);
+ final GetResult getResult = new GetResult();
+ new ExtendedFcpAdapter() {
+
+ @SuppressWarnings("synthetic-access")
+ private final String identifier = createIdentifier("client-get");
+
+ @Override
+ @SuppressWarnings("synthetic-access")
+ public void run() throws IOException {
+ ClientGet clientGet = new ClientGet(uri, identifier);
+ clientGet.setFilterData(filterData);
+ fcpConnection.sendMessage(clientGet);
+ }
+
+ @Override
+ public void receivedGetFailed(FcpConnection fcpConnection, GetFailed getFailed) {
+ if (!getFailed.getIdentifier().equals(identifier)) {
+ return;
+ }
+ if ((getFailed.getCode() == 27) || (getFailed.getCode() == 24)) {
+ /* redirect! */
+ String newUri = getFailed.getRedirectURI();
+ getResult.realUri(newUri);
+ try {
+ ClientGet clientGet = new ClientGet(newUri, identifier);
+ clientGet.setFilterData(filterData);
+ fcpConnection.sendMessage(clientGet);
+ } catch (IOException ioe1) {
+ getResult.success(false).exception(ioe1);
+ completionLatch.countDown();
+ }
+ } else {
+ getResult.success(false).errorCode(getFailed.getCode());
+ completionLatch.countDown();
+ }
+ }
+
+ @Override
+ public void receivedAllData(FcpConnection fcpConnection, AllData allData) {
+ if (!allData.getIdentifier().equals(identifier)) {
+ return;
+ }
+ getResult.success(true).contentType(allData.getContentType()).contentLength(allData.getDataLength()).inputStream(allData.getPayloadInputStream());
+ completionLatch.countDown();
+ }
+
+ }.execute();
+ return getResult;
+ }
+
+ /**
* Disconnects the FCP client.
*/
public void disconnect() {
}
/**
+ * {@inheritDoc}
+ */
+ @Override
+ public void close() {
+ disconnect();
+ }
+
+ /**
* Returns whether this client is currently connected.
*
* @return {@code true} if the client is currently connected, {@code false}
return connected;
}
+ /**
+ * Detaches this client from its underlying FCP connection.
+ */
+ public void detach() {
+ fcpConnection.removeFcpListener(connectionClosedListener);
+ }
+
//
// PEER MANAGEMENT
//
/**
* Adds a peer, reading the noderef of the peer from the given file.
- * <strong>Note:</strong> the file to read the noderef from has to reside on
- * the same machine as the node!
+ * <strong>Note:</strong> the file to read the noderef from has to reside
+ * on the same machine as the node!
*
* @param file
* The name of the file containing the peer’s noderef
* if an FCP error occurs
*/
public PeerNote getPeerNote(final Peer peer) throws IOException, FcpException {
- final ObjectWrapper<PeerNote> objectWrapper = new ObjectWrapper<PeerNote>();
+ final AtomicReference<PeerNote> objectWrapper = new AtomicReference<PeerNote>();
new ExtendedFcpAdapter() {
/**
* if an FCP error occurs
*/
public SSKKeypair generateKeyPair() throws IOException, FcpException {
- final ObjectWrapper<SSKKeypair> sskKeypairWrapper = new ObjectWrapper<SSKKeypair>();
+ final AtomicReference<SSKKeypair> sskKeypairWrapper = new AtomicReference<SSKKeypair>();
new ExtendedFcpAdapter() {
/**
* if an FCP error occurs
*/
public Collection<Request> getGetRequests(final boolean global) throws IOException, FcpException {
- return Filters.filteredCollection(getRequests(global), new Filter<Request>() {
-
- /**
- * {@inheritDoc}
- */
- public boolean filterObject(Request request) {
+ return from(getRequests(global)).filter(new Predicate<Request>() {
+ @Override
+ public boolean apply(Request request) {
return request instanceof GetRequest;
}
- });
+ }).toList();
}
/**
* if an FCP error occurs
*/
public Collection<Request> getPutRequests(final boolean global) throws IOException, FcpException {
- return Filters.filteredCollection(getRequests(global), new Filter<Request>() {
-
- /**
- * {@inheritDoc}
- */
- public boolean filterObject(Request request) {
+ return from(getRequests(global)).filter(new Predicate<Request>() {
+ @Override
+ public boolean apply(Request request) {
return request instanceof PutRequest;
}
- });
+ }).toList();
}
/**
*
* @param global
* <code>true</code> to return requests from the global queue,
- * <code>false</code> to only show requests from the client-local
- * queue
+ * <code>false</code> to only show requests from the
+ * client-local queue
* @return All requests
* @throws IOException
* if an I/O error occurs
* if an I/O error occurs
*/
public NodeData getNodeInformation(final Boolean giveOpennetRef, final Boolean withPrivate, final Boolean withVolatile) throws IOException, FcpException {
- final ObjectWrapper<NodeData> nodeDataWrapper = new ObjectWrapper<NodeData>();
+ final AtomicReference<NodeData> nodeDataWrapper = new AtomicReference<NodeData>();
new ExtendedFcpAdapter() {
@Override
package net.pterodactylus.fcp.highlevel;
-import net.pterodactylus.util.event.AbstractListenerManager;
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
/**
* Manages {@link FcpClientListener}s and fires events.
*
* @author David ‘Bombe’ Roden <bombe@freenetproject.org>
*/
-public class FcpClientListenerManager extends AbstractListenerManager<FcpClient, FcpClientListener> {
+public class FcpClientListenerManager {
+
+ private final FcpClient source;
+ private final List<FcpClientListener> listeners = new CopyOnWriteArrayList<FcpClientListener>();
/**
* Creates a new FCP client listener manager.
* The source FCP client
*/
public FcpClientListenerManager(FcpClient fcpClient) {
- super(fcpClient);
+ this.source = fcpClient;
+ }
+
+ private FcpClient getSource() {
+ return source;
+ }
+
+ public List<FcpClientListener> getListeners() {
+ return listeners;
}
/**
}
}
+ public void addListener(FcpClientListener fcpClientListener) {
+ listeners.add(fcpClientListener);
+ }
+
+ public void removeListener(FcpClientListener fcpClientListener) {
+ listeners.remove(fcpClientListener);
+ }
+
}
--- /dev/null
+/*
+ * jFCPlib - GetResult.java - Copyright © 2010 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 3 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, see <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.fcp.highlevel;
+
+import java.io.InputStream;
+import java.util.EventListener;
+
+/**
+ * A get result encapsulates the result of {@link FcpClient#getURI(String)}. It
+ * is used to allow synchronous retrieval of a file without resorting to
+ * {@link EventListener} interfaces to notify the application of intermediary
+ * results, such as redirects.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class GetResult {
+
+ /** Whether the request was successful. */
+ private boolean success;
+
+ /** The error code, if an error occured. */
+ private int errorCode;
+
+ /** The exception, if an exception occured. */
+ private Throwable exception;
+
+ /** The real URI, if a redirect was found. */
+ private String realUri;
+
+ /** The content type of the file. */
+ private String contentType;
+
+ /** The length of the file. */
+ private long contentLength;
+
+ /** An input stream containing the data of the file. */
+ private InputStream inputStream;
+
+ /**
+ * Returns whether the request was successful.
+ *
+ * @return {@code true} if the request was successful, {@code false}
+ * otherwise
+ */
+ public boolean isSuccess() {
+ return success;
+ }
+
+ /**
+ * Sets whether the request was successful.
+ *
+ * @param success
+ * {@code true} if the request was successful, {@code false}
+ * otherwise
+ * @return This result, to allow method chaning
+ */
+ GetResult success(boolean success) {
+ this.success = success;
+ return this;
+ }
+
+ /**
+ * Returns the error code of the request. The error code is the error code
+ * that is transferred in FCP’s “GetFailed” message. The error code is not
+ * valid if {@link #isSuccess()} is {@code true}. If an exception occured
+ * (i.e. if {@link #getException()} returns a non-{@code null} value) the
+ * error code might also be invalid.
+ *
+ * @return The error code of the request
+ */
+ public int getErrorCode() {
+ return errorCode;
+ }
+
+ /**
+ * Sets the error code of the request.
+ *
+ * @param errorCode
+ * The error code of the request
+ * @return This result, to allow method chaining
+ */
+ GetResult errorCode(int errorCode) {
+ this.errorCode = errorCode;
+ return this;
+ }
+
+ /**
+ * Returns the exception, if any occured.
+ *
+ * @return The occured exception, or {@code null} if there was no exception
+ */
+ public Throwable getException() {
+ return exception;
+ }
+
+ /**
+ * Sets the exception that occured.
+ *
+ * @param exception
+ * The occured exception
+ * @return This result, to allow method chaining
+ */
+ GetResult exception(Throwable exception) {
+ this.exception = exception;
+ return this;
+ }
+
+ /**
+ * Returns the real URI in case of a redirect.
+ *
+ * @return The real URI, or {@code null} if there was no redirect
+ */
+ public String getRealUri() {
+ return realUri;
+ }
+
+ /**
+ * Sets the real URI in case of a redirect.
+ *
+ * @param realUri
+ * The real URI
+ * @return This result, to allow method chaining
+ */
+ GetResult realUri(String realUri) {
+ this.realUri = realUri;
+ return this;
+ }
+
+ /**
+ * Returns the content type of the result.
+ *
+ * @return The content type of the result
+ */
+ public String getContentType() {
+ return contentType;
+ }
+
+ /**
+ * Sets the content type of the result.
+ *
+ * @param contentType
+ * The content type of the result
+ * @return This result, to allow method chaining
+ */
+ GetResult contentType(String contentType) {
+ this.contentType = contentType;
+ return this;
+ }
+
+ /**
+ * Returns the content length of the result.
+ *
+ * @return The content length of the result
+ */
+ public long getContentLength() {
+ return contentLength;
+ }
+
+ /**
+ * Sets the content length of the result.
+ *
+ * @param contentLength
+ * The content length of the result
+ * @return This result, to allow method chaining
+ */
+ GetResult contentLength(long contentLength) {
+ this.contentLength = contentLength;
+ return this;
+ }
+
+ /**
+ * Returns the data.
+ *
+ * @return The data
+ */
+ public InputStream getInputStream() {
+ return inputStream;
+ }
+
+ /**
+ * Sets the input stream that will deliver the data.
+ *
+ * @param inputStream
+ * The input stream containing the data
+ * @return This result, to allow method chaining
+ */
+ GetResult inputStream(InputStream inputStream) {
+ this.inputStream = inputStream;
+ return this;
+ }
+
+ //
+ // OBJECT METHODS
+ //
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toString() {
+ return getClass().getName() + "[success=" + success + ",errorCode=" + errorCode + ",exception=" + exception + ",realUri=" + realUri + ",contentType=" + contentType + ",contentLength=" + contentLength + ",inputStream=" + inputStream + "]";
+ }
+
+}
* Sets whether this request is complete.
*
* @param complete
- * <code>true</code> if this request is complete, false otherwise
+ * <code>true</code> if this request is complete, false
+ * otherwise
*/
void setComplete(boolean complete) {
this.complete = complete;
}
/**
- * Returns whether this request has fatally failed, i.e. repitition will not
- * cause the request to succeed.
+ * Returns whether this request has fatally failed, i.e. repitition will
+ * not cause the request to succeed.
*
* @return <code>true</code> if this request can not be made succeed by
* repeating, <code>false</code> otherwise
}
/**
- * Returns the number of required blocks. Any progress percentages should be
- * calculated against this value as 100%. Also, as long as
+ * Returns the number of required blocks. Any progress percentages should
+ * be calculated against this value as 100%. Also, as long as
* {@link #isFinalizedTotal()} returns {@code false} this value might
* change.
*
/**
* Package that holds all the message types that are used in the communication
* with a Freenet Node.
- *
+ *
* <h2>Usage</h2>
- *
+ *
* This library was designed to implement the full range of the Freenet Client
* Protocol, Version 2.0. At the moment the library provides a rather low-level
* approach, wrapping each FCP message into its own object but some kind of
* high-level client that does not require any interfaces to be implemented
* will probably provided as well.
- *
+ *
* First, create a connection to the node:
- *
+ *
* <pre>
* FcpConnection fcpConnection = new FcpConnection();
* </pre>
- *
+ *
* Now implement the {@link net.pterodactylus.fcp.FcpListener} interface
* and handle all incoming events.
- *
+ *
* <pre>
* public class MyClass implements FcpListener {
- *
+ *
* public void receivedProtocolError(FcpConnection fcpConnection, ProtocolError protocolError) {
* …
* }
- *
+ *
* // implement all further methods here
- *
+ *
* }
* </pre>
*/
--- /dev/null
+/*
+ * jFCPlib - CalculatedTrust.java - Copyright © 2009–2014 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.plugin;
+
+/**
+ * Container that stores the trust that is calculated by taking all trustees
+ * and their trust lists into account.
+ *
+ * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
+ */
+public class CalculatedTrust {
+
+ /** The calculated trust value. */
+ private final Byte trust;
+
+ /** The calculated score value. */
+ private final Integer score;
+
+ /** The calculated rank. */
+ private final Integer rank;
+
+ /**
+ * Creates a new calculated trust container.
+ *
+ * @param trust
+ * The calculated trust value
+ * @param score
+ * The calculated score value
+ * @param rank
+ * The calculated rank of the
+ */
+ public CalculatedTrust(Byte trust, Integer score, Integer rank) {
+ this.trust = trust;
+ this.score = score;
+ this.rank = rank;
+ }
+
+ /**
+ * Returns the calculated trust value.
+ *
+ * @return The calculated trust value, or {@code null} if the trust
+ * value is not known
+ */
+ public Byte getTrust() {
+ return trust;
+ }
+
+ /**
+ * Returns the calculated score value.
+ *
+ * @return The calculated score value, or {@code null} if the score
+ * value is not known
+ */
+ public Integer getScore() {
+ return score;
+ }
+
+ /**
+ * Returns the calculated rank.
+ *
+ * @return The calculated rank, or {@code null} if the rank is not known
+ */
+ public Integer getRank() {
+ return rank;
+ }
+
+}
--- /dev/null
+/*
+ * jFCPlib - Identity.java - Copyright © 2009–2014 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.plugin;
+
+/**
+ * Wrapper around a web-of-trust identity.
+ *
+ * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
+ */
+public class Identity {
+
+ /** The identity’s identifier. */
+ private final String identifier;
+
+ /** The identity’s nickname. */
+ private final String nickname;
+
+ /** The identity’s request URI. */
+ private final String requestUri;
+
+ /**
+ * Creates a new identity.
+ *
+ * @param identifier
+ * The identifies of the identity
+ * @param nickname
+ * The nickname of the identity
+ * @param requestUri
+ * The request URI of the identity
+ */
+ public Identity(String identifier, String nickname, String requestUri) {
+ this.identifier = identifier;
+ this.nickname = nickname;
+ this.requestUri = requestUri;
+ }
+
+ /**
+ * Returns the identifier of this identity.
+ *
+ * @return This identity’s identifier
+ */
+ public String getIdentifier() {
+ return identifier;
+ }
+
+ /**
+ * Returns the nickname of this identity.
+ *
+ * @return This identity’s nickname
+ */
+ public String getNickname() {
+ return nickname;
+ }
+
+ /**
+ * Returns the request URI of this identity.
+ *
+ * @return This identity’s request URI
+ */
+ public String getRequestUri() {
+ return requestUri;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if ((obj == null) || (obj.getClass() != this.getClass())) {
+ return false;
+ }
+ Identity identity = (Identity) obj;
+ return identifier.equals(identity.identifier);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int hashCode() {
+ return identifier.hashCode();
+ }
+
+}
--- /dev/null
+/*
+ * jFCPlib - IdentityTrust.java - Copyright © 2009–2014 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.plugin;
+
+/**
+ * Container for the trust given from one identity to another.
+ *
+ * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
+ */
+public class IdentityTrust {
+
+ /** The trust given to the identity. */
+ private final byte trust;
+
+ /** The command for the trust value. */
+ private final String comment;
+
+ /**
+ * Creates a new identity trust container.
+ *
+ * @param trust
+ * The trust given to the identity
+ * @param comment
+ * The comment for the trust value
+ */
+ public IdentityTrust(byte trust, String comment) {
+ this.trust = trust;
+ this.comment = comment;
+ }
+
+ /**
+ * Returns the trust value given to the identity.
+ *
+ * @return The trust value
+ */
+ public byte getTrust() {
+ return trust;
+ }
+
+ /**
+ * Returns the comment for the trust value.
+ *
+ * @return The comment for the trust value
+ */
+ public String getComment() {
+ return comment;
+ }
+
+}
--- /dev/null
+/*
+ * jFCPlib - OwnIdentity.java - Copyright © 2009–2014 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.plugin;
+
+/**
+ * Wrapper around a web-of-trust own identity.
+ *
+ * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
+ */
+public class OwnIdentity extends Identity {
+
+ /** The identity’s insert URI. */
+ private final String insertUri;
+
+ /**
+ * Creates a new web-of-trust own identity.
+ *
+ * @param identifier
+ * The identifier of the identity
+ * @param nickname
+ * The nickname of the identity
+ * @param requestUri
+ * The request URI of the identity
+ * @param insertUri
+ * The insert URI of the identity
+ */
+ public OwnIdentity(String identifier, String nickname, String requestUri, String insertUri) {
+ super(identifier, nickname, requestUri);
+ this.insertUri = insertUri;
+ }
+
+ /**
+ * Returns the insert URI of this identity.
+ *
+ * @return This identity’s insert URI
+ */
+ public String getInsertUri() {
+ return insertUri;
+ }
+
+}
/*
- * jFCPlib - WebOfTrustPlugin.java - Copyright © 2009 David Roden
+ * jFCPlib - WebOfTrustPlugin.java - Copyright © 2009–2014 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
return parameterMap;
}
- /**
- * Wrapper around a web-of-trust identity.
- *
- * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
- */
- public static class Identity {
-
- /** The identity’s identifier. */
- private final String identifier;
-
- /** The identity’s nickname. */
- private final String nickname;
-
- /** The identity’s request URI. */
- private final String requestUri;
-
- /**
- * Creates a new identity.
- *
- * @param identifier
- * The identifies of the identity
- * @param nickname
- * The nickname of the identity
- * @param requestUri
- * The request URI of the identity
- */
- public Identity(String identifier, String nickname, String requestUri) {
- this.identifier = identifier;
- this.nickname = nickname;
- this.requestUri = requestUri;
- }
-
- /**
- * Returns the identifier of this identity.
- *
- * @return This identity’s identifier
- */
- public String getIdentifier() {
- return identifier;
- }
-
- /**
- * Returns the nickname of this identity.
- *
- * @return This identity’s nickname
- */
- public String getNickname() {
- return nickname;
- }
-
- /**
- * Returns the request URI of this identity.
- *
- * @return This identity’s request URI
- */
- public String getRequestUri() {
- return requestUri;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean equals(Object obj) {
- if ((obj == null) || (obj.getClass() != this.getClass())) {
- return false;
- }
- Identity identity = (Identity) obj;
- return identifier.equals(identity.identifier);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public int hashCode() {
- return identifier.hashCode();
- }
-
- }
-
- /**
- * Container for the trust given from one identity to another.
- *
- * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
- */
- public static class IdentityTrust {
-
- /** The trust given to the identity. */
- private final byte trust;
-
- /** The command for the trust value. */
- private final String comment;
-
- /**
- * Creates a new identity trust container.
- *
- * @param trust
- * The trust given to the identity
- * @param comment
- * The comment for the trust value
- */
- public IdentityTrust(byte trust, String comment) {
- this.trust = trust;
- this.comment = comment;
- }
-
- /**
- * Returns the trust value given to the identity.
- *
- * @return The trust value
- */
- public byte getTrust() {
- return trust;
- }
-
- /**
- * Returns the comment for the trust value.
- *
- * @return The comment for the trust value
- */
- public String getComment() {
- return comment;
- }
-
- }
-
- /**
- * Container that stores the trust that is calculated by taking all trustees
- * and their trust lists into account.
- *
- * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
- */
- public static class CalculatedTrust {
-
- /** The calculated trust value. */
- private final Byte trust;
-
- /** The calculated score value. */
- private final Integer score;
-
- /** The calculated rank. */
- private final Integer rank;
-
- /**
- * Creates a new calculated trust container.
- *
- * @param trust
- * The calculated trust value
- * @param score
- * The calculated score value
- * @param rank
- * The calculated rank of the
- */
- public CalculatedTrust(Byte trust, Integer score, Integer rank) {
- this.trust = trust;
- this.score = score;
- this.rank = rank;
- }
-
- /**
- * Returns the calculated trust value.
- *
- * @return The calculated trust value, or {@code null} if the trust
- * value is not known
- */
- public Byte getTrust() {
- return trust;
- }
-
- /**
- * Returns the calculated score value.
- *
- * @return The calculated score value, or {@code null} if the score
- * value is not known
- */
- public Integer getScore() {
- return score;
- }
-
- /**
- * Returns the calculated rank.
- *
- * @return The calculated rank, or {@code null} if the rank is not known
- */
- public Integer getRank() {
- return rank;
- }
-
- }
-
- /**
- * Wrapper around a web-of-trust own identity.
- *
- * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
- */
- public static class OwnIdentity extends Identity {
-
- /** The identity’s insert URI. */
- private final String insertUri;
-
- /**
- * Creates a new web-of-trust own identity.
- *
- * @param identifier
- * The identifier of the identity
- * @param nickname
- * The nickname of the identity
- * @param requestUri
- * The request URI of the identity
- * @param insertUri
- * The insert URI of the identity
- */
- public OwnIdentity(String identifier, String nickname, String requestUri, String insertUri) {
- super(identifier, nickname, requestUri);
- this.insertUri = insertUri;
- }
-
- /**
- * Returns the insert URI of this identity.
- *
- * @return This identity’s insert URI
- */
- public String getInsertUri() {
- return insertUri;
- }
-
- }
-
}
+++ /dev/null
-/*
- * jFCPlib - FcpConnectionTest.java -
- * Copyright © 2008 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;
-
-import java.io.IOException;
-import java.io.InputStream;
-
-
-/**
- * TODO
- * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
- */
-public class FcpConnectionTest extends FcpAdapter {
-
- public static void main(String[] commandLine) throws IllegalStateException, IOException {
- new FcpConnectionTest();
- }
-
- private FcpConnectionTest() throws IllegalStateException, IOException {
- FcpConnection fcpConnection = new FcpConnection("wing");
- fcpConnection.addFcpListener(this);
- fcpConnection.connect();
- ClientHello clientHello = new ClientHello("bug-test");
- fcpConnection.sendMessage(clientHello);
- ClientGet clientGet = new ClientGet("KSK@gpl.txt", "test");
- fcpConnection.sendMessage(clientGet);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void receivedAllData(FcpConnection fcpConnection, AllData allData) {
- System.out.println("AllData");
- InputStream payloadInputStream = allData.getPayloadInputStream();
- int r = 0;
- byte[] buffer = new byte[1024];
- try {
- while ((r = payloadInputStream.read(buffer)) != -1) {
- for (int i = 0; i < r; i++) {
- System.out.print((char) buffer[i]);
- }
- }
- } catch (IOException e) {
- // TODO Auto-generated catch block
- }
- fcpConnection.close();
- }
-
-}
+++ /dev/null
-/*
- * jFCPlib - FcpTest.java - Copyright © 2008 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;
-
-import java.io.IOException;
-
-import junit.framework.TestCase;
-
-/**
- * Tests various commands and the FCP connection.
- *
- * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
- */
-public class FcpTest extends TestCase {
-
- /** The FCP connection. */
- private FcpConnection fcpConnection;
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected void setUp() throws Exception {
- fcpConnection = new FcpConnection("wing");
- fcpConnection.connect();
- fcpConnection.sendMessage(new ClientHello("FcpTest"));
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected void tearDown() throws Exception {
- fcpConnection.close();
- }
-
- /**
- * Tests the FCP connection be simply {@link #setUp() setting it up} and
- * {@link #tearDown() tearing it down} again.
- */
- public void testFcpConnection() {
- /* do nothing. */
- }
-
- /**
- * Generates an SSK key pair.
- *
- * @throws IOException
- * if an I/O error occurs
- * @throws InterruptedException
- * if {@link Object#wait()} wakes up spuriously
- */
- public void testGenerateSSK() throws IOException, InterruptedException {
- final SSKKeypair[] keypair = new SSKKeypair[1];
- FcpAdapter fcpAdapter = new FcpAdapter() {
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void receivedSSKKeypair(FcpConnection fcpConnection, SSKKeypair sskKeypair) {
- keypair[0] = sskKeypair;
- synchronized (this) {
- notify();
- }
- }
- };
- fcpConnection.addFcpListener(fcpAdapter);
- synchronized (fcpAdapter) {
- fcpConnection.sendMessage(new GenerateSSK());
- fcpAdapter.wait();
- }
- assertNotNull("ssk keypair", keypair[0]);
- }
-
-}