2 * jFCPlib - NodeRef.java - Copyright © 2008–2016 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 3 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, see <http://www.gnu.org/licenses/>.
18 package net.pterodactylus.fcp;
21 * A reference for a node. The noderef contains all data that is necessary to
22 * establish a trusted and secure connection to the node.
24 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
26 public class NodeRef {
28 /** The identity of the node. */
29 private String identity;
31 /** Whether the node is an opennet peer. */
32 private boolean opennet;
34 /** The name of the node. */
37 /** The location of the node. */
38 private double location;
40 /** The IP addresses and ports of the node. */
41 private String physicalUDP;
43 /** The ARK of the node. */
46 /** The public DSA key of the node. */
47 private String dsaPublicKey;
49 /** The DSA group of the node. */
50 private DSAGroup dsaGroup;
52 /** The node’s supported negotiation types. */
53 private int[] negotiationTypes;
55 /** The version of the node. */
56 private Version version;
58 /** The oldest version the node will connect to. */
59 private Version lastGoodVersion;
61 /** Whether the node is a testnet node. */
62 private boolean testnet;
64 /** The signature of the reference. */
65 private String signature;
68 * Creates a new, empty noderef.
71 /* intentionally left blank. */
75 * Creates a new noderef that is initialized with fields from the given
79 * The message to get initial values for the noderef from
81 public NodeRef(FcpMessage fromMessage) {
82 identity = fromMessage.getField("identity");
83 opennet = Boolean.valueOf(fromMessage.getField("opennet"));
84 name = fromMessage.getField("myName");
85 if (fromMessage.hasField("location")) {
86 location = Double.valueOf(fromMessage.getField("location"));
88 physicalUDP = fromMessage.getField("physical.udp");
89 ark = new ARK(fromMessage.getField("ark.pubURI"), fromMessage.getField("ark.privURI"), fromMessage.getField("ark.number"));
90 dsaPublicKey = fromMessage.getField("dsaPubKey.y");
91 dsaGroup = new DSAGroup(fromMessage.getField("dsaGroup.b"), fromMessage.getField("dsaGroup.p"), fromMessage.getField("dsaGroup.q"));
92 negotiationTypes = FcpUtils.decodeMultiIntegerField(fromMessage.getField("auth.negTypes"));
93 version = new Version(fromMessage.getField("version"));
94 lastGoodVersion = new Version(fromMessage.getField("lastGoodVersion"));
95 testnet = Boolean.valueOf(fromMessage.getField("testnet"));
96 signature = fromMessage.getField("sig");
100 * Returns the identity of the node.
102 * @return The identity of the node
104 public String getIdentity() {
109 * Sets the identity of the node.
112 * The identity of the node
114 public void setIdentity(String identity) {
115 this.identity = identity;
119 * Returns whether the node is an opennet peer.
121 * @return <code>true</code> if the node is an opennet peer,
122 * <code>false</code> otherwise
124 public boolean isOpennet() {
129 * Sets whether the node is an opennet peer.
132 * <code>true</code> if the node is an opennet peer,
133 * <code>false</code> otherwise
135 public void setOpennet(boolean opennet) {
136 this.opennet = opennet;
140 * Returns the name of the node. If the node is an opennet peer, it will
143 * @return The name of the node, or <code>null</code> if the node is an
146 public String getMyName() {
151 * Sets the name of the peer.
154 * The name of the peer
156 public void setName(String name) {
161 * Returns the location of the node.
163 * @return The location of the node
165 public double getLocation() {
170 * Sets the location of the node
173 * The location of the node
175 public void setLocation(double location) {
176 this.location = location;
180 * Returns the IP addresses and port numbers of the node.
182 * @return The IP addresses and port numbers of the node
184 public String getPhysicalUDP() {
189 * Sets the IP addresses and port numbers of the node.
192 * The IP addresses and port numbers of the node
194 public void setPhysicalUDP(String physicalUDP) {
195 this.physicalUDP = physicalUDP;
199 * Returns the ARK of the node.
201 * @return The ARK of the node
203 public ARK getARK() {
208 * Sets the ARK of the node.
211 * The ARK of the node
213 public void setARK(ARK ark) {
218 * Returns the public DSA key of the node.
220 * @return The public DSA key of the node
222 public String getDSAPublicKey() {
227 * Sets the public DSA key of the node.
229 * @param dsaPublicKey
230 * The public DSA key of the node
232 public void setDSAPublicKey(String dsaPublicKey) {
233 this.dsaPublicKey = dsaPublicKey;
237 * Returns the DSA group of the node.
239 * @return The DSA group of the node
241 public DSAGroup getDSAGroup() {
246 * Sets the DSA group of the node.
249 * The DSA group of the node
251 public void setDSAGroup(DSAGroup dsaGroup) {
252 this.dsaGroup = dsaGroup;
256 * Returns the negotiation types supported by the node.
258 * @return The node’s supported negotiation types
260 public int[] getNegotiationTypes() {
261 return negotiationTypes;
265 * Sets the negotiation types supported by the node.
267 * @param negotiationTypes
268 * The node’s supported negotiation types
270 public void setNegotiationTypes(int[] negotiationTypes) {
271 this.negotiationTypes = negotiationTypes;
275 * Returns the version of the node.
277 * @return The version of the node
279 public Version getVersion() {
284 * Sets the version of the node.
287 * The version of the node
289 public void setVersion(Version version) {
290 this.version = version;
294 * Returns the last good version of the node.
296 * @return The oldest version the node will connect to
298 public Version getLastGoodVersion() {
299 return lastGoodVersion;
303 * Sets the last good version of the node.
305 * @param lastGoodVersion
306 * The oldest version the node will connect to
308 public void setLastGoodVersion(Version lastGoodVersion) {
309 this.lastGoodVersion = lastGoodVersion;
313 * Returns whether the node is a testnet node.
315 * @return <code>true</code> if the node is a testnet node,
316 * <code>false</code> otherwise
318 public boolean isTestnet() {
323 * Sets whether this node is a testnet node.
326 * <code>true</code> if the node is a testnet node,
327 * <code>false</code> otherwise
329 public void setTestnet(boolean testnet) {
330 this.testnet = testnet;
334 * Returns the signature of the noderef.
336 * @return The signature of the noderef
338 public String getSignature() {
343 * Sets the signature of the noderef.
346 * The signature of the noderef
348 public void setSignature(String signature) {
349 this.signature = signature;