2 * © 2008 INA Service GmbH
4 package net.pterodactylus.util.fcp;
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.
10 * @author <a href="mailto:dr@ina-germany.de">David Roden</a>
13 public class NodeRef {
15 /** The identity of the node. */
16 private String identity;
18 /** Whether the node is an opennet peer. */
19 private boolean opennet;
21 /** The name of the node. */
24 /** The location of the node. */
25 private double location;
27 /** The IP addresses and ports of the node. */
28 private String physicalUDP;
30 /** The ARK of the node. */
33 /** The public DSA key of the node. */
34 private String dsaPublicKey;
36 /** The DSA group of the node. */
37 private DSAGroup dsaGroup;
39 /** The node’s supported negotiation types. */
40 private int[] negotiationTypes;
42 /** The version of the node. */
43 private Version version;
45 /** The oldest version the node will connect to. */
46 private Version lastGoodVersion;
48 /** Whether the node is a testnet node. */
49 private boolean testnet;
51 /** The signature of the reference. */
52 private String signature;
55 * Creates a new, empty noderef.
61 * Creates a new noderef that is initialized with fields from the given
65 * The message to get initial values for the noderef from
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"));
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");
86 * Returns the identity of the node.
88 * @return The identity of the node
90 public String getIdentity() {
95 * Sets the identity of the node.
98 * The identity of the node
100 public void setIdentity(String identity) {
101 this.identity = identity;
105 * Returns whether the node is an opennet peer.
107 * @return <code>true</code> if the node is an opennet peer,
108 * <code>false</code> otherwise
110 public boolean isOpennet() {
115 * Sets whether the node is an opennet peer.
118 * <code>true</code> if the node is an opennet peer,
119 * <code>false</code> otherwise
121 public void setOpennet(boolean opennet) {
122 this.opennet = opennet;
126 * Returns the name of the node. If the node is an opennet peer, it will not
129 * @return The name of the node, or <code>null</code> if the node is an
132 public String getMyName() {
137 * Sets the name of the peer.
140 * The name of the peer
142 public void setName(String name) {
147 * Returns the location of the node.
149 * @return The location of the node
151 public double getLocation() {
156 * Sets the location of the node
159 * The location of the node
161 public void setLocation(double location) {
162 this.location = location;
166 * Returns the IP addresses and port numbers of the node.
168 * @return The IP addresses and port numbers of the node
170 public String getPhysicalUDP() {
175 * Sets the IP addresses and port numbers of the node.
178 * The IP addresses and port numbers of the node
180 public void setPhysicalUDP(String physicalUDP) {
181 this.physicalUDP = physicalUDP;
185 * Returns the ARK of the node.
187 * @return The ARK of the node
189 public ARK getARK() {
194 * Sets the ARK of the node.
197 * The ARK of the node
199 public void setARK(ARK ark) {
204 * Returns the public DSA key of the node.
206 * @return The public DSA key of the node
208 public String getDSAPublicKey() {
213 * Sets the public DSA key of the node.
215 * @param dsaPublicKey
216 * The public DSA key of the node
218 public void setDSAPublicKey(String dsaPublicKey) {
219 this.dsaPublicKey = dsaPublicKey;
223 * Returns the DSA group of the node.
225 * @return The DSA group of the node
227 public DSAGroup getDSAGroup() {
232 * Sets the DSA group of the node.
235 * The DSA group of the node
237 public void setDSAGroup(DSAGroup dsaGroup) {
238 this.dsaGroup = dsaGroup;
242 * Returns the negotiation types supported by the node.
244 * @return The node’s supported negotiation types
246 public int[] getNegotiationTypes() {
247 return negotiationTypes;
251 * Sets the negotiation types supported by the node.
253 * @param negotiationTypes
254 * The node’s supported negotiation types
256 public void setNegotiationTypes(int[] negotiationTypes) {
257 this.negotiationTypes = negotiationTypes;
261 * Returns the version of the node.
263 * @return The version of the node
265 public Version getVersion() {
270 * Sets the version of the node.
273 * The version of the node
275 public void setVersion(Version version) {
276 this.version = version;
280 * Returns the last good version of the node.
282 * @return The oldest version the node will connect to
284 public Version getLastGoodVersion() {
285 return lastGoodVersion;
289 * Sets the last good version of the node.
291 * @param lastGoodVersion
292 * The oldest version the node will connect to
294 public void setLastGoodVersion(Version lastGoodVersion) {
295 this.lastGoodVersion = lastGoodVersion;
299 * Returns whether the node is a testnet node.
301 * @return <code>true</code> if the node is a testnet node,
302 * <code>false</code> otherwise
304 public boolean isTestnet() {
309 * Sets whether this node is a testnet node.
312 * <code>true</code> if the node is a testnet node,
313 * <code>false</code> otherwise
315 public void setTestnet(boolean testnet) {
316 this.testnet = testnet;
320 * Returns the signature of the noderef.
322 * @return The signature of the noderef
324 public String getSignature() {
329 * Sets the signature of the noderef.
332 * The signature of the noderef
334 public void setSignature(String signature) {
335 this.signature = signature;