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