move message package to top-level package
[jSite2.git] / src / net / pterodactylus / util / fcp / Peer.java
1 /**
2  * © 2008 INA Service GmbH
3  */
4 package net.pterodactylus.util.fcp;
5
6
7
8 /**
9  * The “Peer” reply by the node contains information about a peer.
10  * 
11  * @author <a href="mailto:dr@ina-germany.de">David Roden</a>
12  * @version $Id$
13  */
14 public class Peer extends BaseMessage {
15
16         /**
17          * Creates a new “Peer” reply from the received message.
18          * 
19          * @param receivedMessage
20          *            The received message
21          */
22         public Peer(FcpMessage receivedMessage) {
23                 super(receivedMessage);
24         }
25
26         /**
27          * Returns the “physical.udp” line from the message. It contains all IP
28          * addresses and port numbers of the peer.
29          * 
30          * @return The IP addresses and port numbers of the peer
31          */
32         public String getPhysicalUDP() {
33                 return getField("physical.udp");
34         }
35
36         /**
37          * Returns whether the listed peer is an opennet peer.
38          * 
39          * @return <code>true</code> if the peer is an opennet peer,
40          *         <code>false</code> if the peer is a darknet peer
41          */
42         public boolean isOpennet() {
43                 return Boolean.valueOf(getField("opennet"));
44         }
45
46         /**
47          * Returns the “y” part of the peer’s public DSA key.
48          * 
49          * @return The public DSA key
50          */
51         public String getDSAPublicKey() {
52                 return getField("dsaPubKey.y");
53         }
54
55         /**
56          * Returns the DSA group of the peer.
57          * 
58          * @return The DSA group of the peer
59          */
60         public DSAGroup getDSAGroup() {
61                 return new DSAGroup(getField("dsaGroup.g"), getField("dsaGroup.p"), getField("dsaGroup.q"));
62         }
63
64         /**
65          * Returns the last good version of the peer, i.e. the oldest version the
66          * peer will connect to.
67          * 
68          * @return The last good version of the peer
69          */
70         public Version getLastGoodVersion() {
71                 return new Version(getField("lastGoodVersion"));
72         }
73
74         /**
75          * Returns the ARK of the peer.
76          * 
77          * @return The ARK of the peer
78          */
79         public ARK getARK() {
80                 return new ARK(getField("ark.pubURI"), getField("ark.number"));
81         }
82
83         /**
84          * Returns the identity of the peer.
85          * 
86          * @return The identity of the peer
87          */
88         public String getIdentity() {
89                 return getField("identity");
90         }
91
92         /**
93          * Returns the name of the peer. If the peer is not a darknet peer it will
94          * have no name.
95          * 
96          * @return The name of the peer, or <code>null</code> if the peer is an
97          *         opennet peer
98          */
99         public String getMyName() {
100                 return getField("myName");
101         }
102
103         /**
104          * Returns the location of the peer.
105          * 
106          * @return The location of the peer
107          * @throws NumberFormatException
108          *             if the field can not be parsed
109          */
110         public double getLocation() throws NumberFormatException {
111                 return Double.valueOf(getField("location"));
112         }
113
114         /**
115          * Returns whether the peer is a testnet node.
116          * 
117          * @return <code>true</code> if the peer is a testnet node,
118          *         <code>false</code> otherwise
119          */
120         public boolean isTestnet() {
121                 return Boolean.valueOf("testnet");
122         }
123
124         /**
125          * Returns the version of the peer.
126          * 
127          * @return The version of the peer
128          */
129         public Version getVersion() {
130                 return new Version(getField("version"));
131         }
132
133         /**
134          * Returns the negotiation types the peer supports.
135          * 
136          * @return The supported negotiation types
137          */
138         public int[] getNegotiationTypes() {
139                 return FcpUtils.parseMultiIntegerField(getField("auth.negTypes"));
140         }
141
142 }