2 * © 2008 INA Service GmbH
4 package net.pterodactylus.util.fcp;
7 * A reference for a node. The noderef contains all data that is necessary to
8 * establish a trusted and secure connection to the node.
10 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
13 public class NodeRef {
15 /** The identity of the node. */
16 private String identity;
18 /** Whether the node is an opennet peer. */
19 private boolean opennet;
21 /** The name of the node. */
24 /** The location of the node. */
25 private double location;
27 /** The IP addresses and ports of the node. */
28 private String physicalUDP;
30 /** The ARK of the node. */
33 /** The public DSA key of the node. */
34 private String dsaPublicKey;
36 /** The DSA group of the node. */
37 private DSAGroup dsaGroup;
39 /** The node’s supported negotiation types. */
40 private int[] negotiationTypes;
42 /** The version of the node. */
43 private Version version;
45 /** The oldest version the node will connect to. */
46 private Version lastGoodVersion;
48 /** Whether the node is a testnet node. */
49 private boolean testnet;
51 /** The signature of the reference. */
52 private String signature;
55 * Creates a new, empty noderef.
58 /* intentionally left blank. */
62 * Creates a new noderef that is initialized with fields from the given
66 * The message to get initial values for the noderef from
68 public NodeRef(FcpMessage fromMessage) {
69 identity = fromMessage.getField("identity");
70 opennet = Boolean.valueOf(fromMessage.getField("opennet"));
71 name = fromMessage.getField("myName");
72 if (fromMessage.hasField("location")) {
73 location = Double.valueOf(fromMessage.getField("location"));
75 physicalUDP = fromMessage.getField("physical.udp");
76 ark = new ARK(fromMessage.getField("ark.pubURI"), fromMessage.getField("ark.privURI"), fromMessage.getField("ark.number"));
77 dsaPublicKey = fromMessage.getField("dsaPubKey.y");
78 dsaGroup = new DSAGroup(fromMessage.getField("dsaGroup.b"), fromMessage.getField("dsaGroup.p"), fromMessage.getField("dsaGroup.q"));
79 negotiationTypes = FcpUtils.decodeMultiIntegerField(fromMessage.getField("auth.negTypes"));
80 version = new Version(fromMessage.getField("version"));
81 lastGoodVersion = new Version(fromMessage.getField("lastGoodVersion"));
82 testnet = Boolean.valueOf(fromMessage.getField("testnet"));
83 signature = fromMessage.getField("sig");
87 * Returns the identity of the node.
89 * @return The identity of the node
91 public String getIdentity() {
96 * Sets the identity of the node.
99 * The identity of the node
101 public void setIdentity(String identity) {
102 this.identity = identity;
106 * Returns whether the node is an opennet peer.
108 * @return <code>true</code> if the node is an opennet peer,
109 * <code>false</code> otherwise
111 public boolean isOpennet() {
116 * Sets whether the node is an opennet peer.
119 * <code>true</code> if the node is an opennet peer,
120 * <code>false</code> otherwise
122 public void setOpennet(boolean opennet) {
123 this.opennet = opennet;
127 * Returns the name of the node. If the node is an opennet peer, it will not
130 * @return The name of the node, or <code>null</code> if the node is an
133 public String getMyName() {
138 * Sets the name of the peer.
141 * The name of the peer
143 public void setName(String name) {
148 * Returns the location of the node.
150 * @return The location of the node
152 public double getLocation() {
157 * Sets the location of the node
160 * The location of the node
162 public void setLocation(double location) {
163 this.location = location;
167 * Returns the IP addresses and port numbers of the node.
169 * @return The IP addresses and port numbers of the node
171 public String getPhysicalUDP() {
176 * Sets the IP addresses and port numbers of the node.
179 * The IP addresses and port numbers of the node
181 public void setPhysicalUDP(String physicalUDP) {
182 this.physicalUDP = physicalUDP;
186 * Returns the ARK of the node.
188 * @return The ARK of the node
190 public ARK getARK() {
195 * Sets the ARK of the node.
198 * The ARK of the node
200 public void setARK(ARK ark) {
205 * Returns the public DSA key of the node.
207 * @return The public DSA key of the node
209 public String getDSAPublicKey() {
214 * Sets the public DSA key of the node.
216 * @param dsaPublicKey
217 * The public DSA key of the node
219 public void setDSAPublicKey(String dsaPublicKey) {
220 this.dsaPublicKey = dsaPublicKey;
224 * Returns the DSA group of the node.
226 * @return The DSA group of the node
228 public DSAGroup getDSAGroup() {
233 * Sets the DSA group of the node.
236 * The DSA group of the node
238 public void setDSAGroup(DSAGroup dsaGroup) {
239 this.dsaGroup = dsaGroup;
243 * Returns the negotiation types supported by the node.
245 * @return The node’s supported negotiation types
247 public int[] getNegotiationTypes() {
248 return negotiationTypes;
252 * Sets the negotiation types supported by the node.
254 * @param negotiationTypes
255 * The node’s supported negotiation types
257 public void setNegotiationTypes(int[] negotiationTypes) {
258 this.negotiationTypes = negotiationTypes;
262 * Returns the version of the node.
264 * @return The version of the node
266 public Version getVersion() {
271 * Sets the version of the node.
274 * The version of the node
276 public void setVersion(Version version) {
277 this.version = version;
281 * Returns the last good version of the node.
283 * @return The oldest version the node will connect to
285 public Version getLastGoodVersion() {
286 return lastGoodVersion;
290 * Sets the last good version of the node.
292 * @param lastGoodVersion
293 * The oldest version the node will connect to
295 public void setLastGoodVersion(Version lastGoodVersion) {
296 this.lastGoodVersion = lastGoodVersion;
300 * Returns whether the node is a testnet node.
302 * @return <code>true</code> if the node is a testnet node,
303 * <code>false</code> otherwise
305 public boolean isTestnet() {
310 * Sets whether this node is a testnet node.
313 * <code>true</code> if the node is a testnet node,
314 * <code>false</code> otherwise
316 public void setTestnet(boolean testnet) {
317 this.testnet = testnet;
321 * Returns the signature of the noderef.
323 * @return The signature of the noderef
325 public String getSignature() {
330 * Sets the signature of the noderef.
333 * The signature of the noderef
335 public void setSignature(String signature) {
336 this.signature = signature;