add TestDDAResponse
[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 <a href="mailto:dr@ina-germany.de">David Roden</a>
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         }
59
60         /**
61          * Creates a new noderef that is initialized with fields from the given
62          * message.
63          * 
64          * @param fromMessage
65          *            The message to get initial values for the noderef from
66          */
67         public NodeRef(FcpMessage fromMessage) {
68                 identity = fromMessage.getField("identity");
69                 opennet = Boolean.valueOf(fromMessage.getField("opennet"));
70                 name = fromMessage.getField("myName");
71                 if (fromMessage.hasField("location")) {
72                         location = Double.valueOf(fromMessage.getField("location"));
73                 }
74                 physicalUDP = fromMessage.getField("physical.udp");
75                 ark = new ARK(fromMessage.getField("ark.pubURI"), fromMessage.getField("ark.privURI"), fromMessage.getField("ark.number"));
76                 dsaPublicKey = fromMessage.getField("dsaPubKey.y");
77                 dsaGroup = new DSAGroup(fromMessage.getField("dsaGroup.b"), fromMessage.getField("dsaGroup.p"), fromMessage.getField("dsaGroup.q"));
78                 negotiationTypes = FcpUtils.decodeMultiIntegerField(fromMessage.getField("auth.negTypes"));
79                 version = new Version(fromMessage.getField("version"));
80                 lastGoodVersion = new Version(fromMessage.getField("lastGoodVersion"));
81                 testnet = Boolean.valueOf(fromMessage.getField("testnet"));
82                 signature = fromMessage.getField("sig");
83         }
84
85         /**
86          * Returns the identity of the node.
87          * 
88          * @return The identity of the node
89          */
90         public String getIdentity() {
91                 return identity;
92         }
93
94         /**
95          * Sets the identity of the node.
96          * 
97          * @param identity
98          *            The identity of the node
99          */
100         public void setIdentity(String identity) {
101                 this.identity = identity;
102         }
103
104         /**
105          * Returns whether the node is an opennet peer.
106          * 
107          * @return <code>true</code> if the node is an opennet peer,
108          *         <code>false</code> otherwise
109          */
110         public boolean isOpennet() {
111                 return opennet;
112         }
113
114         /**
115          * Sets whether the node is an opennet peer.
116          * 
117          * @param opennet
118          *            <code>true</code> if the node is an opennet peer,
119          *            <code>false</code> otherwise
120          */
121         public void setOpennet(boolean opennet) {
122                 this.opennet = opennet;
123         }
124
125         /**
126          * Returns the name of the node. If the node is an opennet peer, it will not
127          * have a name!
128          * 
129          * @return The name of the node, or <code>null</code> if the node is an
130          *         opennet peer
131          */
132         public String getMyName() {
133                 return name;
134         }
135
136         /**
137          * Sets the name of the peer.
138          * 
139          * @param name
140          *            The name of the peer
141          */
142         public void setName(String name) {
143                 this.name = name;
144         }
145
146         /**
147          * Returns the location of the node.
148          * 
149          * @return The location of the node
150          */
151         public double getLocation() {
152                 return location;
153         }
154
155         /**
156          * Sets the location of the node
157          * 
158          * @param location
159          *            The location of the node
160          */
161         public void setLocation(double location) {
162                 this.location = location;
163         }
164
165         /**
166          * Returns the IP addresses and port numbers of the node.
167          * 
168          * @return The IP addresses and port numbers of the node
169          */
170         public String getPhysicalUDP() {
171                 return physicalUDP;
172         }
173
174         /**
175          * Sets the IP addresses and port numbers of the node.
176          * 
177          * @param physicalUDP
178          *            The IP addresses and port numbers of the node
179          */
180         public void setPhysicalUDP(String physicalUDP) {
181                 this.physicalUDP = physicalUDP;
182         }
183
184         /**
185          * Returns the ARK of the node.
186          * 
187          * @return The ARK of the node
188          */
189         public ARK getARK() {
190                 return ark;
191         }
192
193         /**
194          * Sets the ARK of the node.
195          * 
196          * @param ark
197          *            The ARK of the node
198          */
199         public void setARK(ARK ark) {
200                 this.ark = ark;
201         }
202
203         /**
204          * Returns the public DSA key of the node.
205          * 
206          * @return The public DSA key of the node
207          */
208         public String getDSAPublicKey() {
209                 return dsaPublicKey;
210         }
211
212         /**
213          * Sets the public DSA key of the node.
214          * 
215          * @param dsaPublicKey
216          *            The public DSA key of the node
217          */
218         public void setDSAPublicKey(String dsaPublicKey) {
219                 this.dsaPublicKey = dsaPublicKey;
220         }
221
222         /**
223          * Returns the DSA group of the node.
224          * 
225          * @return The DSA group of the node
226          */
227         public DSAGroup getDSAGroup() {
228                 return dsaGroup;
229         }
230
231         /**
232          * Sets the DSA group of the node.
233          * 
234          * @param dsaGroup
235          *            The DSA group of the node
236          */
237         public void setDSAGroup(DSAGroup dsaGroup) {
238                 this.dsaGroup = dsaGroup;
239         }
240
241         /**
242          * Returns the negotiation types supported by the node.
243          * 
244          * @return The node’s supported negotiation types
245          */
246         public int[] getNegotiationTypes() {
247                 return negotiationTypes;
248         }
249
250         /**
251          * Sets the negotiation types supported by the node.
252          * 
253          * @param negotiationTypes
254          *            The node’s supported negotiation types
255          */
256         public void setNegotiationTypes(int[] negotiationTypes) {
257                 this.negotiationTypes = negotiationTypes;
258         }
259
260         /**
261          * Returns the version of the node.
262          * 
263          * @return The version of the node
264          */
265         public Version getVersion() {
266                 return version;
267         }
268
269         /**
270          * Sets the version of the node.
271          * 
272          * @param version
273          *            The version of the node
274          */
275         public void setVersion(Version version) {
276                 this.version = version;
277         }
278
279         /**
280          * Returns the last good version of the node.
281          * 
282          * @return The oldest version the node will connect to
283          */
284         public Version getLastGoodVersion() {
285                 return lastGoodVersion;
286         }
287
288         /**
289          * Sets the last good version of the node.
290          * 
291          * @param lastGoodVersion
292          *            The oldest version the node will connect to
293          */
294         public void setLastGoodVersion(Version lastGoodVersion) {
295                 this.lastGoodVersion = lastGoodVersion;
296         }
297
298         /**
299          * Returns whether the node is a testnet node.
300          * 
301          * @return <code>true</code> if the node is a testnet node,
302          *         <code>false</code> otherwise
303          */
304         public boolean isTestnet() {
305                 return testnet;
306         }
307
308         /**
309          * Sets whether this node is a testnet node.
310          * 
311          * @param testnet
312          *            <code>true</code> if the node is a testnet node,
313          *            <code>false</code> otherwise
314          */
315         public void setTestnet(boolean testnet) {
316                 this.testnet = testnet;
317         }
318
319         /**
320          * Returns the signature of the noderef.
321          * 
322          * @return The signature of the noderef
323          */
324         public String getSignature() {
325                 return signature;
326         }
327
328         /**
329          * Sets the signature of the noderef.
330          * 
331          * @param signature
332          *            The signature of the noderef
333          */
334         public void setSignature(String signature) {
335                 this.signature = signature;
336         }
337
338 }