2 * jFCPlib - NodeRef.java - Copyright © 2008 David Roden
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 package net.pterodactylus.fcp;
22 * A reference for a node. The noderef contains all data that is necessary to
23 * establish a trusted and secure connection to the node.
25 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
27 public class NodeRef {
29 /** The identity of the node. */
30 private String identity;
32 /** Whether the node is an opennet peer. */
33 private boolean opennet;
35 /** The name of the node. */
38 /** The location of the node. */
39 private double location;
41 /** The IP addresses and ports of the node. */
42 private String physicalUDP;
44 /** The ARK of the node. */
47 /** The public DSA key of the node. */
48 private String dsaPublicKey;
50 /** The DSA group of the node. */
51 private DSAGroup dsaGroup;
53 /** The node’s supported negotiation types. */
54 private int[] negotiationTypes;
56 /** The version of the node. */
57 private Version version;
59 /** The oldest version the node will connect to. */
60 private Version lastGoodVersion;
62 /** Whether the node is a testnet node. */
63 private boolean testnet;
65 /** The signature of the reference. */
66 private String signature;
69 * Creates a new, empty noderef.
72 /* intentionally left blank. */
76 * Creates a new noderef that is initialized with fields from the given
80 * The message to get initial values for the noderef from
82 public NodeRef(FcpMessage fromMessage) {
83 identity = fromMessage.getField("identity");
84 opennet = Boolean.valueOf(fromMessage.getField("opennet"));
85 name = fromMessage.getField("myName");
86 if (fromMessage.hasField("location")) {
87 location = Double.valueOf(fromMessage.getField("location"));
89 physicalUDP = fromMessage.getField("physical.udp");
90 ark = new ARK(fromMessage.getField("ark.pubURI"), fromMessage.getField("ark.privURI"), fromMessage.getField("ark.number"));
91 dsaPublicKey = fromMessage.getField("dsaPubKey.y");
92 dsaGroup = new DSAGroup(fromMessage.getField("dsaGroup.b"), fromMessage.getField("dsaGroup.p"), fromMessage.getField("dsaGroup.q"));
93 negotiationTypes = FcpUtils.decodeMultiIntegerField(fromMessage.getField("auth.negTypes"));
94 version = new Version(fromMessage.getField("version"));
95 lastGoodVersion = new Version(fromMessage.getField("lastGoodVersion"));
96 testnet = Boolean.valueOf(fromMessage.getField("testnet"));
97 signature = fromMessage.getField("sig");
101 * Returns the identity of the node.
103 * @return The identity of the node
105 public String getIdentity() {
110 * Sets the identity of the node.
113 * The identity of the node
115 public void setIdentity(String identity) {
116 this.identity = identity;
120 * Returns whether the node is an opennet peer.
122 * @return <code>true</code> if the node is an opennet peer,
123 * <code>false</code> otherwise
125 public boolean isOpennet() {
130 * Sets whether the node is an opennet peer.
133 * <code>true</code> if the node is an opennet peer,
134 * <code>false</code> otherwise
136 public void setOpennet(boolean opennet) {
137 this.opennet = opennet;
141 * Returns the name of the node. If the node is an opennet peer, it will
144 * @return The name of the node, or <code>null</code> if the node is an
147 public String getMyName() {
152 * Sets the name of the peer.
155 * The name of the peer
157 public void setName(String name) {
162 * Returns the location of the node.
164 * @return The location of the node
166 public double getLocation() {
171 * Sets the location of the node
174 * The location of the node
176 public void setLocation(double location) {
177 this.location = location;
181 * Returns the IP addresses and port numbers of the node.
183 * @return The IP addresses and port numbers of the node
185 public String getPhysicalUDP() {
190 * Sets the IP addresses and port numbers of the node.
193 * The IP addresses and port numbers of the node
195 public void setPhysicalUDP(String physicalUDP) {
196 this.physicalUDP = physicalUDP;
200 * Returns the ARK of the node.
202 * @return The ARK of the node
204 public ARK getARK() {
209 * Sets the ARK of the node.
212 * The ARK of the node
214 public void setARK(ARK ark) {
219 * Returns the public DSA key of the node.
221 * @return The public DSA key of the node
223 public String getDSAPublicKey() {
228 * Sets the public DSA key of the node.
230 * @param dsaPublicKey
231 * The public DSA key of the node
233 public void setDSAPublicKey(String dsaPublicKey) {
234 this.dsaPublicKey = dsaPublicKey;
238 * Returns the DSA group of the node.
240 * @return The DSA group of the node
242 public DSAGroup getDSAGroup() {
247 * Sets the DSA group of the node.
250 * The DSA group of the node
252 public void setDSAGroup(DSAGroup dsaGroup) {
253 this.dsaGroup = dsaGroup;
257 * Returns the negotiation types supported by the node.
259 * @return The node’s supported negotiation types
261 public int[] getNegotiationTypes() {
262 return negotiationTypes;
266 * Sets the negotiation types supported by the node.
268 * @param negotiationTypes
269 * The node’s supported negotiation types
271 public void setNegotiationTypes(int[] negotiationTypes) {
272 this.negotiationTypes = negotiationTypes;
276 * Returns the version of the node.
278 * @return The version of the node
280 public Version getVersion() {
285 * Sets the version of the node.
288 * The version of the node
290 public void setVersion(Version version) {
291 this.version = version;
295 * Returns the last good version of the node.
297 * @return The oldest version the node will connect to
299 public Version getLastGoodVersion() {
300 return lastGoodVersion;
304 * Sets the last good version of the node.
306 * @param lastGoodVersion
307 * The oldest version the node will connect to
309 public void setLastGoodVersion(Version lastGoodVersion) {
310 this.lastGoodVersion = lastGoodVersion;
314 * Returns whether the node is a testnet node.
316 * @return <code>true</code> if the node is a testnet node,
317 * <code>false</code> otherwise
319 public boolean isTestnet() {
324 * Sets whether this node is a testnet node.
327 * <code>true</code> if the node is a testnet node,
328 * <code>false</code> otherwise
330 public void setTestnet(boolean testnet) {
331 this.testnet = testnet;
335 * Returns the signature of the noderef.
337 * @return The signature of the noderef
339 public String getSignature() {
344 * Sets the signature of the noderef.
347 * The signature of the noderef
349 public void setSignature(String signature) {
350 this.signature = signature;