--- /dev/null
+/**
+ * © 2008 INA Service GmbH
+ */
+package net.pterodactylus.util.fcp;
+
+import java.net.URL;
+
+/**
+ * The “AddPeer” request adds a peer to the node.
+ *
+ * @author <a href="mailto:dr@ina-germany.de">David Roden</a>
+ * @version $Id$
+ */
+public class AddPeer extends FcpMessage {
+
+ /**
+ * Creates a new “AddPeer” request.
+ */
+ private AddPeer() {
+ super("AddPeer");
+ }
+
+ /**
+ * Creates a new “AddPeer” request that reads the noderef of the peer from
+ * the given file.
+ *
+ * @param file
+ * The file to read the noderef from
+ */
+ public AddPeer(String file) {
+ this();
+ setField("File", file);
+ }
+
+ /**
+ * Creates a new “AddPeer” request that reads the noderef of the peer from
+ * the given URL.
+ *
+ * @param url
+ * The URL to read the noderef from
+ */
+ public AddPeer(URL url) {
+ this();
+ setField("URL", String.valueOf(url));
+ }
+
+ /**
+ * Creates a new “AddPeer” request that adds the peer given by the noderef.
+ *
+ * @param nodeRef
+ * The noderef of the peer
+ */
+ public AddPeer(NodeRef nodeRef) {
+ this();
+ setNodeRef(nodeRef);
+ }
+
+ //
+ // PRIVATE METHODS
+ //
+
+ /**
+ * Sets the noderef of the peer to add.
+ *
+ * @param nodeRef
+ * The noderef of the peer
+ */
+ private void setNodeRef(NodeRef nodeRef) {
+ setField("lastGoodVersion", nodeRef.getLastGoodVersion().toString());
+ setField("opennet", String.valueOf(nodeRef.isOpennet()));
+ setField("identity", nodeRef.getIdentity());
+ setField("myName", nodeRef.getName());
+ setField("location", String.valueOf(nodeRef.getLocation()));
+ setField("testnet", String.valueOf(nodeRef.isTestnet()));
+ setField("version", String.valueOf(nodeRef.getVersion()));
+ setField("physical.udp", nodeRef.getPhysicalUDP());
+ setField("ark.pubURI", nodeRef.getArk().getPublicURI());
+ setField("ark.number", String.valueOf(nodeRef.getArk().getNumber()));
+ setField("dsaPubKey.y", nodeRef.getDSAPublicKey());
+ setField("dsaGroup.g", nodeRef.getDSAGroup().getBase());
+ setField("dsaGroup.p", nodeRef.getDSAGroup().getPrime());
+ setField("dsaGroup.q", nodeRef.getDSAGroup().getSubprime());
+ setField("auth.negTypes", FcpUtils.encodeMultiIntegerField(nodeRef.getNegotiationTypes()));
+ setField("signature", nodeRef.getSignature());
+ }
+
+}
--- /dev/null
+/**
+ * © 2008 INA Service GmbH
+ */
+package net.pterodactylus.util.fcp;
+
+/**
+ * A reference for a node. The noderef contains all data that is necessary to
+ * establish a trusted and secure connection to the node.
+ *
+ * @author <a href="mailto:dr@ina-germany.de">David Roden</a>
+ * @version $Id$
+ */
+public class NodeRef {
+
+ /** The identity of the node. */
+ private String identity;
+
+ /** Whether the node is an opennet peer. */
+ private boolean opennet;
+
+ /** The name of the node. */
+ private String name;
+
+ /** The location of the node. */
+ private double location;
+
+ /** The IP addresses and ports of the node. */
+ private String physicalUDP;
+
+ /** The ARK of the node. */
+ private ARK ark;
+
+ /** The public DSA key of the node. */
+ private String dsaPublicKey;
+
+ /** The DSA group of the node. */
+ private DSAGroup dsaGroup;
+
+ /** The node’s supported negotiation types. */
+ private int[] negotiationTypes;
+
+ /** The version of the node. */
+ private Version version;
+
+ /** The oldest version the node will connect to. */
+ private Version lastGoodVersion;
+
+ /** Whether the node is a testnet node. */
+ private boolean testnet;
+
+ /** The signature of the reference. */
+ private String signature;
+
+ /**
+ * Returns the identity of the node.
+ *
+ * @return The identity of the node
+ */
+ public String getIdentity() {
+ return identity;
+ }
+
+ /**
+ * Sets the identity of the node.
+ *
+ * @param identity
+ * The identity of the node
+ */
+ public void setIdentity(String identity) {
+ this.identity = identity;
+ }
+
+ /**
+ * Returns whether the node is an opennet peer.
+ *
+ * @return <code>true</code> if the node is an opennet peer,
+ * <code>false</code> otherwise
+ */
+ public boolean isOpennet() {
+ return opennet;
+ }
+
+ /**
+ * Sets whether the node is an opennet peer.
+ *
+ * @param opennet
+ * <code>true</code> if the node is an opennet peer,
+ * <code>false</code> otherwise
+ */
+ public void setOpennet(boolean opennet) {
+ this.opennet = opennet;
+ }
+
+ /**
+ * 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
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Sets the name of the peer.
+ *
+ * @param name
+ * The name of the peer
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
+ * Returns the location of the node.
+ *
+ * @return The location of the node
+ */
+ public double getLocation() {
+ return location;
+ }
+
+ /**
+ * Sets the location of the node
+ *
+ * @param location
+ * The location of the node
+ */
+ public void setLocation(double location) {
+ this.location = location;
+ }
+
+ /**
+ * Returns the IP addresses and port numbers of the node.
+ *
+ * @return The IP addresses and port numbers of the node
+ */
+ public String getPhysicalUDP() {
+ return physicalUDP;
+ }
+
+ /**
+ * Sets the IP addresses and port numbers of the node.
+ *
+ * @param physicalUDP
+ * The IP addresses and port numbers of the node
+ */
+ public void setPhysicalUDP(String physicalUDP) {
+ this.physicalUDP = physicalUDP;
+ }
+
+ /**
+ * Returns the ARK of the node.
+ *
+ * @return The ARK of the node
+ */
+ public ARK getArk() {
+ return ark;
+ }
+
+ /**
+ * Sets the ARK of the node.
+ *
+ * @param ark
+ * The ARK of the node
+ */
+ public void setArk(ARK ark) {
+ this.ark = ark;
+ }
+
+ /**
+ * Returns the public DSA key of the node.
+ *
+ * @return The public DSA key of the node
+ */
+ public String getDSAPublicKey() {
+ return dsaPublicKey;
+ }
+
+ /**
+ * Sets the public DSA key of the node.
+ *
+ * @param dsaPublicKey
+ * The public DSA key of the node
+ */
+ public void setDSAPublicKey(String dsaPublicKey) {
+ this.dsaPublicKey = dsaPublicKey;
+ }
+
+ /**
+ * Returns the DSA group of the node.
+ *
+ * @return The DSA group of the node
+ */
+ public DSAGroup getDSAGroup() {
+ return dsaGroup;
+ }
+
+ /**
+ * Sets the DSA group of the node.
+ *
+ * @param dsaGroup
+ * The DSA group of the node
+ */
+ public void setDSAGroup(DSAGroup dsaGroup) {
+ this.dsaGroup = dsaGroup;
+ }
+
+ /**
+ * Returns the negotiation types supported by the node.
+ *
+ * @return The node’s supported negotiation types
+ */
+ public int[] getNegotiationTypes() {
+ return negotiationTypes;
+ }
+
+ /**
+ * Sets the negotiation types supported by the node.
+ *
+ * @param negotiationTypes
+ * The node’s supported negotiation types
+ */
+ public void setNegotiationTypes(int[] negotiationTypes) {
+ this.negotiationTypes = negotiationTypes;
+ }
+
+ /**
+ * Returns the version of the node.
+ *
+ * @return The version of the node
+ */
+ public Version getVersion() {
+ return version;
+ }
+
+ /**
+ * Sets the version of the node.
+ *
+ * @param version
+ * The version of the node
+ */
+ public void setVersion(Version version) {
+ this.version = version;
+ }
+
+ /**
+ * Returns the last good version of the node.
+ *
+ * @return The oldest version the node will connect to
+ */
+ public Version getLastGoodVersion() {
+ return lastGoodVersion;
+ }
+
+ /**
+ * Sets the last good version of the node.
+ *
+ * @param lastGoodVersion
+ * The oldest version the node will connect to
+ */
+ public void setLastGoodVersion(Version lastGoodVersion) {
+ this.lastGoodVersion = lastGoodVersion;
+ }
+
+ /**
+ * Returns whether the node is a testnet node.
+ *
+ * @return <code>true</code> if the node is a testnet node,
+ * <code>false</code> otherwise
+ */
+ public boolean isTestnet() {
+ return testnet;
+ }
+
+ /**
+ * Sets whether this node is a testnet node.
+ *
+ * @param testnet
+ * <code>true</code> if the node is a testnet node,
+ * <code>false</code> otherwise
+ */
+ public void setTestnet(boolean testnet) {
+ this.testnet = testnet;
+ }
+
+ /**
+ * Returns the signature of the noderef.
+ *
+ * @return The signature of the noderef
+ */
+ public String getSignature() {
+ return signature;
+ }
+
+ /**
+ * Sets the signature of the noderef.
+ *
+ * @param signature
+ * The signature of the noderef
+ */
+ public void setSignature(String signature) {
+ this.signature = signature;
+ }
+
+}