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