2 * jSite2 - NodeRef.java -
3 * Copyright © 2008 David Roden
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 package net.pterodactylus.fcp;
23 * A reference for a node. The noderef contains all data that is necessary to
24 * establish a trusted and secure connection to the node.
26 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
28 public class NodeRef {
30 /** The identity of the node. */
31 private String identity;
33 /** Whether the node is an opennet peer. */
34 private boolean opennet;
36 /** The name of the node. */
39 /** The location of the node. */
40 private double location;
42 /** The IP addresses and ports of the node. */
43 private String physicalUDP;
45 /** The ARK of the node. */
48 /** The public DSA key of the node. */
49 private String dsaPublicKey;
51 /** The DSA group of the node. */
52 private DSAGroup dsaGroup;
54 /** The node’s supported negotiation types. */
55 private int[] negotiationTypes;
57 /** The version of the node. */
58 private Version version;
60 /** The oldest version the node will connect to. */
61 private Version lastGoodVersion;
63 /** Whether the node is a testnet node. */
64 private boolean testnet;
66 /** The signature of the reference. */
67 private String signature;
70 * Creates a new, empty noderef.
73 /* intentionally left blank. */
77 * Creates a new noderef that is initialized with fields from the given
81 * The message to get initial values for the noderef from
83 public NodeRef(FcpMessage fromMessage) {
84 identity = fromMessage.getField("identity");
85 opennet = Boolean.valueOf(fromMessage.getField("opennet"));
86 name = fromMessage.getField("myName");
87 if (fromMessage.hasField("location")) {
88 location = Double.valueOf(fromMessage.getField("location"));
90 physicalUDP = fromMessage.getField("physical.udp");
91 ark = new ARK(fromMessage.getField("ark.pubURI"), fromMessage.getField("ark.privURI"), fromMessage.getField("ark.number"));
92 dsaPublicKey = fromMessage.getField("dsaPubKey.y");
93 dsaGroup = new DSAGroup(fromMessage.getField("dsaGroup.b"), fromMessage.getField("dsaGroup.p"), fromMessage.getField("dsaGroup.q"));
94 negotiationTypes = FcpUtils.decodeMultiIntegerField(fromMessage.getField("auth.negTypes"));
95 version = new Version(fromMessage.getField("version"));
96 lastGoodVersion = new Version(fromMessage.getField("lastGoodVersion"));
97 testnet = Boolean.valueOf(fromMessage.getField("testnet"));
98 signature = fromMessage.getField("sig");
102 * Returns the identity of the node.
104 * @return The identity of the node
106 public String getIdentity() {
111 * Sets the identity of the node.
114 * The identity of the node
116 public void setIdentity(String identity) {
117 this.identity = identity;
121 * Returns whether the node is an opennet peer.
123 * @return <code>true</code> if the node is an opennet peer,
124 * <code>false</code> otherwise
126 public boolean isOpennet() {
131 * Sets whether the node is an opennet peer.
134 * <code>true</code> if the node is an opennet peer,
135 * <code>false</code> otherwise
137 public void setOpennet(boolean opennet) {
138 this.opennet = opennet;
142 * Returns the name of the node. If the node is an opennet peer, it will not
145 * @return The name of the node, or <code>null</code> if the node is an
148 public String getMyName() {
153 * Sets the name of the peer.
156 * The name of the peer
158 public void setName(String name) {
163 * Returns the location of the node.
165 * @return The location of the node
167 public double getLocation() {
172 * Sets the location of the node
175 * The location of the node
177 public void setLocation(double location) {
178 this.location = location;
182 * Returns the IP addresses and port numbers of the node.
184 * @return The IP addresses and port numbers of the node
186 public String getPhysicalUDP() {
191 * Sets the IP addresses and port numbers of the node.
194 * The IP addresses and port numbers of the node
196 public void setPhysicalUDP(String physicalUDP) {
197 this.physicalUDP = physicalUDP;
201 * Returns the ARK of the node.
203 * @return The ARK of the node
205 public ARK getARK() {
210 * Sets the ARK of the node.
213 * The ARK of the node
215 public void setARK(ARK ark) {
220 * Returns the public DSA key of the node.
222 * @return The public DSA key of the node
224 public String getDSAPublicKey() {
229 * Sets the public DSA key of the node.
231 * @param dsaPublicKey
232 * The public DSA key of the node
234 public void setDSAPublicKey(String dsaPublicKey) {
235 this.dsaPublicKey = dsaPublicKey;
239 * Returns the DSA group of the node.
241 * @return The DSA group of the node
243 public DSAGroup getDSAGroup() {
248 * Sets the DSA group of the node.
251 * The DSA group of the node
253 public void setDSAGroup(DSAGroup dsaGroup) {
254 this.dsaGroup = dsaGroup;
258 * Returns the negotiation types supported by the node.
260 * @return The node’s supported negotiation types
262 public int[] getNegotiationTypes() {
263 return negotiationTypes;
267 * Sets the negotiation types supported by the node.
269 * @param negotiationTypes
270 * The node’s supported negotiation types
272 public void setNegotiationTypes(int[] negotiationTypes) {
273 this.negotiationTypes = negotiationTypes;
277 * Returns the version of the node.
279 * @return The version of the node
281 public Version getVersion() {
286 * Sets the version of the node.
289 * The version of the node
291 public void setVersion(Version version) {
292 this.version = version;
296 * Returns the last good version of the node.
298 * @return The oldest version the node will connect to
300 public Version getLastGoodVersion() {
301 return lastGoodVersion;
305 * Sets the last good version of the node.
307 * @param lastGoodVersion
308 * The oldest version the node will connect to
310 public void setLastGoodVersion(Version lastGoodVersion) {
311 this.lastGoodVersion = lastGoodVersion;
315 * Returns whether the node is a testnet node.
317 * @return <code>true</code> if the node is a testnet node,
318 * <code>false</code> otherwise
320 public boolean isTestnet() {
325 * Sets whether this node is a testnet node.
328 * <code>true</code> if the node is a testnet node,
329 * <code>false</code> otherwise
331 public void setTestnet(boolean testnet) {
332 this.testnet = testnet;
336 * Returns the signature of the noderef.
338 * @return The signature of the noderef
340 public String getSignature() {
345 * Sets the signature of the noderef.
348 * The signature of the noderef
350 public void setSignature(String signature) {
351 this.signature = signature;