3 * Copyright © 2008 David Roden
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.
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.
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.
20 package net.pterodactylus.fcp;
23 * The “Peer” reply by the node contains information about a peer.
25 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
28 public class Peer extends BaseMessage {
31 * Creates a new “Peer” reply from the received message.
33 * @param receivedMessage
34 * The received message
36 Peer(FcpMessage receivedMessage) {
37 super(receivedMessage);
41 * Returns a collection of fields as a node reference.
43 * @return The node reference contained within this message
45 public NodeRef getNodeRef() {
46 NodeRef nodeRef = new NodeRef();
47 nodeRef.setARK(getARK());
48 nodeRef.setDSAGroup(getDSAGroup());
49 nodeRef.setDSAPublicKey(getDSAPublicKey());
50 nodeRef.setIdentity(getIdentity());
51 nodeRef.setLastGoodVersion(getLastGoodVersion());
52 nodeRef.setLocation(getLocation());
53 nodeRef.setName(getMyName());
54 nodeRef.setNegotiationTypes(getNegotiationTypes());
55 nodeRef.setOpennet(isOpennet());
56 nodeRef.setPhysicalUDP(getPhysicalUDP());
57 nodeRef.setVersion(getVersion());
62 * Returns the “physical.udp” line from the message. It contains all IP
63 * addresses and port numbers of the peer.
65 * @return The IP addresses and port numbers of the peer
67 public String getPhysicalUDP() {
68 return getField("physical.udp");
72 * Returns whether the listed peer is an opennet peer.
74 * @return <code>true</code> if the peer is an opennet peer,
75 * <code>false</code> if the peer is a darknet peer
77 public boolean isOpennet() {
78 return Boolean.valueOf(getField("opennet"));
82 * Returns the “y” part of the peer’s public DSA key.
84 * @return The public DSA key
86 public String getDSAPublicKey() {
87 return getField("dsaPubKey.y");
91 * Returns the DSA group of the peer.
93 * @return The DSA group of the peer
95 public DSAGroup getDSAGroup() {
96 return new DSAGroup(getField("dsaGroup.g"), getField("dsaGroup.p"), getField("dsaGroup.q"));
100 * Returns the last good version of the peer, i.e. the oldest version the
101 * peer will connect to.
103 * @return The last good version of the peer
105 public Version getLastGoodVersion() {
106 return new Version(getField("lastGoodVersion"));
110 * Returns the ARK of the peer.
112 * @return The ARK of the peer
114 public ARK getARK() {
115 return new ARK(getField("ark.pubURI"), getField("ark.number"));
119 * Returns the identity of the peer.
121 * @return The identity of the peer
123 public String getIdentity() {
124 return getField("identity");
128 * Returns the name of the peer. If the peer is not a darknet peer it will
131 * @return The name of the peer, or <code>null</code> if the peer is an
134 public String getMyName() {
135 return getField("myName");
139 * Returns the location of the peer.
141 * @return The location of the peer
142 * @throws NumberFormatException
143 * if the field can not be parsed
145 public double getLocation() throws NumberFormatException {
146 return Double.valueOf(getField("location"));
150 * Returns whether the peer is a testnet node.
152 * @return <code>true</code> if the peer is a testnet node,
153 * <code>false</code> otherwise
155 public boolean isTestnet() {
156 return Boolean.valueOf("testnet");
160 * Returns the version of the peer.
162 * @return The version of the peer
164 public Version getVersion() {
165 return new Version(getField("version"));
169 * Returns the negotiation types the peer supports.
171 * @return The supported negotiation types
173 public int[] getNegotiationTypes() {
174 return FcpUtils.decodeMultiIntegerField(getField("auth.negTypes"));