Merge branch 'release-0.1.3' into master
authorDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Fri, 21 Aug 2015 05:19:51 +0000 (07:19 +0200)
committerDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Fri, 21 Aug 2015 05:19:51 +0000 (07:19 +0200)
73 files changed:
.classpath [deleted file]
.project [deleted file]
pom.xml
src/main/java/net/pterodactylus/fcp/AllData.java
src/main/java/net/pterodactylus/fcp/ClientGet.java
src/main/java/net/pterodactylus/fcp/ClientPut.java
src/main/java/net/pterodactylus/fcp/ClientPutComplexDir.java
src/main/java/net/pterodactylus/fcp/ClientPutDiskDir.java
src/main/java/net/pterodactylus/fcp/DSAGroup.java
src/main/java/net/pterodactylus/fcp/DataFound.java
src/main/java/net/pterodactylus/fcp/EndListPeerNotes.java
src/main/java/net/pterodactylus/fcp/EndListPeers.java
src/main/java/net/pterodactylus/fcp/EndListPersistentRequests.java
src/main/java/net/pterodactylus/fcp/FCPPluginMessage.java
src/main/java/net/pterodactylus/fcp/FCPPluginReply.java
src/main/java/net/pterodactylus/fcp/FcpAdapter.java
src/main/java/net/pterodactylus/fcp/FcpConnection.java
src/main/java/net/pterodactylus/fcp/FcpConnectionHandler.java
src/main/java/net/pterodactylus/fcp/FcpListener.java
src/main/java/net/pterodactylus/fcp/FcpListenerManager.java
src/main/java/net/pterodactylus/fcp/FcpMessage.java
src/main/java/net/pterodactylus/fcp/FcpUtils.java
src/main/java/net/pterodactylus/fcp/FinishedCompression.java
src/main/java/net/pterodactylus/fcp/GetConfig.java
src/main/java/net/pterodactylus/fcp/GetFailed.java
src/main/java/net/pterodactylus/fcp/GetNode.java
src/main/java/net/pterodactylus/fcp/GetRequestStatus.java
src/main/java/net/pterodactylus/fcp/Identifiable.java [new file with mode: 0644]
src/main/java/net/pterodactylus/fcp/IdentifierCollision.java
src/main/java/net/pterodactylus/fcp/ListPeer.java
src/main/java/net/pterodactylus/fcp/ListPeers.java
src/main/java/net/pterodactylus/fcp/ModifyPeer.java
src/main/java/net/pterodactylus/fcp/ModifyPeerNote.java
src/main/java/net/pterodactylus/fcp/NodeData.java
src/main/java/net/pterodactylus/fcp/NodeHello.java
src/main/java/net/pterodactylus/fcp/NodeRef.java
src/main/java/net/pterodactylus/fcp/Peer.java
src/main/java/net/pterodactylus/fcp/PeerNote.java
src/main/java/net/pterodactylus/fcp/PersistentGet.java
src/main/java/net/pterodactylus/fcp/PersistentPut.java
src/main/java/net/pterodactylus/fcp/PersistentPutDir.java
src/main/java/net/pterodactylus/fcp/PersistentRequestModified.java
src/main/java/net/pterodactylus/fcp/PersistentRequestRemoved.java
src/main/java/net/pterodactylus/fcp/PluginInfo.java
src/main/java/net/pterodactylus/fcp/ProtocolError.java
src/main/java/net/pterodactylus/fcp/PutFailed.java
src/main/java/net/pterodactylus/fcp/PutFetchable.java
src/main/java/net/pterodactylus/fcp/PutSuccessful.java
src/main/java/net/pterodactylus/fcp/ReceivedBookmarkFeed.java
src/main/java/net/pterodactylus/fcp/SSKKeypair.java
src/main/java/net/pterodactylus/fcp/SendBookmarkFeed.java
src/main/java/net/pterodactylus/fcp/SentFeed.java
src/main/java/net/pterodactylus/fcp/SimpleProgress.java
src/main/java/net/pterodactylus/fcp/StartedCompression.java
src/main/java/net/pterodactylus/fcp/SubscribedUSKUpdate.java
src/main/java/net/pterodactylus/fcp/TestDDAReply.java
src/main/java/net/pterodactylus/fcp/TestDDARequest.java
src/main/java/net/pterodactylus/fcp/TestDDAResponse.java
src/main/java/net/pterodactylus/fcp/URIGenerated.java
src/main/java/net/pterodactylus/fcp/Verbosity.java
src/main/java/net/pterodactylus/fcp/Version.java
src/main/java/net/pterodactylus/fcp/highlevel/FcpClient.java
src/main/java/net/pterodactylus/fcp/highlevel/FcpClientListenerManager.java
src/main/java/net/pterodactylus/fcp/highlevel/GetResult.java [new file with mode: 0644]
src/main/java/net/pterodactylus/fcp/highlevel/Request.java
src/main/java/net/pterodactylus/fcp/package-info.java
src/main/java/net/pterodactylus/fcp/plugin/CalculatedTrust.java [new file with mode: 0644]
src/main/java/net/pterodactylus/fcp/plugin/Identity.java [new file with mode: 0644]
src/main/java/net/pterodactylus/fcp/plugin/IdentityTrust.java [new file with mode: 0644]
src/main/java/net/pterodactylus/fcp/plugin/OwnIdentity.java [new file with mode: 0644]
src/main/java/net/pterodactylus/fcp/plugin/WebOfTrustPlugin.java
test/main/java/net/pterodactylus/fcp/FcpConnectionTest.java [deleted file]
test/main/java/net/pterodactylus/fcp/FcpTest.java [deleted file]

diff --git a/.classpath b/.classpath
deleted file mode 100644 (file)
index 1f3c1ff..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-<?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>
diff --git a/.project b/.project
deleted file mode 100644 (file)
index 157656e..0000000
--- a/.project
+++ /dev/null
@@ -1,29 +0,0 @@
-<?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>
diff --git a/pom.xml b/pom.xml
index a698719..4309367 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -2,7 +2,7 @@
        <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>
@@ -43,6 +48,7 @@
                                <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>
index d1541bf..b4daa27 100644 (file)
@@ -22,16 +22,16 @@ import java.io.InputStream;
 
 /**
  * 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 &lt;bombe@freenetproject.org&gt;
  */
-public class AllData extends BaseMessage {
+public class AllData extends BaseMessage implements Identifiable {
 
        /** The payload. */
        private InputStream payloadInputStream;
@@ -54,6 +54,7 @@ public class AllData extends BaseMessage {
         *
         * @return The identifier of the request
         */
+       @Override
        public String getIdentifier() {
                return getField("Identifier");
        }
@@ -99,4 +100,13 @@ public class AllData extends BaseMessage {
                return payloadInputStream;
        }
 
+       /**
+        * Returns the content type of the found file.
+        *
+        * @return The content type
+        */
+       public String getContentType() {
+               return getField("Metadata.ContentType");
+       }
+
 }
index 8b03ee4..1126824 100644 (file)
@@ -89,8 +89,8 @@ public class ClientGet extends FcpMessage {
        }
 
        /**
-        * 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
@@ -174,6 +174,16 @@ public class ClientGet extends FcpMessage {
        }
 
        /**
+        * 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!
@@ -197,8 +207,8 @@ public class ClientGet extends FcpMessage {
        }
 
        /**
-        * 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
index f7dfabc..5dcbf71 100644 (file)
@@ -55,8 +55,8 @@ public class ClientPut extends FcpMessage {
         * 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
@@ -117,8 +117,8 @@ public class ClientPut extends FcpMessage {
        }
 
        /**
-        * 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,
@@ -129,6 +129,37 @@ public class ClientPut extends FcpMessage {
        }
 
        /**
+        * 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
@@ -144,17 +175,17 @@ public class ClientPut extends FcpMessage {
         * 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
index 55e5779..154c837 100644 (file)
@@ -102,6 +102,37 @@ public class ClientPutComplexDir extends FcpMessage {
        }
 
        /**
+        * 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
@@ -198,8 +229,8 @@ public class ClientPutComplexDir extends FcpMessage {
         * {@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) {
index d9b3924..67022e5 100644 (file)
@@ -78,8 +78,8 @@ public class ClientPutDiskDir extends FcpMessage {
        }
 
        /**
-        * 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,
@@ -90,6 +90,37 @@ public class ClientPutDiskDir extends FcpMessage {
        }
 
        /**
+        * 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
@@ -105,17 +136,17 @@ public class ClientPutDiskDir extends FcpMessage {
         * 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
@@ -135,8 +166,8 @@ public class ClientPutDiskDir extends FcpMessage {
        }
 
        /**
-        * 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
index 4674e66..b9f1fcd 100644 (file)
@@ -21,8 +21,8 @@ package net.pterodactylus.fcp;
 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 &lt;bombe@freenetproject.org&gt;
index 81318c1..742f6ac 100644 (file)
@@ -20,12 +20,12 @@ package net.pterodactylus.fcp;
 
 /**
  * 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 &lt;bombe@freenetproject.org&gt;
  */
-public class DataFound extends BaseMessage {
+public class DataFound extends BaseMessage implements Identifiable {
 
        /**
         * Creates a new “DataFound” message that wraps the received message.
@@ -52,6 +52,7 @@ public class DataFound extends BaseMessage {
         *
         * @return The identifier of the request
         */
+       @Override
        public String getIdentifier() {
                return getField("Identifier");
        }
index 5c381f6..31a52af 100644 (file)
@@ -27,7 +27,8 @@ package net.pterodactylus.fcp;
 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
index c0cf82f..bb98f23 100644 (file)
@@ -23,7 +23,7 @@ package net.pterodactylus.fcp;
  *
  * @author David ‘Bombe’ Roden &lt;bombe@freenetproject.org&gt;
  */
-public class EndListPeers extends BaseMessage {
+public class EndListPeers extends BaseMessage implements Identifiable {
 
        /**
         * Creates a new “EndListPeers” message that wraps the received message.
@@ -40,6 +40,7 @@ public class EndListPeers extends BaseMessage {
         *
         * @return The identifier of the request
         */
+       @Override
        public String getIdentifier() {
                return getField("Identifier");
        }
index 893f2f1..baa8de2 100644 (file)
@@ -27,8 +27,8 @@ package net.pterodactylus.fcp;
 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
index c167411..99cb0d0 100644 (file)
@@ -38,9 +38,9 @@ public class FCPPluginMessage extends FcpMessage {
        }
 
        /**
-        * 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
@@ -63,8 +63,8 @@ public class FCPPluginMessage extends FcpMessage {
 
        /**
         * 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
index c3b5281..44e96ba 100644 (file)
@@ -29,7 +29,7 @@ import java.util.Map.Entry;
  *
  * @author David ‘Bombe’ Roden &lt;bombe@freenetproject.org&gt;
  */
-public class FCPPluginReply extends BaseMessage {
+public class FCPPluginReply extends BaseMessage implements Identifiable {
 
        /** The payload input stream. */
        private final InputStream payloadInputStream;
@@ -61,6 +61,7 @@ public class FCPPluginReply extends BaseMessage {
         *
         * @return The identifier of the request
         */
+       @Override
        public String getIdentifier() {
                return getField("Identifier");
        }
index a358d4c..063d363 100644 (file)
@@ -28,6 +28,7 @@ public class FcpAdapter implements FcpListener {
        /**
         * {@inheritDoc}
         */
+       @Override
        public void receivedNodeHello(FcpConnection fcpConnection, NodeHello nodeHello) {
                /* empty. */
        }
@@ -35,6 +36,7 @@ public class FcpAdapter implements FcpListener {
        /**
         * {@inheritDoc}
         */
+       @Override
        public void receivedCloseConnectionDuplicateClientName(FcpConnection fcpConnection, CloseConnectionDuplicateClientName closeConnectionDuplicateClientName) {
                /* empty. */
        }
@@ -42,6 +44,7 @@ public class FcpAdapter implements FcpListener {
        /**
         * {@inheritDoc}
         */
+       @Override
        public void receivedSSKKeypair(FcpConnection fcpConnection, SSKKeypair sskKeypair) {
                /* empty. */
        }
@@ -49,6 +52,7 @@ public class FcpAdapter implements FcpListener {
        /**
         * {@inheritDoc}
         */
+       @Override
        public void receivedPeer(FcpConnection fcpConnection, Peer peer) {
                /* empty. */
        }
@@ -56,6 +60,7 @@ public class FcpAdapter implements FcpListener {
        /**
         * {@inheritDoc}
         */
+       @Override
        public void receivedEndListPeers(FcpConnection fcpConnection, EndListPeers endListPeers) {
                /* empty. */
        }
@@ -63,6 +68,7 @@ public class FcpAdapter implements FcpListener {
        /**
         * {@inheritDoc}
         */
+       @Override
        public void receivedPeerNote(FcpConnection fcpConnection, PeerNote peerNote) {
                /* empty. */
        }
@@ -70,6 +76,7 @@ public class FcpAdapter implements FcpListener {
        /**
         * {@inheritDoc}
         */
+       @Override
        public void receivedEndListPeerNotes(FcpConnection fcpConnection, EndListPeerNotes endListPeerNotes) {
                /* empty. */
        }
@@ -77,6 +84,7 @@ public class FcpAdapter implements FcpListener {
        /**
         * {@inheritDoc}
         */
+       @Override
        public void receivedPeerRemoved(FcpConnection fcpConnection, PeerRemoved peerRemoved) {
                /* empty. */
        }
@@ -86,6 +94,7 @@ public class FcpAdapter implements FcpListener {
         *
         * @see FcpListener#receivedNodeData(FcpConnection, NodeData)
         */
+       @Override
        public void receivedNodeData(FcpConnection fcpConnection, NodeData nodeData) {
                /* empty. */
        }
@@ -95,6 +104,7 @@ public class FcpAdapter implements FcpListener {
         *
         * @see FcpListener#receivedTestDDAReply(FcpConnection, TestDDAReply)
         */
+       @Override
        public void receivedTestDDAReply(FcpConnection fcpConnection, TestDDAReply testDDAReply) {
                /* empty. */
        }
@@ -102,6 +112,7 @@ public class FcpAdapter implements FcpListener {
        /**
         * {@inheritDoc}
         */
+       @Override
        public void receivedTestDDAComplete(FcpConnection fcpConnection, TestDDAComplete testDDAComplete) {
                /* empty. */
        }
@@ -109,6 +120,7 @@ public class FcpAdapter implements FcpListener {
        /**
         * {@inheritDoc}
         */
+       @Override
        public void receivedPersistentGet(FcpConnection fcpConnection, PersistentGet persistentGet) {
                /* empty. */
        }
@@ -116,6 +128,7 @@ public class FcpAdapter implements FcpListener {
        /**
         * {@inheritDoc}
         */
+       @Override
        public void receivedPersistentPut(FcpConnection fcpConnection, PersistentPut persistentPut) {
                /* empty. */
        }
@@ -123,6 +136,7 @@ public class FcpAdapter implements FcpListener {
        /**
         * {@inheritDoc}
         */
+       @Override
        public void receivedEndListPersistentRequests(FcpConnection fcpConnection, EndListPersistentRequests endListPersistentRequests) {
                /* empty. */
        }
@@ -130,6 +144,7 @@ public class FcpAdapter implements FcpListener {
        /**
         * {@inheritDoc}
         */
+       @Override
        public void receivedURIGenerated(FcpConnection fcpConnection, URIGenerated uriGenerated) {
                /* empty. */
        }
@@ -137,6 +152,7 @@ public class FcpAdapter implements FcpListener {
        /**
         * {@inheritDoc}
         */
+       @Override
        public void receivedDataFound(FcpConnection fcpConnection, DataFound dataFound) {
                /* empty. */
        }
@@ -144,6 +160,7 @@ public class FcpAdapter implements FcpListener {
        /**
         * {@inheritDoc}
         */
+       @Override
        public void receivedAllData(FcpConnection fcpConnection, AllData allData) {
                /* empty. */
        }
@@ -151,6 +168,7 @@ public class FcpAdapter implements FcpListener {
        /**
         * {@inheritDoc}
         */
+       @Override
        public void receivedSimpleProgress(FcpConnection fcpConnection, SimpleProgress simpleProgress) {
                /* empty. */
        }
@@ -158,6 +176,7 @@ public class FcpAdapter implements FcpListener {
        /**
         * {@inheritDoc}
         */
+       @Override
        public void receivedStartedCompression(FcpConnection fcpConnection, StartedCompression startedCompression) {
                /* empty. */
        }
@@ -165,6 +184,7 @@ public class FcpAdapter implements FcpListener {
        /**
         * {@inheritDoc}
         */
+       @Override
        public void receivedFinishedCompression(FcpConnection fcpConnection, FinishedCompression finishedCompression) {
                /* empty. */
        }
@@ -172,6 +192,7 @@ public class FcpAdapter implements FcpListener {
        /**
         * {@inheritDoc}
         */
+       @Override
        public void receivedUnknownPeerNoteType(FcpConnection fcpConnection, UnknownPeerNoteType unknownPeerNoteType) {
                /* empty. */
        }
@@ -179,6 +200,7 @@ public class FcpAdapter implements FcpListener {
        /**
         * {@inheritDoc}
         */
+       @Override
        public void receivedUnknownNodeIdentifier(FcpConnection fcpConnection, UnknownNodeIdentifier unknownNodeIdentifier) {
                /* empty. */
        }
@@ -186,6 +208,7 @@ public class FcpAdapter implements FcpListener {
        /**
         * {@inheritDoc}
         */
+       @Override
        public void receivedConfigData(FcpConnection fcpConnection, ConfigData configData) {
                /* empty. */
        }
@@ -193,6 +216,7 @@ public class FcpAdapter implements FcpListener {
        /**
         * {@inheritDoc}
         */
+       @Override
        public void receivedGetFailed(FcpConnection fcpConnection, GetFailed getFailed) {
                /* empty. */
        }
@@ -200,6 +224,7 @@ public class FcpAdapter implements FcpListener {
        /**
         * {@inheritDoc}
         */
+       @Override
        public void receivedPutFailed(FcpConnection fcpConnection, PutFailed putFailed) {
                /* empty. */
        }
@@ -207,6 +232,7 @@ public class FcpAdapter implements FcpListener {
        /**
         * {@inheritDoc}
         */
+       @Override
        public void receivedIdentifierCollision(FcpConnection fcpConnection, IdentifierCollision identifierCollision) {
                /* empty. */
        }
@@ -214,6 +240,7 @@ public class FcpAdapter implements FcpListener {
        /**
         * {@inheritDoc}
         */
+       @Override
        public void receivedPersistentPutDir(FcpConnection fcpConnection, PersistentPutDir persistentPutDir) {
                /* empty. */
        }
@@ -221,6 +248,7 @@ public class FcpAdapter implements FcpListener {
        /**
         * {@inheritDoc}
         */
+       @Override
        public void receivedPersistentRequestRemoved(FcpConnection fcpConnection, PersistentRequestRemoved persistentRequestRemoved) {
                /* empty. */
        }
@@ -228,6 +256,7 @@ public class FcpAdapter implements FcpListener {
        /**
         * {@inheritDoc}
         */
+       @Override
        public void receivedSubscribedUSKUpdate(FcpConnection fcpConnection, SubscribedUSKUpdate subscribedUSKUpdate) {
                /* empty. */
        }
@@ -235,6 +264,7 @@ public class FcpAdapter implements FcpListener {
        /**
         * {@inheritDoc}
         */
+       @Override
        public void receivedPluginInfo(FcpConnection fcpConnection, PluginInfo pluginInfo) {
                /* empty. */
        }
@@ -242,6 +272,7 @@ public class FcpAdapter implements FcpListener {
        /**
         * {@inheritDoc}
         */
+       @Override
        public void receivedFCPPluginReply(FcpConnection fcpConnection, FCPPluginReply fcpPluginReply) {
                /* empty. */
        }
@@ -249,6 +280,7 @@ public class FcpAdapter implements FcpListener {
        /**
         * {@inheritDoc}
         */
+       @Override
        public void receivedPersistentRequestModified(FcpConnection fcpConnection, PersistentRequestModified persistentRequestModified) {
                /* empty. */
        }
@@ -256,6 +288,7 @@ public class FcpAdapter implements FcpListener {
        /**
         * {@inheritDoc}
         */
+       @Override
        public void receivedPutSuccessful(FcpConnection fcpConnection, PutSuccessful putSuccessful) {
                /* empty. */
        }
@@ -263,6 +296,7 @@ public class FcpAdapter implements FcpListener {
        /**
         * {@inheritDoc}
         */
+       @Override
        public void receivedPutFetchable(FcpConnection fcpConnection, PutFetchable putFetchable) {
                /* empty. */
        }
@@ -270,6 +304,7 @@ public class FcpAdapter implements FcpListener {
        /**
         * {@inheritDoc}
         */
+       @Override
        public void receivedProtocolError(FcpConnection fcpConnection, ProtocolError protocolError) {
                /* empty. */
        }
@@ -277,6 +312,7 @@ public class FcpAdapter implements FcpListener {
        /**
         * {@inheritDoc}
         */
+       @Override
        public void receivedSentFeed(FcpConnection source, SentFeed sentFeed) {
                /* empty. */
        }
@@ -284,6 +320,7 @@ public class FcpAdapter implements FcpListener {
        /**
         * {@inheritDoc}
         */
+       @Override
        public void receivedBookmarkFeed(FcpConnection fcpConnection, ReceivedBookmarkFeed receivedBookmarkFeed) {
                /* empty. */
        }
@@ -291,6 +328,7 @@ public class FcpAdapter implements FcpListener {
        /**
         * {@inheritDoc}
         */
+       @Override
        public void receivedMessage(FcpConnection fcpConnection, FcpMessage fcpMessage) {
                /* empty. */
        }
@@ -298,6 +336,7 @@ public class FcpAdapter implements FcpListener {
        /**
         * {@inheritDoc}
         */
+       @Override
        public void connectionClosed(FcpConnection fcpConnection, Throwable throwable) {
                /* empty. */
        }
index 484e7c3..66377a2 100644 (file)
@@ -31,8 +31,6 @@ import java.util.HashMap;
 import java.util.Map;
 import java.util.logging.Logger;
 
-import net.pterodactylus.util.logging.Logging;
-
 /**
  * An FCP connection to a Freenet node.
  *
@@ -41,7 +39,7 @@ import net.pterodactylus.util.logging.Logging;
 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;
@@ -193,9 +191,10 @@ public class FcpConnection implements Closeable {
        }
 
        /**
-        * 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);
        }
@@ -323,8 +322,8 @@ public class FcpConnection implements Closeable {
         * 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);
@@ -372,8 +371,8 @@ public class FcpConnection implements Closeable {
        }
 
        /**
-        * 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 &lt;bombe@freenetproject.org&gt;
         */
index fcceec7..36be123 100644 (file)
@@ -25,8 +25,6 @@ import java.nio.charset.Charset;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
-import net.pterodactylus.util.logging.Logging;
-
 /**
  * Handles an FCP connection to a node.
  *
@@ -35,7 +33,7 @@ import net.pterodactylus.util.logging.Logging;
 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;
@@ -66,6 +64,7 @@ class FcpConnectionHandler implements Runnable {
        /**
         * {@inheritDoc}
         */
+       @Override
        public void run() {
                FcpMessage fcpMessage = null;
                Throwable throwable = null;
@@ -100,7 +99,7 @@ class FcpConnectionHandler implements Runnable {
                                }
                                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;
index 4f0c77a..02eeed5 100644 (file)
@@ -401,9 +401,10 @@ public interface FcpListener extends EventListener {
        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
@@ -413,15 +414,15 @@ public interface FcpListener extends EventListener {
        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);
 
index a312ec6..7969da1 100644 (file)
 
 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 &lt;bombe@pterodactylus.net&gt;
  */
-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.
@@ -34,7 +38,23 @@ public class FcpListenerManager extends AbstractListenerManager<FcpConnection, F
         *            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;
        }
 
        /**
@@ -291,7 +311,8 @@ public class FcpListenerManager extends AbstractListenerManager<FcpConnection, F
        }
 
        /**
-        * Notifies all listeners that a “FinishedCompression” message was received.
+        * Notifies all listeners that a “FinishedCompression” message was
+        * received.
         *
         * @see FcpListener#receivedFinishedCompression(FcpConnection,
         *      FinishedCompression)
@@ -418,7 +439,8 @@ public class FcpListenerManager extends AbstractListenerManager<FcpConnection, F
        }
 
        /**
-        * Notifies all listeners that a “SubscribedUSKUpdate” message was received.
+        * Notifies all listeners that a “SubscribedUSKUpdate” message was
+        * received.
         *
         * @see FcpListener#receivedSubscribedUSKUpdate(FcpConnection,
         *      SubscribedUSKUpdate)
@@ -556,8 +578,8 @@ public class FcpListenerManager extends AbstractListenerManager<FcpConnection, F
         * 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) {
index b238db3..ed4ae46 100644 (file)
@@ -59,9 +59,9 @@ public class FcpMessage implements Iterable<String> {
        }
 
        /**
-        * 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
@@ -87,8 +87,8 @@ public class FcpMessage implements Iterable<String> {
         *
         * @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);
@@ -134,6 +134,7 @@ public class FcpMessage implements Iterable<String> {
        /**
         * {@inheritDoc}
         */
+       @Override
        public Iterator<String> iterator() {
                return fields.keySet().iterator();
        }
@@ -152,8 +153,8 @@ public class FcpMessage implements Iterable<String> {
         * 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
index 0957083..415cf1a 100644 (file)
@@ -110,8 +110,8 @@ public class FcpUtils {
        }
 
        /**
-        * 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
index 9d09d62..91c0341 100644 (file)
@@ -24,7 +24,7 @@ package net.pterodactylus.fcp;
  *
  * @author David ‘Bombe’ Roden &lt;bombe@freenetproject.org&gt;
  */
-public class FinishedCompression extends BaseMessage {
+public class FinishedCompression extends BaseMessage implements Identifiable {
 
        /**
         * Creates a new “FinishedCompression” message that wraps the received
@@ -42,6 +42,7 @@ public class FinishedCompression extends BaseMessage {
         *
         * @return The identifier of the request
         */
+       @Override
        public String getIdentifier() {
                return getField("Identifier");
        }
index 11e4cc6..230a790 100644 (file)
@@ -58,8 +58,8 @@ public class GetConfig extends FcpMessage {
        }
 
        /**
-        * 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
@@ -70,8 +70,8 @@ public class GetConfig extends FcpMessage {
        }
 
        /**
-        * 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,
@@ -94,8 +94,8 @@ public class GetConfig extends FcpMessage {
        }
 
        /**
-        * 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,
index c01bf2b..01ec1c8 100644 (file)
@@ -30,7 +30,7 @@ import java.util.Map.Entry;
  *
  * @author David ‘Bombe’ Roden &lt;bombe@freenetproject.org&gt;
  */
-public class GetFailed extends BaseMessage {
+public class GetFailed extends BaseMessage implements Identifiable {
 
        /**
         * Creates a new “GetFailed” message that wraps the received message.
@@ -45,8 +45,8 @@ public class GetFailed extends BaseMessage {
        /**
         * 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"));
@@ -57,6 +57,7 @@ public class GetFailed extends BaseMessage {
         *
         * @return The identifier of the request
         */
+       @Override
        public String getIdentifier() {
                return getField("Identifier");
        }
@@ -118,10 +119,11 @@ public class GetFailed extends BaseMessage {
        }
 
        /**
-        * 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
@@ -142,8 +144,8 @@ public class GetFailed extends BaseMessage {
        }
 
        /**
-        * 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
index 799b44b..3419860 100644 (file)
@@ -27,17 +27,18 @@ package net.pterodactylus.fcp;
 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,
index 5e2d63b..14a0555 100644 (file)
@@ -20,8 +20,9 @@ package net.pterodactylus.fcp;
 
 /**
  * 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 &lt;bombe@freenetproject.org&gt;
  */
diff --git a/src/main/java/net/pterodactylus/fcp/Identifiable.java b/src/main/java/net/pterodactylus/fcp/Identifiable.java
new file mode 100644 (file)
index 0000000..b206209
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * 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();
+
+}
index bc96a70..5ce6f4a 100644 (file)
@@ -24,7 +24,7 @@ package net.pterodactylus.fcp;
  *
  * @author David ‘Bombe’ Roden &lt;bombe@freenetproject.org&gt;
  */
-public class IdentifierCollision extends BaseMessage {
+public class IdentifierCollision extends BaseMessage implements Identifiable {
 
        /**
         * Creates a new “IdentifierCollision” message that wraps the received
@@ -42,6 +42,7 @@ public class IdentifierCollision extends BaseMessage {
         *
         * @return The identifier of the request
         */
+       @Override
        public String getIdentifier() {
                return getField("Identifier");
        }
index f16f385..e96a389 100644 (file)
@@ -27,9 +27,9 @@ public class ListPeer extends FcpMessage {
 
        /**
         * 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
index b0cbd1b..b69e5ee 100644 (file)
@@ -37,7 +37,8 @@ public class ListPeers extends FcpMessage {
        }
 
        /**
-        * 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
@@ -45,8 +46,8 @@ public class ListPeers extends FcpMessage {
         *            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");
index dc9af6b..dfc5aa2 100644 (file)
@@ -26,12 +26,12 @@ package net.pterodactylus.fcp;
 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
index dbb2ea7..6fcc088 100644 (file)
@@ -31,8 +31,8 @@ public class ModifyPeerNote extends FcpMessage {
         *
         * @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
index 5425833..f73bbd5 100644 (file)
@@ -159,10 +159,10 @@ public class NodeData extends BaseMessage {
        }
 
        /**
-        * 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
index 01b0515..7409d9b 100644 (file)
@@ -36,8 +36,8 @@ public class NodeHello extends BaseMessage {
        }
 
        /**
-        * 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
         */
@@ -46,8 +46,8 @@ public class NodeHello extends BaseMessage {
        }
 
        /**
-        * 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
+        * 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
@@ -96,8 +96,8 @@ public class NodeHello extends BaseMessage {
        /**
         * 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());
index 64ca56c..e96d15f 100644 (file)
@@ -138,8 +138,8 @@ public class NodeRef {
        }
 
        /**
-        * 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
index 3cfa856..df1c8f0 100644 (file)
@@ -28,7 +28,7 @@ import java.util.Map.Entry;
  *
  * @author David ‘Bombe’ Roden &lt;bombe@freenetproject.org&gt;
  */
-public class Peer extends BaseMessage {
+public class Peer extends BaseMessage implements Identifiable {
 
        /**
         * Creates a new “Peer” reply from the received message.
@@ -66,6 +66,7 @@ public class Peer extends BaseMessage {
         *
         * @return The identifier of the request
         */
+       @Override
        public String getIdentifier() {
                return getField("Identifier");
        }
@@ -212,9 +213,10 @@ public class Peer extends BaseMessage {
        }
 
        /**
-        * 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
@@ -241,10 +243,10 @@ public class Peer extends BaseMessage {
        }
 
        /**
-        * 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
index 7b32207..67cdfa6 100644 (file)
@@ -60,8 +60,8 @@ public class PeerNote extends BaseMessage {
        /**
         * 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"));
index 7489801..c7bfe20 100644 (file)
@@ -20,11 +20,12 @@ package net.pterodactylus.fcp;
 
 /**
  * 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 &lt;bombe@freenetproject.org&gt;
  */
-public class PersistentGet extends BaseMessage {
+public class PersistentGet extends BaseMessage implements Identifiable {
 
        /**
         * Creates a new “PersistentGet” message that wraps the received message.
@@ -41,6 +42,7 @@ public class PersistentGet extends BaseMessage {
         *
         * @return The identifier of the request
         */
+       @Override
        public String getIdentifier() {
                return getField("Identifier");
        }
@@ -117,8 +119,8 @@ public class PersistentGet extends BaseMessage {
        /**
         * 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 {
@@ -142,9 +144,9 @@ public class PersistentGet extends BaseMessage {
        /**
         * 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);
index 383ea93..2dc8213 100644 (file)
@@ -24,7 +24,7 @@ package net.pterodactylus.fcp;
  *
  * @author David ‘Bombe’ Roden &lt;bombe@freenetproject.org&gt;
  */
-public class PersistentPut extends BaseMessage {
+public class PersistentPut extends BaseMessage implements Identifiable {
 
        /**
         * Creates a new “PersistentPut” message that wraps the received message.
@@ -70,6 +70,7 @@ public class PersistentPut extends BaseMessage {
         *
         * @return The identifier of the request
         */
+       @Override
        public String getIdentifier() {
                return getField("Identifier");
        }
index 47c3d8d..b68c84c 100644 (file)
@@ -25,10 +25,11 @@ package net.pterodactylus.fcp;
  *
  * @author David ‘Bombe’ Roden &lt;bombe@freenetproject.org&gt;
  */
-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
@@ -42,6 +43,7 @@ public class PersistentPutDir extends BaseMessage {
         *
         * @return The identifier of the request
         */
+       @Override
        public String getIdentifier() {
                return getField("Identifier");
        }
index ea8d1ac..f1d2371 100644 (file)
@@ -24,11 +24,11 @@ package net.pterodactylus.fcp;
  *
  * @author David ‘Bombe’ Roden &lt;bombe@freenetproject.org&gt;
  */
-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
@@ -42,6 +42,7 @@ public class PersistentRequestModified extends BaseMessage {
         *
         * @return The identifier of the request
         */
+       @Override
        public String getIdentifier() {
                return getField("Identifier");
        }
index 154c88c..c9ec826 100644 (file)
@@ -24,7 +24,7 @@ package net.pterodactylus.fcp;
  *
  * @author David ‘Bombe’ Roden &lt;bombe@freenetproject.org&gt;
  */
-public class PersistentRequestRemoved extends BaseMessage {
+public class PersistentRequestRemoved extends BaseMessage implements Identifiable {
 
        /**
         * Creates a new “PersistentRequestRemoved” message that wraps the received
@@ -42,6 +42,7 @@ public class PersistentRequestRemoved extends BaseMessage {
         *
         * @return The identifier of the request
         */
+       @Override
        public String getIdentifier() {
                return getField("Identifier");
        }
@@ -50,8 +51,8 @@ public class PersistentRequestRemoved extends BaseMessage {
         * 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"));
index 84ddaea..fbce581 100644 (file)
@@ -23,7 +23,7 @@ package net.pterodactylus.fcp;
  *
  * @author David ‘Bombe’ Roden &lt;bombe@freenetproject.org&gt;
  */
-public class PluginInfo extends BaseMessage {
+public class PluginInfo extends BaseMessage implements Identifiable {
 
        /**
         * Creates a new “PluginInfo” message that wraps the received message.
@@ -49,6 +49,7 @@ public class PluginInfo extends BaseMessage {
         *
         * @return The identifier of the request
         */
+       @Override
        public String getIdentifier() {
                return getField("Identifier");
        }
index f59d1fe..8b7b510 100644 (file)
@@ -48,8 +48,8 @@ public class ProtocolError extends BaseMessage {
        /**
         * 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"));
index b6916f4..8535bcb 100644 (file)
@@ -30,7 +30,7 @@ import java.util.Map.Entry;
  *
  * @author David ‘Bombe’ Roden &lt;bombe@freenetproject.org&gt;
  */
-public class PutFailed extends BaseMessage {
+public class PutFailed extends BaseMessage implements Identifiable {
 
        /**
         * Creates a new “PutFailed” message that wraps the received message.
@@ -45,8 +45,8 @@ public class PutFailed extends BaseMessage {
        /**
         * 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"));
@@ -57,6 +57,7 @@ public class PutFailed extends BaseMessage {
         *
         * @return The identifier of the request
         */
+       @Override
        public String getIdentifier() {
                return getField("Identifier");
        }
@@ -108,8 +109,8 @@ public class PutFailed extends BaseMessage {
        }
 
        /**
-        * 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
index 0c4e941..767b4ad 100644 (file)
@@ -25,7 +25,7 @@ package net.pterodactylus.fcp;
  *
  * @author David ‘Bombe’ Roden &lt;bombe@freenetproject.org&gt;
  */
-public class PutFetchable extends BaseMessage {
+public class PutFetchable extends BaseMessage implements Identifiable {
 
        /**
         * Creates a new “PutFetchable” message that wraps the received message.
@@ -42,6 +42,7 @@ public class PutFetchable extends BaseMessage {
         *
         * @return The identifier of the request
         */
+       @Override
        public String getIdentifier() {
                return getField("Identifier");
        }
index cea36ee..d8c4434 100644 (file)
@@ -24,7 +24,7 @@ package net.pterodactylus.fcp;
  *
  * @author David ‘Bombe’ Roden &lt;bombe@freenetproject.org&gt;
  */
-public class PutSuccessful extends BaseMessage {
+public class PutSuccessful extends BaseMessage implements Identifiable {
 
        /**
         * Creates a new “PutSuccessful” message that wraps the received message.
@@ -41,6 +41,7 @@ public class PutSuccessful extends BaseMessage {
         *
         * @return The identifier of the request
         */
+       @Override
        public String getIdentifier() {
                return getField("Identifier");
        }
index 02369f0..3b54177 100644 (file)
@@ -57,16 +57,16 @@ public class ReceivedBookmarkFeed extends BaseMessage {
        /**
         * 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
index fd0b40a..55b27e9 100644 (file)
@@ -24,7 +24,7 @@ package net.pterodactylus.fcp;
  *
  * @author David ‘Bombe’ Roden &lt;bombe@freenetproject.org&gt;
  */
-public class SSKKeypair extends BaseMessage {
+public class SSKKeypair extends BaseMessage implements Identifiable {
 
        /**
         * Creates a new “SSKKeypair” message that wraps the received message.
@@ -41,6 +41,7 @@ public class SSKKeypair extends BaseMessage {
         *
         * @return The identifier of the request
         */
+       @Override
        public String getIdentifier() {
                return getField("Identifier");
        }
index 522e830..69191fc 100644 (file)
@@ -39,8 +39,8 @@ public class SendBookmarkFeed extends AbstractSendFeedMessage {
         * @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);
index eb7ca0a..133bd12 100644 (file)
@@ -23,7 +23,7 @@ package net.pterodactylus.fcp;
  *
  * @author David ‘Bombe’ Roden &lt;bombe@freenetproject.org&gt;
  */
-public class SentFeed extends BaseMessage {
+public class SentFeed extends BaseMessage implements Identifiable {
 
        /**
         * Creates a new “SentFeed” message from the given FCP message.
@@ -42,6 +42,7 @@ public class SentFeed extends BaseMessage {
         *
         * @return The send feed’s identifier
         */
+       @Override
        public String getIdentifier() {
                return getField("Identifier");
        }
index 4d93512..5f4da24 100644 (file)
@@ -24,7 +24,7 @@ package net.pterodactylus.fcp;
  *
  * @author David ‘Bombe’ Roden &lt;bombe@freenetproject.org&gt;
  */
-public class SimpleProgress extends BaseMessage {
+public class SimpleProgress extends BaseMessage implements Identifiable {
 
        /**
         * Creates a new “SimpleProgress” message that wraps the received message.
@@ -104,6 +104,7 @@ public class SimpleProgress extends BaseMessage {
         *
         * @return The identifier of the request
         */
+       @Override
        public String getIdentifier() {
                return getField("Identifier");
        }
index a7c4fa2..1fd44f1 100644 (file)
@@ -24,7 +24,7 @@ package net.pterodactylus.fcp;
  *
  * @author David ‘Bombe’ Roden &lt;bombe@freenetproject.org&gt;
  */
-public class StartedCompression extends BaseMessage {
+public class StartedCompression extends BaseMessage implements Identifiable {
 
        /**
         * Creates a new “StartedCompression” message that wraps the received
@@ -42,6 +42,7 @@ public class StartedCompression extends BaseMessage {
         *
         * @return The identifier of the request
         */
+       @Override
        public String getIdentifier() {
                return getField("Identifier");
        }
index e616b5d..d2e132d 100644 (file)
 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 &lt;bombe@freenetproject.org&gt;
  */
-public class SubscribedUSKUpdate extends BaseMessage {
+public class SubscribedUSKUpdate extends BaseMessage implements Identifiable {
 
        /**
         * Creates a new “SubscribedUSKUpdate” message that wraps the received
@@ -45,6 +45,7 @@ public class SubscribedUSKUpdate extends BaseMessage {
         *
         * @return The identifier of the subscription
         */
+       @Override
        public String getIdentifier() {
                return getField("Identifier");
        }
index bf102d6..9764a02 100644 (file)
@@ -22,8 +22,9 @@ package net.pterodactylus.fcp;
  * 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 &lt;bombe@freenetproject.org&gt;
  */
index 89a0202..4f5c9a0 100644 (file)
@@ -31,7 +31,8 @@ public class TestDDARequest extends FcpMessage {
         * @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
         */
index 76660c5..2d6d2a4 100644 (file)
@@ -21,15 +21,16 @@ package net.pterodactylus.fcp;
 /**
  * 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 &lt;bombe@freenetproject.org&gt;
  */
 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
@@ -40,11 +41,11 @@ public class TestDDAResponse extends FcpMessage {
        }
 
        /**
-        * 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
index 06d3888..4939570 100644 (file)
 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 &lt;bombe@freenetproject.org&gt;
  */
-public class URIGenerated extends BaseMessage {
+public class URIGenerated extends BaseMessage implements Identifiable {
 
        /**
         * Creates a new “URIGenerated” message that wraps the received message.
@@ -42,6 +42,7 @@ public class URIGenerated extends BaseMessage {
         *
         * @return The identifier of the request
         */
+       @Override
        public String getIdentifier() {
                return getField("Identifier");
        }
@@ -56,8 +57,8 @@ public class URIGenerated extends BaseMessage {
        }
 
        /**
-        * 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
index 62a2da8..0dac50c 100644 (file)
@@ -20,8 +20,8 @@ package net.pterodactylus.fcp;
 
 /**
  * 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)}.
  *
@@ -91,8 +91,8 @@ public class 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 {
index 0f1d5cb..0f1de3e 100644 (file)
@@ -41,8 +41,8 @@ public class Version {
 
        /**
         * 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
index c159157..bc1092e 100644 (file)
@@ -18,6 +18,9 @@
 
 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;
@@ -28,11 +31,14 @@ import java.util.Collections;
 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;
@@ -65,9 +71,8 @@ import net.pterodactylus.fcp.RemovePeer;
 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
@@ -75,7 +80,7 @@ import net.pterodactylus.util.thread.ObjectWrapper;
  *
  * @author David ‘Bombe’ Roden &lt;bombe@freenetproject.org&gt;
  */
-public class FcpClient {
+public class FcpClient implements Closeable {
 
        /** Object used for synchronization. */
        private final Object syncObject = new Object();
@@ -83,9 +88,6 @@ public class FcpClient {
        /** 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;
 
@@ -95,37 +97,34 @@ public class FcpClient {
        /** 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
@@ -133,36 +132,56 @@ public class FcpClient {
         * @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}
@@ -170,10 +189,11 @@ public class FcpClient {
                        @Override
                        @SuppressWarnings("synthetic-access")
                        public void connectionClosed(FcpConnection fcpConnection, Throwable throwable) {
-                               connected = false;
+                               FcpClient.this.connected = false;
                                fcpClientListenerManager.fireFcpClientDisconnected();
                        }
-               });
+               };
+               fcpConnection.addFcpListener(connectionClosedListener);
        }
 
        //
@@ -250,12 +270,14 @@ public class FcpClient {
        /**
         * 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() {
@@ -286,6 +308,88 @@ public class FcpClient {
        }
 
        /**
+        * 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() {
@@ -296,6 +400,14 @@ public class FcpClient {
        }
 
        /**
+        * {@inheritDoc}
+        */
+       @Override
+       public void close() {
+               disconnect();
+       }
+
+       /**
         * Returns whether this client is currently connected.
         *
         * @return {@code true} if the client is currently connected, {@code false}
@@ -305,6 +417,13 @@ public class FcpClient {
                return connected;
        }
 
+       /**
+        * Detaches this client from its underlying FCP connection.
+        */
+       public void detach() {
+               fcpConnection.removeFcpListener(connectionClosedListener);
+       }
+
        //
        // PEER MANAGEMENT
        //
@@ -478,8 +597,8 @@ public class FcpClient {
 
        /**
         * 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
@@ -618,7 +737,7 @@ public class FcpClient {
         *             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() {
 
                        /**
@@ -704,7 +823,7 @@ public class FcpClient {
         *             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() {
 
                        /**
@@ -746,15 +865,12 @@ public class FcpClient {
         *             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();
        }
 
        /**
@@ -771,15 +887,12 @@ public class FcpClient {
         *             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();
        }
 
        /**
@@ -787,8 +900,8 @@ public class FcpClient {
         *
         * @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
@@ -993,7 +1106,7 @@ public class FcpClient {
         *             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
index aa797e4..eb9ef2f 100644 (file)
 
 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 &lt;bombe@freenetproject.org&gt;
  */
-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.
@@ -34,7 +38,15 @@ public class FcpClientListenerManager extends AbstractListenerManager<FcpClient,
         *            The source FCP client
         */
        public FcpClientListenerManager(FcpClient fcpClient) {
-               super(fcpClient);
+               this.source = fcpClient;
+       }
+
+       private FcpClient getSource() {
+               return source;
+       }
+
+       public List<FcpClientListener> getListeners() {
+               return listeners;
        }
 
        /**
@@ -48,4 +60,12 @@ public class FcpClientListenerManager extends AbstractListenerManager<FcpClient,
                }
        }
 
+       public void addListener(FcpClientListener fcpClientListener) {
+               listeners.add(fcpClientListener);
+       }
+
+       public void removeListener(FcpClientListener fcpClientListener) {
+               listeners.remove(fcpClientListener);
+       }
+
 }
diff --git a/src/main/java/net/pterodactylus/fcp/highlevel/GetResult.java b/src/main/java/net/pterodactylus/fcp/highlevel/GetResult.java
new file mode 100644 (file)
index 0000000..15bbb8d
--- /dev/null
@@ -0,0 +1,219 @@
+/*
+ * 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 + "]";
+       }
+
+}
index 2038523..4b73398 100644 (file)
@@ -132,7 +132,8 @@ public abstract class Request {
         * 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;
@@ -219,8 +220,8 @@ public abstract class Request {
        }
 
        /**
-        * 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
@@ -260,8 +261,8 @@ public abstract class Request {
        }
 
        /**
-        * 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.
         *
index dbda870..04b0cc6 100644 (file)
@@ -1,33 +1,33 @@
 /**
  * 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>
  */
diff --git a/src/main/java/net/pterodactylus/fcp/plugin/CalculatedTrust.java b/src/main/java/net/pterodactylus/fcp/plugin/CalculatedTrust.java
new file mode 100644 (file)
index 0000000..7df10c9
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+ * 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 &lt;bombe@freenetproject.org&gt;
+ */
+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;
+       }
+
+}
diff --git a/src/main/java/net/pterodactylus/fcp/plugin/Identity.java b/src/main/java/net/pterodactylus/fcp/plugin/Identity.java
new file mode 100644 (file)
index 0000000..01c6d48
--- /dev/null
@@ -0,0 +1,100 @@
+/*
+ * 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 &lt;bombe@freenetproject.org&gt;
+ */
+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();
+       }
+
+}
diff --git a/src/main/java/net/pterodactylus/fcp/plugin/IdentityTrust.java b/src/main/java/net/pterodactylus/fcp/plugin/IdentityTrust.java
new file mode 100644 (file)
index 0000000..aff79ee
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * 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 &lt;bombe@freenetproject.org&gt;
+ */
+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;
+       }
+
+}
diff --git a/src/main/java/net/pterodactylus/fcp/plugin/OwnIdentity.java b/src/main/java/net/pterodactylus/fcp/plugin/OwnIdentity.java
new file mode 100644 (file)
index 0000000..ec4b217
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * 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 &lt;bombe@freenetproject.org&gt;
+ */
+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;
+       }
+
+}
index 3e99b1e..e83b071 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 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
@@ -429,233 +429,4 @@ public class WebOfTrustPlugin {
                return parameterMap;
        }
 
-       /**
-        * Wrapper around a web-of-trust identity.
-        *
-        * @author David ‘Bombe’ Roden &lt;bombe@freenetproject.org&gt;
-        */
-       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 &lt;bombe@freenetproject.org&gt;
-        */
-       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 &lt;bombe@freenetproject.org&gt;
-        */
-       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 &lt;bombe@freenetproject.org&gt;
-        */
-       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;
-               }
-
-       }
-
 }
diff --git a/test/main/java/net/pterodactylus/fcp/FcpConnectionTest.java b/test/main/java/net/pterodactylus/fcp/FcpConnectionTest.java
deleted file mode 100644 (file)
index 30da36b..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * 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 &lt;bombe@freenetproject.org&gt;
- */
-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();
-       }
-
-}
diff --git a/test/main/java/net/pterodactylus/fcp/FcpTest.java b/test/main/java/net/pterodactylus/fcp/FcpTest.java
deleted file mode 100644 (file)
index 6c51848..0000000
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * 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 &lt;bombe@freenetproject.org&gt;
- */
-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]);
-       }
-
-}