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