X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;ds=inline;f=src%2Fnet%2Fpterodactylus%2Ffcp%2FPeer.java;h=aec2959791b711a22d41970a3572ffb2c19567a6;hb=c200f549b8ebde87b6145f1f5bacf932e68151f5;hp=f7d33787d0c5639d7d15fcd78b49fdc33a53c0fe;hpb=4bdce9b8232e900d6c7fbfea7823505412cb7a32;p=jFCPlib.git
diff --git a/src/net/pterodactylus/fcp/Peer.java b/src/net/pterodactylus/fcp/Peer.java
index f7d3378..aec2959 100644
--- a/src/net/pterodactylus/fcp/Peer.java
+++ b/src/net/pterodactylus/fcp/Peer.java
@@ -19,17 +19,21 @@
package net.pterodactylus.fcp;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+
/**
* The âPeerâ reply by the node contains information about a peer.
- *
+ *
* @author David âBombeâ Roden <bombe@freenetproject.org>
- * @version $Id$
*/
public class Peer extends BaseMessage {
/**
* Creates a new âPeerâ reply from the received message.
- *
+ *
* @param receivedMessage
* The received message
*/
@@ -39,7 +43,7 @@ public class Peer extends BaseMessage {
/**
* Returns a collection of fields as a node reference.
- *
+ *
* @return The node reference contained within this message
*/
public NodeRef getNodeRef() {
@@ -60,7 +64,7 @@ public class Peer extends BaseMessage {
/**
* Returns the identifier of the request.
- *
+ *
* @return The identifier of the request
*/
public String getIdentifier() {
@@ -70,7 +74,7 @@ public class Peer extends BaseMessage {
/**
* Returns the âphysical.udpâ line from the message. It contains all IP
* addresses and port numbers of the peer.
- *
+ *
* @return The IP addresses and port numbers of the peer
*/
public String getPhysicalUDP() {
@@ -79,7 +83,7 @@ public class Peer extends BaseMessage {
/**
* Returns whether the listed peer is an opennet peer.
- *
+ *
* @return true
if the peer is an opennet peer,
* false
if the peer is a darknet peer
*/
@@ -88,8 +92,18 @@ public class Peer extends BaseMessage {
}
/**
+ * Returns whether this peer is a seed.
+ *
+ * @return true
if the peer is a seed, false
+ * otherwise
+ */
+ public boolean isSeed() {
+ return Boolean.valueOf(getField("seed"));
+ }
+
+ /**
* Returns the âyâ part of the peerâs public DSA key.
- *
+ *
* @return The public DSA key
*/
public String getDSAPublicKey() {
@@ -98,7 +112,7 @@ public class Peer extends BaseMessage {
/**
* Returns the DSA group of the peer.
- *
+ *
* @return The DSA group of the peer
*/
public DSAGroup getDSAGroup() {
@@ -108,7 +122,7 @@ public class Peer extends BaseMessage {
/**
* Returns the last good version of the peer, i.e. the oldest version the
* peer will connect to.
- *
+ *
* @return The last good version of the peer
*/
public Version getLastGoodVersion() {
@@ -117,7 +131,7 @@ public class Peer extends BaseMessage {
/**
* Returns the ARK of the peer.
- *
+ *
* @return The ARK of the peer
*/
public ARK getARK() {
@@ -126,7 +140,7 @@ public class Peer extends BaseMessage {
/**
* Returns the identity of the peer.
- *
+ *
* @return The identity of the peer
*/
public String getIdentity() {
@@ -136,7 +150,7 @@ public class Peer extends BaseMessage {
/**
* Returns the name of the peer. If the peer is not a darknet peer it will
* have no name.
- *
+ *
* @return The name of the peer, or null
if the peer is an
* opennet peer
*/
@@ -146,7 +160,7 @@ public class Peer extends BaseMessage {
/**
* Returns the location of the peer.
- *
+ *
* @return The location of the peer
* @throws NumberFormatException
* if the field can not be parsed
@@ -157,7 +171,7 @@ public class Peer extends BaseMessage {
/**
* Returns whether the peer is a testnet node.
- *
+ *
* @return true
if the peer is a testnet node,
* false
otherwise
*/
@@ -167,7 +181,7 @@ public class Peer extends BaseMessage {
/**
* Returns the version of the peer.
- *
+ *
* @return The version of the peer
*/
public Version getVersion() {
@@ -176,7 +190,7 @@ public class Peer extends BaseMessage {
/**
* Returns the negotiation types the peer supports.
- *
+ *
* @return The supported negotiation types
*/
public int[] getNegotiationTypes() {
@@ -184,29 +198,59 @@ public class Peer extends BaseMessage {
}
/**
+ * Returns all volatile fields from the message.
+ *
+ * @return All volatile files
+ */
+ public Map getVolatileFields() {
+ Map volatileFields = new HashMap();
+ for (Entry field : getFields().entrySet()) {
+ if (field.getKey().startsWith("volatile.")) {
+ volatileFields.put(field.getKey(), field.getValue());
+ }
+ }
+ return Collections.unmodifiableMap(volatileFields);
+ }
+
+ /**
* Returns one of the volatile fields from the message. The given field name
* is prepended with âvolatile.â so if you want to get the value of the
* field with the name âvolatile.statusâ you only need to specify âstatusâ.
- *
+ *
* @param field
* The name of the field
- * @return The value of the field, or null
if there is no
- * such field
+ * @return The value of the field, or null
if there is no such
+ * field
*/
public String getVolatile(String field) {
return getField("volatile." + field);
}
/**
+ * Returns all metadata fields from the message.
+ *
+ * @return All volatile files
+ */
+ public Map getMetadataFields() {
+ Map metadataFields = new HashMap();
+ for (Entry field : getFields().entrySet()) {
+ if (field.getKey().startsWith("metadata.")) {
+ metadataFields.put(field.getKey(), field.getValue());
+ }
+ }
+ return Collections.unmodifiableMap(metadataFields);
+ }
+
+ /**
* Returns one of the metadata fields from the message. The given field name
* is prepended with âmetadata.â so if you want to get the value of the
* field with the name âmetadata.timeLastRoutableâ you only need to specify
* âtimeLastRoutableâ.
- *
+ *
* @param field
* The name of the field
- * @return The value of the field, or null
if there is no
- * such field
+ * @return The value of the field, or null
if there is no such
+ * field
*/
public String getMetadata(String field) {
return getField("metadata." + field);