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>
29 public class NodeRef {
31 /** The identity of the node. */
32 private String identity;
34 /** Whether the node is an opennet peer. */
35 private boolean opennet;
37 /** The name of the node. */
40 /** The location of the node. */
41 private double location;
43 /** The IP addresses and ports of the node. */
44 private String physicalUDP;
46 /** The ARK of the node. */
49 /** The public DSA key of the node. */
50 private String dsaPublicKey;
52 /** The DSA group of the node. */
53 private DSAGroup dsaGroup;
55 /** The node’s supported negotiation types. */
56 private int[] negotiationTypes;
58 /** The version of the node. */
59 private Version version;
61 /** The oldest version the node will connect to. */
62 private Version lastGoodVersion;
64 /** Whether the node is a testnet node. */
65 private boolean testnet;
67 /** The signature of the reference. */
68 private String signature;
71 * Creates a new, empty noderef.
74 /* intentionally left blank. */
78 * Creates a new noderef that is initialized with fields from the given
82 * The message to get initial values for the noderef from
84 public NodeRef(FcpMessage fromMessage) {
85 identity = fromMessage.getField("identity");
86 opennet = Boolean.valueOf(fromMessage.getField("opennet"));
87 name = fromMessage.getField("myName");
88 if (fromMessage.hasField("location")) {
89 location = Double.valueOf(fromMessage.getField("location"));
91 physicalUDP = fromMessage.getField("physical.udp");
92 ark = new ARK(fromMessage.getField("ark.pubURI"), fromMessage.getField("ark.privURI"), fromMessage.getField("ark.number"));
93 dsaPublicKey = fromMessage.getField("dsaPubKey.y");
94 dsaGroup = new DSAGroup(fromMessage.getField("dsaGroup.b"), fromMessage.getField("dsaGroup.p"), fromMessage.getField("dsaGroup.q"));
95 negotiationTypes = FcpUtils.decodeMultiIntegerField(fromMessage.getField("auth.negTypes"));
96 version = new Version(fromMessage.getField("version"));
97 lastGoodVersion = new Version(fromMessage.getField("lastGoodVersion"));
98 testnet = Boolean.valueOf(fromMessage.getField("testnet"));
99 signature = fromMessage.getField("sig");
103 * Returns the identity of the node.
105 * @return The identity of the node
107 public String getIdentity() {
112 * Sets the identity of the node.
115 * The identity of the node
117 public void setIdentity(String identity) {
118 this.identity = identity;
122 * Returns whether the node is an opennet peer.
124 * @return <code>true</code> if the node is an opennet peer,
125 * <code>false</code> otherwise
127 public boolean isOpennet() {
132 * Sets whether the node is an opennet peer.
135 * <code>true</code> if the node is an opennet peer,
136 * <code>false</code> otherwise
138 public void setOpennet(boolean opennet) {
139 this.opennet = opennet;
143 * Returns the name of the node. If the node is an opennet peer, it will not
146 * @return The name of the node, or <code>null</code> if the node is an
149 public String getMyName() {
154 * Sets the name of the peer.
157 * The name of the peer
159 public void setName(String name) {
164 * Returns the location of the node.
166 * @return The location of the node
168 public double getLocation() {
173 * Sets the location of the node
176 * The location of the node
178 public void setLocation(double location) {
179 this.location = location;
183 * Returns the IP addresses and port numbers of the node.
185 * @return The IP addresses and port numbers of the node
187 public String getPhysicalUDP() {
192 * Sets the IP addresses and port numbers of the node.
195 * The IP addresses and port numbers of the node
197 public void setPhysicalUDP(String physicalUDP) {
198 this.physicalUDP = physicalUDP;
202 * Returns the ARK of the node.
204 * @return The ARK of the node
206 public ARK getARK() {
211 * Sets the ARK of the node.
214 * The ARK of the node
216 public void setARK(ARK ark) {
221 * Returns the public DSA key of the node.
223 * @return The public DSA key of the node
225 public String getDSAPublicKey() {
230 * Sets the public DSA key of the node.
232 * @param dsaPublicKey
233 * The public DSA key of the node
235 public void setDSAPublicKey(String dsaPublicKey) {
236 this.dsaPublicKey = dsaPublicKey;
240 * Returns the DSA group of the node.
242 * @return The DSA group of the node
244 public DSAGroup getDSAGroup() {
249 * Sets the DSA group of the node.
252 * The DSA group of the node
254 public void setDSAGroup(DSAGroup dsaGroup) {
255 this.dsaGroup = dsaGroup;
259 * Returns the negotiation types supported by the node.
261 * @return The node’s supported negotiation types
263 public int[] getNegotiationTypes() {
264 return negotiationTypes;
268 * Sets the negotiation types supported by the node.
270 * @param negotiationTypes
271 * The node’s supported negotiation types
273 public void setNegotiationTypes(int[] negotiationTypes) {
274 this.negotiationTypes = negotiationTypes;
278 * Returns the version of the node.
280 * @return The version of the node
282 public Version getVersion() {
287 * Sets the version of the node.
290 * The version of the node
292 public void setVersion(Version version) {
293 this.version = version;
297 * Returns the last good version of the node.
299 * @return The oldest version the node will connect to
301 public Version getLastGoodVersion() {
302 return lastGoodVersion;
306 * Sets the last good version of the node.
308 * @param lastGoodVersion
309 * The oldest version the node will connect to
311 public void setLastGoodVersion(Version lastGoodVersion) {
312 this.lastGoodVersion = lastGoodVersion;
316 * Returns whether the node is a testnet node.
318 * @return <code>true</code> if the node is a testnet node,
319 * <code>false</code> otherwise
321 public boolean isTestnet() {
326 * Sets whether this node is a testnet node.
329 * <code>true</code> if the node is a testnet node,
330 * <code>false</code> otherwise
332 public void setTestnet(boolean testnet) {
333 this.testnet = testnet;
337 * Returns the signature of the noderef.
339 * @return The signature of the noderef
341 public String getSignature() {
346 * Sets the signature of the noderef.
349 * The signature of the noderef
351 public void setSignature(String signature) {
352 this.signature = signature;