Reformat source code, new line length for comments (79), some trailing whitespace...
[jFCPlib.git] / src / main / java / net / pterodactylus / fcp / NodeRef.java
1 /*
2  * jFCPlib - NodeRef.java - Copyright © 2008 David Roden
3  *
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.
8  *
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.
13  *
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.
17  */
18
19 package net.pterodactylus.fcp;
20
21 /**
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.
24  *
25  * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
26  */
27 public class NodeRef {
28
29         /** The identity of the node. */
30         private String identity;
31
32         /** Whether the node is an opennet peer. */
33         private boolean opennet;
34
35         /** The name of the node. */
36         private String name;
37
38         /** The location of the node. */
39         private double location;
40
41         /** The IP addresses and ports of the node. */
42         private String physicalUDP;
43
44         /** The ARK of the node. */
45         private ARK ark;
46
47         /** The public DSA key of the node. */
48         private String dsaPublicKey;
49
50         /** The DSA group of the node. */
51         private DSAGroup dsaGroup;
52
53         /** The node’s supported negotiation types. */
54         private int[] negotiationTypes;
55
56         /** The version of the node. */
57         private Version version;
58
59         /** The oldest version the node will connect to. */
60         private Version lastGoodVersion;
61
62         /** Whether the node is a testnet node. */
63         private boolean testnet;
64
65         /** The signature of the reference. */
66         private String signature;
67
68         /**
69          * Creates a new, empty noderef.
70          */
71         public NodeRef() {
72                 /* intentionally left blank. */
73         }
74
75         /**
76          * Creates a new noderef that is initialized with fields from the given
77          * message.
78          *
79          * @param fromMessage
80          *            The message to get initial values for the noderef from
81          */
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"));
88                 }
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");
98         }
99
100         /**
101          * Returns the identity of the node.
102          *
103          * @return The identity of the node
104          */
105         public String getIdentity() {
106                 return identity;
107         }
108
109         /**
110          * Sets the identity of the node.
111          *
112          * @param identity
113          *            The identity of the node
114          */
115         public void setIdentity(String identity) {
116                 this.identity = identity;
117         }
118
119         /**
120          * Returns whether the node is an opennet peer.
121          *
122          * @return <code>true</code> if the node is an opennet peer,
123          *         <code>false</code> otherwise
124          */
125         public boolean isOpennet() {
126                 return opennet;
127         }
128
129         /**
130          * Sets whether the node is an opennet peer.
131          *
132          * @param opennet
133          *            <code>true</code> if the node is an opennet peer,
134          *            <code>false</code> otherwise
135          */
136         public void setOpennet(boolean opennet) {
137                 this.opennet = opennet;
138         }
139
140         /**
141          * Returns the name of the node. If the node is an opennet peer, it will
142          * not have a name!
143          *
144          * @return The name of the node, or <code>null</code> if the node is an
145          *         opennet peer
146          */
147         public String getMyName() {
148                 return name;
149         }
150
151         /**
152          * Sets the name of the peer.
153          *
154          * @param name
155          *            The name of the peer
156          */
157         public void setName(String name) {
158                 this.name = name;
159         }
160
161         /**
162          * Returns the location of the node.
163          *
164          * @return The location of the node
165          */
166         public double getLocation() {
167                 return location;
168         }
169
170         /**
171          * Sets the location of the node
172          *
173          * @param location
174          *            The location of the node
175          */
176         public void setLocation(double location) {
177                 this.location = location;
178         }
179
180         /**
181          * Returns the IP addresses and port numbers of the node.
182          *
183          * @return The IP addresses and port numbers of the node
184          */
185         public String getPhysicalUDP() {
186                 return physicalUDP;
187         }
188
189         /**
190          * Sets the IP addresses and port numbers of the node.
191          *
192          * @param physicalUDP
193          *            The IP addresses and port numbers of the node
194          */
195         public void setPhysicalUDP(String physicalUDP) {
196                 this.physicalUDP = physicalUDP;
197         }
198
199         /**
200          * Returns the ARK of the node.
201          *
202          * @return The ARK of the node
203          */
204         public ARK getARK() {
205                 return ark;
206         }
207
208         /**
209          * Sets the ARK of the node.
210          *
211          * @param ark
212          *            The ARK of the node
213          */
214         public void setARK(ARK ark) {
215                 this.ark = ark;
216         }
217
218         /**
219          * Returns the public DSA key of the node.
220          *
221          * @return The public DSA key of the node
222          */
223         public String getDSAPublicKey() {
224                 return dsaPublicKey;
225         }
226
227         /**
228          * Sets the public DSA key of the node.
229          *
230          * @param dsaPublicKey
231          *            The public DSA key of the node
232          */
233         public void setDSAPublicKey(String dsaPublicKey) {
234                 this.dsaPublicKey = dsaPublicKey;
235         }
236
237         /**
238          * Returns the DSA group of the node.
239          *
240          * @return The DSA group of the node
241          */
242         public DSAGroup getDSAGroup() {
243                 return dsaGroup;
244         }
245
246         /**
247          * Sets the DSA group of the node.
248          *
249          * @param dsaGroup
250          *            The DSA group of the node
251          */
252         public void setDSAGroup(DSAGroup dsaGroup) {
253                 this.dsaGroup = dsaGroup;
254         }
255
256         /**
257          * Returns the negotiation types supported by the node.
258          *
259          * @return The node’s supported negotiation types
260          */
261         public int[] getNegotiationTypes() {
262                 return negotiationTypes;
263         }
264
265         /**
266          * Sets the negotiation types supported by the node.
267          *
268          * @param negotiationTypes
269          *            The node’s supported negotiation types
270          */
271         public void setNegotiationTypes(int[] negotiationTypes) {
272                 this.negotiationTypes = negotiationTypes;
273         }
274
275         /**
276          * Returns the version of the node.
277          *
278          * @return The version of the node
279          */
280         public Version getVersion() {
281                 return version;
282         }
283
284         /**
285          * Sets the version of the node.
286          *
287          * @param version
288          *            The version of the node
289          */
290         public void setVersion(Version version) {
291                 this.version = version;
292         }
293
294         /**
295          * Returns the last good version of the node.
296          *
297          * @return The oldest version the node will connect to
298          */
299         public Version getLastGoodVersion() {
300                 return lastGoodVersion;
301         }
302
303         /**
304          * Sets the last good version of the node.
305          *
306          * @param lastGoodVersion
307          *            The oldest version the node will connect to
308          */
309         public void setLastGoodVersion(Version lastGoodVersion) {
310                 this.lastGoodVersion = lastGoodVersion;
311         }
312
313         /**
314          * Returns whether the node is a testnet node.
315          *
316          * @return <code>true</code> if the node is a testnet node,
317          *         <code>false</code> otherwise
318          */
319         public boolean isTestnet() {
320                 return testnet;
321         }
322
323         /**
324          * Sets whether this node is a testnet node.
325          *
326          * @param testnet
327          *            <code>true</code> if the node is a testnet node,
328          *            <code>false</code> otherwise
329          */
330         public void setTestnet(boolean testnet) {
331                 this.testnet = testnet;
332         }
333
334         /**
335          * Returns the signature of the noderef.
336          *
337          * @return The signature of the noderef
338          */
339         public String getSignature() {
340                 return signature;
341         }
342
343         /**
344          * Sets the signature of the noderef.
345          *
346          * @param signature
347          *            The signature of the noderef
348          */
349         public void setSignature(String signature) {
350                 this.signature = signature;
351         }
352
353 }