Add NFD.getKeyLocator()
diff --git a/src/main/java/com/intel/jndn/management/NFD.java b/src/main/java/com/intel/jndn/management/NFD.java
index 381291d..ed9c598 100644
--- a/src/main/java/com/intel/jndn/management/NFD.java
+++ b/src/main/java/com/intel/jndn/management/NFD.java
@@ -33,6 +33,7 @@
import net.named_data.jndn.encoding.EncodingException;
import net.named_data.jndn.security.SecurityException;
import java.util.logging.Logger;
+import net.named_data.jndn.KeyLocator;
/**
* Helper class for interacting with an NDN forwarder daemon; see
@@ -95,12 +96,7 @@
* @throws java.lang.Exception
*/
public static ForwarderStatus getForwarderStatus(Face forwarder) throws Exception {
- Interest interest = new Interest(new Name("/localhost/nfd/status"));
- interest.setMustBeFresh(true);
- interest.setChildSelector(Interest.CHILD_SELECTOR_RIGHT);
- interest.setInterestLifetimeMilliseconds(DEFAULT_TIMEOUT);
-
- Data data = SimpleClient.getDefault().getSync(forwarder, interest);
+ Data data = retrieveStatus(forwarder);
ForwarderStatus status = new ForwarderStatus();
status.wireDecode(data.getContent().buf());
return status;
@@ -152,6 +148,22 @@
}
/**
+ * Retrieve the {@link KeyLocator} for an NFD.
+ *
+ * @param forwarder only a localhost {@link Face}
+ * @return the {@link KeyLocator} of the NFD's key
+ * @throws ManagementException if the key is not available
+ * @throws IOException if the request fails
+ */
+ public static KeyLocator getKeyLocator(Face forwarder) throws ManagementException, IOException {
+ Data data = retrieveStatus(forwarder);
+ if (!KeyLocator.canGetFromSignature(data.getSignature())) {
+ throw new ManagementException("No key locator available.");
+ }
+ return KeyLocator.getFromSignature(data.getSignature());
+ }
+
+ /**
* Helper method to register a new face on the forwarder; as mentioned at
* <a href="http://named-data.net/doc/NFD/current/manpages/nfdc.html">http://named-data.net/doc/NFD/current/manpages/nfdc.html</a>,
* this is more for debugging; use 'register' instead
@@ -446,15 +458,31 @@
}
/**
+ * Build an interest to retrieve the NFD status.
+ *
+ * @param forwarder only a localhost {@link Face}
+ * @return the status {@link Data} packet
+ * @throws IOException if the retrieval fails
+ */
+ private static Data retrieveStatus(Face forwarder) throws IOException {
+ Interest interest = new Interest(new Name("/localhost/nfd/status"));
+ interest.setMustBeFresh(true);
+ interest.setChildSelector(Interest.CHILD_SELECTOR_RIGHT);
+ interest.setInterestLifetimeMilliseconds(DEFAULT_TIMEOUT);
+ Data data = SimpleClient.getDefault().getSync(forwarder, interest);
+ return data;
+ }
+
+ /**
* Build an interest to retrieve a segmented data set from the NFD; for
* details on the DataSet, see
* <a href="http://redmine.named-data.net/projects/nfd/wiki/StatusDataset">http://redmine.named-data.net/projects/nfd/wiki/StatusDataset</a>
*
- * @param forwarder
- * @param datasetName
- * @return
- * @throws IOException
- * @throws ManagementException
+ * @param forwarder the {@link Face} to an NFD
+ * @param datasetName the {@link Name} of the dataset to retrieve
+ * @return the re-assembled {@link Data} packet
+ * @throws IOException if the request fails
+ * @throws ManagementException if the returned TLV is not the expected type
*/
public static Data retrieveDataSet(Face forwarder, Name datasetName) throws IOException, ManagementException {
// build management Interest packet; see <a href="http://redmine.named-data.net/projects/nfd/wiki/StatusDataset">http://redmine.named-data.net/projects/nfd/wiki/StatusDataset</a>
@@ -486,7 +514,7 @@
* <a href="http://redmine.named-data.net/projects/nfd/wiki/ControlCommand,">http://redmine.named-data.net/projects/nfd/wiki/ControlCommand,</a>
* the requested interest must have encoded ControlParameters appended to the
* interest name
- * @return
+ * @return a {@link ControlResponse}
* @throws java.io.IOException
* @throws net.named_data.jndn.encoding.EncodingException
* @throws com.intel.jndn.management.ManagementException
diff --git a/src/test/java/com/intel/jndn/management/IntegrationSuite.java b/src/test/java/com/intel/jndn/management/IntegrationSuite.java
index 7a324ab..2758e98 100644
--- a/src/test/java/com/intel/jndn/management/IntegrationSuite.java
+++ b/src/test/java/com/intel/jndn/management/IntegrationSuite.java
@@ -17,6 +17,7 @@
import java.util.logging.Logger;
import junit.framework.Assert;
import net.named_data.jndn.Face;
+import net.named_data.jndn.KeyLocator;
import net.named_data.jndn.Name;
import net.named_data.jndn.security.KeyChain;
@@ -42,6 +43,11 @@
face.setCommandSigningInfo(keyChain, keyChain.getDefaultCertificateName());
Assert.assertTrue(NFD.pingLocal(face));
+
+ // grab key locator
+ KeyLocator keyLocator = NFD.getKeyLocator(face);
+ Assert.assertNotNull(keyLocator);
+ logger.info("Connected to NFD with key locator: " + keyLocator.getKeyName().toUri());
// grab datasets
Assert.assertTrue(NFD.getForwarderStatus(face).getStartTimestamp() > 0);