add constructor that creates noderef from fcp message
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 9 Apr 2008 19:39:07 +0000 (19:39 +0000)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 9 Apr 2008 19:39:07 +0000 (19:39 +0000)
git-svn-id: http://trooper/svn/projects/jSite/trunk@674 c3eda9e8-030b-0410-8277-bc7414b0a119

src/net/pterodactylus/util/fcp/NodeRef.java

index 4eb80eb..cc8241f 100644 (file)
@@ -52,6 +52,37 @@ public class NodeRef {
        private String signature;
 
        /**
+        * Creates a new, empty noderef.
+        */
+       public NodeRef() {
+       }
+
+       /**
+        * Creates a new noderef that is initialized with fields from the given
+        * message.
+        * 
+        * @param fromMessage
+        *            The message to get initial values for the noderef from
+        */
+       public NodeRef(FcpMessage fromMessage) {
+               identity = fromMessage.getField("identity");
+               opennet = Boolean.valueOf(fromMessage.getField("opennet"));
+               name = fromMessage.getField("myName");
+               if (fromMessage.hasField("location")) {
+                       location = Double.valueOf(fromMessage.getField("location"));
+               }
+               physicalUDP = fromMessage.getField("physical.udp");
+               ark = new ARK(fromMessage.getField("ark.pubURI"), fromMessage.getField("ark.privURI"), fromMessage.getField("ark.number"));
+               dsaPublicKey = fromMessage.getField("dsaPubKey.y");
+               dsaGroup = new DSAGroup(fromMessage.getField("dsaGroup.b"), fromMessage.getField("dsaGroup.p"), fromMessage.getField("dsaGroup.q"));
+               negotiationTypes = FcpUtils.decodeMultiIntegerField(fromMessage.getField("auth.negTypes"));
+               version = new Version(fromMessage.getField("version"));
+               lastGoodVersion = new Version(fromMessage.getField("lastGoodVersion"));
+               testnet = Boolean.valueOf(fromMessage.getField("testnet"));
+               signature = fromMessage.getField("sig");
+       }
+
+       /**
         * Returns the identity of the node.
         * 
         * @return The identity of the node
@@ -155,7 +186,7 @@ public class NodeRef {
         * 
         * @return The ARK of the node
         */
-       public ARK getArk() {
+       public ARK getARK() {
                return ark;
        }
 
@@ -165,7 +196,7 @@ public class NodeRef {
         * @param ark
         *            The ARK of the node
         */
-       public void setArk(ARK ark) {
+       public void setARK(ARK ark) {
                this.ark = ark;
        }