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