2 * © 2008 INA Service GmbH
4 package net.pterodactylus.util.fcp;
7 * The “Peer” reply by the node contains information about a peer.
9 * @author <a href="mailto:dr@ina-germany.de">David Roden</a>
12 public class Peer extends BaseMessage {
15 * Creates a new “Peer” reply from the received message.
17 * @param receivedMessage
18 * The received message
20 public Peer(FcpMessage receivedMessage) {
21 super(receivedMessage);
25 * Returns a collection of fields as a node reference.
27 * @return The node reference contained within this message
29 public NodeRef getNodeRef() {
30 NodeRef nodeRef = new NodeRef();
31 nodeRef.setARK(getARK());
32 nodeRef.setDSAGroup(getDSAGroup());
33 nodeRef.setDSAPublicKey(getDSAPublicKey());
34 nodeRef.setIdentity(getIdentity());
35 nodeRef.setLastGoodVersion(getLastGoodVersion());
36 nodeRef.setLocation(getLocation());
37 nodeRef.setName(getMyName());
38 nodeRef.setNegotiationTypes(getNegotiationTypes());
39 nodeRef.setOpennet(isOpennet());
40 nodeRef.setPhysicalUDP(getPhysicalUDP());
41 nodeRef.setVersion(getVersion());
46 * Returns the “physical.udp” line from the message. It contains all IP
47 * addresses and port numbers of the peer.
49 * @return The IP addresses and port numbers of the peer
51 public String getPhysicalUDP() {
52 return getField("physical.udp");
56 * Returns whether the listed peer is an opennet peer.
58 * @return <code>true</code> if the peer is an opennet peer,
59 * <code>false</code> if the peer is a darknet peer
61 public boolean isOpennet() {
62 return Boolean.valueOf(getField("opennet"));
66 * Returns the “y” part of the peer’s public DSA key.
68 * @return The public DSA key
70 public String getDSAPublicKey() {
71 return getField("dsaPubKey.y");
75 * Returns the DSA group of the peer.
77 * @return The DSA group of the peer
79 public DSAGroup getDSAGroup() {
80 return new DSAGroup(getField("dsaGroup.g"), getField("dsaGroup.p"), getField("dsaGroup.q"));
84 * Returns the last good version of the peer, i.e. the oldest version the
85 * peer will connect to.
87 * @return The last good version of the peer
89 public Version getLastGoodVersion() {
90 return new Version(getField("lastGoodVersion"));
94 * Returns the ARK of the peer.
96 * @return The ARK of the peer
99 return new ARK(getField("ark.pubURI"), getField("ark.number"));
103 * Returns the identity of the peer.
105 * @return The identity of the peer
107 public String getIdentity() {
108 return getField("identity");
112 * Returns the name of the peer. If the peer is not a darknet peer it will
115 * @return The name of the peer, or <code>null</code> if the peer is an
118 public String getMyName() {
119 return getField("myName");
123 * Returns the location of the peer.
125 * @return The location of the peer
126 * @throws NumberFormatException
127 * if the field can not be parsed
129 public double getLocation() throws NumberFormatException {
130 return Double.valueOf(getField("location"));
134 * Returns whether the peer is a testnet node.
136 * @return <code>true</code> if the peer is a testnet node,
137 * <code>false</code> otherwise
139 public boolean isTestnet() {
140 return Boolean.valueOf("testnet");
144 * Returns the version of the peer.
146 * @return The version of the peer
148 public Version getVersion() {
149 return new Version(getField("version"));
153 * Returns the negotiation types the peer supports.
155 * @return The supported negotiation types
157 public int[] getNegotiationTypes() {
158 return FcpUtils.decodeMultiIntegerField(getField("auth.negTypes"));