From: David ‘Bombe’ Roden Date: Wed, 9 Apr 2008 12:23:28 +0000 (+0000) Subject: move message package to top-level package X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=474a0f39c87d520b0ce8c23ea8e8046441e13ea7;p=jSite2.git move message package to top-level package convert helper classes to top-level types git-svn-id: http://trooper/svn/projects/jSite/trunk@665 c3eda9e8-030b-0410-8277-bc7414b0a119 --- diff --git a/src/net/pterodactylus/util/fcp/ARK.java b/src/net/pterodactylus/util/fcp/ARK.java new file mode 100644 index 0000000..27c37f7 --- /dev/null +++ b/src/net/pterodactylus/util/fcp/ARK.java @@ -0,0 +1,55 @@ +package net.pterodactylus.util.fcp; + +/** + * Container for ARKs (address resolution keys). + * + * @author David Roden + * @version $Id$ + */ +public class ARK { + + /** The public URI of the ARK. */ + private final String publicURI; + + /** The number of the ARK. */ + private final int number; + + /** + * Creates a new ARK with the given URI and number. + * + * @param publicURI + * The public URI of the ARK + * @param number + * The number of the ARK + */ + public ARK(String publicURI, String number) { + if ((publicURI == null) || (number == null)) { + throw new NullPointerException(((publicURI == null) ? "publicURI" : "number") + " must not be null"); + } + this.publicURI = publicURI; + try { + this.number = Integer.valueOf(number); + } catch (NumberFormatException nfe1) { + throw new IllegalArgumentException("number must be numeric", nfe1); + } + } + + /** + * Returns the public URI of the ARK. + * + * @return The public URI of the ARK + */ + public String getPublicURI() { + return publicURI; + } + + /** + * Returns the number of the ARK. + * + * @return The number of the ARK + */ + public int getNumber() { + return number; + } + +} \ No newline at end of file diff --git a/src/net/pterodactylus/util/fcp/BaseMessage.java b/src/net/pterodactylus/util/fcp/BaseMessage.java new file mode 100644 index 0000000..3f8fda2 --- /dev/null +++ b/src/net/pterodactylus/util/fcp/BaseMessage.java @@ -0,0 +1,49 @@ +/** + * © 2008 INA Service GmbH + */ +package net.pterodactylus.util.fcp; + + +/** + * A basic message abstraction that wraps a received FCP message. + * + * @author David Roden + * @version $Id$ + */ +public class BaseMessage { + + /** The received message, wrapped here. */ + private final FcpMessage receivedMessage; + + /** + * Creates a new base message that wraps the given message. + * + * @param receivedMessage + * The FCP message that was received + */ + public BaseMessage(FcpMessage receivedMessage) { + this.receivedMessage = receivedMessage; + } + + /** + * Returns the name of the message. + * + * @return The name of the message + */ + public String getName() { + return receivedMessage.getName(); + } + + /** + * Returns the content of the field. + * + * @param field + * The name of the field + * @return The content of the field, or null if there is no + * such field + */ + public String getField(String field) { + return receivedMessage.getField(field); + } + +} diff --git a/src/net/pterodactylus/util/fcp/ClientHello.java b/src/net/pterodactylus/util/fcp/ClientHello.java new file mode 100644 index 0000000..3cc7889 --- /dev/null +++ b/src/net/pterodactylus/util/fcp/ClientHello.java @@ -0,0 +1,46 @@ +/** + * © 2008 INA Service GmbH + */ +package net.pterodactylus.util.fcp; + + +/** + * A “ClientHello” message that must be sent to the node first thing + * after calling {@link FcpConnection#connect()}. + * + * @author David Roden + * @version $Id$ + */ +public class ClientHello extends FcpMessage { + + /** + * Creates a new “ClientHello” message with the given client name. The + * client name has to be unique to the node otherwise you will get a + * {@link CloseConnectionDuplicateClientName} response from the node! + * + * @param clientName + * The unique client name + */ + public ClientHello(String clientName) { + this(clientName, "2.0"); + } + + /** + * Creates a new “ClientHello” message with the given client name. The + * client name has to be unique to the node otherwise you will get a + * {@link CloseConnectionDuplicateClientName} response from the node! + * + * The expected FCP version is currently ignored by the node. + * + * @param clientName + * The unique client name + * @param expectedVersion + * The FCP version that the node is expected to talk + */ + public ClientHello(String clientName, String expectedVersion) { + super("ClientHello"); + setField("Name", clientName); + setField("ExpectedVersion", expectedVersion); + } + +} diff --git a/src/net/pterodactylus/util/fcp/CloseConnectionDuplicateClientName.java b/src/net/pterodactylus/util/fcp/CloseConnectionDuplicateClientName.java new file mode 100644 index 0000000..1087ddc --- /dev/null +++ b/src/net/pterodactylus/util/fcp/CloseConnectionDuplicateClientName.java @@ -0,0 +1,26 @@ +/** + * © 2008 INA Service GmbH + */ +package net.pterodactylus.util.fcp; + + +/** + * A “CloseConnectionDuplicateClientName” message. + * + * @author David Roden + * @version $Id$ + */ +public class CloseConnectionDuplicateClientName extends BaseMessage { + + /** + * Creates a new CloseConnectionDuplicateClientName message that wraps the + * given message. + * + * @param receivedMessage + * The received message + */ + public CloseConnectionDuplicateClientName(FcpMessage receivedMessage) { + super(receivedMessage); + } + +} diff --git a/src/net/pterodactylus/util/fcp/DSAGroup.java b/src/net/pterodactylus/util/fcp/DSAGroup.java new file mode 100644 index 0000000..7fe274e --- /dev/null +++ b/src/net/pterodactylus/util/fcp/DSAGroup.java @@ -0,0 +1,68 @@ +package net.pterodactylus.util.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”). + * + * @see DSAParams + * @author David Roden + * @version $Id$ + */ +public class DSAGroup { + + /** The base of the DSA group. */ + private final String base; + + /** The prime of the DSA group. */ + private final String prime; + + /** The subprime of the DSA group. */ + private final String subprime; + + /** + * Creates a new DSA group with the given base (“g”), prime (“p”), and + * subprime (“q”). + * + * @param base + * The base of the DSA group + * @param prime + * The prime of the DSA group + * @param subprime + * The subprime of the DSA group + */ + public DSAGroup(String base, String prime, String subprime) { + this.base = base; + this.prime = prime; + this.subprime = subprime; + } + + /** + * Returns the base (“g”) of the DSA group. + * + * @return The base of the DSA group + */ + public String getBase() { + return base; + } + + /** + * Returns the prime (“p”) of the DSA group. + * + * @return The prime of the DSA group + */ + public String getPrime() { + return prime; + } + + /** + * Returns the subprime (“q”) of the DSA group. + * + * @return The subprime of the DSA group + */ + public String getSubprime() { + return subprime; + } + +} \ No newline at end of file diff --git a/src/net/pterodactylus/util/fcp/EndListPeerNotes.java b/src/net/pterodactylus/util/fcp/EndListPeerNotes.java new file mode 100644 index 0000000..edde167 --- /dev/null +++ b/src/net/pterodactylus/util/fcp/EndListPeerNotes.java @@ -0,0 +1,26 @@ +/** + * © 2008 INA Service GmbH + */ +package net.pterodactylus.util.fcp; + + +/** + * The “EndListPeerNotes” message signals the end of a list of “PeerNote” + * messages. + * + * @author David Roden + * @version $Id$ + */ +public class EndListPeerNotes extends BaseMessage { + + /** + * Creates a new “EndListPeerNotes” message that wraps the received message. + * + * @param fcpMessage + * The received message + */ + public EndListPeerNotes(FcpMessage fcpMessage) { + super(fcpMessage); + } + +} diff --git a/src/net/pterodactylus/util/fcp/EndListPeers.java b/src/net/pterodactylus/util/fcp/EndListPeers.java new file mode 100644 index 0000000..e8ffff8 --- /dev/null +++ b/src/net/pterodactylus/util/fcp/EndListPeers.java @@ -0,0 +1,25 @@ +/** + * © 2008 INA Service GmbH + */ +package net.pterodactylus.util.fcp; + + +/** + * This message marks the end of a list of “Peer” replies. + * + * @author David Roden + * @version $Id$ + */ +public class EndListPeers extends BaseMessage { + + /** + * Creates a new “EndListPeers” message that wraps the received message. + * + * @param receivedMessage + * The message that was received + */ + public EndListPeers(FcpMessage receivedMessage) { + super(receivedMessage); + } + +} diff --git a/src/net/pterodactylus/util/fcp/FcpAdapter.java b/src/net/pterodactylus/util/fcp/FcpAdapter.java index 74d7967..69cc9f8 100644 --- a/src/net/pterodactylus/util/fcp/FcpAdapter.java +++ b/src/net/pterodactylus/util/fcp/FcpAdapter.java @@ -3,13 +3,6 @@ */ package net.pterodactylus.util.fcp; -import net.pterodactylus.util.fcp.message.CloseConnectionDuplicateClientName; -import net.pterodactylus.util.fcp.message.EndListPeerNotes; -import net.pterodactylus.util.fcp.message.EndListPeers; -import net.pterodactylus.util.fcp.message.NodeHello; -import net.pterodactylus.util.fcp.message.Peer; -import net.pterodactylus.util.fcp.message.PeerNote; -import net.pterodactylus.util.fcp.message.SSKKeypair; /** * Adapter for {@link FcpListener}. @@ -21,7 +14,7 @@ public class FcpAdapter implements FcpListener { /** * @see net.pterodactylus.util.fcp.FcpListener#receivedNodeHello(net.pterodactylus.util.fcp.FcpConnection, - * net.pterodactylus.util.fcp.message.NodeHello) + * net.pterodactylus.util.fcp.NodeHello) */ public void receivedNodeHello(FcpConnection fcpConnection, NodeHello nodeHello) { /* empty. */ @@ -29,7 +22,7 @@ public class FcpAdapter implements FcpListener { /** * @see net.pterodactylus.util.fcp.FcpListener#receivedCloseConnectionDuplicateClientName(net.pterodactylus.util.fcp.FcpConnection, - * net.pterodactylus.util.fcp.message.CloseConnectionDuplicateClientName) + * net.pterodactylus.util.fcp.CloseConnectionDuplicateClientName) */ public void receivedCloseConnectionDuplicateClientName(FcpConnection fcpConnection, CloseConnectionDuplicateClientName closeConnectionDuplicateClientName) { /* empty. */ @@ -37,7 +30,7 @@ public class FcpAdapter implements FcpListener { /** * @see net.pterodactylus.util.fcp.FcpListener#receivedSSKKeypair(net.pterodactylus.util.fcp.FcpConnection, - * net.pterodactylus.util.fcp.message.SSKKeypair) + * net.pterodactylus.util.fcp.SSKKeypair) */ public void receivedSSKKeypair(FcpConnection fcpConnection, SSKKeypair sskKeypair) { /* empty. */ @@ -45,7 +38,7 @@ public class FcpAdapter implements FcpListener { /** * @see net.pterodactylus.util.fcp.FcpListener#receivedPeer(net.pterodactylus.util.fcp.FcpConnection, - * net.pterodactylus.util.fcp.message.Peer) + * net.pterodactylus.util.fcp.Peer) */ public void receivedPeer(FcpConnection fcpConnection, Peer peer) { /* empty. */ @@ -53,7 +46,7 @@ public class FcpAdapter implements FcpListener { /** * @see net.pterodactylus.util.fcp.FcpListener#receivedEndListPeers(net.pterodactylus.util.fcp.FcpConnection, - * net.pterodactylus.util.fcp.message.EndListPeers) + * net.pterodactylus.util.fcp.EndListPeers) */ public void receivedEndListPeers(FcpConnection fcpConnection, EndListPeers endListPeers) { /* empty. */ @@ -61,7 +54,7 @@ public class FcpAdapter implements FcpListener { /** * @see net.pterodactylus.util.fcp.FcpListener#receviedPeerNote(net.pterodactylus.util.fcp.FcpConnection, - * net.pterodactylus.util.fcp.message.PeerNote) + * net.pterodactylus.util.fcp.PeerNote) */ public void receviedPeerNote(FcpConnection fcpConnection, PeerNote peerNote) { /* empty. */ @@ -69,7 +62,7 @@ public class FcpAdapter implements FcpListener { /** * @see net.pterodactylus.util.fcp.FcpListener#receivedEndListPeerNotes(net.pterodactylus.util.fcp.FcpConnection, - * net.pterodactylus.util.fcp.message.EndListPeerNotes) + * net.pterodactylus.util.fcp.EndListPeerNotes) */ public void receivedEndListPeerNotes(FcpConnection fcpConnection, EndListPeerNotes endListPeerNotes) { /* empty. */ diff --git a/src/net/pterodactylus/util/fcp/FcpConnection.java b/src/net/pterodactylus/util/fcp/FcpConnection.java index a8b6024..32237f4 100644 --- a/src/net/pterodactylus/util/fcp/FcpConnection.java +++ b/src/net/pterodactylus/util/fcp/FcpConnection.java @@ -28,13 +28,6 @@ import java.net.UnknownHostException; import java.util.ArrayList; import java.util.List; -import net.pterodactylus.util.fcp.message.CloseConnectionDuplicateClientName; -import net.pterodactylus.util.fcp.message.EndListPeerNotes; -import net.pterodactylus.util.fcp.message.EndListPeers; -import net.pterodactylus.util.fcp.message.NodeHello; -import net.pterodactylus.util.fcp.message.Peer; -import net.pterodactylus.util.fcp.message.PeerNote; -import net.pterodactylus.util.fcp.message.SSKKeypair; import net.pterodactylus.util.io.Closer; /** diff --git a/src/net/pterodactylus/util/fcp/FcpListener.java b/src/net/pterodactylus/util/fcp/FcpListener.java index c949d48..aa8147b 100644 --- a/src/net/pterodactylus/util/fcp/FcpListener.java +++ b/src/net/pterodactylus/util/fcp/FcpListener.java @@ -21,13 +21,6 @@ package net.pterodactylus.util.fcp; import java.util.EventListener; -import net.pterodactylus.util.fcp.message.CloseConnectionDuplicateClientName; -import net.pterodactylus.util.fcp.message.EndListPeerNotes; -import net.pterodactylus.util.fcp.message.EndListPeers; -import net.pterodactylus.util.fcp.message.NodeHello; -import net.pterodactylus.util.fcp.message.Peer; -import net.pterodactylus.util.fcp.message.PeerNote; -import net.pterodactylus.util.fcp.message.SSKKeypair; /** * Interface for objects that want to be notified on certain FCP events. diff --git a/src/net/pterodactylus/util/fcp/FcpTest.java b/src/net/pterodactylus/util/fcp/FcpTest.java index e0d20e4..7aca867 100644 --- a/src/net/pterodactylus/util/fcp/FcpTest.java +++ b/src/net/pterodactylus/util/fcp/FcpTest.java @@ -22,10 +22,6 @@ package net.pterodactylus.util.fcp; import java.io.IOException; import junit.framework.TestCase; -import net.pterodactylus.util.fcp.message.ClientHello; -import net.pterodactylus.util.fcp.message.CloseConnectionDuplicateClientName; -import net.pterodactylus.util.fcp.message.GenerateSSK; -import net.pterodactylus.util.fcp.message.NodeHello; /** * Tests various commands and the FCP connection. @@ -98,7 +94,7 @@ public class FcpTest extends TestCase { FcpAdapter fcpAdapter = new FcpAdapter() { /** * @see net.pterodactylus.util.fcp.FcpAdapter#receivedNodeHello(net.pterodactylus.util.fcp.FcpConnection, - * net.pterodactylus.util.fcp.message.NodeHello) + * net.pterodactylus.util.fcp.NodeHello) */ @Override public void receivedNodeHello(FcpConnection fcpConnection, NodeHello nodeHello) { @@ -110,7 +106,7 @@ public class FcpTest extends TestCase { /** * @see net.pterodactylus.util.fcp.FcpAdapter#receivedCloseConnectionDuplicateClientName(net.pterodactylus.util.fcp.FcpConnection, - * net.pterodactylus.util.fcp.message.CloseConnectionDuplicateClientName) + * net.pterodactylus.util.fcp.CloseConnectionDuplicateClientName) */ @Override public void receivedCloseConnectionDuplicateClientName(FcpConnection fcpConnection, CloseConnectionDuplicateClientName closeConnectionDuplicateClientName) { diff --git a/src/net/pterodactylus/util/fcp/GenerateSSK.java b/src/net/pterodactylus/util/fcp/GenerateSSK.java new file mode 100644 index 0000000..7d82156 --- /dev/null +++ b/src/net/pterodactylus/util/fcp/GenerateSSK.java @@ -0,0 +1,34 @@ +/** + * © 2008 INA Service GmbH + */ +package net.pterodactylus.util.fcp; + + +/** + * A “GenerateSSK” message. This message tells the node to generate a new SSK + * key pair. + * + * @author David Roden + * @version $Id$ + */ +public class GenerateSSK extends FcpMessage { + + /** + * Creates a new “GenerateSSK” message. + */ + public GenerateSSK() { + this(FcpUtils.getUniqueIdentifier()); + } + + /** + * Creates a new “GenerateSSK” message with the given client identifier. + * + * @param clientIdentifier + * The client identifier + */ + public GenerateSSK(String clientIdentifier) { + super("GenerateSSK"); + setField("Identifier", clientIdentifier); + } + +} diff --git a/src/net/pterodactylus/util/fcp/ListPeer.java b/src/net/pterodactylus/util/fcp/ListPeer.java new file mode 100644 index 0000000..c54a905 --- /dev/null +++ b/src/net/pterodactylus/util/fcp/ListPeer.java @@ -0,0 +1,29 @@ +/** + * © 2008 INA Service GmbH + */ +package net.pterodactylus.util.fcp; + + +/** + * The “ListPeer” request asks the node about the details of a given peer. + * + * @author David Roden + * @version $Id$ + */ +public class ListPeer extends FcpMessage { + + /** + * Creates a new “ListPeer” request that returns information about the node + * specified by nodeIdentifier. nodeIdentifier + * 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 + */ + public ListPeer(String nodeIdentifier) { + super("ListPeer"); + setField("NodeIdentifier", nodeIdentifier); + } + +} diff --git a/src/net/pterodactylus/util/fcp/ListPeerNotes.java b/src/net/pterodactylus/util/fcp/ListPeerNotes.java new file mode 100644 index 0000000..0d1c65c --- /dev/null +++ b/src/net/pterodactylus/util/fcp/ListPeerNotes.java @@ -0,0 +1,28 @@ +/** + * © 2008 INA Service GmbH + */ +package net.pterodactylus.util.fcp; + + +/** + * A “ListPeerNodes” request tells the node to list all notes that have been + * entered for a node. Note that notes are only supported for darknet nodes. + * + * @author David Roden + * @version $Id$ + */ +public class ListPeerNotes extends FcpMessage { + + /** + * Creates a new “ListPeerNotes” request that lists all notes of the + * specified node. + * + * @param nodeIdentifier + * The identifier of the node + */ + public ListPeerNotes(String nodeIdentifier) { + super("ListPeerNotes"); + setField("NodeIdentifier", nodeIdentifier); + } + +} diff --git a/src/net/pterodactylus/util/fcp/ListPeers.java b/src/net/pterodactylus/util/fcp/ListPeers.java new file mode 100644 index 0000000..5efaedf --- /dev/null +++ b/src/net/pterodactylus/util/fcp/ListPeers.java @@ -0,0 +1,39 @@ +/** + * © 2008 INA Service GmbH + */ +package net.pterodactylus.util.fcp; + + +/** + * The “ListPeer” requests asks the node for a list of all peers it has. + * + * @author David Roden + * @version $Id$ + */ +public class ListPeers extends FcpMessage { + + /** + * Creates a new “ListPeers” request that only includes basic data of the + * peers. + */ + public ListPeers() { + this(false, false); + } + + /** + * Creates a new “ListPeers” request that includes wanted data of the peers. + * + * @param withMetadata + * If true metadata of the peers is included in + * the reply + * @param withVolatile + * if true volatile data of the peers is included + * in the reply + */ + public ListPeers(boolean withMetadata, boolean withVolatile) { + super("ListPeers"); + setField("WithMetadata", String.valueOf(withMetadata)); + setField("WithVolatile", String.valueOf(withVolatile)); + } + +} diff --git a/src/net/pterodactylus/util/fcp/NodeHello.java b/src/net/pterodactylus/util/fcp/NodeHello.java new file mode 100644 index 0000000..8094013 --- /dev/null +++ b/src/net/pterodactylus/util/fcp/NodeHello.java @@ -0,0 +1,208 @@ +/** + * © 2008 INA Service GmbH + */ +package net.pterodactylus.util.fcp; + + +/** + * Some convenience methods for parsing a “NodeHello” message from the node. + * + * @author David Roden + * @version $Id$ + */ +public class NodeHello extends BaseMessage { + + /** + * Createa a new “NodeHello” message that wraps the received message. + * + * @param receivedMessage + * The received FCP message + */ + public NodeHello(FcpMessage receivedMessage) { + super(receivedMessage); + } + + /** + * 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 + */ + public String getBuild() { + return getField("Build"); + } + + /** + * Returns the build number of the node. This may not be a number but also a + * string like “@custom@” in case you built the node yourself. + * + * @return The build number of the node, or -1 if the build + * number could not be determined + */ + public int getBuildNumber() { + String build = getBuild(); + try { + return Integer.valueOf(build); + } catch (NumberFormatException nfe1) { + /* ignore. */ + } + return -1; + } + + /** + * Returns the number of compression codecs. + * + * @return The number of compression codecs + */ + public String getCompressionCodecs() { + return getField("CompressionCodecs"); + } + + /** + * Returns the number of compression codecs. + * + * @return The number of compression codecs, or -1 if the + * number of compression codecs could not be determined + */ + public int getCompressionCodecsNumber() { + String compressionCodecs = getCompressionCodecs(); + try { + return Integer.valueOf(compressionCodecs); + } catch (NumberFormatException nfe1) { + /* ignore. */ + } + return -1; + } + + /** + * Returns the unique connection identifier. + * + * @return The connection identifier + */ + public String getConnectionIdentifier() { + return getField("ConnectionIdentifier"); + } + + /** + * Returns the build of the external library file. + * + * @return The build of the external library file + */ + public String getExtBuild() { + return getField("ExtBuild"); + } + + /** + * Returns the build number of the external library file. + * + * @return The build number of the external library file, or -1 + * if the build number could not be determined + */ + public int getExtBuildNumber() { + String extBuild = getExtBuild(); + try { + return Integer.valueOf(extBuild); + } catch (NumberFormatException nfe1) { + /* ignore. */ + } + return -1; + } + + /** + * Returns the revision of the external library file. + * + * @return The revision of the external library file + */ + public String getExtRevision() { + return getField("ExtRevision"); + } + + /** + * Returns the revision number of the external library file. + * + * @return The revision number of the external library file, or + * -1 if the revision number could not be determined + */ + public int getExtRevisionNumber() { + String extRevision = getExtRevision(); + try { + return Integer.valueOf(extRevision); + } catch (NumberFormatException nfe1) { + /* ignore. */ + } + return -1; + } + + /** + * Returns the FCP version the node speaks. + * + * @return The FCP version the node speaks + */ + public String getFCPVersion() { + return getField("FCPVersion"); + } + + /** + * Returns the make of the node, e.g. “Fred” (freenet reference + * implementation). + * + * @return The make of the node + */ + public String getNode() { + return getField("Node"); + } + + /** + * Returns the language of the node as 2-letter code, e.g. “en” or “de”. + * + * @return The language of the node + */ + public String getNodeLanguage() { + return getField("NodeLanguage"); + } + + /** + * Returns the revision of the node. + * + * @return The revision of the node + */ + public String getRevision() { + return getField("Revision"); + } + + /** + * Returns the revision number of the node. + * + * @return The revision number of the node, or -1 if the + * revision number coult not be determined + */ + public int getRevisionNumber() { + String revision = getRevision(); + try { + return Integer.valueOf(revision); + } catch (NumberFormatException nfe1) { + /* ignore. */ + } + return -1; + } + + /** + * Returns whether the node is currently is testnet mode. + * + * @return true if the node is currently in testnet mode, + * false otherwise + */ + public boolean getTestnet() { + return Boolean.valueOf(getField("Testnet")); + } + + /** + * Returns the version of the node. + * + * @return The version of the node + */ + public String getVersion() { + return getField("Version"); + } + +} diff --git a/src/net/pterodactylus/util/fcp/Peer.java b/src/net/pterodactylus/util/fcp/Peer.java new file mode 100644 index 0000000..c3dac0d --- /dev/null +++ b/src/net/pterodactylus/util/fcp/Peer.java @@ -0,0 +1,142 @@ +/** + * © 2008 INA Service GmbH + */ +package net.pterodactylus.util.fcp; + + + +/** + * The “Peer” reply by the node contains information about a peer. + * + * @author David Roden + * @version $Id$ + */ +public class Peer extends BaseMessage { + + /** + * Creates a new “Peer” reply from the received message. + * + * @param receivedMessage + * The received message + */ + public Peer(FcpMessage receivedMessage) { + super(receivedMessage); + } + + /** + * Returns the “physical.udp” line from the message. It contains all IP + * addresses and port numbers of the peer. + * + * @return The IP addresses and port numbers of the peer + */ + public String getPhysicalUDP() { + return getField("physical.udp"); + } + + /** + * Returns whether the listed peer is an opennet peer. + * + * @return true if the peer is an opennet peer, + * false if the peer is a darknet peer + */ + public boolean isOpennet() { + return Boolean.valueOf(getField("opennet")); + } + + /** + * Returns the “y” part of the peer’s public DSA key. + * + * @return The public DSA key + */ + public String getDSAPublicKey() { + return getField("dsaPubKey.y"); + } + + /** + * Returns the DSA group of the peer. + * + * @return The DSA group of the peer + */ + public DSAGroup getDSAGroup() { + return new DSAGroup(getField("dsaGroup.g"), getField("dsaGroup.p"), getField("dsaGroup.q")); + } + + /** + * Returns the last good version of the peer, i.e. the oldest version the + * peer will connect to. + * + * @return The last good version of the peer + */ + public Version getLastGoodVersion() { + return new Version(getField("lastGoodVersion")); + } + + /** + * Returns the ARK of the peer. + * + * @return The ARK of the peer + */ + public ARK getARK() { + return new ARK(getField("ark.pubURI"), getField("ark.number")); + } + + /** + * Returns the identity of the peer. + * + * @return The identity of the peer + */ + public String getIdentity() { + return getField("identity"); + } + + /** + * Returns the name of the peer. If the peer is not a darknet peer it will + * have no name. + * + * @return The name of the peer, or null if the peer is an + * opennet peer + */ + public String getMyName() { + return getField("myName"); + } + + /** + * Returns the location of the peer. + * + * @return The location of the peer + * @throws NumberFormatException + * if the field can not be parsed + */ + public double getLocation() throws NumberFormatException { + return Double.valueOf(getField("location")); + } + + /** + * Returns whether the peer is a testnet node. + * + * @return true if the peer is a testnet node, + * false otherwise + */ + public boolean isTestnet() { + return Boolean.valueOf("testnet"); + } + + /** + * Returns the version of the peer. + * + * @return The version of the peer + */ + public Version getVersion() { + return new Version(getField("version")); + } + + /** + * Returns the negotiation types the peer supports. + * + * @return The supported negotiation types + */ + public int[] getNegotiationTypes() { + return FcpUtils.parseMultiIntegerField(getField("auth.negTypes")); + } + +} diff --git a/src/net/pterodactylus/util/fcp/PeerNote.java b/src/net/pterodactylus/util/fcp/PeerNote.java new file mode 100644 index 0000000..a1a0e35 --- /dev/null +++ b/src/net/pterodactylus/util/fcp/PeerNote.java @@ -0,0 +1,51 @@ +/** + * © 2008 INA Service GmbH + */ +package net.pterodactylus.util.fcp; + + +/** + * The “PeerNote” message contains a private note that has been entered for a + * darknet peer. + * + * @author David Roden + * @version $Id$ + */ +public class PeerNote extends BaseMessage { + + /** The type for base64 encoded peer notes. */ + public static final int NOTE_TYPE_BASE64 = 1; + + /** + * Creates a “PeerNote” message that wraps the recevied message. + * + * @param receivedMessage + * The received message + */ + public PeerNote(FcpMessage receivedMessage) { + super(receivedMessage); + } + + /** + * Returns the note text in whatever format is specified by + * {@link #getPeerNoteType()}. + * + * @return The note text + */ + public String getNoteText() { + return getField("NoteText"); + } + + /** + * Returns the type of the peer note. The type 1 means that + * the text of the note is base64-encoded. + * + * @return The type of the peer note + * @throws NumberFormatException + * if the field can not be parsed + */ + public int getPeerNoteType() throws NumberFormatException { + return Integer.valueOf(getField("PeerNoteType")); + } + +} diff --git a/src/net/pterodactylus/util/fcp/SSKKeypair.java b/src/net/pterodactylus/util/fcp/SSKKeypair.java new file mode 100644 index 0000000..ededed9 --- /dev/null +++ b/src/net/pterodactylus/util/fcp/SSKKeypair.java @@ -0,0 +1,53 @@ +/** + * © 2008 INA Service GmbH + */ +package net.pterodactylus.util.fcp; + + +/** + * An “SSKKeypair” message that is sent as a response to a {@link GenerateSSK} + * message. + * + * @author David Roden + * @version $Id$ + */ +public class SSKKeypair extends BaseMessage { + + /** + * Creates a new “SSKKeypair” message that wraps the received message. + * + * @param receivedMessage + * The received message + */ + public SSKKeypair(FcpMessage receivedMessage) { + super(receivedMessage); + } + + /** + * Returns the identifier of the request. + * + * @return The identifier of the request + */ + public String getIdentifier() { + return getField("Identifier"); + } + + /** + * Returns the URI that must be used to insert data. + * + * @return The insert URI + */ + public String getInsertURI() { + return getField("InsertURI"); + } + + /** + * Returns the URI that must be used to request data. + * + * @return The request URI + */ + public String getRequestURI() { + return getField("RequestURI"); + } + +} diff --git a/src/net/pterodactylus/util/fcp/Version.java b/src/net/pterodactylus/util/fcp/Version.java new file mode 100644 index 0000000..0bcb28b --- /dev/null +++ b/src/net/pterodactylus/util/fcp/Version.java @@ -0,0 +1,110 @@ +package net.pterodactylus.util.fcp; + +import java.util.StringTokenizer; + +/** + * Container for the “lastGoodVersion” field. + * + * @author David Roden + * @version $Id$ + */ +public class Version { + + /** The name of the node implementation. */ + private final String nodeName; + + /** The tree version of the node. */ + private final String treeVersion; + + /** The protocol version of the node. */ + private final String protocolVersion; + + /** The build number of the node. */ + private final int buildNumber; + + /** + * 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. + * + * @param version + * The version string + * @throws NullPointerException + * if version is null + * @throws IllegalArgumentException + * if version is not in the right format + */ + public Version(String version) { + if (version == null) { + throw new NullPointerException("version must not be null"); + } + StringTokenizer versionTokens = new StringTokenizer(version, ","); + if (versionTokens.countTokens() != 4) { + throw new IllegalArgumentException("version must consist of four fields"); + } + this.nodeName = versionTokens.nextToken(); + this.treeVersion = versionTokens.nextToken(); + this.protocolVersion = versionTokens.nextToken(); + try { + this.buildNumber = Integer.valueOf(versionTokens.nextToken()); + } catch (NumberFormatException nfe1) { + throw new IllegalArgumentException("last part of version must be numeric", nfe1); + } + } + + /** + * Creates a new Version from the given parts. + * + * @param nodeName + * The name of the node implementation + * @param treeVersion + * The tree version + * @param protocolVersion + * The protocol version + * @param buildNumber + * The build number of the node + */ + public Version(String nodeName, String treeVersion, String protocolVersion, int buildNumber) { + this.nodeName = nodeName; + this.treeVersion = treeVersion; + this.protocolVersion = protocolVersion; + this.buildNumber = buildNumber; + } + + /** + * Returns the name of the node implementation. + * + * @return The node name + */ + public String getNodeName() { + return nodeName; + } + + /** + * The tree version of the node. + * + * @return The tree version of the node + */ + public String getTreeVersion() { + return treeVersion; + } + + /** + * The protocol version of the node + * + * @return The protocol version of the node + */ + public String getProtocolVersion() { + return protocolVersion; + } + + /** + * The build number of the node. + * + * @return The build number of the node + */ + public int getBuildNumber() { + return buildNumber; + } + +} \ No newline at end of file diff --git a/src/net/pterodactylus/util/fcp/message/BaseMessage.java b/src/net/pterodactylus/util/fcp/message/BaseMessage.java deleted file mode 100644 index 03613a6..0000000 --- a/src/net/pterodactylus/util/fcp/message/BaseMessage.java +++ /dev/null @@ -1,50 +0,0 @@ -/** - * © 2008 INA Service GmbH - */ -package net.pterodactylus.util.fcp.message; - -import net.pterodactylus.util.fcp.FcpMessage; - -/** - * A basic message abstraction that wraps a received FCP message. - * - * @author David Roden - * @version $Id$ - */ -public class BaseMessage { - - /** The received message, wrapped here. */ - private final FcpMessage receivedMessage; - - /** - * Creates a new base message that wraps the given message. - * - * @param receivedMessage - * The FCP message that was received - */ - public BaseMessage(FcpMessage receivedMessage) { - this.receivedMessage = receivedMessage; - } - - /** - * Returns the name of the message. - * - * @return The name of the message - */ - public String getName() { - return receivedMessage.getName(); - } - - /** - * Returns the content of the field. - * - * @param field - * The name of the field - * @return The content of the field, or null if there is no - * such field - */ - public String getField(String field) { - return receivedMessage.getField(field); - } - -} diff --git a/src/net/pterodactylus/util/fcp/message/ClientHello.java b/src/net/pterodactylus/util/fcp/message/ClientHello.java deleted file mode 100644 index fe68321..0000000 --- a/src/net/pterodactylus/util/fcp/message/ClientHello.java +++ /dev/null @@ -1,48 +0,0 @@ -/** - * © 2008 INA Service GmbH - */ -package net.pterodactylus.util.fcp.message; - -import net.pterodactylus.util.fcp.FcpConnection; -import net.pterodactylus.util.fcp.FcpMessage; - -/** - * A “ClientHello” message that must be sent to the node first thing - * after calling {@link FcpConnection#connect()}. - * - * @author David Roden - * @version $Id$ - */ -public class ClientHello extends FcpMessage { - - /** - * Creates a new “ClientHello” message with the given client name. The - * client name has to be unique to the node otherwise you will get a - * {@link CloseConnectionDuplicateClientName} response from the node! - * - * @param clientName - * The unique client name - */ - public ClientHello(String clientName) { - this(clientName, "2.0"); - } - - /** - * Creates a new “ClientHello” message with the given client name. The - * client name has to be unique to the node otherwise you will get a - * {@link CloseConnectionDuplicateClientName} response from the node! - * - * The expected FCP version is currently ignored by the node. - * - * @param clientName - * The unique client name - * @param expectedVersion - * The FCP version that the node is expected to talk - */ - public ClientHello(String clientName, String expectedVersion) { - super("ClientHello"); - setField("Name", clientName); - setField("ExpectedVersion", expectedVersion); - } - -} diff --git a/src/net/pterodactylus/util/fcp/message/CloseConnectionDuplicateClientName.java b/src/net/pterodactylus/util/fcp/message/CloseConnectionDuplicateClientName.java deleted file mode 100644 index 6d7aa64..0000000 --- a/src/net/pterodactylus/util/fcp/message/CloseConnectionDuplicateClientName.java +++ /dev/null @@ -1,27 +0,0 @@ -/** - * © 2008 INA Service GmbH - */ -package net.pterodactylus.util.fcp.message; - -import net.pterodactylus.util.fcp.FcpMessage; - -/** - * A “CloseConnectionDuplicateClientName” message. - * - * @author David Roden - * @version $Id$ - */ -public class CloseConnectionDuplicateClientName extends BaseMessage { - - /** - * Creates a new CloseConnectionDuplicateClientName message that wraps the - * given message. - * - * @param receivedMessage - * The received message - */ - public CloseConnectionDuplicateClientName(FcpMessage receivedMessage) { - super(receivedMessage); - } - -} diff --git a/src/net/pterodactylus/util/fcp/message/EndListPeerNotes.java b/src/net/pterodactylus/util/fcp/message/EndListPeerNotes.java deleted file mode 100644 index 5efa7b2..0000000 --- a/src/net/pterodactylus/util/fcp/message/EndListPeerNotes.java +++ /dev/null @@ -1,27 +0,0 @@ -/** - * © 2008 INA Service GmbH - */ -package net.pterodactylus.util.fcp.message; - -import net.pterodactylus.util.fcp.FcpMessage; - -/** - * The “EndListPeerNotes” message signals the end of a list of “PeerNote” - * messages. - * - * @author David Roden - * @version $Id$ - */ -public class EndListPeerNotes extends BaseMessage { - - /** - * Creates a new “EndListPeerNotes” message that wraps the received message. - * - * @param fcpMessage - * The received message - */ - public EndListPeerNotes(FcpMessage fcpMessage) { - super(fcpMessage); - } - -} diff --git a/src/net/pterodactylus/util/fcp/message/EndListPeers.java b/src/net/pterodactylus/util/fcp/message/EndListPeers.java deleted file mode 100644 index 2fac3fb..0000000 --- a/src/net/pterodactylus/util/fcp/message/EndListPeers.java +++ /dev/null @@ -1,26 +0,0 @@ -/** - * © 2008 INA Service GmbH - */ -package net.pterodactylus.util.fcp.message; - -import net.pterodactylus.util.fcp.FcpMessage; - -/** - * This message marks the end of a list of “Peer” replies. - * - * @author David Roden - * @version $Id$ - */ -public class EndListPeers extends BaseMessage { - - /** - * Creates a new “EndListPeers” message that wraps the received message. - * - * @param receivedMessage - * The message that was received - */ - public EndListPeers(FcpMessage receivedMessage) { - super(receivedMessage); - } - -} diff --git a/src/net/pterodactylus/util/fcp/message/GenerateSSK.java b/src/net/pterodactylus/util/fcp/message/GenerateSSK.java deleted file mode 100644 index f6f2929..0000000 --- a/src/net/pterodactylus/util/fcp/message/GenerateSSK.java +++ /dev/null @@ -1,36 +0,0 @@ -/** - * © 2008 INA Service GmbH - */ -package net.pterodactylus.util.fcp.message; - -import net.pterodactylus.util.fcp.FcpMessage; -import net.pterodactylus.util.fcp.FcpUtils; - -/** - * A “GenerateSSK” message. This message tells the node to generate a new SSK - * key pair. - * - * @author David Roden - * @version $Id$ - */ -public class GenerateSSK extends FcpMessage { - - /** - * Creates a new “GenerateSSK” message. - */ - public GenerateSSK() { - this(FcpUtils.getUniqueIdentifier()); - } - - /** - * Creates a new “GenerateSSK” message with the given client identifier. - * - * @param clientIdentifier - * The client identifier - */ - public GenerateSSK(String clientIdentifier) { - super("GenerateSSK"); - setField("Identifier", clientIdentifier); - } - -} diff --git a/src/net/pterodactylus/util/fcp/message/ListPeer.java b/src/net/pterodactylus/util/fcp/message/ListPeer.java deleted file mode 100644 index a09a868..0000000 --- a/src/net/pterodactylus/util/fcp/message/ListPeer.java +++ /dev/null @@ -1,30 +0,0 @@ -/** - * © 2008 INA Service GmbH - */ -package net.pterodactylus.util.fcp.message; - -import net.pterodactylus.util.fcp.FcpMessage; - -/** - * The “ListPeer” request asks the node about the details of a given peer. - * - * @author David Roden - * @version $Id$ - */ -public class ListPeer extends FcpMessage { - - /** - * Creates a new “ListPeer” request that returns information about the node - * specified by nodeIdentifier. nodeIdentifier - * 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 - */ - public ListPeer(String nodeIdentifier) { - super("ListPeer"); - setField("NodeIdentifier", nodeIdentifier); - } - -} diff --git a/src/net/pterodactylus/util/fcp/message/ListPeerNotes.java b/src/net/pterodactylus/util/fcp/message/ListPeerNotes.java deleted file mode 100644 index 2d5641b..0000000 --- a/src/net/pterodactylus/util/fcp/message/ListPeerNotes.java +++ /dev/null @@ -1,29 +0,0 @@ -/** - * © 2008 INA Service GmbH - */ -package net.pterodactylus.util.fcp.message; - -import net.pterodactylus.util.fcp.FcpMessage; - -/** - * A “ListPeerNodes” request tells the node to list all notes that have been - * entered for a node. Note that notes are only supported for darknet nodes. - * - * @author David Roden - * @version $Id$ - */ -public class ListPeerNotes extends FcpMessage { - - /** - * Creates a new “ListPeerNotes” request that lists all notes of the - * specified node. - * - * @param nodeIdentifier - * The identifier of the node - */ - public ListPeerNotes(String nodeIdentifier) { - super("ListPeerNotes"); - setField("NodeIdentifier", nodeIdentifier); - } - -} diff --git a/src/net/pterodactylus/util/fcp/message/ListPeers.java b/src/net/pterodactylus/util/fcp/message/ListPeers.java deleted file mode 100644 index c585868..0000000 --- a/src/net/pterodactylus/util/fcp/message/ListPeers.java +++ /dev/null @@ -1,40 +0,0 @@ -/** - * © 2008 INA Service GmbH - */ -package net.pterodactylus.util.fcp.message; - -import net.pterodactylus.util.fcp.FcpMessage; - -/** - * The “ListPeer” requests asks the node for a list of all peers it has. - * - * @author David Roden - * @version $Id$ - */ -public class ListPeers extends FcpMessage { - - /** - * Creates a new “ListPeers” request that only includes basic data of the - * peers. - */ - public ListPeers() { - this(false, false); - } - - /** - * Creates a new “ListPeers” request that includes wanted data of the peers. - * - * @param withMetadata - * If true metadata of the peers is included in - * the reply - * @param withVolatile - * if true volatile data of the peers is included - * in the reply - */ - public ListPeers(boolean withMetadata, boolean withVolatile) { - super("ListPeers"); - setField("WithMetadata", String.valueOf(withMetadata)); - setField("WithVolatile", String.valueOf(withVolatile)); - } - -} diff --git a/src/net/pterodactylus/util/fcp/message/NodeHello.java b/src/net/pterodactylus/util/fcp/message/NodeHello.java deleted file mode 100644 index c8e8540..0000000 --- a/src/net/pterodactylus/util/fcp/message/NodeHello.java +++ /dev/null @@ -1,209 +0,0 @@ -/** - * © 2008 INA Service GmbH - */ -package net.pterodactylus.util.fcp.message; - -import net.pterodactylus.util.fcp.FcpMessage; - -/** - * Some convenience methods for parsing a “NodeHello” message from the node. - * - * @author David Roden - * @version $Id$ - */ -public class NodeHello extends BaseMessage { - - /** - * Createa a new “NodeHello” message that wraps the received message. - * - * @param receivedMessage - * The received FCP message - */ - public NodeHello(FcpMessage receivedMessage) { - super(receivedMessage); - } - - /** - * 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 - */ - public String getBuild() { - return getField("Build"); - } - - /** - * Returns the build number of the node. This may not be a number but also a - * string like “@custom@” in case you built the node yourself. - * - * @return The build number of the node, or -1 if the build - * number could not be determined - */ - public int getBuildNumber() { - String build = getBuild(); - try { - return Integer.valueOf(build); - } catch (NumberFormatException nfe1) { - /* ignore. */ - } - return -1; - } - - /** - * Returns the number of compression codecs. - * - * @return The number of compression codecs - */ - public String getCompressionCodecs() { - return getField("CompressionCodecs"); - } - - /** - * Returns the number of compression codecs. - * - * @return The number of compression codecs, or -1 if the - * number of compression codecs could not be determined - */ - public int getCompressionCodecsNumber() { - String compressionCodecs = getCompressionCodecs(); - try { - return Integer.valueOf(compressionCodecs); - } catch (NumberFormatException nfe1) { - /* ignore. */ - } - return -1; - } - - /** - * Returns the unique connection identifier. - * - * @return The connection identifier - */ - public String getConnectionIdentifier() { - return getField("ConnectionIdentifier"); - } - - /** - * Returns the build of the external library file. - * - * @return The build of the external library file - */ - public String getExtBuild() { - return getField("ExtBuild"); - } - - /** - * Returns the build number of the external library file. - * - * @return The build number of the external library file, or -1 - * if the build number could not be determined - */ - public int getExtBuildNumber() { - String extBuild = getExtBuild(); - try { - return Integer.valueOf(extBuild); - } catch (NumberFormatException nfe1) { - /* ignore. */ - } - return -1; - } - - /** - * Returns the revision of the external library file. - * - * @return The revision of the external library file - */ - public String getExtRevision() { - return getField("ExtRevision"); - } - - /** - * Returns the revision number of the external library file. - * - * @return The revision number of the external library file, or - * -1 if the revision number could not be determined - */ - public int getExtRevisionNumber() { - String extRevision = getExtRevision(); - try { - return Integer.valueOf(extRevision); - } catch (NumberFormatException nfe1) { - /* ignore. */ - } - return -1; - } - - /** - * Returns the FCP version the node speaks. - * - * @return The FCP version the node speaks - */ - public String getFCPVersion() { - return getField("FCPVersion"); - } - - /** - * Returns the make of the node, e.g. “Fred” (freenet reference - * implementation). - * - * @return The make of the node - */ - public String getNode() { - return getField("Node"); - } - - /** - * Returns the language of the node as 2-letter code, e.g. “en” or “de”. - * - * @return The language of the node - */ - public String getNodeLanguage() { - return getField("NodeLanguage"); - } - - /** - * Returns the revision of the node. - * - * @return The revision of the node - */ - public String getRevision() { - return getField("Revision"); - } - - /** - * Returns the revision number of the node. - * - * @return The revision number of the node, or -1 if the - * revision number coult not be determined - */ - public int getRevisionNumber() { - String revision = getRevision(); - try { - return Integer.valueOf(revision); - } catch (NumberFormatException nfe1) { - /* ignore. */ - } - return -1; - } - - /** - * Returns whether the node is currently is testnet mode. - * - * @return true if the node is currently in testnet mode, - * false otherwise - */ - public boolean getTestnet() { - return Boolean.valueOf(getField("Testnet")); - } - - /** - * Returns the version of the node. - * - * @return The version of the node - */ - public String getVersion() { - return getField("Version"); - } - -} diff --git a/src/net/pterodactylus/util/fcp/message/Peer.java b/src/net/pterodactylus/util/fcp/message/Peer.java deleted file mode 100644 index 9a20378..0000000 --- a/src/net/pterodactylus/util/fcp/message/Peer.java +++ /dev/null @@ -1,372 +0,0 @@ -/** - * © 2008 INA Service GmbH - */ -package net.pterodactylus.util.fcp.message; - -import java.security.interfaces.DSAParams; -import java.util.StringTokenizer; - -import net.pterodactylus.util.fcp.FcpMessage; -import net.pterodactylus.util.fcp.FcpUtils; - -/** - * The “Peer” reply by the node contains information about a peer. - * - * @author David Roden - * @version $Id$ - */ -public class Peer extends BaseMessage { - - /** - * Creates a new “Peer” reply from the received message. - * - * @param receivedMessage - * The received message - */ - public Peer(FcpMessage receivedMessage) { - super(receivedMessage); - } - - /** - * Returns the “physical.udp” line from the message. It contains all IP - * addresses and port numbers of the peer. - * - * @return The IP addresses and port numbers of the peer - */ - public String getPhysicalUDP() { - return getField("physical.udp"); - } - - /** - * Returns whether the listed peer is an opennet peer. - * - * @return true if the peer is an opennet peer, - * false if the peer is a darknet peer - */ - public boolean isOpennet() { - return Boolean.valueOf(getField("opennet")); - } - - /** - * Returns the “y” part of the peer’s public DSA key. - * - * @return The public DSA key - */ - public String getDSAPublicKey() { - return getField("dsaPubKey.y"); - } - - /** - * Returns the DSA group of the peer. - * - * @return The DSA group of the peer - */ - public DSAGroup getDSAGroup() { - return new DSAGroup(getField("dsaGroup.g"), getField("dsaGroup.p"), getField("dsaGroup.q")); - } - - /** - * Returns the last good version of the peer, i.e. the oldest version the - * peer will connect to. - * - * @return The last good version of the peer - */ - public Version getLastGoodVersion() { - return new Version(getField("lastGoodVersion")); - } - - /** - * Returns the ARK of the peer. - * - * @return The ARK of the peer - */ - public ARK getARK() { - return new ARK(getField("ark.pubURI"), getField("ark.number")); - } - - /** - * Returns the identity of the peer. - * - * @return The identity of the peer - */ - public String getIdentity() { - return getField("identity"); - } - - /** - * Returns the name of the peer. If the peer is not a darknet peer it will - * have no name. - * - * @return The name of the peer, or null if the peer is an - * opennet peer - */ - public String getMyName() { - return getField("myName"); - } - - /** - * Returns the location of the peer. - * - * @return The location of the peer - * @throws NumberFormatException - * if the field can not be parsed - */ - public double getLocation() throws NumberFormatException { - return Double.valueOf(getField("location")); - } - - /** - * Returns whether the peer is a testnet node. - * - * @return true if the peer is a testnet node, - * false otherwise - */ - public boolean isTestnet() { - return Boolean.valueOf("testnet"); - } - - /** - * Returns the version of the peer. - * - * @return The version of the peer - */ - public Version getVersion() { - return new Version(getField("version")); - } - - /** - * Returns the negotiation types the peer supports. - * - * @return The supported negotiation types - */ - public int[] getNegotiationTypes() { - return FcpUtils.parseMultiIntegerField(getField("auth.negTypes")); - } - - /** - * Container for the “lastGoodVersion” field. - * - * @author David Roden - * @version $Id$ - */ - public static class Version { - - /** The name of the node implementation. */ - private final String nodeName; - - /** The tree version of the node. */ - private final String treeVersion; - - /** The protocol version of the node. */ - private final String protocolVersion; - - /** The build number of the node. */ - private final int buildNumber; - - /** - * 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. - * - * @param version - * The version string - * @throws NullPointerException - * if version is null - * @throws IllegalArgumentException - * if version is not in the right format - */ - public Version(String version) { - if (version == null) { - throw new NullPointerException("version must not be null"); - } - StringTokenizer versionTokens = new StringTokenizer(version, ","); - if (versionTokens.countTokens() != 4) { - throw new IllegalArgumentException("version must consist of four fields"); - } - this.nodeName = versionTokens.nextToken(); - this.treeVersion = versionTokens.nextToken(); - this.protocolVersion = versionTokens.nextToken(); - try { - this.buildNumber = Integer.valueOf(versionTokens.nextToken()); - } catch (NumberFormatException nfe1) { - throw new IllegalArgumentException("last part of version must be numeric", nfe1); - } - } - - /** - * Creates a new Version from the given parts. - * - * @param nodeName - * The name of the node implementation - * @param treeVersion - * The tree version - * @param protocolVersion - * The protocol version - * @param buildNumber - * The build number of the node - */ - public Version(String nodeName, String treeVersion, String protocolVersion, int buildNumber) { - this.nodeName = nodeName; - this.treeVersion = treeVersion; - this.protocolVersion = protocolVersion; - this.buildNumber = buildNumber; - } - - /** - * Returns the name of the node implementation. - * - * @return The node name - */ - public String getNodeName() { - return nodeName; - } - - /** - * The tree version of the node. - * - * @return The tree version of the node - */ - public String getTreeVersion() { - return treeVersion; - } - - /** - * The protocol version of the node - * - * @return The protocol version of the node - */ - public String getProtocolVersion() { - return protocolVersion; - } - - /** - * The build number of the node. - * - * @return The build number of the node - */ - public int getBuildNumber() { - return buildNumber; - } - - } - - /** - * Container for ARKs (address resolution keys). - * - * @author David Roden - * @version $Id$ - */ - public static class ARK { - - /** The public URI of the ARK. */ - private final String publicURI; - - /** The number of the ARK. */ - private final int number; - - /** - * Creates a new ARK with the given URI and number. - * - * @param publicURI - * The public URI of the ARK - * @param number - * The number of the ARK - */ - public ARK(String publicURI, String number) { - if ((publicURI == null) || (number == null)) { - throw new NullPointerException(((publicURI == null) ? "publicURI" : "number") + " must not be null"); - } - this.publicURI = publicURI; - try { - this.number = Integer.valueOf(number); - } catch (NumberFormatException nfe1) { - throw new IllegalArgumentException("number must be numeric", nfe1); - } - } - - /** - * Returns the public URI of the ARK. - * - * @return The public URI of the ARK - */ - public String getPublicURI() { - return publicURI; - } - - /** - * Returns the number of the ARK. - * - * @return The number of the ARK - */ - public int getNumber() { - return number; - } - - } - - /** - * 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 Roden - * @version $Id$ - */ - public static class DSAGroup { - - /** The base of the DSA group. */ - private final String base; - - /** The prime of the DSA group. */ - private final String prime; - - /** The subprime of the DSA group. */ - private final String subprime; - - /** - * Creates a new DSA group with the given base (“g”), prime (“p”), and - * subprime (“q”). - * - * @param base - * The base of the DSA group - * @param prime - * The prime of the DSA group - * @param subprime - * The subprime of the DSA group - */ - public DSAGroup(String base, String prime, String subprime) { - this.base = base; - this.prime = prime; - this.subprime = subprime; - } - - /** - * Returns the base (“g”) of the DSA group. - * - * @return The base of the DSA group - */ - public String getBase() { - return base; - } - - /** - * Returns the prime (“p”) of the DSA group. - * - * @return The prime of the DSA group - */ - public String getPrime() { - return prime; - } - - /** - * Returns the subprime (“q”) of the DSA group. - * - * @return The subprime of the DSA group - */ - public String getSubprime() { - return subprime; - } - - } - -} diff --git a/src/net/pterodactylus/util/fcp/message/PeerNote.java b/src/net/pterodactylus/util/fcp/message/PeerNote.java deleted file mode 100644 index cd8b157..0000000 --- a/src/net/pterodactylus/util/fcp/message/PeerNote.java +++ /dev/null @@ -1,52 +0,0 @@ -/** - * © 2008 INA Service GmbH - */ -package net.pterodactylus.util.fcp.message; - -import net.pterodactylus.util.fcp.FcpMessage; - -/** - * The “PeerNote” message contains a private note that has been entered for a - * darknet peer. - * - * @author David Roden - * @version $Id$ - */ -public class PeerNote extends BaseMessage { - - /** The type for base64 encoded peer notes. */ - public static final int NOTE_TYPE_BASE64 = 1; - - /** - * Creates a “PeerNote” message that wraps the recevied message. - * - * @param receivedMessage - * The received message - */ - public PeerNote(FcpMessage receivedMessage) { - super(receivedMessage); - } - - /** - * Returns the note text in whatever format is specified by - * {@link #getPeerNoteType()}. - * - * @return The note text - */ - public String getNoteText() { - return getField("NoteText"); - } - - /** - * Returns the type of the peer note. The type 1 means that - * the text of the note is base64-encoded. - * - * @return The type of the peer note - * @throws NumberFormatException - * if the field can not be parsed - */ - public int getPeerNoteType() throws NumberFormatException { - return Integer.valueOf(getField("PeerNoteType")); - } - -} diff --git a/src/net/pterodactylus/util/fcp/message/SSKKeypair.java b/src/net/pterodactylus/util/fcp/message/SSKKeypair.java deleted file mode 100644 index 52b0c1b..0000000 --- a/src/net/pterodactylus/util/fcp/message/SSKKeypair.java +++ /dev/null @@ -1,54 +0,0 @@ -/** - * © 2008 INA Service GmbH - */ -package net.pterodactylus.util.fcp.message; - -import net.pterodactylus.util.fcp.FcpMessage; - -/** - * An “SSKKeypair” message that is sent as a response to a {@link GenerateSSK} - * message. - * - * @author David Roden - * @version $Id$ - */ -public class SSKKeypair extends BaseMessage { - - /** - * Creates a new “SSKKeypair” message that wraps the received message. - * - * @param receivedMessage - * The received message - */ - public SSKKeypair(FcpMessage receivedMessage) { - super(receivedMessage); - } - - /** - * Returns the identifier of the request. - * - * @return The identifier of the request - */ - public String getIdentifier() { - return getField("Identifier"); - } - - /** - * Returns the URI that must be used to insert data. - * - * @return The insert URI - */ - public String getInsertURI() { - return getField("InsertURI"); - } - - /** - * Returns the URI that must be used to request data. - * - * @return The request URI - */ - public String getRequestURI() { - return getField("RequestURI"); - } - -} diff --git a/src/net/pterodactylus/util/fcp/message/package-info.java b/src/net/pterodactylus/util/fcp/message/package-info.java deleted file mode 100644 index 5426433..0000000 --- a/src/net/pterodactylus/util/fcp/message/package-info.java +++ /dev/null @@ -1,4 +0,0 @@ -/** - * Package that holds all the message types that are used in the communication with a Freenet Node. - */ -package net.pterodactylus.util.fcp.message; \ No newline at end of file diff --git a/src/net/pterodactylus/util/fcp/package-info.java b/src/net/pterodactylus/util/fcp/package-info.java new file mode 100644 index 0000000..0567b50 --- /dev/null +++ b/src/net/pterodactylus/util/fcp/package-info.java @@ -0,0 +1,4 @@ +/** + * Package that holds all the message types that are used in the communication with a Freenet Node. + */ +package net.pterodactylus.util.fcp; \ No newline at end of file