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