Update license to GPLv3, fix header comments
[jFCPlib.git] / src / main / java / net / pterodactylus / fcp / NodeData.java
1 /*
2  * jFCPlib - NodeData.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  * The “NodeData” contains the noderef of the node, along with additional data.
22  *
23  * @author David ‘Bombe’ Roden &lt;bombe@freenetproject.org&gt;
24  */
25 public class NodeData extends BaseMessage {
26
27         /** The noderef of the node. */
28         private final NodeRef nodeRef;
29
30         /**
31          * Creates a new “NodeData” message that wraps the received message.
32          *
33          * @param receivedMessage
34          *            The received message
35          */
36         public NodeData(FcpMessage receivedMessage) {
37                 super(receivedMessage);
38                 nodeRef = new NodeRef(receivedMessage);
39         }
40
41         /**
42          * Returns the noderef of the node.
43          *
44          * @return The noderef of the node
45          */
46         public NodeRef getNodeRef() {
47                 return nodeRef;
48         }
49
50         /**
51          * Returns the last good version, i.e. the oldest version the node will
52          * connect to.
53          *
54          * @return The last good version
55          */
56         public Version getLastGoodVersion() {
57                 return nodeRef.getLastGoodVersion();
58         }
59
60         /**
61          * Returns the signature of the noderef.
62          *
63          * @return The signature of the noderef
64          */
65         public String getSignature() {
66                 return nodeRef.getSignature();
67         }
68
69         /**
70          * Returns whether the noderef is the opennet noderef of the node
71          *
72          * @return <code>true</code> if the noderef is the opennet noderef of the
73          *         node, <code>false</code> otherwise
74          */
75         public boolean isOpennet() {
76                 return nodeRef.isOpennet();
77         }
78
79         /**
80          * Returns the identity of the node
81          *
82          * @return The identity of the node
83          */
84         public String getIdentity() {
85                 return nodeRef.getIdentity();
86         }
87
88         /**
89          * Returns the name of the node.
90          *
91          * @return The name of the node
92          */
93         public String getMyName() {
94                 return nodeRef.getMyName();
95         }
96
97         /**
98          * Returns the version of the node.
99          *
100          * @return The version of the node
101          */
102         public Version getVersion() {
103                 return nodeRef.getVersion();
104         }
105
106         /**
107          * Returns IP addresses and port number of the node.
108          *
109          * @return The IP addresses and port numbers of the node
110          */
111         public String getPhysicalUDP() {
112                 return nodeRef.getPhysicalUDP();
113         }
114
115         /**
116          * Returns the ARK of the node.
117          *
118          * @return The ARK of the node
119          */
120         public ARK getARK() {
121                 return nodeRef.getARK();
122         }
123
124         /**
125          * Returns the public key of the node.
126          *
127          * @return The public key of the node
128          */
129         public String getDSAPublicKey() {
130                 return nodeRef.getDSAPublicKey();
131         }
132
133         /**
134          * Returns the private key of the node.
135          *
136          * @return The private key of the node
137          */
138         public String getDSKPrivateKey() {
139                 return getField("dsaPrivKey.x");
140         }
141
142         /**
143          * Returns the DSA group of the node.
144          *
145          * @return The DSA group of the node
146          */
147         public DSAGroup getDSAGroup() {
148                 return nodeRef.getDSAGroup();
149         }
150
151         /**
152          * Returns the negotiation types supported by the node.
153          *
154          * @return The node’s supported negotiation types
155          */
156         public int[] getNegotiationTypes() {
157                 return nodeRef.getNegotiationTypes();
158         }
159
160         /**
161          * Returns one of the volatile fields from the message. The given field
162          * name is prepended with “volatile.” so if you want to get the value of
163          * the field with the name “volatile.freeJavaMemory” you only need to
164          * specify “freeJavaMemory”.
165          *
166          * @param field
167          *            The name of the field
168          * @return The value of the field, or <code>null</code> if there is no such
169          *         field
170          */
171         public String getVolatile(String field) {
172                 return getField("volatile." + field);
173         }
174
175 }