gui: Upgrade management library and relevant gui parts
Change-Id: Ib1875b5d844df0853892e41b2c02aae7c8a5f65f
Fixes: #3399
diff --git a/app/build.gradle b/app/build.gradle
index 50234dd..a18648d 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -99,11 +99,6 @@
}
clean.dependsOn cleanNative
-
- // TODO: remove after switching to jndn-management:1.1.0
- lintOptions {
- abortOnError false
- }
}
def getNdkBuildCmd() {
@@ -133,6 +128,9 @@
repositories {
mavenLocal()
mavenCentral()
+ maven {
+ url "https://oss.sonatype.org/content/repositories/snapshots/"
+ }
}
dependencies {
@@ -140,21 +138,10 @@
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.android.support:support-v4:21.0.3'
- /// Temporarily, the modified code is embedded within NFD app
- //
- // compile('com.intel.jndn.utils:jndn-utils:0.9.7') {
- // exclude group: 'com.intel.jndn.mock', module: 'jndn-mock'
- // exclude group: 'net.named-data', module: 'jndn'
- // }
-
- // compile('com.intel.jndn.management:jndn-management:0.9.7') {
- // exclude group: 'net.named-data', module: 'jndn'
- // exclude group: 'com.intel.jndn.utils', module: 'jndn-utils'
- // exclude group: 'com.intel.jndn.mock', module: 'jndn-mock'
- // }
-
- // compile('net.named-data:jndn-android:0.7') {
- compile('net.named-data:jndn:0.4') {
+ compile('com.intel.jndn.management:jndn-management:1.1.0') {
+ exclude group: 'net.named-data', module: 'jndn'
+ }
+ compile('net.named-data:jndn-android:0.10') {
exclude group: 'org.xerial'
}
compile 'net.named-data.jndn-xx:jndn-xx-util:0.0.1'
diff --git a/app/src/main/java/com/intel/jndn/management/EncodingHelper.java b/app/src/main/java/com/intel/jndn/management/EncodingHelper.java
deleted file mode 100644
index 5d658ee..0000000
--- a/app/src/main/java/com/intel/jndn/management/EncodingHelper.java
+++ /dev/null
@@ -1,144 +0,0 @@
-/*
- * jndn-management
- * Copyright (c) 2015, Intel Corporation.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU Lesser General Public License,
- * version 3, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
- * more details.
- */
-package com.intel.jndn.management;
-
-import java.nio.ByteBuffer;
-import net.named_data.jndn.ControlParameters;
-import net.named_data.jndn.ForwardingFlags;
-import net.named_data.jndn.Name;
-import net.named_data.jndn.encoding.EncodingException;
-import net.named_data.jndn.encoding.tlv.Tlv;
-import net.named_data.jndn.encoding.tlv.TlvDecoder;
-import net.named_data.jndn.encoding.tlv.TlvEncoder;
-import net.named_data.jndn.util.Blob;
-
-/**
- * Provide helper methods to cover areas too protected in Tlv0_1_1WireFormat;
- * this class can be deprecated if WireFormats allow passing in an existing
- * TlvEncoder/TlvDecoder (currently these methods are protected).
- *
- * @author Andrew Brown <andrew.brown@intel.com>
- */
-public class EncodingHelper {
-
- /**
- * Helper to decode names since Tlv0_1_1WireFormat.java uses its own internal,
- * protected implementation.
- *
- * @param input
- * @return
- * @throws EncodingException
- */
- public static Name decodeName(ByteBuffer input) throws EncodingException {
- TlvDecoder decoder = new TlvDecoder(input);
- return decodeName(decoder);
- }
-
- /**
- * Helper to decode names using an existing decoding context; could be merged
- * to Tlv0_1_1WireFormat.java.
- *
- * @param decoder
- * @return
- * @throws EncodingException
- */
- public static Name decodeName(TlvDecoder decoder) throws EncodingException {
- Name name = new Name();
- int endOffset = decoder.readNestedTlvsStart(Tlv.Name);
- while (decoder.getOffset() < endOffset) {
- name.append(new Blob(decoder.readBlobTlv(Tlv.NameComponent), true));
- }
-
- decoder.finishNestedTlvs(endOffset);
- return name;
- }
-
- /**
- * Helper to encode names since Tlv0_1_1WireFormat.java uses its own internal,
- * protected implementation.
- *
- * @param name
- * @return
- */
- public static Blob encodeName(Name name) {
- TlvEncoder encoder = new TlvEncoder();
- encodeName(name, encoder);
- return new Blob(encoder.getOutput(), false);
- }
-
- /**
- * Helper to encode names using an existing encoding context; could be merged
- * to Tlv0_1_1WireFormat.java.
- *
- * @param name
- * @param encoder
- */
- public static final void encodeName(Name name, TlvEncoder encoder) {
- int saveLength = encoder.getLength();
- for (int i = name.size() - 1; i >= 0; --i) {
- encoder.writeBlobTlv(Tlv.NameComponent, name.get(i).getValue().buf());
- }
- encoder.writeTypeAndLength(Tlv.Name, encoder.getLength() - saveLength);
- }
-
- /**
- * Helper to encode control parameters using an existing encoding context;
- * could be merged to Tlv0_1_1WireFormat.java.
- *
- * @param controlParameters
- * @param encoder
- */
- public static final void encodeControlParameters(ControlParameters controlParameters, TlvEncoder encoder) {
- int saveLength = encoder.getLength();
-
- // Encode backwards.
- encoder.writeOptionalNonNegativeIntegerTlvFromDouble(Tlv.ControlParameters_ExpirationPeriod,
- controlParameters.getExpirationPeriod());
-
- // Encode strategy
- if (controlParameters.getStrategy().size() != 0) {
- int strategySaveLength = encoder.getLength();
- encodeName(controlParameters.getStrategy(), encoder);
- encoder.writeTypeAndLength(Tlv.ControlParameters_Strategy,
- encoder.getLength() - strategySaveLength);
- }
-
- // Encode ForwardingFlags
- int flags = controlParameters.getForwardingFlags().getNfdForwardingFlags();
- if (flags != new ForwardingFlags().getNfdForwardingFlags()) // The flags are not the default value.
- {
- encoder.writeNonNegativeIntegerTlv(Tlv.ControlParameters_Flags, flags);
- }
-
- encoder.writeOptionalNonNegativeIntegerTlv(Tlv.ControlParameters_Cost, controlParameters.getCost());
- encoder.writeOptionalNonNegativeIntegerTlv(Tlv.ControlParameters_Origin, controlParameters.getOrigin());
- encoder.writeOptionalNonNegativeIntegerTlv(Tlv.ControlParameters_LocalControlFeature,
- controlParameters.getLocalControlFeature());
-
- // Encode URI
- if (!controlParameters.getUri().isEmpty()) {
- encoder.writeBlobTlv(Tlv.ControlParameters_Uri,
- new Blob(controlParameters.getUri()).buf());
- }
-
- encoder.writeOptionalNonNegativeIntegerTlv(Tlv.ControlParameters_FaceId, controlParameters.getFaceId());
-
- // Encode name
- if (controlParameters.getName().size() != 0) {
- encodeName(controlParameters.getName(), encoder);
- }
-
- encoder.writeTypeAndLength(Tlv.ControlParameters_ControlParameters, encoder.getLength() - saveLength);
- }
-}
diff --git a/app/src/main/java/com/intel/jndn/management/ManagementException.java b/app/src/main/java/com/intel/jndn/management/ManagementException.java
deleted file mode 100644
index 70a15d1..0000000
--- a/app/src/main/java/com/intel/jndn/management/ManagementException.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * jndn-management
- * Copyright (c) 2015, Intel Corporation.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU Lesser General Public License,
- * version 3, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
- * more details.
- */
-package com.intel.jndn.management;
-
-import com.intel.jndn.management.types.ControlResponse;
-import net.named_data.jndn.encoding.EncodingException;
-import net.named_data.jndn.util.Blob;
-
-/**
- * Represent a failure to correctly manage the NDN Forwarding Daemon (NFD).
- * Inspect this object with getCause() to see why the management operation
- * failed.
- *
- * @author Andrew Brown <andrew.brown@intel.com>
- */
-public class ManagementException extends Exception {
-
- /**
- *
- * @param message
- */
- public ManagementException(String message) {
- super(message);
- }
-
- /**
- *
- * @param message
- * @param cause
- */
- public ManagementException(String message, Throwable cause) {
- super(message, cause);
- }
-
- /**
- * Parse an NFD response to create a ManagementException.
- *
- * @param forwarderResponse
- * @return
- */
- public static ManagementException fromResponse(Blob forwarderResponse) {
- ControlResponse response = new ControlResponse();
- try {
- response.wireDecode(forwarderResponse.buf());
- String message = "Action failed, forwarder returned: " + response.getStatusCode() + " " + response.getStatusText();
- return new ManagementException(message);
- } catch (EncodingException e) {
- return new ManagementException("Action failed and forwarder response was unparseable.", e);
- }
- }
-
- /**
- * Parse an NFD response to create a ManagementException.
- *
- * @param forwarderResponse
- * @return
- */
- public static ManagementException fromResponse(ControlResponse response) {
- String message = "Action failed, forwarder returned: " + response.getStatusCode() + " " + response.getStatusText();
- return new ManagementException(message);
- }
-}
diff --git a/app/src/main/java/com/intel/jndn/management/NFD.java b/app/src/main/java/com/intel/jndn/management/NFD.java
deleted file mode 100644
index b62cbe6..0000000
--- a/app/src/main/java/com/intel/jndn/management/NFD.java
+++ /dev/null
@@ -1,520 +0,0 @@
-/*
- * jndn-management
- * Copyright (c) 2015, Intel Corporation.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU Lesser General Public License,
- * version 3, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
- * more details.
- */
-package com.intel.jndn.management;
-
-import com.intel.jndn.management.types.StatusDataset;
-import com.intel.jndn.management.types.ControlResponse;
-import com.intel.jndn.management.types.FaceStatus;
-import com.intel.jndn.management.types.FibEntry;
-import com.intel.jndn.management.types.ForwarderStatus;
-import com.intel.jndn.management.types.LocalControlHeader;
-import com.intel.jndn.management.types.RibEntry;
-import com.intel.jndn.utils.SimpleClient;
-import com.intel.jndn.utils.SegmentedClient;
-import java.io.IOException;
-import java.util.List;
-import net.named_data.jndn.ControlParameters;
-import net.named_data.jndn.Data;
-import net.named_data.jndn.Face;
-import net.named_data.jndn.ForwardingFlags;
-import net.named_data.jndn.Interest;
-import net.named_data.jndn.Name;
-import net.named_data.jndn.encoding.EncodingException;
-import net.named_data.jndn.security.SecurityException;
-import java.util.logging.Logger;
-
-import net.named_data.nfd.utils.G;
-
-/**
- * Helper class for interacting with an NDN forwarder daemon; see
- * <a href="http://redmine.named-data.net/projects/nfd/wiki/Management">http://redmine.named-data.net/projects/nfd/wiki/Management</a>
- * for explanations of the various protocols used.
- *
- * @author Andrew Brown <andrew.brown@intel.com>
- */
-public class NFD {
-
- public final static long DEFAULT_TIMEOUT = 2000;
- public final static int OK_STATUS = 200;
- static private final Logger logger = Logger.getLogger(NFD.class.getName());
-
- /**
- * Ping a forwarder on an existing face to verify that the forwarder is
- * working and responding to requests; this version sends a discovery packet
- * to /localhost/nfd which should always respond if the requestor is on the
- * same machine as the NDN forwarding daemon.
- *
- * @param face only a localhost Face
- * @return true if successful, false otherwise
- */
- public static boolean pingLocal(Face face) {
- return ping(face, new Name("/localhost/nfd"));
- }
-
- /**
- * Request a name on an existing face to verify the forwarder is working and
- * responding to requests. Note that the name must be served or cached on the
- * forwarder for this to return true.
- *
- * @param face
- * @param name
- * @return true if successful, false otherwise
- */
- public static boolean ping(Face face, Name name) {
- // build interest
- Interest interest = new Interest(name);
- interest.setInterestLifetimeMilliseconds(DEFAULT_TIMEOUT);
- interest.setMustBeFresh(true);
-
- // send packet
- try {
- Data data = SimpleClient.getDefault().getSync(face, interest);
- return data != null;
- } catch (IOException e) {
- return false;
- }
- }
-
- /**
- * Retrieve the status of the given forwarder; calls /localhost/nfd/status
- * which requires a local Face (all non-local packets are dropped)
- *
- * @param forwarder only a localhost Face
- * @return the forwarder status object, see
- * <a href="http://redmine.named-data.net/projects/nfd/wiki/ForwarderStatus">
- * http://redmine.named-data.net/projects/nfd/wiki/ForwarderStatus</a>.
- * @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);
- G.Log("-----------" + data.getName().toUri());
- ForwarderStatus status = new ForwarderStatus();
- status.wireDecode(data.getContent().buf());
- G.Log("----------- done");
- return status;
- }
-
- /**
- * Retrieve a list of faces and their status from the given forwarder; calls
- * /localhost/nfd/faces/list which requires a local Face (all non-local
- * packets are dropped)
- *
- * @param forwarder only a localhost Face
- * @return a list of face status objects, see
- * http://redmine.named-data.net/projects/nfd/wiki/FaceMgmt.
- * @throws java.lang.Exception
- */
- public static List<FaceStatus> getFaceList(Face forwarder) throws Exception {
- Data data = retrieveDataSet(forwarder, new Name("/localhost/nfd/faces/list"));
- return StatusDataset.wireDecode(data.getContent(), FaceStatus.class);
- }
-
- /**
- * Retrieve a list of FIB entries and their NextHopRecords from the given
- * forwarder; calls /localhost/nfd/fib/list which requires a local Face (all
- * non-local packets are dropped).
- *
- * @param forwarder only a localhost Face
- * @return a list of FIB entries, see
- * http://redmine.named-data.net/projects/nfd/wiki/FibMgmt#FIB-Dataset.
- * @throws java.lang.Exception
- */
- public static List<FibEntry> getFibList(Face forwarder) throws Exception {
- Data data = retrieveDataSet(forwarder, new Name("/localhost/nfd/fib/list"));
- return StatusDataset.wireDecode(data.getContent(), FibEntry.class);
- }
-
- /**
- * Retrieve a list of routing entries from the RIB; calls
- * /localhost/nfd/rib/list which requires a local Face (all non-local packets
- * are dropped).
- *
- * @param forwarder only a localhost Face
- * @return a list of RIB entries, i.e. routes, see
- * http://redmine.named-data.net/projects/nfd/wiki/RibMgmt#RIB-Dataset.
- * @throws java.lang.Exception
- */
- public static List<RibEntry> getRouteList(Face forwarder) throws Exception {
- Data data = retrieveDataSet(forwarder, new Name("/localhost/nfd/rib/list"));
- return StatusDataset.wireDecode(data.getContent(), RibEntry.class);
- }
-
- /**
- * 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
- *
- * @param forwarder only a localhost Face
- * @param faceId
- * @param prefix
- * @throws java.lang.Exception
- */
- public static void addNextHop(Face forwarder, int faceId, Name prefix) throws Exception {
- // build command name
- Name command = new Name("/localhost/nfd/fib/add-nexthop");
- ControlParameters parameters = new ControlParameters();
- parameters.setName(prefix);
- parameters.setFaceId(faceId);
- command.append(parameters.wireEncode());
-
- // send the interest
- sendCommand(forwarder, new Interest(command));
- }
-
- /**
- * Create a new face on the given forwarder. Ensure the forwarding face is on
- * the local machine (management requests are to /localhost/...) and that
- * command signing has been set up (e.g. forwarder.setCommandSigningInfo()).
- *
- * @param forwarder only a localhost Face
- * @param uri
- * @return
- * @throws java.lang.Exception
- */
- public static int createFace(Face forwarder, String uri) throws Exception {
- Name command = new Name("/localhost/nfd/faces/create");
- ControlParameters parameters = new ControlParameters();
- parameters.setUri(uri);
- command.append(parameters.wireEncode());
-
- // send the interest
- ControlResponse response = sendCommand(forwarder, new Interest(command));
-
- // return
- return response.getBody().get(0).getFaceId();
- }
-
- /**
- * Destroy a face on given forwarder. Ensure the forwarding face is on the
- * local machine (management requests are to /localhost/...) and that command
- * signing has been set up (e.g. forwarder.setCommandSigningInfo()).
- *
- * @param forwarder only a localhost Face
- * @param faceId
- * @throws java.lang.Exception
- */
- public static void destroyFace(Face forwarder, int faceId) throws Exception {
- Name command = new Name("/localhost/nfd/faces/destroy");
- ControlParameters parameters = new ControlParameters();
- parameters.setFaceId(faceId);
- command.append(parameters.wireEncode());
-
- // send the interest
- sendCommand(forwarder, new Interest(command));
- }
-
- /**
- * Enable a local control feature on the given forwarder. See
- * <a href="http://redmine.named-data.net/projects/nfd/wiki/FaceMgmt#Enable-a-LocalControlHeader-feature">http://redmine.named-data.net/projects/nfd/wiki/FaceMgmt#Enable-a-LocalControlHeader-feature</a>
- *
- * @param forwarder
- * @param header
- * @throws Exception
- */
- public static void enableLocalControlHeader(Face forwarder, LocalControlHeader header) throws Exception {
- // build command name
- Name command = new Name("/localhost/nfd/faces/enable-local-control");
- ControlParameters parameters = new ControlParameters();
- parameters.setLocalControlFeature(header.getNumericValue());
- command.append(parameters.wireEncode());
-
- // send command and return
- sendCommand(forwarder, new Interest(command));
- }
-
- /**
- * Disable a local control feature on the given forwarder. See
- * <a href="http://redmine.named-data.net/projects/nfd/wiki/FaceMgmt#Disable-a-LocalControlHeader-feature">http://redmine.named-data.net/projects/nfd/wiki/FaceMgmt#Disable-a-LocalControlHeader-feature</a>
- *
- * @param forwarder
- * @param header
- * @throws Exception
- */
- public static void disableLocalControlHeader(Face forwarder, LocalControlHeader header) throws Exception {
- // build command name
- Name command = new Name("/localhost/nfd/faces/disable-local-control");
- ControlParameters parameters = new ControlParameters();
- parameters.setLocalControlFeature(header.getNumericValue());
- command.append(parameters.wireEncode());
-
- // send command and return
- sendCommand(forwarder, new Interest(command));
- }
-
- /**
- * Register a route on the forwarder; see
- * <a href="http://named-data.net/doc/NFD/current/manpages/nfdc.html">http://named-data.net/doc/NFD/current/manpages/nfdc.html</a>
- * for command-line usage and
- * <a href="http://redmine.named-data.net/projects/nfd/wiki/RibMgmt">http://redmine.named-data.net/projects/nfd/wiki/RibMgmt</a>
- * for protocol documentation. Ensure the forwarding face is on the local
- * machine (management requests are to /localhost/...) and that command
- * signing has been set up (e.g. forwarder.setCommandSigningInfo()).
- *
- * @param forwarder only a localhost Face
- * @param controlParameters
- * @throws Exception
- */
- public static void register(Face forwarder, ControlParameters controlParameters) throws Exception {
- // build command name
- Name command = new Name("/localhost/nfd/rib/register");
- command.append(controlParameters.wireEncode());
-
- // send the interest
- sendCommand(forwarder, new Interest(command));
- }
-
- /**
- * Register a route on a forwarder; this will create a new face on the
- * forwarder to the given URI/route pair. See register(Face,
- * ControlParameters) for more details documentation.
- *
- * @param forwarder only a localhost Face
- * @param uri
- * @param cost
- * @param route
- * @throws java.lang.Exception
- */
- public static void register(Face forwarder, String uri, Name route, int cost) throws Exception {
- // create the new face
- int faceId = createFace(forwarder, uri);
-
- // run base method
- register(forwarder, faceId, route, cost);
- }
-
- /**
- * Register a route on a forwarder; this will not create a new face since it
- * is provided a faceId. See register(Face, ControlParameters) for full
- * documentation
- *
- * @param forwarder only a localhost Face
- * @param faceId
- * @param route
- * @param cost
- * @throws java.lang.Exception
- */
- public static void register(Face forwarder, int faceId, Name route, int cost) throws Exception {
- // build command name
- ControlParameters parameters = new ControlParameters();
- parameters.setName(route);
- parameters.setFaceId(faceId);
- parameters.setCost(cost);
- ForwardingFlags flags = new ForwardingFlags();
- flags.setCapture(true);
- flags.setChildInherit(true);
- parameters.setForwardingFlags(flags);
-
- // run base method
- register(forwarder, parameters);
- }
-
- /**
- * Unregister a route on a forwarder; see
- * <a href="http://named-data.net/doc/NFD/current/manpages/nfdc.html">http://named-data.net/doc/NFD/current/manpages/nfdc.html</a>
- * for command-line usage and
- * <a href="http://redmine.named-data.net/projects/nfd/wiki/RibMgmt">http://redmine.named-data.net/projects/nfd/wiki/RibMgmt</a>
- * for protocol documentation. Ensure the forwarding face is on the local
- * machine (management requests are to /localhost/...) and that command
- * signing has been set up (e.g. forwarder.setCommandSigningInfo()
- *
- * @param forwarder
- * @param controlParameters
- * @throws java.lang.Exception
- */
- public static void unregister(Face forwarder, ControlParameters controlParameters) throws Exception {
- // build command name
- Name command = new Name("/localhost/nfd/rib/unregister");
- command.append(controlParameters.wireEncode());
-
- // send the interest
- sendCommand(forwarder, new Interest(command));
- }
-
- /**
- * Unregister a route on a forwarder; see
- * <a href="http://named-data.net/doc/NFD/current/manpages/nfdc.html">http://named-data.net/doc/NFD/current/manpages/nfdc.html</a>
- * for command-line usage and
- * <a href="http://redmine.named-data.net/projects/nfd/wiki/RibMgmt">http://redmine.named-data.net/projects/nfd/wiki/RibMgmt</a>
- * for protocol documentation. Ensure the forwarding face is on the local
- * machine (management requests are to /localhost/...) and that command
- * signing has been set up (e.g. forwarder.setCommandSigningInfo()
- *
- * @param forwarder
- * @param route
- * @throws java.lang.Exception
- */
- public static void unregister(Face forwarder, Name route) throws Exception {
- // build command name
- ControlParameters controlParameters = new ControlParameters();
- controlParameters.setName(route);
-
- // send the interest
- unregister(forwarder, controlParameters);
- }
-
- /**
- * Unregister a route on a forwarder; see
- * <a href="http://named-data.net/doc/NFD/current/manpages/nfdc.html">http://named-data.net/doc/NFD/current/manpages/nfdc.html</a>
- * for command-line usage and
- * <a href="http://redmine.named-data.net/projects/nfd/wiki/RibMgmt">http://redmine.named-data.net/projects/nfd/wiki/RibMgmt</a>
- * for protocol documentation. Ensure the forwarding face is on the local
- * machine (management requests are to /localhost/...) and that command
- * signing has been set up (e.g. forwarder.setCommandSigningInfo()
- *
- * @param forwarder
- * @param route
- * @param faceId
- * @throws java.lang.Exception
- */
- public static void unregister(Face forwarder, Name route, int faceId) throws Exception {
- // build command name
- ControlParameters controlParameters = new ControlParameters();
- controlParameters.setName(route);
- controlParameters.setFaceId(faceId);
-
- // send the interest
- unregister(forwarder, controlParameters);
- }
-
- /**
- * Unregister a route on a forwarder; see
- * <a href="http://named-data.net/doc/NFD/current/manpages/nfdc.html">http://named-data.net/doc/NFD/current/manpages/nfdc.html</a>
- * for command-line usage and
- * <a href="http://redmine.named-data.net/projects/nfd/wiki/RibMgmt">http://redmine.named-data.net/projects/nfd/wiki/RibMgmt</a>
- * for protocol documentation. Ensure the forwarding face is on the local
- * machine (management requests are to /localhost/...) and that command
- * signing has been set up (e.g. forwarder.setCommandSigningInfo()
- *
- * @param forwarder
- * @param route
- * @param uri
- * @throws java.lang.Exception
- */
- public static void unregister(Face forwarder, Name route, String uri) throws Exception {
- int faceId = -1;
- for (FaceStatus face : getFaceList(forwarder)) {
- if (face.getUri().matches(uri)) {
- faceId = face.getFaceId();
- break;
- }
- }
-
- if (faceId == -1) {
- throw new ManagementException("Face not found: " + uri);
- }
-
- // send the interest
- unregister(forwarder, route, faceId);
- }
-
- /**
- * Set a strategy on the forwarder; see
- * <a href="http://named-data.net/doc/NFD/current/manpages/nfdc.html">http://named-data.net/doc/NFD/current/manpages/nfdc.html</a>
- * for command-line usage and
- * <a href="http://redmine.named-data.net/projects/nfd/wiki/StrategyChoice">http://redmine.named-data.net/projects/nfd/wiki/StrategyChoice</a>
- * for protocol documentation. Ensure the forwarding face is on the local
- * machine (management requests are to /localhost/...) and that command
- * signing has been set up (e.g. forwarder.setCommandSigningInfo()).
- *
- * @param forwarder only a localhost Face
- * @param prefix
- * @param strategy
- * @throws Exception
- */
- public static void setStrategy(Face forwarder, Name prefix, Name strategy) throws Exception {
- // build command name
- Name command = new Name("/localhost/nfd/strategy-choice/set");
- ControlParameters parameters = new ControlParameters();
- parameters.setName(prefix);
- parameters.setStrategy(strategy);
- command.append(parameters.wireEncode());
-
- // send the interest
- sendCommand(forwarder, new Interest(command));
- }
-
- /**
- * 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
- */
- 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>
- Interest interest = new Interest(datasetName);
- interest.setMustBeFresh(true);
- interest.setChildSelector(Interest.CHILD_SELECTOR_RIGHT);
- interest.setInterestLifetimeMilliseconds(DEFAULT_TIMEOUT);
-
- // send packet
- Data data = SegmentedClient.getDefault().getSync(forwarder, interest);
-
- // check for failed request
- if (data.getContent().buf().get(0) == ControlResponse.TLV_CONTROL_RESPONSE) {
- throw ManagementException.fromResponse(data.getContent());
- }
-
- return data;
- }
-
- /**
- * Send an interest as a command to the forwarder; this method will convert
- * the interest to a command interest and block until a response is received
- * from the forwarder. Ensure the forwarding face is on the local machine
- * (management requests are to /localhost/...) and that command signing has
- * been set up (e.g. forwarder.setCommandSigningInfo()).
- *
- * @param forwarder only a localhost Face, command signing info must be set
- * @param interest As described at
- * <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
- * @throws java.io.IOException
- * @throws net.named_data.jndn.encoding.EncodingException
- * @throws com.intel.jndn.management.ManagementException
- */
- public static ControlResponse sendCommand(Face forwarder, Interest interest) throws IOException, EncodingException, ManagementException {
- // forwarder must have command signing info set
- try {
- forwarder.makeCommandInterest(interest);
- } catch (SecurityException e) {
- throw new IllegalArgumentException("Failed to make command interest; ensure command signing info is set on the face.", e);
- }
-
- // send command packet
- Data data = SimpleClient.getDefault().getSync(forwarder, interest);
-
- // decode response
- ControlResponse response = new ControlResponse();
- response.wireDecode(data.getContent().buf());
-
- // check response for success
- if (response.getStatusCode() != OK_STATUS) {
- throw ManagementException.fromResponse(response);
- }
-
- return response;
- }
-}
diff --git a/app/src/main/java/com/intel/jndn/management/types/ControlResponse.java b/app/src/main/java/com/intel/jndn/management/types/ControlResponse.java
deleted file mode 100644
index 5514244..0000000
--- a/app/src/main/java/com/intel/jndn/management/types/ControlResponse.java
+++ /dev/null
@@ -1,170 +0,0 @@
-/*
- * jndn-management
- * Copyright (c) 2015, Intel Corporation.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU Lesser General Public License,
- * version 3, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
- * more details.
- */
-package com.intel.jndn.management.types;
-
-import com.intel.jndn.management.EncodingHelper;
-import java.nio.ByteBuffer;
-import java.util.ArrayList;
-import java.util.List;
-import net.named_data.jndn.ControlParameters;
-import net.named_data.jndn.encoding.EncodingException;
-import net.named_data.jndn.encoding.tlv.Tlv;
-import net.named_data.jndn.encoding.tlv.TlvDecoder;
-import net.named_data.jndn.encoding.tlv.TlvEncoder;
-import net.named_data.jndn.util.Blob;
-
-/**
- * Represent a ControlResponse, a Data packet sent in response to a
- * ControlCommand to the NFD, see
- * <a href="http://redmine.named-data.net/projects/nfd/wiki/ControlCommand">http://redmine.named-data.net/projects/nfd/wiki/ControlCommand</a>
- *
- * @author Andrew Brown <andrew.brown@intel.com>
- */
-public class ControlResponse {
-
- /**
- * Use TLV codes from jndn.encoding.tlv.Tlv.java See
- * <a href="http://redmine.named-data.net/projects/nfd/wiki/ControlCommand">http://redmine.named-data.net/projects/nfd/wiki/ControlCommand</a>
- */
- public final static int TLV_CONTROL_RESPONSE = 101;
- public final static int TLV_CONTROL_RESPONSE_STATUS_CODE = 102;
- public final static int TLV_CONTROL_RESPONSE_STATUS_TEXT = 103;
-
- /**
- * Encode using a new TLV encoder.
- *
- * @return The encoded buffer.
- */
- public final Blob wireEncode() {
- TlvEncoder encoder = new TlvEncoder();
- wireEncode(encoder);
- return new Blob(encoder.getOutput(), false);
- }
-
- /**
- * Encode as part of an existing encode context.
- *
- * @param encoder
- */
- public final void wireEncode(TlvEncoder encoder) {
- int saveLength = encoder.getLength();
- for (ControlParameters parameters : body) {
- EncodingHelper.encodeControlParameters(parameters, encoder);
- }
- encoder.writeBlobTlv(TLV_CONTROL_RESPONSE_STATUS_TEXT, new Blob(statusText).buf());
- encoder.writeNonNegativeIntegerTlv(TLV_CONTROL_RESPONSE_STATUS_CODE, statusCode);
- encoder.writeTypeAndLength(TLV_CONTROL_RESPONSE, encoder.getLength() - saveLength);
- }
-
- /**
- * Decode the input from its TLV format.
- *
- * @param input The input buffer to decode. This reads from position() to
- * limit(), but does not change the position.
- * @throws net.named_data.jndn.encoding.EncodingException
- */
- public final void wireDecode(ByteBuffer input) throws EncodingException {
- TlvDecoder decoder = new TlvDecoder(input);
- wireDecode(decoder, input);
- }
-
- /**
- * Decode as part of an existing decode context.
- *
- * @param decoder
- * @param input the WireFormat version that decodes ControlParameters does not
- * allow passing a TlvDecoder, so we must pass the buffer itself
- * @throws EncodingException
- */
- public void wireDecode(TlvDecoder decoder, ByteBuffer input) throws EncodingException {
- int endOffset = decoder.readNestedTlvsStart(TLV_CONTROL_RESPONSE);
-
- // parse known TLVs
- this.statusCode = (int) decoder.readNonNegativeIntegerTlv(TLV_CONTROL_RESPONSE_STATUS_CODE);
- Blob statusText_ = new Blob(decoder.readBlobTlv(TLV_CONTROL_RESPONSE_STATUS_TEXT), true); // copy because buffer is immutable
- this.statusText = statusText_.toString();
-
- // use the already-written decoder for ControlParameters (but we have to copy the buffer)
- while (decoder.peekType(Tlv.ControlParameters_ControlParameters, endOffset)) {
- ByteBuffer copyInput = input.duplicate();
- copyInput.position(decoder.getOffset());
- int internalEndOffset = decoder.readNestedTlvsStart(Tlv.ControlParameters_ControlParameters);
- ControlParameters copyParameters = new ControlParameters();
- copyParameters.wireDecode(copyInput);
- this.body.add(copyParameters);
- decoder.seek(internalEndOffset);
- decoder.finishNestedTlvs(internalEndOffset);
- }
-
- decoder.finishNestedTlvs(endOffset);
- }
-
- /**
- * Get status code
- *
- * @return
- */
- public int getStatusCode() {
- return statusCode;
- }
-
- /**
- * Set status code
- *
- * @param statusCode
- */
- public void setStatusCode(int statusCode) {
- this.statusCode = statusCode;
- }
-
- /**
- * Get status text
- *
- * @return
- */
- public String getStatusText() {
- return statusText;
- }
-
- /**
- * Set status text
- *
- * @param statusText
- */
- public void setStatusText(String statusText) {
- this.statusText = statusText;
- }
-
- /**
- * Get body
- *
- * @return
- */
- public List<ControlParameters> getBody() {
- return body;
- }
-
- /**
- * Set body
- *
- * @param body
- */
- public void setBody(List<ControlParameters> body) {
- this.body = body;
- }
-
- private int statusCode = -1;
- private String statusText = "";
- private List<ControlParameters> body = new ArrayList<>();
-}
diff --git a/app/src/main/java/com/intel/jndn/management/types/Decodable.java b/app/src/main/java/com/intel/jndn/management/types/Decodable.java
deleted file mode 100644
index aec50dd..0000000
--- a/app/src/main/java/com/intel/jndn/management/types/Decodable.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * jndn-management
- * Copyright (c) 2015, Intel Corporation.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU Lesser General Public License,
- * version 3, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
- * more details.
- */
-package com.intel.jndn.management.types;
-
-import net.named_data.jndn.encoding.EncodingException;
-import net.named_data.jndn.encoding.tlv.TlvDecoder;
-
-/**
- * Interface used by StatusDataset to decode generic message types; if they are
- * Decodable, then StatusDataset will instantiate and decode them.
- *
- * @author Andrew Brown <andrew.brown@intel.com>
- */
-public interface Decodable {
-
- public void wireDecode(TlvDecoder decoder) throws EncodingException;
-}
diff --git a/app/src/main/java/com/intel/jndn/management/types/FacePersistency.java b/app/src/main/java/com/intel/jndn/management/types/FacePersistency.java
deleted file mode 100644
index d294fcb..0000000
--- a/app/src/main/java/com/intel/jndn/management/types/FacePersistency.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * jndn-management
- * Copyright (c) 2015, Intel Corporation.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU Lesser General Public License,
- * version 3, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
- * more details.
- */
-package com.intel.jndn.management.types;
-
-/**
- * Indicate whether the face is persistent; used by FaceStatus. See
- * <a href="http://redmine.named-data.net/projects/nfd/widi/FaceMgmt">http://redmine.named-data.net/projects/nfd/widi/FaceMgmt</a>
- *
- * @author Andrew Brown <andrew.brown@intel.com>
- */
-public enum FacePersistency {
-
- PERSISTENT(0),
- ON_DEMAND(1),
- PERMANENT(2);
-
- FacePersistency(int value) {
- value_ = value;
- }
-
- public final int getNumericValue() {
- return value_;
- }
- private final int value_;
-}
diff --git a/app/src/main/java/com/intel/jndn/management/types/FaceScope.java b/app/src/main/java/com/intel/jndn/management/types/FaceScope.java
deleted file mode 100644
index bcba855..0000000
--- a/app/src/main/java/com/intel/jndn/management/types/FaceScope.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * jndn-management
- * Copyright (c) 2015, Intel Corporation.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU Lesser General Public License,
- * version 3, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
- * more details.
- */
-package com.intel.jndn.management.types;
-
-/**
- * Indicate whether the face is local for scope control purposes; used by
- * FaceStatus See
- * <a href="http://redmine.named-data.net/projects/nfd/widi/FaceMgmt">http://redmine.named-data.net/projects/nfd/widi/FaceMgmt</a>
- *
- * @author andrew
- */
-public enum FaceScope {
-
- LOCAL(0),
- NON_LOCAL(1);
-
- FaceScope(int value) {
- value_ = value;
- }
-
- public final int getNumericValue() {
- return value_;
- }
- private final int value_;
-}
diff --git a/app/src/main/java/com/intel/jndn/management/types/FaceStatus.java b/app/src/main/java/com/intel/jndn/management/types/FaceStatus.java
deleted file mode 100644
index 6a101a0..0000000
--- a/app/src/main/java/com/intel/jndn/management/types/FaceStatus.java
+++ /dev/null
@@ -1,401 +0,0 @@
-/*
- * jndn-management
- * Copyright (c) 2015, Intel Corporation.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU Lesser General Public License,
- * version 3, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
- * more details.
- */
-package com.intel.jndn.management.types;
-
-import java.nio.ByteBuffer;
-import net.named_data.jndn.encoding.EncodingException;
-import net.named_data.jndn.encoding.tlv.TlvDecoder;
-import net.named_data.jndn.encoding.tlv.TlvEncoder;
-import net.named_data.jndn.util.Blob;
-
-/**
- * Represent a FaceStatus object from /localhost/nfd/faces/list; see
- * <a href="http://redmine.named-data.net/projects/nfd/wiki/FaceMgmt">http://redmine.named-data.net/projects/nfd/wiki/FaceMgmt</a>
- * for details
- *
- * @author Andrew Brown <andrew.brown@intel.com>
- */
-public class FaceStatus implements Decodable {
-
- /**
- * Spec from
- * <a href="http://redmine.named-data.net/projects/nfd/wiki/ControlCommand">http://redmine.named-data.net/projects/nfd/wiki/ControlCommand</a>
- */
- public static final int TLV_FACE_ID = 105;
- public static final int TLV_URI = 114;
- public static final int TLV_EXPIRATION_PERIOD = 109;
-
- /**
- * Spec from
- * <a href="http://redmine.named-data.net/projects/nfd/widi/FaceMgmt">http://redmine.named-data.net/projects/nfd/widi/FaceMgmt</a>
- */
- public static final int TLV_FACE_STATUS = 128;
- public static final int TLV_LOCAL_URI = 129;
- public static final int TLV_CHANNEL_STATUS = 130;
- public static final int TLV_FACE_SCOPE = 132;
- public static final int TLV_FACE_PERSISTENCY = 133;
- public static final int TLV_LINK_TYPE = 134;
- public static final int TLV_N_IN_INTERESTS = 144;
- public static final int TLV_N_IN_DATAS = 145;
- public static final int TLV_N_OUT_INTERESTS = 146;
- public static final int TLV_N_OUT_DATAS = 147;
- public static final int TLV_N_IN_BYTES = 148;
- public static final int TLV_N_OUT_BYTES = 149;
- public static final int TLV_NUM_IN_NACKS = 151;
- public static final int TLV_NUM_OUT_NACKS = 152;
-
- /**
- * Encode using a new TLV encoder.
- *
- * @return The encoded buffer.
- */
- public final Blob wireEncode() {
- TlvEncoder encoder = new TlvEncoder();
- wireEncode(encoder);
- return new Blob(encoder.getOutput(), false);
- }
-
- /**
- * Encode as part of an existing encode context.
- *
- * @param encoder
- */
- public final void wireEncode(TlvEncoder encoder) {
- int saveLength = encoder.getLength();
- encoder.writeNonNegativeIntegerTlv(TLV_N_OUT_BYTES, outBytes);
- encoder.writeNonNegativeIntegerTlv(TLV_N_IN_BYTES, inBytes);
- encoder.writeNonNegativeIntegerTlv(TLV_NUM_OUT_NACKS, numOutNacks);
- encoder.writeNonNegativeIntegerTlv(TLV_N_OUT_DATAS, outDatas);
- encoder.writeNonNegativeIntegerTlv(TLV_N_OUT_INTERESTS, outInterests);
- encoder.writeNonNegativeIntegerTlv(TLV_NUM_IN_NACKS, numInNacks);
- encoder.writeNonNegativeIntegerTlv(TLV_N_IN_DATAS, inDatas);
- encoder.writeNonNegativeIntegerTlv(TLV_N_IN_INTERESTS, inInterests);
- encoder.writeNonNegativeIntegerTlv(TLV_LINK_TYPE, linkType.getNumericValue());
- encoder.writeNonNegativeIntegerTlv(TLV_FACE_PERSISTENCY, facePersistency.getNumericValue());
- encoder.writeNonNegativeIntegerTlv(TLV_FACE_SCOPE, faceScope.getNumericValue());
- encoder.writeOptionalNonNegativeIntegerTlv(TLV_EXPIRATION_PERIOD, expirationPeriod);
- encoder.writeBlobTlv(TLV_LOCAL_URI, new Blob(localUri).buf());
- encoder.writeBlobTlv(TLV_URI, new Blob(uri).buf());
- encoder.writeNonNegativeIntegerTlv(TLV_FACE_ID, faceId);
- encoder.writeTypeAndLength(TLV_FACE_STATUS, encoder.getLength() - saveLength);
- }
-
- /**
- * Decode the input from its TLV format.
- *
- * @param input The input buffer to decode. This reads from position() to
- * limit(), but does not change the position.
- * @throws net.named_data.jndn.encoding.EncodingException
- */
- public final void wireDecode(ByteBuffer input) throws EncodingException {
- TlvDecoder decoder = new TlvDecoder(input);
- wireDecode(decoder);
- }
-
- /**
- * Decode as part of an existing decode context.
- *
- * @param decoder
- * @throws EncodingException
- */
- @Override
- public void wireDecode(TlvDecoder decoder) throws EncodingException {
- int endOffset = decoder.readNestedTlvsStart(TLV_FACE_STATUS);
- // parse
- this.faceId = (int) decoder.readNonNegativeIntegerTlv(TLV_FACE_ID);
- Blob uri_ = new Blob(decoder.readBlobTlv(TLV_URI), true); // copy because buffer is immutable
- this.uri = uri_.toString();
- Blob localUri_ = new Blob(decoder.readBlobTlv(TLV_LOCAL_URI), true); // copy because buffer is immutable
- this.localUri = localUri_.toString();
- this.expirationPeriod = (int) decoder.readOptionalNonNegativeIntegerTlv(TLV_EXPIRATION_PERIOD, endOffset);
- this.faceScope = FaceScope.values()[(int) decoder.readNonNegativeIntegerTlv(TLV_FACE_SCOPE)];
- this.facePersistency = FacePersistency.values()[(int) decoder.readNonNegativeIntegerTlv(TLV_FACE_PERSISTENCY)];
- this.linkType = LinkType.values()[(int) decoder.readNonNegativeIntegerTlv(TLV_LINK_TYPE)];
- this.inInterests = (int) decoder.readNonNegativeIntegerTlv(TLV_N_IN_INTERESTS);
- this.inDatas = (int) decoder.readNonNegativeIntegerTlv(TLV_N_IN_DATAS);
- this.numInNacks = decoder.readNonNegativeIntegerTlv(TLV_NUM_IN_NACKS);
- this.outInterests = (int) decoder.readNonNegativeIntegerTlv(TLV_N_OUT_INTERESTS);
- this.outDatas = (int) decoder.readNonNegativeIntegerTlv(TLV_N_OUT_DATAS);
- this.numOutNacks = decoder.readNonNegativeIntegerTlv(TLV_NUM_OUT_NACKS);
- this.inBytes = (int) decoder.readNonNegativeIntegerTlv(TLV_N_IN_BYTES);
- this.outBytes = (int) decoder.readNonNegativeIntegerTlv(TLV_N_OUT_BYTES);
- decoder.finishNestedTlvs(endOffset);
- }
-
- /**
- * Get face ID
- *
- * @return
- */
- public int getFaceId() {
- return faceId;
- }
-
- /**
- * Set face ID
- *
- * @param faceId
- */
- public void setFaceId(int faceId) {
- this.faceId = faceId;
- }
-
- /**
- * Get face ID
- *
- * @return
- */
- public String getUri() {
- return uri;
- }
-
- /**
- * Set URI
- *
- * @param uri
- */
- public void setUri(String uri) {
- this.uri = uri;
- }
-
- /**
- * Get face ID
- *
- * @return
- */
- public String getLocalUri() {
- return localUri;
- }
-
- /**
- * Set local URI
- *
- * @param localUri
- */
- public void setLocalUri(String localUri) {
- this.localUri = localUri;
- }
-
- /**
- * Get expiration period
- *
- * @return
- */
- public int getExpirationPeriod() {
- return expirationPeriod;
- }
-
- /**
- * Set expiration period
- *
- * @param expirationPeriod
- */
- public void setExpirationPeriod(int expirationPeriod) {
- this.expirationPeriod = expirationPeriod;
- }
-
- /**
- * Get face scope value
- *
- * @return
- */
- public FaceScope getFaceScope() {
- return faceScope;
- }
-
- /**
- * Set face scope value
- *
- * @param faceScope
- */
- public void setFaceScope(FaceScope faceScope) {
- this.faceScope = faceScope;
- }
-
- /**
- * Get face persistency value
- *
- * @return
- */
- public FacePersistency getFacePersistency() {
- return facePersistency;
- }
-
- /**
- * Set face persistency value
- *
- * @param facePersistency
- */
- public void setFacePersistency(FacePersistency facePersistency) {
- this.facePersistency = facePersistency;
- }
-
- /**
- * Get link type
- *
- * @return
- */
- public LinkType getLinkType() {
- return linkType;
- }
-
- /**
- * Set link type
- *
- * @param linkType
- */
- public void setLinkType(LinkType linkType) {
- this.linkType = linkType;
- }
-
- /**
- * Get number of received Interest packets
- *
- * @return
- */
- public int getInInterests() {
- return inInterests;
- }
-
- /**
- * Set number of received Interest packets
- *
- * @param inInterests
- */
- public void setInInterests(int inInterests) {
- this.inInterests = inInterests;
- }
-
- /**
- * Get number of sent Interest packets
- *
- * @return
- */
- public int getOutInterests() {
- return outInterests;
- }
-
- /**
- * Set number of sent Interest packets
- *
- * @param outInterests
- */
- public void setOutInterests(int outInterests) {
- this.outInterests = outInterests;
- }
-
- /**
- * Get number of received Data packets
- *
- * @return
- */
- public int getInDatas() {
- return inDatas;
- }
-
- /**
- * Set number of received Data packets
- *
- * @param inDatas
- */
- public void setInDatas(int inDatas) {
- this.inDatas = inDatas;
- }
-
- /**
- * Get number of sent Data packets
- *
- * @return
- */
- public int getOutDatas() {
- return outDatas;
- }
-
- /**
- * Set number of sent Data packets
- *
- * @param outDatas
- */
- public void setOutDatas(int outDatas) {
- this.outDatas = outDatas;
- }
-
- /**
- * Get number of input bytes
- *
- * @return
- */
- public int getInBytes() {
- return inBytes;
- }
-
- /**
- * Set number of input bytes
- *
- * @param inBytes
- */
- public void setInBytes(int inBytes) {
- this.inBytes = inBytes;
- }
-
- /**
- * Get number of output bytes
- *
- * @return
- */
- public int getOutBytes() {
- return outBytes;
- }
-
- /**
- * Set number of output bytes
- *
- * @param outBytes
- */
- public void setOutBytes(int outBytes) {
- this.outBytes = outBytes;
- }
-
- public long getNumInNacks() {
- return numInNacks;
- }
-
- public void setNumInNacks(long numInNacks) {
- this.numInNacks = numInNacks;
- }
-
- public long getNumOutNacks() {
- return numOutNacks;
- }
-
- public void setNumOutNacks(long numOutNacks) {
- this.numOutNacks = numOutNacks;
- }
-
- private int faceId = -1;
- private String uri = ""; // can't use URI because some are invalid syntax
- private String localUri = ""; // can't use URI because some are invalid syntax
- private int expirationPeriod = 0;
- private FaceScope faceScope = FaceScope.LOCAL;
- private FacePersistency facePersistency = FacePersistency.ON_DEMAND;
- private LinkType linkType = LinkType.POINT_TO_POINT;
- private int inInterests = 0;
- private int outInterests = 0;
- private int inDatas = 0;
- private int outDatas = 0;
- private int inBytes = 0;
- private int outBytes = 0;
- private long numInNacks = 0;
- private long numOutNacks = 0;
-}
diff --git a/app/src/main/java/com/intel/jndn/management/types/FibEntry.java b/app/src/main/java/com/intel/jndn/management/types/FibEntry.java
deleted file mode 100644
index 8c74636..0000000
--- a/app/src/main/java/com/intel/jndn/management/types/FibEntry.java
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * jndn-management
- * Copyright (c) 2015, Intel Corporation.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU Lesser General Public License,
- * version 3, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
- * more details.
- */
-package com.intel.jndn.management.types;
-
-import com.intel.jndn.management.EncodingHelper;
-import java.nio.ByteBuffer;
-import java.util.ArrayList;
-import java.util.List;
-import net.named_data.jndn.Name;
-import net.named_data.jndn.encoding.EncodingException;
-import net.named_data.jndn.encoding.tlv.TlvDecoder;
-import net.named_data.jndn.encoding.tlv.TlvEncoder;
-import net.named_data.jndn.util.Blob;
-
-/**
- * Represent a FibEntry returned from /localhost/nfd/fib/list; see
- * <a href="http://redmine.named-data.net/projects/nfd/wiki/FibMgmt#FIB-Dataset">http://redmine.named-data.net/projects/nfd/wiki/FibMgmt#FIB-Dataset</a>
- *
- * @author Andrew Brown <andrew.brown@intel.com>
- */
-public class FibEntry implements Decodable {
-
- public final static int TLV_FIB_ENTRY = 128;
-
- /**
- * Encode using a new TLV encoder.
- *
- * @return The encoded buffer.
- */
- public final Blob wireEncode() {
- TlvEncoder encoder = new TlvEncoder();
- wireEncode(encoder);
- return new Blob(encoder.getOutput(), false);
- }
-
- /**
- * Encode as part of an existing encode context.
- *
- * @param encoder
- */
- public final void wireEncode(TlvEncoder encoder) {
- int saveLength = encoder.getLength();
- for (NextHopRecord record : records) {
- record.wireEncode(encoder);
- }
- EncodingHelper.encodeName(name, encoder);
- encoder.writeTypeAndLength(TLV_FIB_ENTRY, encoder.getLength() - saveLength);
- }
-
- /**
- * Decode the input from its TLV format.
- *
- * @param input The input buffer to decode. This reads from position() to
- * limit(), but does not change the position.
- * @throws EncodingException For invalid encoding.
- */
- public final void wireDecode(ByteBuffer input) throws EncodingException {
- TlvDecoder decoder = new TlvDecoder(input);
- wireDecode(decoder);
- }
-
- /**
- * Decode as part of an existing decode context.
- *
- * @param decoder
- * @throws EncodingException
- */
- @Override
- public final void wireDecode(TlvDecoder decoder) throws EncodingException {
- int endOffset = decoder.readNestedTlvsStart(TLV_FIB_ENTRY);
- name = EncodingHelper.decodeName(decoder);
- while (decoder.getOffset() < endOffset) {
- NextHopRecord record = new NextHopRecord();
- record.wireDecode(decoder);
- records.add(record);
- }
- decoder.finishNestedTlvs(endOffset);
- }
-
- /**
- * Get name
- *
- * @return
- */
- public Name getName() {
- return name;
- }
-
- /**
- * Set name
- *
- * @param name
- */
- public void setName(Name name) {
- this.name = name;
- }
-
- /**
- * Get records
- *
- * @return
- */
- public List<NextHopRecord> getRecords() {
- return records;
- }
-
- /**
- * Set records
- *
- * @param records
- */
- public void setRecords(List<NextHopRecord> records) {
- this.records = records;
- }
-
- private Name name = new Name();
- private List<NextHopRecord> records = new ArrayList<>();
-}
diff --git a/app/src/main/java/com/intel/jndn/management/types/ForwarderStatus.java b/app/src/main/java/com/intel/jndn/management/types/ForwarderStatus.java
deleted file mode 100644
index 6240bbd..0000000
--- a/app/src/main/java/com/intel/jndn/management/types/ForwarderStatus.java
+++ /dev/null
@@ -1,240 +0,0 @@
-/*
- * jndn-management
- * Copyright (c) 2015, Intel Corporation.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU Lesser General Public License,
- * version 3, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
- * more details.
- */
-package com.intel.jndn.management.types;
-
-import java.nio.ByteBuffer;
-import net.named_data.jndn.encoding.EncodingException;
-import net.named_data.jndn.encoding.tlv.TlvDecoder;
-import net.named_data.jndn.encoding.tlv.TlvEncoder;
-import net.named_data.jndn.util.Blob;
-
-/**
- * Represent a ForwarderStatus object from
- * http://redmine.named-data.net/projects/nfd/wiki/ForwarderStatus.
- *
- * @author Andrew Brown <andrew.brown@intel.com>
- */
-public class ForwarderStatus implements Decodable {
-
- public static final int TLV_NFD_VERSION = 0x80;
- public static final int TLV_START_TIMESTAMP = 0x81;
- public static final int TLV_CURRENT_TIMESTAMP = 0x82;
- public static final int TLV_NUM_NAME_TREE_ENTRIES = 0x83;
- public static final int TLV_NUM_FIB_ENTRIES = 0x84;
- public static final int TLV_NUM_PIT_ENTRIES = 0x85;
- public static final int TLV_NUM_MEASUREMENT_ENTRIES = 0x86;
- public static final int TLV_NUM_CS_ENTRIES = 0x87;
- public static final int TLV_NUM_IN_INTERESTS = 0x90;
- public static final int TLV_NUM_IN_DATAS = 0x91;
- public static final int TLV_NUM_OUT_INTERESTS = 0x92;
- public static final int TLV_NUM_OUT_DATAS = 0x93;
- public static final int TLV_NUM_IN_NACKS = 0x97;
- public static final int TLV_NUM_OUT_NACKS = 0x98;
-
- /**
- * Encode using a new TLV encoder.
- *
- * @return The encoded buffer.
- */
- public final Blob wireEncode() {
- TlvEncoder encoder = new TlvEncoder();
- wireEncode(encoder);
- return new Blob(encoder.getOutput(), false);
- }
-
- /**
- * Encode as part of an existing encode context.
- *
- * @param encoder
- */
- public final void wireEncode(TlvEncoder encoder) {
- encoder.writeNonNegativeIntegerTlv(TLV_NUM_OUT_NACKS, numOutNacks);
- encoder.writeNonNegativeIntegerTlv(TLV_NUM_OUT_DATAS, numOutDatas);
- encoder.writeNonNegativeIntegerTlv(TLV_NUM_OUT_INTERESTS, numOutInterests);
- encoder.writeNonNegativeIntegerTlv(TLV_NUM_IN_NACKS, numInNacks);
- encoder.writeNonNegativeIntegerTlv(TLV_NUM_IN_DATAS, numInDatas);
- encoder.writeNonNegativeIntegerTlv(TLV_NUM_IN_INTERESTS, numInInterests);
- encoder.writeNonNegativeIntegerTlv(TLV_NUM_CS_ENTRIES, numCsEntries);
- encoder.writeNonNegativeIntegerTlv(TLV_NUM_MEASUREMENT_ENTRIES, numMeasurementEntries);
- encoder.writeNonNegativeIntegerTlv(TLV_NUM_PIT_ENTRIES, numPitEntries);
- encoder.writeNonNegativeIntegerTlv(TLV_NUM_FIB_ENTRIES, numFibEntries);
- encoder.writeNonNegativeIntegerTlv(TLV_NUM_NAME_TREE_ENTRIES, numNameTreeEntries);
- encoder.writeNonNegativeIntegerTlv(TLV_CURRENT_TIMESTAMP, currentTimestamp);
- encoder.writeNonNegativeIntegerTlv(TLV_START_TIMESTAMP, startTimestamp);
- encoder.writeBlobTlv(TLV_NFD_VERSION, new Blob(nfdVersion).buf());
- }
-
- /**
- * Decode the input from its TLV format.
- *
- * @param input The input buffer to decode. This reads from position() to
- * limit(), but does not change the position.
- * @throws EncodingException For invalid encoding.
- */
- public final void wireDecode(ByteBuffer input) throws EncodingException {
- TlvDecoder decoder = new TlvDecoder(input);
- wireDecode(decoder);
- }
-
- /**
- * Decode as part of an existing decode context.
- *
- * @param decoder
- * @throws EncodingException
- */
- @Override
- public void wireDecode(TlvDecoder decoder) throws EncodingException {
- this.nfdVersion = new Blob(decoder.readBlobTlv(TLV_NFD_VERSION), true).toString();
- this.startTimestamp = decoder.readNonNegativeIntegerTlv(TLV_START_TIMESTAMP);
- this.currentTimestamp = decoder.readNonNegativeIntegerTlv(TLV_CURRENT_TIMESTAMP);
- this.numNameTreeEntries = decoder.readNonNegativeIntegerTlv(TLV_NUM_NAME_TREE_ENTRIES);
- this.numFibEntries = decoder.readNonNegativeIntegerTlv(TLV_NUM_FIB_ENTRIES);
- this.numPitEntries = decoder.readNonNegativeIntegerTlv(TLV_NUM_PIT_ENTRIES);
- this.numMeasurementEntries = decoder.readNonNegativeIntegerTlv(TLV_NUM_MEASUREMENT_ENTRIES);
- this.numCsEntries = decoder.readNonNegativeIntegerTlv(TLV_NUM_CS_ENTRIES);
- this.numInInterests = decoder.readNonNegativeIntegerTlv(TLV_NUM_IN_INTERESTS);
- this.numInDatas = decoder.readNonNegativeIntegerTlv(TLV_NUM_IN_DATAS);
- this.numInNacks = decoder.readNonNegativeIntegerTlv(TLV_NUM_IN_NACKS);
- this.numOutInterests = decoder.readNonNegativeIntegerTlv(TLV_NUM_OUT_INTERESTS);
- this.numOutDatas = decoder.readNonNegativeIntegerTlv(TLV_NUM_OUT_DATAS);
- this.numOutNacks = decoder.readNonNegativeIntegerTlv(TLV_NUM_OUT_NACKS);
- }
-
- public String getNfdVersion() {
- return nfdVersion;
- }
-
- public void setNfdVersion(String nfdVersion) {
- this.nfdVersion = nfdVersion;
- }
-
- public long getStartTimestamp() {
- return startTimestamp;
- }
-
- public void setStartTimestamp(long startTimestamp) {
- this.startTimestamp = startTimestamp;
- }
-
- public long getCurrentTimestamp() {
- return currentTimestamp;
- }
-
- public void setCurrentTimestamp(long currentTimestamp) {
- this.currentTimestamp = currentTimestamp;
- }
-
- public long getNumNameTreeEntries() {
- return numNameTreeEntries;
- }
-
- public void setNumNameTreeEntries(long numNameTreeEntries) {
- this.numNameTreeEntries = numNameTreeEntries;
- }
-
- public long getNumFibEntries() {
- return numFibEntries;
- }
-
- public void setNumFibEntries(long numFibEntries) {
- this.numFibEntries = numFibEntries;
- }
-
- public long getNumPitEntries() {
- return numPitEntries;
- }
-
- public void setNumPitEntries(long numPitEntries) {
- this.numPitEntries = numPitEntries;
- }
-
- public long getNumMeasurementEntries() {
- return numMeasurementEntries;
- }
-
- public void setNumMeasurementEntries(long numMeasurementEntries) {
- this.numMeasurementEntries = numMeasurementEntries;
- }
-
- public long getNumCsEntries() {
- return numCsEntries;
- }
-
- public void setNumCsEntries(long numCsEntries) {
- this.numCsEntries = numCsEntries;
- }
-
- public long getNumInInterests() {
- return numInInterests;
- }
-
- public void setNumInInterests(long numInInterests) {
- this.numInInterests = numInInterests;
- }
-
- public long getNumInDatas() {
- return numInDatas;
- }
-
- public void setNumInDatas(long numInDatas) {
- this.numInDatas = numInDatas;
- }
-
- public long getNumInNacks() {
- return numInNacks;
- }
-
- public void setNumInNacks(long numInNacks) {
- this.numInNacks = numInNacks;
- }
-
- public long getNumOutInterests() {
- return numOutInterests;
- }
-
- public void setNumOutInterests(long numOutInterests) {
- this.numOutInterests = numOutInterests;
- }
-
- public long getNumOutDatas() {
- return numOutDatas;
- }
-
- public void setNumOutDatas(long numOutDatas) {
- this.numOutDatas = numOutDatas;
- }
-
- public long getNumOutNacks() {
- return numOutNacks;
- }
-
- public void setNumOutNacks(long numOutNacks) {
- this.numOutNacks = numOutNacks;
- }
-
- private String nfdVersion = "";
- private long startTimestamp;
- private long currentTimestamp;
- private long numNameTreeEntries;
- private long numFibEntries;
- private long numPitEntries;
- private long numMeasurementEntries;
- private long numCsEntries;
- private long numInInterests;
- private long numInDatas;
- private long numInNacks;
- private long numOutInterests;
- private long numOutDatas;
- private long numOutNacks;
-}
diff --git a/app/src/main/java/com/intel/jndn/management/types/LinkType.java b/app/src/main/java/com/intel/jndn/management/types/LinkType.java
deleted file mode 100644
index a0f517c..0000000
--- a/app/src/main/java/com/intel/jndn/management/types/LinkType.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * jndn-management
- * Copyright (c) 2015, Intel Corporation.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU Lesser General Public License,
- * version 3, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
- * more details.
- */
-package com.intel.jndn.management.types;
-
-/**
- * Indicate the type of communication link; used by FaceStatus See
- * <a href="http://redmine.named-data.net/projects/nfd/widi/FaceMgmt">http://redmine.named-data.net/projects/nfd/widi/FaceMgmt</a>
- *
- * @author Andrew Brown <andrew.brown@intel.com>
- */
-public enum LinkType {
-
- POINT_TO_POINT(0),
- MULTI_ACCESS(1);
-
- LinkType(int value) {
- value_ = value;
- }
-
- public final int getNumericValue() {
- return value_;
- }
- private final int value_;
-}
diff --git a/app/src/main/java/com/intel/jndn/management/types/LocalControlHeader.java b/app/src/main/java/com/intel/jndn/management/types/LocalControlHeader.java
deleted file mode 100644
index 5ca393f..0000000
--- a/app/src/main/java/com/intel/jndn/management/types/LocalControlHeader.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * jndn-management
- * Copyright (c) 2015, Intel Corporation.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU Lesser General Public License,
- * version 3, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
- * more details.
- */
-package com.intel.jndn.management.types;
-
-/**
- * Define constants for local control header options. See
- * <a href="http://redmine.named-data.net/projects/nfd/wiki/FaceMgmt#Enable-a-LocalControlHeader-feature">http://redmine.named-data.net/projects/nfd/wiki/FaceMgmt#Enable-a-LocalControlHeader-feature</a>
- *
- * @author Andrew Brown <andrew.brown@intel.com>
- */
-public enum LocalControlHeader {
-
- INCOMING_FACE_ID(1),
- NEXT_HOP_FACE_ID(2),
- CACHING_POLICY(3);
-
- LocalControlHeader(int value) {
- value_ = value;
- }
-
- public final int getNumericValue() {
- return value_;
- }
- private final int value_;
-}
diff --git a/app/src/main/java/com/intel/jndn/management/types/NextHopRecord.java b/app/src/main/java/com/intel/jndn/management/types/NextHopRecord.java
deleted file mode 100644
index 3b40104..0000000
--- a/app/src/main/java/com/intel/jndn/management/types/NextHopRecord.java
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * jndn-management
- * Copyright (c) 2015, Intel Corporation.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU Lesser General Public License,
- * version 3, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
- * more details.
- */
-package com.intel.jndn.management.types;
-
-import java.nio.ByteBuffer;
-import net.named_data.jndn.encoding.EncodingException;
-import net.named_data.jndn.encoding.tlv.Tlv;
-import net.named_data.jndn.encoding.tlv.TlvDecoder;
-import net.named_data.jndn.encoding.tlv.TlvEncoder;
-import net.named_data.jndn.util.Blob;
-
-/**
- * Represent a NextHopRecord in a FibEntry; see
- * <a href="http://redmine.named-data.net/projects/nfd/wiki/FibMgmt#FIB-Dataset">http://redmine.named-data.net/projects/nfd/wiki/FibMgmt#FIB-Dataset</a>
- *
- * @author Andrew Brown <andrew.brown@intel.com>
- */
-public class NextHopRecord {
-
- public final static int TLV_NEXT_HOP_RECORD = 129;
-
- /**
- * Encode using a new TLV encoder.
- *
- * @return The encoded buffer.
- */
- public final Blob wireEncode() {
- TlvEncoder encoder = new TlvEncoder();
- wireEncode(encoder);
- return new Blob(encoder.getOutput(), false);
- }
-
- /**
- * Encode as part of an existing encode context.
- *
- * @param encoder
- */
- public final void wireEncode(TlvEncoder encoder) {
- int saveLength = encoder.getLength();
- encoder.writeNonNegativeIntegerTlv(Tlv.ControlParameters_Cost, cost);
- encoder.writeNonNegativeIntegerTlv(Tlv.ControlParameters_FaceId, faceId);
- encoder.writeTypeAndLength(TLV_NEXT_HOP_RECORD, encoder.getLength() - saveLength);
- }
-
- /**
- * Decode the input from its TLV format.
- *
- * @param input The input buffer to decode. This reads from position() to
- * limit(), but does not change the position.
- * @throws EncodingException For invalid encoding.
- */
- public final void wireDecode(ByteBuffer input) throws EncodingException {
- TlvDecoder decoder = new TlvDecoder(input);
- wireDecode(decoder);
- }
-
- /**
- * Decode as part of an existing decode context.
- *
- * @param decoder
- * @throws EncodingException
- */
- public final void wireDecode(TlvDecoder decoder) throws EncodingException {
- int endOffset = decoder.readNestedTlvsStart(TLV_NEXT_HOP_RECORD);
- this.faceId = (int) decoder.readNonNegativeIntegerTlv(Tlv.ControlParameters_FaceId);
- this.cost = (int) decoder.readNonNegativeIntegerTlv(Tlv.ControlParameters_Cost);
- decoder.finishNestedTlvs(endOffset);
- }
-
- /**
- * Get face ID
- *
- * @return
- */
- public int getFaceId() {
- return faceId;
- }
-
- /**
- * Set face ID
- *
- * @param faceId
- */
- public void setFaceId(int faceId) {
- this.faceId = faceId;
- }
-
- /**
- * Get cost
- *
- * @return
- */
- public int getCost() {
- return cost;
- }
-
- /**
- * Set cost
- *
- * @param cost
- */
- public void setCost(int cost) {
- this.cost = cost;
- }
-
- private int faceId;
- private int cost;
-}
diff --git a/app/src/main/java/com/intel/jndn/management/types/RibEntry.java b/app/src/main/java/com/intel/jndn/management/types/RibEntry.java
deleted file mode 100644
index 705352c..0000000
--- a/app/src/main/java/com/intel/jndn/management/types/RibEntry.java
+++ /dev/null
@@ -1,134 +0,0 @@
-/*
- * jndn-management
- * Copyright (c) 2015, Intel Corporation.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU Lesser General Public License,
- * version 3, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
- * more details.
- */
-package com.intel.jndn.management.types;
-
-import com.intel.jndn.management.EncodingHelper;
-import java.nio.ByteBuffer;
-import java.util.ArrayList;
-import java.util.List;
-import net.named_data.jndn.Name;
-import net.named_data.jndn.encoding.EncodingException;
-import net.named_data.jndn.encoding.tlv.TlvDecoder;
-import net.named_data.jndn.encoding.tlv.TlvEncoder;
-import net.named_data.jndn.util.Blob;
-
-/**
- * Represent a entry in the RIB; see
- * <a href="http://redmine.named-data.net/projects/nfd/wiki/RibMgmt#RIB-Dataset">http://redmine.named-data.net/projects/nfd/wiki/RibMgmt#RIB-Dataset</a>
- * for details
- *
- * @author Andrew Brown <andrew.brown@intel.com>
- */
-public class RibEntry implements Decodable {
-
- /**
- * TLV type, see
- * <a href="http://redmine.named-data.net/projects/nfd/wiki/RibMgmt#TLV-TYPE-assignments">http://redmine.named-data.net/projects/nfd/wiki/RibMgmt#TLV-TYPE-assignments</a>
- */
- public final static int TLV_RIB_ENTRY = 128;
-
- /**
- * Encode using a new TLV encoder.
- *
- * @return The encoded buffer.
- */
- public final Blob wireEncode() {
- TlvEncoder encoder = new TlvEncoder();
- wireEncode(encoder);
- return new Blob(encoder.getOutput(), false);
- }
-
- /**
- * Encode as part of an existing encode context.
- *
- * @param encoder
- */
- public final void wireEncode(TlvEncoder encoder) {
- int saveLength = encoder.getLength();
- for (Route route : routes) {
- route.wireEncode(encoder);
- }
- EncodingHelper.encodeName(name, encoder);
- encoder.writeTypeAndLength(TLV_RIB_ENTRY, encoder.getLength() - saveLength);
- }
-
- /**
- * Decode the input from its TLV format.
- *
- * @param input The input buffer to decode. This reads from position() to
- * limit(), but does not change the position.
- * @throws EncodingException For invalid encoding.
- */
- public final void wireDecode(ByteBuffer input) throws EncodingException {
- TlvDecoder decoder = new TlvDecoder(input);
- wireDecode(decoder);
- }
-
- /**
- * Decode as part of an existing decode context.
- *
- * @param decoder
- * @throws EncodingException
- */
- @Override
- public final void wireDecode(TlvDecoder decoder) throws EncodingException {
- int endOffset = decoder.readNestedTlvsStart(TLV_RIB_ENTRY);
- name = EncodingHelper.decodeName(decoder);
- while (decoder.getOffset() < endOffset) {
- Route route = new Route();
- route.wireDecode(decoder);
- routes.add(route);
- }
- decoder.finishNestedTlvs(endOffset);
- }
-
- /**
- * Get name
- *
- * @return
- */
- public Name getName() {
- return name;
- }
-
- /**
- * Set name
- *
- * @param name
- */
- public void setName(Name name) {
- this.name = name;
- }
-
- /**
- * Get routes
- *
- * @return
- */
- public List<Route> getRoutes() {
- return routes;
- }
-
- /**
- * Set routes
- *
- * @param routes
- */
- public void setRoutes(List<Route> routes) {
- this.routes = routes;
- }
-
- private Name name = new Name();
- private List<Route> routes = new ArrayList<>();
-}
diff --git a/app/src/main/java/com/intel/jndn/management/types/Route.java b/app/src/main/java/com/intel/jndn/management/types/Route.java
deleted file mode 100644
index b4badf0..0000000
--- a/app/src/main/java/com/intel/jndn/management/types/Route.java
+++ /dev/null
@@ -1,188 +0,0 @@
-/*
- * jndn-management
- * Copyright (c) 2015, Intel Corporation.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU Lesser General Public License,
- * version 3, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
- * more details.
- */
-package com.intel.jndn.management.types;
-
-import net.named_data.jndn.encoding.tlv.Tlv;
-import java.nio.ByteBuffer;
-import net.named_data.jndn.ForwardingFlags;
-import net.named_data.jndn.encoding.EncodingException;
-import net.named_data.jndn.encoding.tlv.TlvDecoder;
-import net.named_data.jndn.encoding.tlv.TlvEncoder;
-import net.named_data.jndn.util.Blob;
-
-/**
- * Represent a Route object from /localhost/nfd/rib/list; see
- * <a href="http://redmine.named-data.net/projects/nfd/wiki/RibMgmt#RIB-Dataset">http://redmine.named-data.net/projects/nfd/wiki/RibMgmt#RIB-Dataset</a>
- * for details.
- *
- * @author Andrew Brown <andrew.brown@intel.com>
- */
-public class Route {
-
- /**
- * TLV type, see
- * <a href="http://redmine.named-data.net/projects/nfd/wiki/RibMgmt#TLV-TYPE-assignments">http://redmine.named-data.net/projects/nfd/wiki/RibMgmt#TLV-TYPE-assignments</a>
- */
- public final static int TLV_ROUTE = 129;
-
- /**
- * Encode using a new TLV encoder.
- *
- * @return The encoded buffer.
- */
- public final Blob wireEncode() {
- TlvEncoder encoder = new TlvEncoder();
- wireEncode(encoder);
- return new Blob(encoder.getOutput(), false);
- }
-
- /**
- * Encode as part of an existing encode context.
- *
- * @param encoder
- */
- public final void wireEncode(TlvEncoder encoder) {
- int saveLength = encoder.getLength();
- encoder.writeOptionalNonNegativeIntegerTlv(Tlv.ControlParameters_ExpirationPeriod, faceId);
- encoder.writeNonNegativeIntegerTlv(Tlv.ControlParameters_Flags, flags.getForwardingEntryFlags());
- encoder.writeNonNegativeIntegerTlv(Tlv.ControlParameters_Cost, cost);
- encoder.writeNonNegativeIntegerTlv(Tlv.ControlParameters_Origin, origin);
- encoder.writeNonNegativeIntegerTlv(Tlv.ControlParameters_FaceId, faceId);
- encoder.writeTypeAndLength(TLV_ROUTE, encoder.getLength() - saveLength);
- }
-
- /**
- * Decode the input from its TLV format.
- *
- * @param input The input buffer to decode. This reads from position() to
- * limit(), but does not change the position.
- * @throws net.named_data.jndn.encoding.EncodingException
- */
- public final void wireDecode(ByteBuffer input) throws EncodingException {
- TlvDecoder decoder = new TlvDecoder(input);
- wireDecode(decoder);
- }
-
- /**
- * Decode as part of an existing decode context.
- *
- * @param decoder
- * @throws EncodingException
- */
- public final void wireDecode(TlvDecoder decoder) throws EncodingException {
- int endOffset = decoder.readNestedTlvsStart(TLV_ROUTE);
- this.faceId = (int) decoder.readNonNegativeIntegerTlv(Tlv.ControlParameters_FaceId);
- this.origin = (int) decoder.readNonNegativeIntegerTlv(Tlv.ControlParameters_Origin);
- this.cost = (int) decoder.readNonNegativeIntegerTlv(Tlv.ControlParameters_Cost);
- this.flags.setForwardingEntryFlags((int) decoder.readNonNegativeIntegerTlv(Tlv.ControlParameters_Flags));
- this.expirationPeriod = (int) decoder.readOptionalNonNegativeIntegerTlv(Tlv.ControlParameters_ExpirationPeriod, endOffset);
- decoder.finishNestedTlvs(endOffset);
- }
-
- /**
- * Get Face ID
- *
- * @return
- */
- public int getFaceId() {
- return faceId;
- }
-
- /**
- * Set Face ID
- *
- * @param faceId
- */
- public void setFaceId(int faceId) {
- this.faceId = faceId;
- }
-
- /**
- * Get origin
- *
- * @return
- */
- public int getOrigin() {
- return origin;
- }
-
- /**
- * Set origin
- *
- * @param origin
- */
- public void setOrigin(int origin) {
- this.origin = origin;
- }
-
- /**
- * Get cost
- *
- * @return
- */
- public int getCost() {
- return cost;
- }
-
- /**
- * Set cost
- *
- * @param cost
- */
- public void setCost(int cost) {
- this.cost = cost;
- }
-
- /**
- * Get flags
- *
- * @return
- */
- public ForwardingFlags getFlags() {
- return flags;
- }
-
- /**
- * Set flags
- *
- * @param flags
- */
- public void setFlags(ForwardingFlags flags) {
- this.flags = flags;
- }
-
- /**
- * Get expiration period
- *
- * @return
- */
- public double getExpirationPeriod() {
- return expirationPeriod;
- }
-
- /**
- * Set expiration period
- *
- * @param expirationPeriod
- */
- public void setExpirationPeriod(double expirationPeriod) {
- this.expirationPeriod = expirationPeriod;
- }
-
- private int faceId = -1;
- private int origin = -1;
- private int cost = -1;
- private ForwardingFlags flags = new ForwardingFlags();
- private double expirationPeriod = -1.0;
-}
diff --git a/app/src/main/java/com/intel/jndn/management/types/StatusDataset.java b/app/src/main/java/com/intel/jndn/management/types/StatusDataset.java
deleted file mode 100644
index 0cc42c8..0000000
--- a/app/src/main/java/com/intel/jndn/management/types/StatusDataset.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * jndn-management
- * Copyright (c) 2015, Intel Corporation.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU Lesser General Public License,
- * version 3, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
- * more details.
- */
-package com.intel.jndn.management.types;
-
-import com.intel.jndn.management.ManagementException;
-import java.util.ArrayList;
-import java.util.List;
-import net.named_data.jndn.encoding.EncodingException;
-import net.named_data.jndn.encoding.tlv.TlvDecoder;
-import net.named_data.jndn.util.Blob;
-
-/**
- * Helper class to handle StatusDatasets, see
- * <a href="http://redmine.named-data.net/projects/nfd/wiki/StatusDataset">http://redmine.named-data.net/projects/nfd/wiki/StatusDataset</a>
- *
- * @author Andrew Brown <andrew.brown@intel.com>
- */
-public class StatusDataset {
-
- /**
- * Decode multiple status entries as part of a StatusDataset, see
- * <a href="http://redmine.named-data.net/projects/nfd/wiki/StatusDataset">http://redmine.named-data.net/projects/nfd/wiki/StatusDataset</a>
- *
- * @param <T>
- * @param statusDataset
- * @param type
- * @return
- * @throws com.intel.jndn.management.ManagementException
- */
- public static final <T extends Decodable> List<T> wireDecode(Blob statusDataset, Class<T> type) throws ManagementException {
- List<T> entries = new ArrayList<>();
- int endOffset = statusDataset.size();
- TlvDecoder decoder = new TlvDecoder(statusDataset.buf());
- while (decoder.getOffset() < endOffset) {
- try {
- T entry = type.newInstance();
- entry.wireDecode(decoder);
- entries.add(entry);
- } catch (EncodingException | IllegalAccessException | InstantiationException e) {
- throw new ManagementException("Failed to read status dataset.", e);
- }
- }
- return entries;
- }
-}
diff --git a/app/src/main/java/com/intel/jndn/utils/Client.java b/app/src/main/java/com/intel/jndn/utils/Client.java
deleted file mode 100644
index 6b09f9f..0000000
--- a/app/src/main/java/com/intel/jndn/utils/Client.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * jndn-utils
- * Copyright (c) 2015, Intel Corporation.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU Lesser General Public License,
- * version 3, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
- * more details.
- */
-package com.intel.jndn.utils;
-
-import java.io.IOException;
-import java.util.concurrent.Future;
-import net.named_data.jndn.Data;
-import net.named_data.jndn.Face;
-import net.named_data.jndn.Interest;
-
-/**
- * Base functionality provided by all NDN clients in this package.
- *
- * @author Andrew Brown <andrew.brown@intel.com>
- */
-public interface Client {
-
- /**
- * Asynchronously request the Data for an Interest. This will send the
- * Interest and return immediately; use futureData.get() to block until the
- * Data returns (see Future) or manage the event processing independently.
- *
- * @param face
- * @param interest
- * @return
- */
- public Future<Data> getAsync(Face face, Interest interest);
-
- /**
- * Synchronously retrieve the Data for an Interest; this will block until
- * complete (i.e. either data is received or the interest times out).
- *
- * @param face
- * @param interest
- * @return
- * @throws java.io.IOException
- */
- public Data getSync(Face face, Interest interest) throws IOException;
-}
diff --git a/app/src/main/java/com/intel/jndn/utils/DynamicServer.java b/app/src/main/java/com/intel/jndn/utils/DynamicServer.java
deleted file mode 100644
index 8206e27..0000000
--- a/app/src/main/java/com/intel/jndn/utils/DynamicServer.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * jndn-utils
- * Copyright (c) 2015, Intel Corporation.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU Lesser General Public License,
- * version 3, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
- * more details.
- */
-package com.intel.jndn.utils;
-
-import com.intel.jndn.utils.server.RespondWithData;
-import com.intel.jndn.utils.server.Server;
-import java.io.IOException;
-
-/**
- * Defines the API for a {@link Server} producing {@link Data} packets
- * dynamically; in other words, when an {@link Interest} arrives, this server
- * will run a callback to determine what packet to send back. As good practice,
- * keep callback methods as short as possible.
- *
- * @author Andrew Brown <andrew.brown@intel.com>
- */
-public interface DynamicServer extends Server {
-
- /**
- * Set the callback method to run when an {@link Interest} packet is passed to
- * this server. This method should either return a {@link Data} packet that
- * satisfies the Interest or throw an Exception to avoid sending. Calling this
- * method a second time should replace the callback.
- *
- * @param callback the callback instance
- * @throws java.io.IOException if the server fails to register a prefix
- */
- public void respondUsing(RespondWithData callback) throws IOException;
-}
diff --git a/app/src/main/java/com/intel/jndn/utils/InternalFace.java b/app/src/main/java/com/intel/jndn/utils/InternalFace.java
deleted file mode 100644
index 2850363..0000000
--- a/app/src/main/java/com/intel/jndn/utils/InternalFace.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * jndn-utils
- * Copyright (c) 2015, Intel Corporation.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU Lesser General Public License,
- * version 3, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
- * more details.
- */
-package com.intel.jndn.utils;
-
-/**
- * TODO waiting on Face to become overridable
- *
- * @author Andrew Brown <andrew.brown@intel.com>
- */
-public class InternalFace {
-
-}
diff --git a/app/src/main/java/com/intel/jndn/utils/RepositoryServer.java b/app/src/main/java/com/intel/jndn/utils/RepositoryServer.java
deleted file mode 100644
index 0364eb7..0000000
--- a/app/src/main/java/com/intel/jndn/utils/RepositoryServer.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * jndn-utils
- * Copyright (c) 2015, Intel Corporation.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU Lesser General Public License,
- * version 3, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
- * more details.
- */
-package com.intel.jndn.utils;
-
-import com.intel.jndn.utils.server.Server;
-import java.io.IOException;
-import net.named_data.jndn.Data;
-
-/**
- * Defines the API for a {@link Server} producing {@link Data} packets and
- * storing them until they are requested; this server corresponds closely to use
- * cases such as: cache, file system, web server.
- *
- * @author Andrew Brown <andrew.brown@intel.com>
- */
-public interface RepositoryServer extends Server {
-
- /**
- * Store a {@link Data} packet in the server's repository until requested. The
- * task of removing (or retaining) stale packets is not specified here but
- * left to the implementation.
- *
- * @param data the {@link Data} packet to store and serve
- * @throws IOException if the underlying server fails to store the packet
- */
- public void serve(Data data) throws IOException;
-}
diff --git a/app/src/main/java/com/intel/jndn/utils/SegmentedClient.java b/app/src/main/java/com/intel/jndn/utils/SegmentedClient.java
deleted file mode 100644
index 2879a29..0000000
--- a/app/src/main/java/com/intel/jndn/utils/SegmentedClient.java
+++ /dev/null
@@ -1,211 +0,0 @@
-/*
- * jndn-utils
- * Copyright (c) 2015, Intel Corporation.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU Lesser General Public License,
- * version 3, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
- * more details.
- */
-package com.intel.jndn.utils;
-
-import com.intel.jndn.utils.client.SegmentedFutureData;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Future;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import net.named_data.jndn.Data;
-import net.named_data.jndn.Face;
-import net.named_data.jndn.Interest;
-import net.named_data.jndn.Name;
-import net.named_data.jndn.encoding.EncodingException;
-
-import net.named_data.nfd.utils.G;
-
-/**
- * Provide a client to simplify retrieving segmented Data packets over the NDN
- * network. This class expects the Data producer to follow the NDN naming
- * conventions (see http://named-data.net/doc/tech-memos/naming-conventions.pdf)
- * and produce Data packets with a valid segment as the last component of their
- * name; additionally, at least the first packet should set the FinalBlockId of
- * the packet's MetaInfo (see
- * http://named-data.net/doc/ndn-tlv/data.html#finalblockid).
- *
- * @author Andrew Brown <andrew.brown@intel.com>
- */
-public class SegmentedClient implements Client {
-
- private static SegmentedClient defaultInstance;
- private static final Logger logger = Logger.getLogger(SegmentedClient.class.getName());
-
- /**
- * Singleton access for simpler client use.
- *
- * @return
- */
- public static SegmentedClient getDefault() {
- if (defaultInstance == null) {
- defaultInstance = new SegmentedClient();
- }
- return defaultInstance;
- }
-
- /**
- * Asynchronously send Interest packets for a segmented result; will block
- * until the first packet is received and then send remaining interests until
- * the specified FinalBlockId.
- *
- * @param face
- * @param interest should include either a ChildSelector or an initial segment
- * number; the initial segment number will be cut off in the de-segmented
- * packet.
- * @return a list of FutureData packets; if the first segment fails, the list
- * will contain one FutureData with the failure exception
- */
- @Override
- public Future<Data> getAsync(Face face, Interest interest) {
- List<Future<Data>> segments = getAsyncList(face, interest);
- Name name = hasSegment(interest.getName()) ? interest.getName().getPrefix(-1) : interest.getName();
- return new SegmentedFutureData(name, segments);
- }
-
- /**
- * Asynchronously send Interest packets for a segmented result; will block
- * until the first packet is received and then send remaining interests until
- * the specified FinalBlockId.
- *
- * @param face
- * @param name the {@link Name} of the packet to retrieve using a default
- * interest
- * @return an aggregated data packet from all received segments
- */
- public Future<Data> getAsync(Face face, Name name) {
- return getAsync(face, SimpleClient.getDefaultInterest(name));
- }
-
- /**
- * Asynchronously send Interest packets for a segmented result; will block
- * until the first packet is received and then send remaining interests until
- * the specified FinalBlockId.
- *
- * @param face
- * @param interest should include either a ChildSelector or an initial segment
- * number
- * @return a list of FutureData packets; if the first segment fails, the list
- * will contain one FutureData with the failure exception
- */
- public List<Future<Data>> getAsyncList(Face face, Interest interest) {
- // get first segment; default 0 or use a specified start segment
- long firstSegment = 0;
- boolean specifiedSegment = false;
- try {
- firstSegment = interest.getName().get(-1).toSegment();
- specifiedSegment = true;
- } catch (EncodingException e) {
- // check for interest selector if no initial segment found
- if (interest.getChildSelector() == -1) {
- logger.log(Level.WARNING, "No child selector set for a segmented Interest; this may result in incorrect retrieval.");
- // allow this interest to pass without a segment marker since it may still succeed
- }
- }
-
- // setup segments
- final List<Future<Data>> segments = new ArrayList<>();
- segments.add(SimpleClient.getDefault().getAsync(face, interest));
-
- // retrieve first packet to find last segment value
- long lastSegment;
- try {
- G.Log("+++++++ " + segments.get(0).get().getMetaInfo().getFinalBlockId().toEscapedString());
- lastSegment = segments.get(0).get().getMetaInfo().getFinalBlockId().toSegment();
- } catch (ExecutionException | InterruptedException | EncodingException e) {
- logger.log(Level.SEVERE, "Failed to retrieve first segment: ", e);
- return segments;
- }
-
- // cut interest segment off
- if (specifiedSegment) {
- interest.setName(interest.getName().getPrefix(-1));
- }
-
- // send interests in remaining segments
- for (long i = firstSegment + 1; i <= lastSegment; i++) {
- Interest segmentedInterest = new Interest(interest);
- segmentedInterest.getName().appendSegment(i);
- Future<Data> futureData = SimpleClient.getDefault().getAsync(face, segmentedInterest);
- segments.add((int) i, futureData);
- }
-
- return segments;
- }
-
- /**
- * Asynchronously send Interests for a segmented Data packet using a default
- * interest (e.g. 2 second timeout); this will block until complete (i.e.
- * either data is received or the interest times out). See getAsync(Face face)
- * for more information.
- *
- * @param face
- * @param name
- * @return
- */
- public List<Future<Data>> getAsyncList(Face face, Name name) {
- return getAsyncList(face, SimpleClient.getDefaultInterest(name));
- }
-
- /**
- * Retrieve a segmented Data packet; will block until all segments are
- * received and will re-assemble these.
- *
- * @param face
- * @param interest should include either a ChildSelector or an initial segment
- * number
- * @return a Data packet; the name will inherit from the sent Interest, not
- * the returned packets and the content will be a concatenation of all of the
- * packet contents.
- * @throws java.io.IOException
- */
- @Override
- public Data getSync(Face face, Interest interest) throws IOException {
- try {
- return getAsync(face, interest).get();
- } catch (ExecutionException | InterruptedException e) {
- logger.log(Level.WARNING, "Failed to retrieve data.", e);
- throw new IOException("Failed to retrieve data.", e);
- }
- }
-
- /**
- * Synchronously retrieve the Data for a Name using a default interest (e.g. 2
- * second timeout); this will block until complete (i.e. either data is
- * received or the interest times out). See getSync(Face face) for more
- * information.
- *
- * @param face
- * @param name
- * @return
- * @throws java.io.IOException
- */
- public Data getSync(Face face, Name name) throws IOException {
- return getSync(face, SimpleClient.getDefaultInterest(name));
- }
-
- /**
- * Check if a name ends in a segment component; uses marker value found in the
- * NDN naming conventions (see
- * http://named-data.net/doc/tech-memos/naming-conventions.pdf).
- *
- * @param name
- * @return
- */
- public static boolean hasSegment(Name name) {
- return name.get(-1).getValue().buf().get(0) == 0x00;
- }
-}
diff --git a/app/src/main/java/com/intel/jndn/utils/SegmentedServer.java b/app/src/main/java/com/intel/jndn/utils/SegmentedServer.java
deleted file mode 100644
index 0daf0af..0000000
--- a/app/src/main/java/com/intel/jndn/utils/SegmentedServer.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * jndn-utils
- * Copyright (c) 2015, Intel Corporation.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU Lesser General Public License,
- * version 3, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
- * more details.
- */
-package com.intel.jndn.utils;
-
-import com.intel.jndn.utils.repository.ForLoopRepository;
-import com.intel.jndn.utils.repository.Repository;
-import com.intel.jndn.utils.server.SegmentedServerHelper;
-import com.intel.jndn.utils.server.ServerBaseImpl;
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.nio.ByteBuffer;
-import java.util.List;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import net.named_data.jndn.Data;
-import net.named_data.jndn.Face;
-import net.named_data.jndn.Interest;
-import net.named_data.jndn.Name;
-import net.named_data.jndn.encoding.EncodingException;
-import net.named_data.jndn.transport.Transport;
-
-/**
- * Implementation of a {@link RepositoryServer} that segments packets stored in
- * its repository.
- *
- * @author Andrew Brown <andrew.brown@intel.com>
- */
-public class SegmentedServer extends ServerBaseImpl implements RepositoryServer {
-
- private static final Logger logger = Logger.getLogger(SegmentedClient.class.getName());
- private final Repository repository = new ForLoopRepository();
-
- /**
- * {@inheritDoc}
- */
- public SegmentedServer(Face face, Name prefix) {
- super(face, prefix);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void serve(Data data) throws IOException {
- if (!isRegistered()) {
- register();
- }
-
- InputStream stream = new ByteArrayInputStream(data.getContent().getImmutableArray());
- List<Data> segments = SegmentedServerHelper.segment(data, stream);
- for (Data segment : segments) {
- logger.info("Added segment: " + segment.getName().toUri());
- repository.put(segment);
- }
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void onInterest(Name prefix, Interest interest, Transport transport, long registeredPrefixId) {
- if (interest.getChildSelector() == -1) {
- try {
- interest.getName().get(-1).toSegment();
- } catch (EncodingException e) {
- interest.setChildSelector(Interest.CHILD_SELECTOR_LEFT);
- }
- }
-
- try {
- Data data = repository.get(interest);
- data = processPipeline(data);
- ByteBuffer buffer = data.wireEncode().buf();
- transport.send(buffer);
- } catch (Exception e) {
- logger.log(Level.SEVERE, "Failed to send data for: " + interest.toUri(), e);
- }
- }
-}
diff --git a/app/src/main/java/com/intel/jndn/utils/SimpleClient.java b/app/src/main/java/com/intel/jndn/utils/SimpleClient.java
deleted file mode 100644
index a751f8e..0000000
--- a/app/src/main/java/com/intel/jndn/utils/SimpleClient.java
+++ /dev/null
@@ -1,145 +0,0 @@
-/*
- * jndn-utils
- * Copyright (c) 2015, Intel Corporation.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU Lesser General Public License,
- * version 3, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
- * more details.
- */
-package com.intel.jndn.utils;
-
-import com.intel.jndn.utils.client.FutureData;
-import java.io.IOException;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Future;
-import java.util.concurrent.TimeoutException;
-import java.util.logging.Level;
-import net.named_data.jndn.Data;
-import net.named_data.jndn.Face;
-import net.named_data.jndn.Interest;
-import net.named_data.jndn.Name;
-import net.named_data.jndn.OnData;
-import net.named_data.jndn.OnTimeout;
-import java.util.logging.Logger;
-
-/**
- * Provide a client to simplify information retrieval over the NDN network.
- *
- * @author Andrew Brown <andrew.brown@intel.com>
- */
-public class SimpleClient implements Client {
-
- public static final long DEFAULT_SLEEP_TIME = 20;
- public static final long DEFAULT_TIMEOUT = 2000;
- private static final Logger logger = Logger.getLogger(SimpleClient.class.getName());
- private static SimpleClient defaultInstance;
-
- /**
- * Singleton access for simpler client use
- *
- * @return
- */
- public static SimpleClient getDefault() {
- if (defaultInstance == null) {
- defaultInstance = new SimpleClient();
- }
- return defaultInstance;
- }
-
- /**
- * Asynchronously request the Data for an Interest. This will send the
- * Interest and return immediately; use futureData.get() to block until the
- * Data returns (see FutureData) or manage the event processing independently.
- *
- * @param face
- * @param interest
- * @return
- */
- @Override
- public Future<Data> getAsync(Face face, Interest interest) {
- final FutureData futureData = new FutureData(face, interest.getName());
-
- // send interest
- try {
- face.expressInterest(interest, new OnData() {
- @Override
- public void onData(Interest interest, Data data) {
- futureData.resolve(data);
- }
- }, new OnTimeout() {
- @Override
- public void onTimeout(Interest interest) {
- futureData.reject(new TimeoutException());
- }
- });
- } catch (IOException e) {
- logger.log(Level.WARNING, "IO failure while sending interest: ", e);
- futureData.reject(e);
- }
-
- return futureData;
- }
-
- /**
- * Synchronously retrieve the Data for a Name using a default interest (e.g. 2
- * second timeout); this will block until complete (i.e. either data is
- * received or the interest times out).
- *
- * @param face
- * @param name
- * @return
- */
- public Future<Data> getAsync(Face face, Name name) {
- return getAsync(face, getDefaultInterest(name));
- }
-
- /**
- * Synchronously retrieve the Data for an Interest; this will block until
- * complete (i.e. either data is received or the interest times out).
- *
- * @param face
- * @param interest
- * @return Data packet or null
- * @throws java.io.IOException
- */
- @Override
- public Data getSync(Face face, Interest interest) throws IOException {
- try {
- return getAsync(face, interest).get();
- } catch (ExecutionException | InterruptedException e) {
- logger.log(Level.WARNING, "Failed to retrieve data.", e);
- throw new IOException("Failed to retrieve data.", e);
- }
- }
-
- /**
- * Synchronously retrieve the Data for a Name using a default interest (e.g. 2
- * second timeout); this will block until complete (i.e. either data is
- * received or the interest times out).
- *
- * @param face
- * @param name
- * @return
- * @throws java.io.IOException
- */
- public Data getSync(Face face, Name name) throws IOException {
- return getSync(face, getDefaultInterest(name));
- }
-
- /**
- * Create a default interest for a given Name using some common settings: -
- * lifetime: 2 seconds
- *
- * @param name
- * @return
- */
- public static Interest getDefaultInterest(Name name) {
- Interest interest = new Interest(name, DEFAULT_TIMEOUT);
- return interest;
- }
-}
diff --git a/app/src/main/java/com/intel/jndn/utils/SimpleServer.java b/app/src/main/java/com/intel/jndn/utils/SimpleServer.java
deleted file mode 100644
index 0bd4667..0000000
--- a/app/src/main/java/com/intel/jndn/utils/SimpleServer.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * jndn-utils
- * Copyright (c) 2015, Intel Corporation.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU Lesser General Public License,
- * version 3, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
- * more details.
- */
-package com.intel.jndn.utils;
-
-import com.intel.jndn.utils.server.RespondWithData;
-import com.intel.jndn.utils.server.RespondWithBlob;
-import com.intel.jndn.utils.server.ServerBaseImpl;
-import java.io.IOException;
-import java.nio.ByteBuffer;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import net.named_data.jndn.Data;
-import net.named_data.jndn.Face;
-import net.named_data.jndn.Interest;
-import net.named_data.jndn.Name;
-import net.named_data.jndn.transport.Transport;
-import net.named_data.jndn.util.Blob;
-
-/**
- * Implementation of a {@link DynamicServer} that wraps the {@link OnInterest}
- * callback with some encoding and pipeline support.
- *
- * @author Andrew Brown <andrew.brown@intel.com>
- */
-public class SimpleServer extends ServerBaseImpl implements DynamicServer {
-
- private static final Logger logger = Logger.getLogger(SegmentedClient.class.getName());
- private RespondWithData callback;
-
- /**
- * {@inheritDoc}
- */
- public SimpleServer(Face face, Name prefix) {
- super(face, prefix);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void respondUsing(RespondWithData callback) throws IOException {
- if (!isRegistered()) {
- register();
- }
- this.callback = callback;
- }
-
- /**
- * Convenience method for responding to an {@link Interest} by returning the
- * {@link Blob} content only; when an Interest arrives, this method wraps the
- * returned Blob with a {@link Data} using the exact {@link Name} of the
- * incoming Interest.
- *
- * @param callback the callback function to retrieve content when an
- * {@link Interest} arrives
- * @throws java.io.IOException if the server fails to register a prefix
- */
- public void respondUsing(final RespondWithBlob callback) throws IOException {
- RespondWithData dataCallback = new RespondWithData() {
- @Override
- public Data onInterest(Name prefix, Interest interest) throws Exception {
- Data data = new Data(interest.getName());
- Blob content = callback.onInterest(prefix, interest);
- data.setContent(content);
- return data;
- }
- };
- respondUsing(dataCallback);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void onInterest(Name prefix, Interest interest, Transport transport, long registeredPrefixId) {
- try {
- Data data = callback.onInterest(prefix, interest);
- data = processPipeline(data);
- ByteBuffer buffer = data.wireEncode().buf();
- transport.send(buffer);
- } catch (Exception e) {
- logger.log(Level.SEVERE, "Failed to send data for: " + interest.toUri(), e);
- }
- }
-}
diff --git a/app/src/main/java/com/intel/jndn/utils/client/FutureData.java b/app/src/main/java/com/intel/jndn/utils/client/FutureData.java
deleted file mode 100644
index dc6b393..0000000
--- a/app/src/main/java/com/intel/jndn/utils/client/FutureData.java
+++ /dev/null
@@ -1,197 +0,0 @@
-/*
- * jndn-utils
- * Copyright (c) 2015, Intel Corporation.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU Lesser General Public License,
- * version 3, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
- * more details.
- */
-package com.intel.jndn.utils.client;
-
-import java.io.IOException;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Future;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
-import net.named_data.jndn.Data;
-import net.named_data.jndn.Face;
-import net.named_data.jndn.Name;
-import net.named_data.jndn.encoding.EncodingException;
-
-/**
- * Reference to a Packet that has yet to be returned from the network. Usage:
- *
- * <pre><code>
- * FutureData futureData = new FutureData(face, interest.getName());
- * face.expressInterest(interest, new OnData(){
- * ... futureData.resolve(data); ...
- * }, new OnTimeout(){
- * ... futureData.reject(new TimeoutException());
- * });
- * Data resolvedData = futureData.get(); // will block and call face.processEvents() until complete
- * </code></pre>
- *
- * @author Andrew Brown <andrew.brown@intel.com>
- */
-public class FutureData implements Future<Data> {
-
- protected final Face face;
- private final Name name;
- private Data data;
- private boolean cancelled = false;
- private Throwable error;
-
- /**
- * Constructor
- *
- * @param face
- * @param name
- */
- public FutureData(Face face, Name name) {
- this.face = face;
- this.name = new Name(name);
- }
-
- /**
- * Get the Interest name.
- *
- * @return
- */
- public Name getName() {
- return name;
- }
-
- /**
- * Cancel the current request.
- *
- * @param mayInterruptIfRunning
- * @return
- */
- @Override
- public boolean cancel(boolean mayInterruptIfRunning) {
- cancelled = true;
- return cancelled;
- }
-
- /**
- * Determine if this request is cancelled.
- *
- * @return
- */
- @Override
- public boolean isCancelled() {
- return cancelled;
- }
-
- /**
- * Determine if the request has completed (successfully or not).
- *
- * @return
- */
- @Override
- public boolean isDone() {
- return data != null || error != null || isCancelled();
- }
-
- /**
- * Set the packet when successfully retrieved; unblocks get().
- *
- * @param d
- */
- public void resolve(Data d) {
- data = d;
- }
-
- /**
- * Set the exception when request failed; unblocks get().
- *
- * @param e
- */
- public void reject(Throwable e) {
- error = e;
- }
-
- /**
- * Block until packet is retrieved.
- *
- * @return
- * @throws InterruptedException
- * @throws ExecutionException
- */
- @Override
- public Data get() throws InterruptedException, ExecutionException {
- while (!isDone()) {
- // process face events
- try {
- synchronized (face) {
- face.processEvents();
- }
- } catch (EncodingException | IOException e) {
- throw new ExecutionException("Failed to retrieve packet.", e);
- }
- }
-
- // case: cancelled
- if (cancelled) {
- throw new InterruptedException("Interrupted by user.");
- }
-
- // case: error
- if (error != null) {
- throw new ExecutionException("Future rejected with error.", error);
- }
-
- return data;
- }
-
- /**
- * Block until packet is retrieved or timeout is reached.
- *
- * @param timeout
- * @param unit
- * @return
- * @throws InterruptedException
- * @throws ExecutionException
- * @throws TimeoutException
- */
- @Override
- public Data get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
- long interval = TimeUnit.MILLISECONDS.convert(timeout, unit);
- long endTime = System.currentTimeMillis() + interval;
- long currentTime = System.currentTimeMillis();
- while (!isDone() && !isCancelled() && currentTime <= endTime) {
- // process face events
- try {
- synchronized (face) {
- face.processEvents();
- }
- } catch (EncodingException | IOException e) {
- throw new ExecutionException("Failed to retrieve packet.", e);
- }
-
- currentTime = System.currentTimeMillis();
- }
-
- // case: cancelled
- if (cancelled) {
- throw new InterruptedException("Interrupted by user.");
- }
-
- // case: error
- if (error != null) {
- throw new ExecutionException("Future rejected with error.", error);
- }
-
- // case: timed out
- if (currentTime > endTime) {
- throw new TimeoutException("Timed out.");
- }
-
- return data;
- }
-}
diff --git a/app/src/main/java/com/intel/jndn/utils/client/SegmentedFutureData.java b/app/src/main/java/com/intel/jndn/utils/client/SegmentedFutureData.java
deleted file mode 100644
index dec33df..0000000
--- a/app/src/main/java/com/intel/jndn/utils/client/SegmentedFutureData.java
+++ /dev/null
@@ -1,172 +0,0 @@
-/*
- * jndn-utils
- * Copyright (c) 2015, Intel Corporation.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU Lesser General Public License,
- * version 3, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
- * more details.
- */
-package com.intel.jndn.utils.client;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.util.List;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Future;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
-import net.named_data.jndn.Data;
-import net.named_data.jndn.Name;
-import net.named_data.jndn.util.Blob;
-
-/**
- * Represents a list of Packets that have been requested asynchronously and have
- * yet to be returned from the network. Usage:
- *
- * <pre><code>
- * SegmentedFutureData segmentedFutureData = new SegmentedFutureData(face, name, futureDataList);
- * Data data = segmentedFutureData.get(); // will block until complete
- * </code></pre>
- *
- * @author Andrew Brown <andrew.brown@intel.com>
- */
-public class SegmentedFutureData implements Future<Data> {
-
- private final Name name;
- List<Future<Data>> segments;
- private boolean cancelled = false;
-
- /**
- * Constructor
- *
- * @param name this will be the name of the returned Data packet, regardless
- * of suffixes (e.g. segment components) on each segment packet
- * @param segments
- */
- public SegmentedFutureData(Name name, List<Future<Data>> segments) {
- this.name = name;
- this.segments = segments;
- }
-
- /**
- * Get the Interest name; this will also be the name of the Data packet
- * returned from get().
- *
- * @return
- */
- public Name getName() {
- return name;
- }
-
- /**
- * Cancel the current request.
- *
- * @param mayInterruptIfRunning
- * @return
- */
- @Override
- public boolean cancel(boolean mayInterruptIfRunning) {
- cancelled = true;
- return cancelled;
- }
-
- /**
- * Determine if this request is cancelled.
- *
- * @return
- */
- @Override
- public boolean isCancelled() {
- return cancelled;
- }
-
- /**
- * Determine if the request has completed (successfully or not).
- *
- * @return
- */
- @Override
- public boolean isDone() {
- // check for errors, cancellation
- if (isCancelled()) {
- return true;
- }
-
- // check each segment for completion
- for (Future<Data> futureData : segments) {
- if (!futureData.isDone()) {
- return false;
- }
- }
-
- return true;
- }
-
- /**
- * Block until packet is retrieved.
- *
- * @return
- * @throws InterruptedException
- * @throws ExecutionException
- */
- @Override
- public Data get() throws InterruptedException, ExecutionException {
- // aggregate bytes
- ByteArrayOutputStream content = new ByteArrayOutputStream();
- for (Future<Data> futureData : segments) {
- try {
- content.write(futureData.get().getContent().getImmutableArray());
- } catch (ExecutionException | IOException | InterruptedException e) {
- throw new ExecutionException("Failed while aggregating retrieved packets.", e);
- }
- }
-
- // build aggregated packet (copy first packet)
- Data data = new Data(segments.get(0).get());
- data.setName(getName());
- data.setContent(new Blob(content.toByteArray()));
- return data;
- }
-
- /**
- * Block until packet is retrieved or timeout is reached.
- *
- * @param timeout
- * @param unit
- * @return
- * @throws InterruptedException
- * @throws ExecutionException
- * @throws TimeoutException
- */
- @Override
- public Data get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
- long interval = TimeUnit.MILLISECONDS.convert(timeout, unit);
- long endTime = System.currentTimeMillis() + interval;
-
- // aggregate bytes
- ByteArrayOutputStream content = new ByteArrayOutputStream();
- for (Future<Data> futureData : segments) {
- try {
- content.write(futureData.get().getContent().getImmutableArray());
- } catch (ExecutionException | IOException | InterruptedException e) {
- throw new ExecutionException("Failed while aggregating retrieved packets.", e);
- }
-
- // check for timeout
- if (System.currentTimeMillis() > endTime) {
- throw new TimeoutException("Timed out.");
- }
- }
-
- // build aggregated packet (copy first packet)
- Data data = new Data(segments.get(0).get());
- data.setName(getName());
- data.setContent(new Blob(content.toByteArray()));
- return data;
- }
-}
diff --git a/app/src/main/java/com/intel/jndn/utils/repository/DataNotFoundException.java b/app/src/main/java/com/intel/jndn/utils/repository/DataNotFoundException.java
deleted file mode 100644
index 732cc9c..0000000
--- a/app/src/main/java/com/intel/jndn/utils/repository/DataNotFoundException.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * jndn-utils
- * Copyright (c) 2015, Intel Corporation.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU Lesser General Public License,
- * version 3, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
- * more details.
- */
-package com.intel.jndn.utils.repository;
-
-/**
- * Thrown when a {@link Repository} cannot retrieve a stored packet.
- *
- * @author Andrew Brown <andrew.brown@intel.com>
- */
-public class DataNotFoundException extends Exception {
-
-}
diff --git a/app/src/main/java/com/intel/jndn/utils/repository/ForLoopRepository.java b/app/src/main/java/com/intel/jndn/utils/repository/ForLoopRepository.java
deleted file mode 100644
index cb43655..0000000
--- a/app/src/main/java/com/intel/jndn/utils/repository/ForLoopRepository.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * jndn-utils
- * Copyright (c) 2015, Intel Corporation.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU Lesser General Public License,
- * version 3, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
- * more details.
- */
-package com.intel.jndn.utils.repository;
-
-import java.util.ArrayList;
-import java.util.List;
-import net.named_data.jndn.Data;
-import net.named_data.jndn.Interest;
-import net.named_data.jndn.Name;
-
-/**
- * Store {@link Data} packets in a linked list and iterate over the list to find
- * the best match; this is a subset of the functionality provided in
- * {@link net.named_data.jndn.util.MemoryContentCache} and borrows the matching
- * logic from there. Code for removing stale packets is not yet implemented.
- *
- * @author Andrew Brown <andrew.brown@intel.com>
- */
-public class ForLoopRepository implements Repository {
-
- private List<Data> storage = new ArrayList<>();
-
- /**
- * Helper data structure
- */
- private class Record {
-
- public Name name;
- public Data data;
-
- public Record(Name name, Data data) {
- this.name = name;
- this.data = data;
- }
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void put(Data data) {
- storage.add(data);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Data get(Interest interest) throws DataNotFoundException {
- Name.Component selectedComponent = null;
- Data selectedData = null;
- for (Data content : storage) {
- if (interest.matchesName(content.getName())) {
- if (interest.getChildSelector() < 0) {
- // No child selector, so send the first match that we have found.
- return content;
- } else {
- // Update selectedEncoding based on the child selector.
- Name.Component component;
- if (content.getName().size() > interest.getName().size()) {
- component = content.getName().get(interest.getName().size());
- } else {
- component = new Name.Component();
- }
-
- boolean gotBetterMatch = false;
- if (selectedData == null) {
- // Save the first match.
- gotBetterMatch = true;
- } else {
- if (interest.getChildSelector() == 0) {
- // Leftmost child.
- if (component.compare(selectedComponent) < 0) {
- gotBetterMatch = true;
- }
- } else {
- // Rightmost child.
- if (component.compare(selectedComponent) > 0) {
- gotBetterMatch = true;
- }
- }
- }
-
- if (gotBetterMatch) {
- selectedComponent = component;
- selectedData = content;
- }
- }
- }
- }
-
- if (selectedData != null) {
- // We found the leftmost or rightmost child.
- return selectedData;
- } else {
- throw new DataNotFoundException();
- }
- }
-}
diff --git a/app/src/main/java/com/intel/jndn/utils/repository/NavigableTreeRepository.java b/app/src/main/java/com/intel/jndn/utils/repository/NavigableTreeRepository.java
deleted file mode 100644
index ec47190..0000000
--- a/app/src/main/java/com/intel/jndn/utils/repository/NavigableTreeRepository.java
+++ /dev/null
@@ -1,146 +0,0 @@
-/*
- * jndn-utils
- * Copyright (c) 2015, Intel Corporation.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU Lesser General Public License,
- * version 3, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
- * more details.
- */
-package com.intel.jndn.utils.repository;
-
-import java.util.NavigableMap;
-import java.util.TreeMap;
-import net.named_data.jndn.Data;
-import net.named_data.jndn.Interest;
-import net.named_data.jndn.Name;
-
-/**
- * Store {@link Data} packets in a {@link TreeMap}; this is an initial concept
- * class and should not be used in production. In tests, see
- * RepositoryTest.java, this class is faster on retrieval but not enough to make
- * up for its slow put().
- *
- * @author Andrew Brown <andrew.brown@intel.com>
- */
-public class NavigableTreeRepository implements Repository {
-
- private NavigableMap<Name, PossibleData> storage = new TreeMap<>();
-
- /**
- * Helper data structure
- */
- private class PossibleData {
-
- public PossibleData() {
- // no data provided
- }
-
- public PossibleData(Data data) {
- this.data = data;
- }
- public Data data;
-
- public boolean hasData() {
- return data != null;
- }
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void put(Data data) {
- storage.put(data.getName(), new PossibleData(data));
-
- Name name = data.getName();
- do {
- name = name.getPrefix(-1);
- if (storage.get(name) == null) {
- storage.put(name, new PossibleData());
- }
- } while (name.size() > 0);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Data get(Interest interest) throws DataNotFoundException {
- Data data;
- if (interest.getChildSelector() == Interest.CHILD_SELECTOR_LEFT) {
- data = getLowest(interest);
- } else if (interest.getChildSelector() == Interest.CHILD_SELECTOR_RIGHT) {
- data = getHighest(interest);
- } else {
- data = getFirstMatching(interest);
- }
- checkForNull(data);
- return data;
- }
-
- /**
- * @param interest the {@link Interest} to search with
- * @return the lowest matching {@link Data} packet
- */
- private Data getLowest(Interest interest) {
- PossibleData found = storage.get(interest.getName());
-
- Name name = interest.getName();
- while (found != null && interest.matchesName(name)) {
- name = storage.lowerKey(name);
- found = (name != null) ? storage.get(name) : null;
- }
-
- return found == null ? null : found.data;
- }
-
- /**
- * @param interest the {@link Interest} to search with
- * @return the highest matching {@link Data} packet
- */
- private Data getHighest(Interest interest) {
- PossibleData found = storage.get(interest.getName());
-
- if (found != null) {
- Name name = interest.getName();
- while (name != null && interest.matchesName(name)) {
- found = storage.get(name);
- name = storage.higherKey(name);
- }
- }
-
- return found == null ? null : found.data;
- }
-
- /**
- * @param interest the {@link Interest} to search with
- * @return the first matching {@link Data} packet
- */
- private Data getFirstMatching(Interest interest) {
- PossibleData found = storage.get(interest.getName());
-
- Name name = interest.getName();
- while (found != null && !found.hasData() && interest.matchesName(name)) {
- name = storage.higherKey(name);
- found = (name != null) ? storage.get(name) : null;
- }
-
- return found == null ? null : found.data;
- }
-
- /**
- * @param data the {@link Data} packet to check
- * @throws DataNotFoundException if data is null
- */
- private void checkForNull(Data data) throws DataNotFoundException {
- if (data == null) {
- throw new DataNotFoundException();
- }
- }
-
-}
diff --git a/app/src/main/java/com/intel/jndn/utils/repository/Repository.java b/app/src/main/java/com/intel/jndn/utils/repository/Repository.java
deleted file mode 100644
index 9444e24..0000000
--- a/app/src/main/java/com/intel/jndn/utils/repository/Repository.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * jndn-utils
- * Copyright (c) 2015, Intel Corporation.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU Lesser General Public License,
- * version 3, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
- * more details.
- */
-package com.intel.jndn.utils.repository;
-
-import com.intel.jndn.utils.repository.DataNotFoundException;
-import net.named_data.jndn.Data;
-import net.named_data.jndn.Interest;
-
-/**
- * Define API for storing and retrieving NDN packets
- *
- * @author Andrew Brown <andrew.brown@intel.com>
- */
-public interface Repository {
-
- /**
- * Put a {@link Data} packet in the repository.
- *
- * @param data a {@link Data} packet
- */
- public void put(Data data);
-
- /**
- * Retrieve a {@link Data} packet in the repository; this method should
- * respect child selectors, exclude selectors, etc.
- *
- * @param interest the {@link Interest}
- * @return a {@link Data} packet
- * @throws DataNotFoundException if the packet is not found
- */
- public Data get(Interest interest) throws DataNotFoundException;
-}
diff --git a/app/src/main/java/com/intel/jndn/utils/server/PipelineStage.java b/app/src/main/java/com/intel/jndn/utils/server/PipelineStage.java
deleted file mode 100644
index 15d23f0..0000000
--- a/app/src/main/java/com/intel/jndn/utils/server/PipelineStage.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * jndn-utils
- * Copyright (c) 2015, Intel Corporation.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU Lesser General Public License,
- * version 3, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
- * more details.
- */
-package com.intel.jndn.utils.server;
-
-/**
- *
- * @author Andrew Brown <andrew.brown@intel.com>
- */
-public interface PipelineStage<T, Y> {
- public Y process(T context) throws Exception;
-// public void setNextStage(PipelineStage<Y, ?> nextStage);
-// public PipelineStage<Y, ?> getNextStage();
-}
diff --git a/app/src/main/java/com/intel/jndn/utils/server/RespondWithBlob.java b/app/src/main/java/com/intel/jndn/utils/server/RespondWithBlob.java
deleted file mode 100644
index fe7f74a..0000000
--- a/app/src/main/java/com/intel/jndn/utils/server/RespondWithBlob.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * jndn-utils
- * Copyright (c) 2015, Intel Corporation.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU Lesser General Public License,
- * version 3, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
- * more details.
- */
-package com.intel.jndn.utils.server;
-
-import net.named_data.jndn.Interest;
-import net.named_data.jndn.Name;
-import net.named_data.jndn.util.Blob;
-
-/**
- * Functional interface for serving data from Server.on()
- *
- * @author Andrew Brown <andrew.brown@intel.com>
- */
-public interface RespondWithBlob {
-
- public Blob onInterest(Name prefix, Interest interest) throws Exception;
-}
diff --git a/app/src/main/java/com/intel/jndn/utils/server/RespondWithData.java b/app/src/main/java/com/intel/jndn/utils/server/RespondWithData.java
deleted file mode 100644
index 95d0e6a..0000000
--- a/app/src/main/java/com/intel/jndn/utils/server/RespondWithData.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * jndn-utils
- * Copyright (c) 2015, Intel Corporation.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU Lesser General Public License,
- * version 3, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
- * more details.
- */
-package com.intel.jndn.utils.server;
-
-import net.named_data.jndn.Data;
-import net.named_data.jndn.Interest;
-import net.named_data.jndn.Name;
-
-/**
- * Functional interface for serving data from Server.on()
- *
- * @author Andrew Brown <andrew.brown@intel.com>
- */
-public interface RespondWithData {
-
- public Data onInterest(Name prefix, Interest interest) throws Exception;
-}
diff --git a/app/src/main/java/com/intel/jndn/utils/server/SegmentedServerHelper.java b/app/src/main/java/com/intel/jndn/utils/server/SegmentedServerHelper.java
deleted file mode 100644
index 2e1f92c..0000000
--- a/app/src/main/java/com/intel/jndn/utils/server/SegmentedServerHelper.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * jndn-utils
- * Copyright (c) 2015, Intel Corporation.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU Lesser General Public License,
- * version 3, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
- * more details.
- */
-package com.intel.jndn.utils.server;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.nio.ByteBuffer;
-import java.util.ArrayList;
-import java.util.List;
-import net.named_data.jndn.Data;
-import net.named_data.jndn.Name;
-import net.named_data.jndn.util.Blob;
-
-/**
- * Helper for segmenting an input stream into a list of Data packets. Current
- * use of the default segment size of 4096 (only for
- * {@link #segment(net.named_data.jndn.Data, java.io.InputStream)} is based on
- * several assumptions: NDN packet size was limited to 8000 at the time this was
- * written and signature size is unknown.
- *
- * @author Andrew Brown <andrew.brown@intel.com>
- */
-public class SegmentedServerHelper {
-
- public static final int DEFAULT_SEGMENT_SIZE = 4096;
-
- /**
- * Segment a stream of bytes into a list of Data packets; this must read all
- * the bytes first in order to determine the end segment for FinalBlockId.
- *
- * @param template the {@link Data} packet to use for the segment {@link Name},
- * {@link net.named_data.jndn.MetaInfo}, etc.
- * @param bytes an {@link InputStream} to the bytes to segment
- * @return a list of segmented {@link Data} packets
- * @throws IOException if the stream fails
- */
- public static List<Data> segment(Data template, InputStream bytes) throws IOException {
- return segment(template, bytes, DEFAULT_SEGMENT_SIZE);
- }
-
- /**
- * Segment a stream of bytes into a list of Data packets; this must read all
- * the bytes first in order to determine the end segment for FinalBlockId.
- *
- * @param template the {@link Data} packet to use for the segment {@link Name},
- * {@link net.named_data.jndn.MetaInfo}, etc.
- * @param bytes an {@link InputStream} to the bytes to segment
- * @return a list of segmented {@link Data} packets
- * @throws IOException if the stream fails
- */
- public static List<Data> segment(Data template, InputStream bytes, int segmentSize) throws IOException {
- List<Data> segments = new ArrayList<>();
- byte[] buffer_ = readAll(bytes);
- int numBytes = buffer_.length;
- int numPackets = (int) Math.ceil((double) numBytes / segmentSize);
- ByteBuffer buffer = ByteBuffer.wrap(buffer_, 0, numBytes);
- Name.Component lastSegment = Name.Component.fromNumberWithMarker(numPackets - 1, 0x00);
-
- for (int i = 0; i < numPackets; i++) {
- Data segment = new Data(template);
- segment.getName().appendSegment(i);
- segment.getMetaInfo().setFinalBlockId(lastSegment);
- byte[] content = new byte[Math.min(segmentSize, buffer.remaining())];
- buffer.get(content);
- segment.setContent(new Blob(content));
- segments.add(segment);
- }
-
- return segments;
- }
-
- /**
- * Read all of the bytes in an input stream.
- *
- * @param bytes the {@link InputStream} of bytes to read
- * @return an array of all bytes retrieved from the stream
- * @throws IOException if the stream fails
- */
- public static byte[] readAll(InputStream bytes) throws IOException {
- ByteArrayOutputStream builder = new ByteArrayOutputStream();
- int read = bytes.read();
- while (read != -1) {
- builder.write(read);
- read = bytes.read();
- }
- builder.flush();
- bytes.close();
- return builder.toByteArray();
- }
-}
diff --git a/app/src/main/java/com/intel/jndn/utils/server/Server.java b/app/src/main/java/com/intel/jndn/utils/server/Server.java
deleted file mode 100644
index ba4ff1c..0000000
--- a/app/src/main/java/com/intel/jndn/utils/server/Server.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * jndn-utils
- * Copyright (c) 2015, Intel Corporation.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU Lesser General Public License,
- * version 3, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
- * more details.
- */
-package com.intel.jndn.utils.server;
-
-import java.util.concurrent.ScheduledThreadPoolExecutor;
-import net.named_data.jndn.Data;
-import net.named_data.jndn.Name;
-import net.named_data.jndn.OnInterest;
-
-/**
- * Base interface for defining a server; see descendant interfaces for different
- * modes of serving packets. This class extends {@link Runnable} expecting
- * implementing classes to do any necessary event processing in the
- * {@link Runnable#run()} block, thus allowing different ways to manage servers
- * (e.g. single-thread vs {@link ScheduledThreadPoolExecutor}.
- *
- * @author Andrew Brown <andrew.brown@intel.com>
- */
-public interface Server extends Runnable, OnInterest {
-
- /**
- * @return the {@link Name} prefix this server is serving on.
- */
- public Name getPrefix();
-
- /**
- * Add a stage to the server pipeline. Each stage should be processed once the
- * server has the {@link Data} packet available to send (e.g. after a callback
- * has produced a packet); also, stages should be processed in the order they
- * are added.
- *
- * @param pipelineStage a Data-to-Data processing stage
- */
- public void addPipelineStage(PipelineStage<Data, Data> pipelineStage);
-}
diff --git a/app/src/main/java/com/intel/jndn/utils/server/ServerBaseImpl.java b/app/src/main/java/com/intel/jndn/utils/server/ServerBaseImpl.java
deleted file mode 100644
index 0d150d6..0000000
--- a/app/src/main/java/com/intel/jndn/utils/server/ServerBaseImpl.java
+++ /dev/null
@@ -1,140 +0,0 @@
-/*
- * jndn-utils
- * Copyright (c) 2015, Intel Corporation.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU Lesser General Public License,
- * version 3, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
- * more details.
- */
-package com.intel.jndn.utils.server;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import net.named_data.jndn.Data;
-import net.named_data.jndn.Face;
-import net.named_data.jndn.ForwardingFlags;
-import net.named_data.jndn.Name;
-import net.named_data.jndn.OnRegisterFailed;
-import net.named_data.jndn.encoding.EncodingException;
-
-/**
- * Base implementation for a {@link Server}.
- *
- * @author Andrew Brown <andrew.brown@intel.com>
- */
-public abstract class ServerBaseImpl implements Server {
-
- private static final Logger logger = Logger.getLogger(ServerBaseImpl.class.getName());
- private final Face face;
- private final Name prefix;
- private final List<PipelineStage> pipeline = new ArrayList<>();
- private boolean registered = false;
-
- /**
- * Build the base server; register() must run separately and is run
- * automatically on {@link #run()}.
- *
- * @param face a {@link Face} allowing prefix registration (see
- * {@link Face#setCommandSigningInfo(net.named_data.jndn.security.KeyChain, net.named_data.jndn.Name)}
- * @param prefix the {@link Name} to register
- */
- public ServerBaseImpl(Face face, Name prefix) {
- this.face = face;
- this.prefix = prefix;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Name getPrefix() {
- return prefix;
- }
-
- /**
- * @return true if the server has registered a prefix on the face
- */
- public boolean isRegistered() {
- return registered;
- }
-
- /**
- * Register a prefix for responding to interests.
- *
- * @throws java.io.IOException if IO fails
- */
- public void register() throws IOException {
- registered = true;
- try {
- face.registerPrefix(prefix, this, new OnRegisterFailed() {
- @Override
- public void onRegisterFailed(Name prefix) {
- registered = false;
- logger.log(Level.SEVERE, "Failed to register prefix: " + prefix.toUri());
- }
- }, new ForwardingFlags());
- } catch (net.named_data.jndn.security.SecurityException e) {
- registered = false;
- throw new IOException("Failed to communicate to face due to security error", e);
- }
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void addPipelineStage(PipelineStage<Data, Data> pipelineStage) {
- pipeline.add(pipelineStage);
- }
-
- /**
- * Process the {@link Data} before sending it; this runs the packet through
- * each registered {@link PipelineStage} in order.
- *
- * @param data the {@link Data} to process
- * @return a processed {@link Data} packet; no guarantee as to whether it is
- * the same instance as passed in as a parameter (and likely not).
- * @throws Exception if a pipeline stage fails
- */
- public Data processPipeline(Data data) throws Exception {
- for (PipelineStage<Data, Data> stage : pipeline) {
- data = stage.process(data);
- }
- return data;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void run() {
- if (!isRegistered()) {
- try {
- register();
- } catch (IOException ex) {
- throw new RuntimeException("Failed to register prefix, aborting.", ex);
- }
- }
-
- // continuously serve packets
- while (true) {
- try {
- synchronized (face) {
- face.processEvents();
- }
- } catch (IOException ex) {
- logger.log(Level.SEVERE, "Failed to process events.", ex);
- } catch (EncodingException ex) {
- logger.log(Level.SEVERE, "Failed to parse bytes.", ex);
- }
- }
- }
-}
diff --git a/app/src/main/java/com/intel/jndn/utils/server/pipeline/CompressionStage.java b/app/src/main/java/com/intel/jndn/utils/server/pipeline/CompressionStage.java
deleted file mode 100644
index 687bde0..0000000
--- a/app/src/main/java/com/intel/jndn/utils/server/pipeline/CompressionStage.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * jndn-utils
- * Copyright (c) 2015, Intel Corporation.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU Lesser General Public License,
- * version 3, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
- * more details.
- */
-package com.intel.jndn.utils.server.pipeline;
-
-import com.intel.jndn.utils.server.PipelineStage;
-import java.io.ByteArrayOutputStream;
-import java.util.zip.GZIPOutputStream;
-import net.named_data.jndn.Data;
-import net.named_data.jndn.util.Blob;
-
-/**
- * Sample stage for compressing {@link Data} content using GZIP
- *
- * @author Andrew Brown <andrew.brown@intel.com>
- */
-public class CompressionStage implements PipelineStage<Data, Data> {
-
- /**
- * Compress and replace the {@link Data} content. Note: this stage will return
- * the same {@link Data} instance and will modify only its content.
- *
- * @param context the {@link Data} packet
- * @return the same packet but with GZIP-compressed content
- * @throws Exception if compression fails
- */
- @Override
- public Data process(Data context) throws Exception {
- ByteArrayOutputStream buffer = new ByteArrayOutputStream();
- try (GZIPOutputStream stream = new GZIPOutputStream(buffer)) {
- stream.write(context.getContent().getImmutableArray(), 0, context.getContent().size());
- stream.close();
- }
-
- context.setContent(new Blob(buffer.toByteArray()));
- return context;
- }
-
-}
diff --git a/app/src/main/java/com/intel/jndn/utils/server/pipeline/SigningStage.java b/app/src/main/java/com/intel/jndn/utils/server/pipeline/SigningStage.java
deleted file mode 100644
index 5296d89..0000000
--- a/app/src/main/java/com/intel/jndn/utils/server/pipeline/SigningStage.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * jndn-utils
- * Copyright (c) 2015, Intel Corporation.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU Lesser General Public License,
- * version 3, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
- * more details.
- */
-package com.intel.jndn.utils.server.pipeline;
-
-import com.intel.jndn.utils.server.PipelineStage;
-import net.named_data.jndn.Data;
-import net.named_data.jndn.Name;
-import net.named_data.jndn.security.KeyChain;
-import net.named_data.jndn.security.SecurityException;
-
-/**
- * As a part of a {@link com.intel.jndn.utils.ServerIn} pipeline, this stage
- * will sign a {@link Data} packet.
- *
- * @author Andrew Brown <andrew.brown@intel.com>
- */
-public class SigningStage implements PipelineStage<Data, Data> {
-
- private final KeyChain keyChain;
- private final Name certificateName;
-
- /**
- * Default constructor.
- *
- * @param keyChain the {@link KeyChain} to use for signing
- * @param certificateName the certificate to sign with
- */
- public SigningStage(KeyChain keyChain, Name certificateName) {
- this.keyChain = keyChain;
- this.certificateName = certificateName;
- }
-
- /**
- * Build the stage using the default certificate name defined on the
- * {@link KeyChain}.
- *
- * @param keyChain the {@link KeyChain} to use for signing
- * @throws SecurityException if no default certificate is found
- */
- public SigningStage(KeyChain keyChain) throws SecurityException {
- this.keyChain = keyChain;
- this.certificateName = keyChain.getDefaultCertificateName();
- }
-
- /**
- * Sign a {@link Data} packet.
- *
- * @param context the data packet to sign
- * @return the signed data packet
- * @throws Exception if signing fails
- */
- @Override
- public Data process(Data context) throws Exception {
- keyChain.sign(context, certificateName);
- return context;
- }
-}
diff --git a/app/src/main/java/net/named_data/nfd/FaceListFragment.java b/app/src/main/java/net/named_data/nfd/FaceListFragment.java
index 540201d..55d1860 100644
--- a/app/src/main/java/net/named_data/nfd/FaceListFragment.java
+++ b/app/src/main/java/net/named_data/nfd/FaceListFragment.java
@@ -45,7 +45,7 @@
import net.named_data.jndn_xx.util.FaceUri;
import net.named_data.nfd.utils.G;
-import net.named_data.nfd.utils.Nfdc;
+import net.named_data.nfd.utils.NfdcHelper;
import java.util.HashSet;
import java.util.List;
@@ -339,7 +339,7 @@
}
FaceStatus info = getItem(position);
- holder.m_faceUri.setText(info.getUri());
+ holder.m_faceUri.setText(info.getRemoteUri());
holder.m_faceId.setText(String.valueOf(info.getFaceId()));
return convertView;
@@ -369,14 +369,14 @@
protected Pair<List<FaceStatus>, Exception>
doInBackground(Void... params) {
Exception returnException = null;
- Nfdc nfdc = new Nfdc();
+ NfdcHelper nfdcHelper = new NfdcHelper();
List<FaceStatus> faceStatusList = null;
try {
- faceStatusList = nfdc.faceList();
+ faceStatusList = nfdcHelper.faceList();
} catch (Exception e) {
returnException = e;
}
- nfdc.shutdown();
+ nfdcHelper.shutdown();
return new Pair<>(faceStatusList, returnException);
}
@@ -421,17 +421,17 @@
doInBackground(Set<Integer>... params) {
Exception retval = null;
- Nfdc nfdc = new Nfdc();
+ NfdcHelper nfdcHelper = new NfdcHelper();
try {
for (Set<Integer> faces : params) {
for (int faceId : faces) {
- nfdc.faceDestroy(faceId);
+ nfdcHelper.faceDestroy(faceId);
}
}
} catch (Exception e) {
retval = e;
}
- nfdc.shutdown();
+ nfdcHelper.shutdown();
return retval;
}
@@ -471,9 +471,9 @@
doInBackground(Void... params)
{
try {
- Nfdc nfdc = new Nfdc();
- int faceId = nfdc.faceCreate(m_faceUri);
- nfdc.shutdown();
+ NfdcHelper nfdcHelper = new NfdcHelper();
+ int faceId = nfdcHelper.faceCreate(m_faceUri);
+ nfdcHelper.shutdown();
return "OK. Face id: " + String.valueOf(faceId);
}
catch (FaceUri.CanonizeError e) {
diff --git a/app/src/main/java/net/named_data/nfd/FaceStatusFragment.java b/app/src/main/java/net/named_data/nfd/FaceStatusFragment.java
index e9804cb..f37a455 100644
--- a/app/src/main/java/net/named_data/nfd/FaceStatusFragment.java
+++ b/app/src/main/java/net/named_data/nfd/FaceStatusFragment.java
@@ -31,10 +31,10 @@
import android.widget.ArrayAdapter;
import android.widget.TextView;
-import com.intel.jndn.management.types.FacePersistency;
-import com.intel.jndn.management.types.FaceScope;
+import com.intel.jndn.management.enums.FacePersistency;
+import com.intel.jndn.management.enums.FaceScope;
+import com.intel.jndn.management.enums.LinkType;
import com.intel.jndn.management.types.FaceStatus;
-import com.intel.jndn.management.types.LinkType;
import net.named_data.jndn.encoding.EncodingException;
import net.named_data.jndn.util.Blob;
@@ -110,22 +110,21 @@
// Creating list of items to be displayed
m_listItems.add(new ListItem(R.string.face_id, String.valueOf(faceStatus.getFaceId())));
m_listItems.add(new ListItem(R.string.local_face_uri, faceStatus.getLocalUri()));
- m_listItems.add(new ListItem(R.string.remote_face_uri, faceStatus.getUri()));
+ m_listItems.add(new ListItem(R.string.remote_face_uri, faceStatus.getRemoteUri()));
m_listItems.add(new ListItem(R.string.expires_in, faceStatus.getExpirationPeriod() < 0 ?
getString(R.string.expire_never) :
PeriodFormat.getDefault().print(new Period(faceStatus.getExpirationPeriod()))));
m_listItems.add(new ListItem(R.string.face_scope, getScope(faceStatus.getFaceScope())));
- m_listItems.add(new ListItem(R.string.face_persistency, getPersistency(
- faceStatus.getFacePersistency())));
+ m_listItems.add(new ListItem(R.string.face_persistency, getPersistency(faceStatus.getFacePersistency())));
m_listItems.add(new ListItem(R.string.link_type, getLinkType(faceStatus.getLinkType())));
m_listItems.add(new ListItem(R.string.in_interests, String.valueOf(
- faceStatus.getInInterests())));
- m_listItems.add(new ListItem(R.string.in_data, String.valueOf(faceStatus.getInDatas())));
+ faceStatus.getNInInterests())));
+ m_listItems.add(new ListItem(R.string.in_data, String.valueOf(faceStatus.getNInDatas())));
m_listItems.add(new ListItem(R.string.out_interests, String.valueOf(
- faceStatus.getOutInterests())));
- m_listItems.add(new ListItem(R.string.out_data, String.valueOf(faceStatus.getOutDatas())));
- m_listItems.add(new ListItem(R.string.in_bytes, String.valueOf(faceStatus.getInBytes())));
- m_listItems.add(new ListItem(R.string.out_bytes, String.valueOf(faceStatus.getOutBytes())));
+ faceStatus.getNOutInterests())));
+ m_listItems.add(new ListItem(R.string.out_data, String.valueOf(faceStatus.getNOutDatas())));
+ m_listItems.add(new ListItem(R.string.in_bytes, String.valueOf(faceStatus.getNInBytes())));
+ m_listItems.add(new ListItem(R.string.out_bytes, String.valueOf(faceStatus.getNOutBytes())));
m_faceStatusAdapter = new FaceStatusAdapter(getActivity(), m_listItems);
}
@@ -145,19 +144,19 @@
private String
getScope(FaceScope scope)
{
- return m_scopes[scope.getNumericValue()];
+ return m_scopes[scope.toInteger()];
}
private String
getPersistency(FacePersistency persistency)
{
- return m_persistencies[persistency.getNumericValue()];
+ return m_persistencies[persistency.toInteger()];
}
private String
getLinkType(LinkType linkType)
{
- return m_linkTypes[linkType.getNumericValue()];
+ return m_linkTypes[linkType.toInteger()];
}
/**
diff --git a/app/src/main/java/net/named_data/nfd/MainFragment.java b/app/src/main/java/net/named_data/nfd/MainFragment.java
index 96443c0..898b504 100644
--- a/app/src/main/java/net/named_data/nfd/MainFragment.java
+++ b/app/src/main/java/net/named_data/nfd/MainFragment.java
@@ -46,7 +46,7 @@
import net.named_data.nfd.service.NfdService;
import net.named_data.nfd.utils.G;
-import net.named_data.nfd.utils.Nfdc;
+import net.named_data.nfd.utils.NfdcHelper;
import org.joda.time.Period;
import org.joda.time.format.PeriodFormat;
@@ -104,6 +104,8 @@
m_outInterestsView = (TextView)v.findViewById(R.id.out_interests);
m_inDataView = (TextView)v.findViewById(R.id.in_data);
m_outDataView = (TextView)v.findViewById(R.id.out_data);
+ m_inNacksView = (TextView)v.findViewById(R.id.in_nacks);
+ m_outNacksView = (TextView)v.findViewById(R.id.out_nacks);
return v;
}
@@ -319,9 +321,9 @@
doInBackground(Void... voids)
{
try {
- Nfdc nfdc = new Nfdc();
- ForwarderStatus fs = nfdc.generalStatus();
- nfdc.shutdown();
+ NfdcHelper nfdcHelper = new NfdcHelper();
+ ForwarderStatus fs = nfdcHelper.generalStatus();
+ nfdcHelper.shutdown();
return fs;
}
catch (Exception e) {
@@ -343,18 +345,21 @@
m_uptimeView.setText(PeriodFormat.getDefault().print(new Period(
fs.getCurrentTimestamp() - fs.getStartTimestamp())));
m_nameTreeEntriesView.setText(String.valueOf(
- fs.getNumNameTreeEntries()));
- m_fibEntriesView.setText(String.valueOf(fs.getNumFibEntries()));
- m_pitEntriesView.setText(String.valueOf(fs.getNumPitEntries()));
+ fs.getNNameTreeEntries()));
+ m_fibEntriesView.setText(String.valueOf(fs.getNFibEntries()));
+ m_pitEntriesView.setText(String.valueOf(fs.getNPitEntries()));
m_measurementEntriesView.setText(String.valueOf(
- fs.getNumMeasurementEntries()));
- m_csEntriesView.setText(String.valueOf(fs.getNumCsEntries()));
+ fs.getNMeasurementsEntries()));
+ m_csEntriesView.setText(String.valueOf(fs.getNCsEntries()));
- m_inInterestsView.setText(String.valueOf(fs.getNumInInterests()));
- m_outInterestsView.setText(String.valueOf(
- fs.getNumOutInterests()));
- m_inDataView.setText(String.valueOf(fs.getNumInDatas()));
- m_outDataView.setText(String.valueOf(fs.getNumOutDatas()));
+ m_inInterestsView.setText(String.valueOf(fs.getNInInterests()));
+ m_outInterestsView.setText(String.valueOf(fs.getNOutInterests()));
+
+ m_inDataView.setText(String.valueOf(fs.getNInDatas()));
+ m_outDataView.setText(String.valueOf(fs.getNOutDatas()));
+
+ m_inNacksView.setText(String.valueOf(fs.getNInNacks()));
+ m_outNacksView.setText(String.valueOf(fs.getNOutNacks()));
m_nfdStatusView.setVisibility(View.VISIBLE);
@@ -392,6 +397,8 @@
private TextView m_outInterestsView;
private TextView m_inDataView;
private TextView m_outDataView;
+ private TextView m_inNacksView;
+ private TextView m_outNacksView;
private Handler m_handler;
private Runnable m_statusUpdateRunnable = new Runnable() {
diff --git a/app/src/main/java/net/named_data/nfd/RouteInfoFragment.java b/app/src/main/java/net/named_data/nfd/RouteInfoFragment.java
index a1979c4..f6e0b4f 100644
--- a/app/src/main/java/net/named_data/nfd/RouteInfoFragment.java
+++ b/app/src/main/java/net/named_data/nfd/RouteInfoFragment.java
@@ -16,6 +16,7 @@
import android.widget.TextView;
import android.widget.Toast;
+import com.intel.jndn.management.enums.RouteFlags;
import com.intel.jndn.management.types.FaceStatus;
import com.intel.jndn.management.types.RibEntry;
import com.intel.jndn.management.types.Route;
@@ -23,7 +24,7 @@
import net.named_data.jndn.encoding.EncodingException;
import net.named_data.jndn.util.Blob;
import net.named_data.nfd.utils.G;
-import net.named_data.nfd.utils.Nfdc;
+import net.named_data.nfd.utils.NfdcHelper;
import java.util.HashMap;
import java.util.List;
@@ -204,14 +205,14 @@
if (m_faces != null) {
FaceStatus status = m_faces.get(r.getFaceId());
- faceInfo += " (" + status.getUri() + ")";
+ faceInfo += " (" + status.getRemoteUri() + ")";
}
holder.m_title.setText(faceInfo);
holder.m_value.setText("origin: " + String.valueOf(r.getOrigin()) + " " +
"cost: " + String.valueOf(r.getCost()) + " " +
- (r.getFlags().getChildInherit() ? "ChildInherit " : "") +
- (r.getFlags().getCapture() ? "Capture " : "")
+ ((r.getFlags() & RouteFlags.CHILD_INHERIT.toInteger()) > 0 ? "ChildInherit " : "") +
+ ((r.getFlags() & RouteFlags.CAPTURE.toInteger()) > 0 ? "Capture " : "")
// +
// (r.getExpirationPeriod() > 0 ? "Expires in " + PeriodFormat.getDefault().print(new Period((int)(1000*r.getExpirationPeriod()))) : "")
);
@@ -243,14 +244,14 @@
protected Pair<List<FaceStatus>, Exception>
doInBackground(Void... params) {
Exception returnException = null;
- Nfdc nfdc = new Nfdc();
+ NfdcHelper nfdcHelper = new NfdcHelper();
List<FaceStatus> faceStatusList = null;
try {
- faceStatusList = nfdc.faceList();
+ faceStatusList = nfdcHelper.faceList();
} catch (Exception e) {
returnException = e;
}
- nfdc.shutdown();
+ nfdcHelper.shutdown();
return new Pair<>(faceStatusList, returnException);
}
diff --git a/app/src/main/java/net/named_data/nfd/RouteListFragment.java b/app/src/main/java/net/named_data/nfd/RouteListFragment.java
index e75fc3d..0d326b0 100644
--- a/app/src/main/java/net/named_data/nfd/RouteListFragment.java
+++ b/app/src/main/java/net/named_data/nfd/RouteListFragment.java
@@ -45,7 +45,7 @@
import net.named_data.jndn.Name;
import net.named_data.jndn_xx.util.FaceUri;
import net.named_data.nfd.utils.G;
-import net.named_data.nfd.utils.Nfdc;
+import net.named_data.nfd.utils.NfdcHelper;
import java.util.ArrayList;
import java.util.List;
@@ -64,7 +64,7 @@
*
* @param ribEntry RibEntry instance with information about the selected route
*/
- public void onRouteItemSelected(RibEntry ribEntry);
+ void onRouteItemSelected(RibEntry ribEntry);
}
@Override
@@ -315,16 +315,16 @@
@Override
protected Pair<List<RibEntry>, Exception>
doInBackground(Void... params) {
- Nfdc nfdc = new Nfdc();
+ NfdcHelper nfdcHelper = new NfdcHelper();
Exception returnException = null;
List<RibEntry> routes = null;
try {
- routes = nfdc.ribList();
+ routes = nfdcHelper.ribList();
}
catch (Exception e) {
returnException = e;
}
- nfdc.shutdown();
+ nfdcHelper.shutdown();
return new Pair<>(routes, returnException);
}
@@ -362,11 +362,11 @@
protected String
doInBackground(Void... params)
{
- Nfdc nfdc = new Nfdc();
+ NfdcHelper nfdcHelper = new NfdcHelper();
try {
- int faceId = nfdc.faceCreate(m_faceUri);
- nfdc.ribRegisterPrefix(new Name(m_prefix), faceId, 10, true, false);
- nfdc.shutdown();
+ int faceId = nfdcHelper.faceCreate(m_faceUri);
+ nfdcHelper.ribRegisterPrefix(new Name(m_prefix), faceId, 10, true, false);
+ nfdcHelper.shutdown();
return "OK";
}
catch (FaceUri.CanonizeError e) {
@@ -379,7 +379,7 @@
return "Error communicating with NFD (" + e.getMessage() + ")";
}
finally {
- nfdc.shutdown();
+ nfdcHelper.shutdown();
}
}
diff --git a/app/src/main/java/net/named_data/nfd/utils/Nfdc.java b/app/src/main/java/net/named_data/nfd/utils/Nfdc.java
deleted file mode 100644
index b376501..0000000
--- a/app/src/main/java/net/named_data/nfd/utils/Nfdc.java
+++ /dev/null
@@ -1,308 +0,0 @@
-/* -*- Mode:jde; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2015 Regents of the University of California
- *
- * This file is part of NFD (Named Data Networking Forwarding Daemon) Android.
- * See AUTHORS.md for complete list of NFD Android authors and contributors.
- *
- * NFD Android is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation,
- * either version 3 of the License, or (at your option) any later version.
- *
- * NFD Android is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * NFD Android, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
- */
-
-package net.named_data.nfd.utils;
-
-import com.intel.jndn.management.NFD;
-import com.intel.jndn.management.types.FaceStatus;
-import com.intel.jndn.management.types.ForwarderStatus;
-import com.intel.jndn.management.types.RibEntry;
-
-import net.named_data.jndn.ControlParameters;
-import net.named_data.jndn.Face;
-import net.named_data.jndn.ForwardingFlags;
-import net.named_data.jndn.Name;
-import net.named_data.jndn.security.*;
-import net.named_data.jndn.security.identity.IdentityManager;
-import net.named_data.jndn.security.identity.MemoryIdentityStorage;
-import net.named_data.jndn.security.identity.MemoryPrivateKeyStorage;
-import net.named_data.jndn.security.policy.SelfVerifyPolicyManager;
-import net.named_data.jndn.util.Blob;
-import net.named_data.jndn_xx.util.FaceUri;
-
-import java.nio.ByteBuffer;
-import java.util.List;
-
-public class Nfdc
-{
- public Nfdc()
- {
- final MemoryIdentityStorage identityStorage = new MemoryIdentityStorage();
- final MemoryPrivateKeyStorage privateKeyStorage = new MemoryPrivateKeyStorage();
- final KeyChain keyChain = new KeyChain(new IdentityManager(identityStorage, privateKeyStorage),
- new SelfVerifyPolicyManager(identityStorage));
-
- // Initialize the storage.
- Name keyName = new Name("/fake-key/ksk-1426265597681");
- Name certificateName = new Name("/fake-key/KEY/ksk-1426265597681/ID-CERT/%FD%00%00%01L%14%0D%E8%00");
-
- try {
- identityStorage.addKey(keyName, KeyType.RSA,
- new Blob(DEFAULT_RSA_PUBLIC_KEY_DER, false));
- privateKeyStorage.setKeyPairForKeyName(keyName, KeyType.RSA,
- DEFAULT_RSA_PUBLIC_KEY_DER,
- DEFAULT_RSA_PRIVATE_KEY_DER);
- }
- catch (net.named_data.jndn.security.SecurityException e) {
- // shouldn't really happen
- /// @todo add logging
- }
- m_face.setCommandSigningInfo(keyChain, certificateName);
- }
-
- public void
- shutdown()
- {
- m_face.shutdown();
- }
-
- /**
- * Get general NFD status
- */
- public ForwarderStatus
- generalStatus() throws Exception
- {
- return NFD.getForwarderStatus(m_face);
- }
-
-
- /**
- * Adds a nexthop to a FIB entry
- * <p>
- * If the FIB entry does not exist, it is inserted automatically
- */
- public void
- fibAddNextHop(Name prefix, int faceId, int cost)
- {
- }
-
- /**
- * Removes a nexthop from an existing FIB entry
- * <p>
- * If the last nexthop record in a FIB entry is removed, the FIB entry is also deleted
- */
- public void
- fibRemoveNextHop(Name prefix, int faceId)
- {
- }
-
- /**
- * Registers name to the given faceId or faceUri
- */
- public void
- ribRegisterPrefix(Name prefix, int faceId, int cost, boolean isChildInherit, boolean isCapture) throws Exception
- {
- ForwardingFlags flags = new ForwardingFlags();
- flags.setChildInherit(isChildInherit);
- flags.setCapture(isCapture);
- NFD.register(m_face,
- new ControlParameters()
- .setName(prefix)
- .setFaceId(faceId)
- .setCost(cost)
- .setForwardingFlags(flags));
- }
-
- /**
- * Unregisters name from the given faceId/faceUri
- */
- public void
- ribUnregisterPrefix(Name prefix, int faceId) throws Exception
- {
- NFD.unregister(m_face,
- new ControlParameters()
- .setName(prefix)
- .setFaceId(faceId));
- }
-
- /**
- * List all of routes (RIB entries)
- */
- public List<RibEntry>
- ribList() throws Exception
- {
- return NFD.getRouteList(m_face);
- }
-
- /**
- * Creates new face
- * <p>
- * This command allows creation of UDP unicast and TCP faces only
- */
- public int
- faceCreate(String faceUri) throws Exception, FaceUri.Error, FaceUri.CanonizeError
- {
- return NFD.createFace(m_face, new FaceUri(faceUri).canonize().toString());
- }
-
- /**
- * Destroys face
- */
- public void
- faceDestroy(int faceId) throws Exception
- {
- NFD.destroyFace(m_face, faceId);
- }
-
- /**
- * List all faces
- */
- public List<FaceStatus>
- faceList() throws Exception
- {
- return NFD.getFaceList(m_face);
- }
-
- /**
- * Sets the strategy for a namespace
- */
- public void
- strategyChoiceSet(Name namespace, Name strategy)
- {
- }
-
- /**
- * Unset the strategy for a namespace
- */
- public void
- strategyChoiceUnset(Name namespace)
- {
-
- }
-
- /////////////////////////////////////////////////////////////////////////////
-
- final private Face m_face = new Face();
-
- // temporary hack
-
- private static final ByteBuffer DEFAULT_RSA_PUBLIC_KEY_DER = toBuffer(new int[]{
- 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01,
- 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01,
- 0x00, 0xb8, 0x09, 0xa7, 0x59, 0x82, 0x84, 0xec, 0x4f, 0x06, 0xfa, 0x1c, 0xb2, 0xe1, 0x38, 0x93,
- 0x53, 0xbb, 0x7d, 0xd4, 0xac, 0x88, 0x1a, 0xf8, 0x25, 0x11, 0xe4, 0xfa, 0x1d, 0x61, 0x24, 0x5b,
- 0x82, 0xca, 0xcd, 0x72, 0xce, 0xdb, 0x66, 0xb5, 0x8d, 0x54, 0xbd, 0xfb, 0x23, 0xfd, 0xe8, 0x8e,
- 0xaf, 0xa7, 0xb3, 0x79, 0xbe, 0x94, 0xb5, 0xb7, 0xba, 0x17, 0xb6, 0x05, 0xae, 0xce, 0x43, 0xbe,
- 0x3b, 0xce, 0x6e, 0xea, 0x07, 0xdb, 0xbf, 0x0a, 0x7e, 0xeb, 0xbc, 0xc9, 0x7b, 0x62, 0x3c, 0xf5,
- 0xe1, 0xce, 0xe1, 0xd9, 0x8d, 0x9c, 0xfe, 0x1f, 0xc7, 0xf8, 0xfb, 0x59, 0xc0, 0x94, 0x0b, 0x2c,
- 0xd9, 0x7d, 0xbc, 0x96, 0xeb, 0xb8, 0x79, 0x22, 0x8a, 0x2e, 0xa0, 0x12, 0x1d, 0x42, 0x07, 0xb6,
- 0x5d, 0xdb, 0xe1, 0xf6, 0xb1, 0x5d, 0x7b, 0x1f, 0x54, 0x52, 0x1c, 0xa3, 0x11, 0x9b, 0xf9, 0xeb,
- 0xbe, 0xb3, 0x95, 0xca, 0xa5, 0x87, 0x3f, 0x31, 0x18, 0x1a, 0xc9, 0x99, 0x01, 0xec, 0xaa, 0x90,
- 0xfd, 0x8a, 0x36, 0x35, 0x5e, 0x12, 0x81, 0xbe, 0x84, 0x88, 0xa1, 0x0d, 0x19, 0x2a, 0x4a, 0x66,
- 0xc1, 0x59, 0x3c, 0x41, 0x83, 0x3d, 0x3d, 0xb8, 0xd4, 0xab, 0x34, 0x90, 0x06, 0x3e, 0x1a, 0x61,
- 0x74, 0xbe, 0x04, 0xf5, 0x7a, 0x69, 0x1b, 0x9d, 0x56, 0xfc, 0x83, 0xb7, 0x60, 0xc1, 0x5e, 0x9d,
- 0x85, 0x34, 0xfd, 0x02, 0x1a, 0xba, 0x2c, 0x09, 0x72, 0xa7, 0x4a, 0x5e, 0x18, 0xbf, 0xc0, 0x58,
- 0xa7, 0x49, 0x34, 0x46, 0x61, 0x59, 0x0e, 0xe2, 0x6e, 0x9e, 0xd2, 0xdb, 0xfd, 0x72, 0x2f, 0x3c,
- 0x47, 0xcc, 0x5f, 0x99, 0x62, 0xee, 0x0d, 0xf3, 0x1f, 0x30, 0x25, 0x20, 0x92, 0x15, 0x4b, 0x04,
- 0xfe, 0x15, 0x19, 0x1d, 0xdc, 0x7e, 0x5c, 0x10, 0x21, 0x52, 0x21, 0x91, 0x54, 0x60, 0x8b, 0x92,
- 0x41, 0x02, 0x03, 0x01, 0x00, 0x01
- });
-
- // Java uses an unencrypted PKCS #8 PrivateKeyInfo, not a PKCS #1 RSAPrivateKey.
- private static final ByteBuffer DEFAULT_RSA_PRIVATE_KEY_DER = toBuffer(new int[]{
- 0x30, 0x82, 0x04, 0xbf, 0x02, 0x01, 0x00, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7,
- 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x04, 0x82, 0x04, 0xa9, 0x30, 0x82, 0x04, 0xa5, 0x02, 0x01,
- 0x00, 0x02, 0x82, 0x01, 0x01, 0x00, 0xb8, 0x09, 0xa7, 0x59, 0x82, 0x84, 0xec, 0x4f, 0x06, 0xfa,
- 0x1c, 0xb2, 0xe1, 0x38, 0x93, 0x53, 0xbb, 0x7d, 0xd4, 0xac, 0x88, 0x1a, 0xf8, 0x25, 0x11, 0xe4,
- 0xfa, 0x1d, 0x61, 0x24, 0x5b, 0x82, 0xca, 0xcd, 0x72, 0xce, 0xdb, 0x66, 0xb5, 0x8d, 0x54, 0xbd,
- 0xfb, 0x23, 0xfd, 0xe8, 0x8e, 0xaf, 0xa7, 0xb3, 0x79, 0xbe, 0x94, 0xb5, 0xb7, 0xba, 0x17, 0xb6,
- 0x05, 0xae, 0xce, 0x43, 0xbe, 0x3b, 0xce, 0x6e, 0xea, 0x07, 0xdb, 0xbf, 0x0a, 0x7e, 0xeb, 0xbc,
- 0xc9, 0x7b, 0x62, 0x3c, 0xf5, 0xe1, 0xce, 0xe1, 0xd9, 0x8d, 0x9c, 0xfe, 0x1f, 0xc7, 0xf8, 0xfb,
- 0x59, 0xc0, 0x94, 0x0b, 0x2c, 0xd9, 0x7d, 0xbc, 0x96, 0xeb, 0xb8, 0x79, 0x22, 0x8a, 0x2e, 0xa0,
- 0x12, 0x1d, 0x42, 0x07, 0xb6, 0x5d, 0xdb, 0xe1, 0xf6, 0xb1, 0x5d, 0x7b, 0x1f, 0x54, 0x52, 0x1c,
- 0xa3, 0x11, 0x9b, 0xf9, 0xeb, 0xbe, 0xb3, 0x95, 0xca, 0xa5, 0x87, 0x3f, 0x31, 0x18, 0x1a, 0xc9,
- 0x99, 0x01, 0xec, 0xaa, 0x90, 0xfd, 0x8a, 0x36, 0x35, 0x5e, 0x12, 0x81, 0xbe, 0x84, 0x88, 0xa1,
- 0x0d, 0x19, 0x2a, 0x4a, 0x66, 0xc1, 0x59, 0x3c, 0x41, 0x83, 0x3d, 0x3d, 0xb8, 0xd4, 0xab, 0x34,
- 0x90, 0x06, 0x3e, 0x1a, 0x61, 0x74, 0xbe, 0x04, 0xf5, 0x7a, 0x69, 0x1b, 0x9d, 0x56, 0xfc, 0x83,
- 0xb7, 0x60, 0xc1, 0x5e, 0x9d, 0x85, 0x34, 0xfd, 0x02, 0x1a, 0xba, 0x2c, 0x09, 0x72, 0xa7, 0x4a,
- 0x5e, 0x18, 0xbf, 0xc0, 0x58, 0xa7, 0x49, 0x34, 0x46, 0x61, 0x59, 0x0e, 0xe2, 0x6e, 0x9e, 0xd2,
- 0xdb, 0xfd, 0x72, 0x2f, 0x3c, 0x47, 0xcc, 0x5f, 0x99, 0x62, 0xee, 0x0d, 0xf3, 0x1f, 0x30, 0x25,
- 0x20, 0x92, 0x15, 0x4b, 0x04, 0xfe, 0x15, 0x19, 0x1d, 0xdc, 0x7e, 0x5c, 0x10, 0x21, 0x52, 0x21,
- 0x91, 0x54, 0x60, 0x8b, 0x92, 0x41, 0x02, 0x03, 0x01, 0x00, 0x01, 0x02, 0x82, 0x01, 0x01, 0x00,
- 0x8a, 0x05, 0xfb, 0x73, 0x7f, 0x16, 0xaf, 0x9f, 0xa9, 0x4c, 0xe5, 0x3f, 0x26, 0xf8, 0x66, 0x4d,
- 0xd2, 0xfc, 0xd1, 0x06, 0xc0, 0x60, 0xf1, 0x9f, 0xe3, 0xa6, 0xc6, 0x0a, 0x48, 0xb3, 0x9a, 0xca,
- 0x21, 0xcd, 0x29, 0x80, 0x88, 0x3d, 0xa4, 0x85, 0xa5, 0x7b, 0x82, 0x21, 0x81, 0x28, 0xeb, 0xf2,
- 0x43, 0x24, 0xb0, 0x76, 0xc5, 0x52, 0xef, 0xc2, 0xea, 0x4b, 0x82, 0x41, 0x92, 0xc2, 0x6d, 0xa6,
- 0xae, 0xf0, 0xb2, 0x26, 0x48, 0xa1, 0x23, 0x7f, 0x02, 0xcf, 0xa8, 0x90, 0x17, 0xa2, 0x3e, 0x8a,
- 0x26, 0xbd, 0x6d, 0x8a, 0xee, 0xa6, 0x0c, 0x31, 0xce, 0xc2, 0xbb, 0x92, 0x59, 0xb5, 0x73, 0xe2,
- 0x7d, 0x91, 0x75, 0xe2, 0xbd, 0x8c, 0x63, 0xe2, 0x1c, 0x8b, 0xc2, 0x6a, 0x1c, 0xfe, 0x69, 0xc0,
- 0x44, 0xcb, 0x58, 0x57, 0xb7, 0x13, 0x42, 0xf0, 0xdb, 0x50, 0x4c, 0xe0, 0x45, 0x09, 0x8f, 0xca,
- 0x45, 0x8a, 0x06, 0xfe, 0x98, 0xd1, 0x22, 0xf5, 0x5a, 0x9a, 0xdf, 0x89, 0x17, 0xca, 0x20, 0xcc,
- 0x12, 0xa9, 0x09, 0x3d, 0xd5, 0xf7, 0xe3, 0xeb, 0x08, 0x4a, 0xc4, 0x12, 0xc0, 0xb9, 0x47, 0x6c,
- 0x79, 0x50, 0x66, 0xa3, 0xf8, 0xaf, 0x2c, 0xfa, 0xb4, 0x6b, 0xec, 0x03, 0xad, 0xcb, 0xda, 0x24,
- 0x0c, 0x52, 0x07, 0x87, 0x88, 0xc0, 0x21, 0xf3, 0x02, 0xe8, 0x24, 0x44, 0x0f, 0xcd, 0xa0, 0xad,
- 0x2f, 0x1b, 0x79, 0xab, 0x6b, 0x49, 0x4a, 0xe6, 0x3b, 0xd0, 0xad, 0xc3, 0x48, 0xb9, 0xf7, 0xf1,
- 0x34, 0x09, 0xeb, 0x7a, 0xc0, 0xd5, 0x0d, 0x39, 0xd8, 0x45, 0xce, 0x36, 0x7a, 0xd8, 0xde, 0x3c,
- 0xb0, 0x21, 0x96, 0x97, 0x8a, 0xff, 0x8b, 0x23, 0x60, 0x4f, 0xf0, 0x3d, 0xd7, 0x8f, 0xf3, 0x2c,
- 0xcb, 0x1d, 0x48, 0x3f, 0x86, 0xc4, 0xa9, 0x00, 0xf2, 0x23, 0x2d, 0x72, 0x4d, 0x66, 0xa5, 0x01,
- 0x02, 0x81, 0x81, 0x00, 0xdc, 0x4f, 0x99, 0x44, 0x0d, 0x7f, 0x59, 0x46, 0x1e, 0x8f, 0xe7, 0x2d,
- 0x8d, 0xdd, 0x54, 0xc0, 0xf7, 0xfa, 0x46, 0x0d, 0x9d, 0x35, 0x03, 0xf1, 0x7c, 0x12, 0xf3, 0x5a,
- 0x9d, 0x83, 0xcf, 0xdd, 0x37, 0x21, 0x7c, 0xb7, 0xee, 0xc3, 0x39, 0xd2, 0x75, 0x8f, 0xb2, 0x2d,
- 0x6f, 0xec, 0xc6, 0x03, 0x55, 0xd7, 0x00, 0x67, 0xd3, 0x9b, 0xa2, 0x68, 0x50, 0x6f, 0x9e, 0x28,
- 0xa4, 0x76, 0x39, 0x2b, 0xb2, 0x65, 0xcc, 0x72, 0x82, 0x93, 0xa0, 0xcf, 0x10, 0x05, 0x6a, 0x75,
- 0xca, 0x85, 0x35, 0x99, 0xb0, 0xa6, 0xc6, 0xef, 0x4c, 0x4d, 0x99, 0x7d, 0x2c, 0x38, 0x01, 0x21,
- 0xb5, 0x31, 0xac, 0x80, 0x54, 0xc4, 0x18, 0x4b, 0xfd, 0xef, 0xb3, 0x30, 0x22, 0x51, 0x5a, 0xea,
- 0x7d, 0x9b, 0xb2, 0x9d, 0xcb, 0xba, 0x3f, 0xc0, 0x1a, 0x6b, 0xcd, 0xb0, 0xe6, 0x2f, 0x04, 0x33,
- 0xd7, 0x3a, 0x49, 0x71, 0x02, 0x81, 0x81, 0x00, 0xd5, 0xd9, 0xc9, 0x70, 0x1a, 0x13, 0xb3, 0x39,
- 0x24, 0x02, 0xee, 0xb0, 0xbb, 0x84, 0x17, 0x12, 0xc6, 0xbd, 0x65, 0x73, 0xe9, 0x34, 0x5d, 0x43,
- 0xff, 0xdc, 0xf8, 0x55, 0xaf, 0x2a, 0xb9, 0xe1, 0xfa, 0x71, 0x65, 0x4e, 0x50, 0x0f, 0xa4, 0x3b,
- 0xe5, 0x68, 0xf2, 0x49, 0x71, 0xaf, 0x15, 0x88, 0xd7, 0xaf, 0xc4, 0x9d, 0x94, 0x84, 0x6b, 0x5b,
- 0x10, 0xd5, 0xc0, 0xaa, 0x0c, 0x13, 0x62, 0x99, 0xc0, 0x8b, 0xfc, 0x90, 0x0f, 0x87, 0x40, 0x4d,
- 0x58, 0x88, 0xbd, 0xe2, 0xba, 0x3e, 0x7e, 0x2d, 0xd7, 0x69, 0xa9, 0x3c, 0x09, 0x64, 0x31, 0xb6,
- 0xcc, 0x4d, 0x1f, 0x23, 0xb6, 0x9e, 0x65, 0xd6, 0x81, 0xdc, 0x85, 0xcc, 0x1e, 0xf1, 0x0b, 0x84,
- 0x38, 0xab, 0x93, 0x5f, 0x9f, 0x92, 0x4e, 0x93, 0x46, 0x95, 0x6b, 0x3e, 0xb6, 0xc3, 0x1b, 0xd7,
- 0x69, 0xa1, 0x0a, 0x97, 0x37, 0x78, 0xed, 0xd1, 0x02, 0x81, 0x80, 0x33, 0x18, 0xc3, 0x13, 0x65,
- 0x8e, 0x03, 0xc6, 0x9f, 0x90, 0x00, 0xae, 0x30, 0x19, 0x05, 0x6f, 0x3c, 0x14, 0x6f, 0xea, 0xf8,
- 0x6b, 0x33, 0x5e, 0xee, 0xc7, 0xf6, 0x69, 0x2d, 0xdf, 0x44, 0x76, 0xaa, 0x32, 0xba, 0x1a, 0x6e,
- 0xe6, 0x18, 0xa3, 0x17, 0x61, 0x1c, 0x92, 0x2d, 0x43, 0x5d, 0x29, 0xa8, 0xdf, 0x14, 0xd8, 0xff,
- 0xdb, 0x38, 0xef, 0xb8, 0xb8, 0x2a, 0x96, 0x82, 0x8e, 0x68, 0xf4, 0x19, 0x8c, 0x42, 0xbe, 0xcc,
- 0x4a, 0x31, 0x21, 0xd5, 0x35, 0x6c, 0x5b, 0xa5, 0x7c, 0xff, 0xd1, 0x85, 0x87, 0x28, 0xdc, 0x97,
- 0x75, 0xe8, 0x03, 0x80, 0x1d, 0xfd, 0x25, 0x34, 0x41, 0x31, 0x21, 0x12, 0x87, 0xe8, 0x9a, 0xb7,
- 0x6a, 0xc0, 0xc4, 0x89, 0x31, 0x15, 0x45, 0x0d, 0x9c, 0xee, 0xf0, 0x6a, 0x2f, 0xe8, 0x59, 0x45,
- 0xc7, 0x7b, 0x0d, 0x6c, 0x55, 0xbb, 0x43, 0xca, 0xc7, 0x5a, 0x01, 0x02, 0x81, 0x81, 0x00, 0xab,
- 0xf4, 0xd5, 0xcf, 0x78, 0x88, 0x82, 0xc2, 0xdd, 0xbc, 0x25, 0xe6, 0xa2, 0xc1, 0xd2, 0x33, 0xdc,
- 0xef, 0x0a, 0x97, 0x2b, 0xdc, 0x59, 0x6a, 0x86, 0x61, 0x4e, 0xa6, 0xc7, 0x95, 0x99, 0xa6, 0xa6,
- 0x55, 0x6c, 0x5a, 0x8e, 0x72, 0x25, 0x63, 0xac, 0x52, 0xb9, 0x10, 0x69, 0x83, 0x99, 0xd3, 0x51,
- 0x6c, 0x1a, 0xb3, 0x83, 0x6a, 0xff, 0x50, 0x58, 0xb7, 0x28, 0x97, 0x13, 0xe2, 0xba, 0x94, 0x5b,
- 0x89, 0xb4, 0xea, 0xba, 0x31, 0xcd, 0x78, 0xe4, 0x4a, 0x00, 0x36, 0x42, 0x00, 0x62, 0x41, 0xc6,
- 0x47, 0x46, 0x37, 0xea, 0x6d, 0x50, 0xb4, 0x66, 0x8f, 0x55, 0x0c, 0xc8, 0x99, 0x91, 0xd5, 0xec,
- 0xd2, 0x40, 0x1c, 0x24, 0x7d, 0x3a, 0xff, 0x74, 0xfa, 0x32, 0x24, 0xe0, 0x11, 0x2b, 0x71, 0xad,
- 0x7e, 0x14, 0xa0, 0x77, 0x21, 0x68, 0x4f, 0xcc, 0xb6, 0x1b, 0xe8, 0x00, 0x49, 0x13, 0x21, 0x02,
- 0x81, 0x81, 0x00, 0xb6, 0x18, 0x73, 0x59, 0x2c, 0x4f, 0x92, 0xac, 0xa2, 0x2e, 0x5f, 0xb6, 0xbe,
- 0x78, 0x5d, 0x47, 0x71, 0x04, 0x92, 0xf0, 0xd7, 0xe8, 0xc5, 0x7a, 0x84, 0x6b, 0xb8, 0xb4, 0x30,
- 0x1f, 0xd8, 0x0d, 0x58, 0xd0, 0x64, 0x80, 0xa7, 0x21, 0x1a, 0x48, 0x00, 0x37, 0xd6, 0x19, 0x71,
- 0xbb, 0x91, 0x20, 0x9d, 0xe2, 0xc3, 0xec, 0xdb, 0x36, 0x1c, 0xca, 0x48, 0x7d, 0x03, 0x32, 0x74,
- 0x1e, 0x65, 0x73, 0x02, 0x90, 0x73, 0xd8, 0x3f, 0xb5, 0x52, 0x35, 0x79, 0x1c, 0xee, 0x93, 0xa3,
- 0x32, 0x8b, 0xed, 0x89, 0x98, 0xf1, 0x0c, 0xd8, 0x12, 0xf2, 0x89, 0x7f, 0x32, 0x23, 0xec, 0x67,
- 0x66, 0x52, 0x83, 0x89, 0x99, 0x5e, 0x42, 0x2b, 0x42, 0x4b, 0x84, 0x50, 0x1b, 0x3e, 0x47, 0x6d,
- 0x74, 0xfb, 0xd1, 0xa6, 0x10, 0x20, 0x6c, 0x6e, 0xbe, 0x44, 0x3f, 0xb9, 0xfe, 0xbc, 0x8d, 0xda,
- 0xcb, 0xea, 0x8f
- });
-
- private static ByteBuffer
- toBuffer(int[] array)
- {
- ByteBuffer result = ByteBuffer.allocate(array.length);
- for (int i = 0; i < array.length; ++i)
- result.put((byte) (array[i] & 0xff));
-
- result.flip();
- return result;
- }
-}
diff --git a/app/src/main/java/net/named_data/nfd/utils/NfdcHelper.java b/app/src/main/java/net/named_data/nfd/utils/NfdcHelper.java
new file mode 100644
index 0000000..35854f0
--- /dev/null
+++ b/app/src/main/java/net/named_data/nfd/utils/NfdcHelper.java
@@ -0,0 +1,186 @@
+/* -*- Mode:jde; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2015 Regents of the University of California
+ *
+ * This file is part of NFD (Named Data Networking Forwarding Daemon) Android.
+ * See AUTHORS.md for complete list of NFD Android authors and contributors.
+ *
+ * NFD Android is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * NFD Android is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * NFD Android, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package net.named_data.nfd.utils;
+
+import com.intel.jndn.management.ManagementException;
+import com.intel.jndn.management.Nfdc;
+import com.intel.jndn.management.types.FaceStatus;
+import com.intel.jndn.management.types.ForwarderStatus;
+import com.intel.jndn.management.types.RibEntry;
+
+import net.named_data.jndn.ControlParameters;
+import net.named_data.jndn.Face;
+import net.named_data.jndn.ForwardingFlags;
+import net.named_data.jndn.Name;
+import net.named_data.jndn.security.*;
+import net.named_data.jndn.security.SecurityException;
+import net.named_data.jndn.security.identity.IdentityManager;
+import net.named_data.jndn.security.identity.MemoryIdentityStorage;
+import net.named_data.jndn.security.identity.MemoryPrivateKeyStorage;
+import net.named_data.jndn.security.policy.SelfVerifyPolicyManager;
+import net.named_data.jndn_xx.util.FaceUri;
+
+import java.util.List;
+
+public class NfdcHelper
+{
+ public NfdcHelper()
+ {
+ m_face = new Face("localhost");
+ try {
+ m_face.setCommandSigningInfo(s_keyChain, s_keyChain.getDefaultCertificateName());
+ }
+ catch (SecurityException e) {
+ // shouldn't really happen
+ /// @todo add logging
+ }
+ }
+
+ public void
+ shutdown()
+ {
+ m_face.shutdown();
+ }
+
+ /**
+ * Get general NFD status
+ */
+ public ForwarderStatus
+ generalStatus() throws Exception
+ {
+ return Nfdc.getForwarderStatus(m_face);
+ }
+
+ /**
+ * Registers name to the given faceId or faceUri
+ */
+ public void
+ ribRegisterPrefix(Name prefix, int faceId, int cost, boolean isChildInherit, boolean isCapture) throws Exception
+ {
+ ForwardingFlags flags = new ForwardingFlags();
+ flags.setChildInherit(isChildInherit);
+ flags.setCapture(isCapture);
+ Nfdc.register(m_face,
+ new ControlParameters()
+ .setName(prefix)
+ .setFaceId(faceId)
+ .setCost(cost)
+ .setForwardingFlags(flags));
+ }
+
+ /**
+ * Unregisters name from the given faceId/faceUri
+ */
+ public void
+ ribUnregisterPrefix(Name prefix, int faceId) throws Exception
+ {
+ Nfdc.unregister(m_face,
+ new ControlParameters()
+ .setName(prefix)
+ .setFaceId(faceId));
+ }
+
+ /**
+ * List all of routes (RIB entries)
+ */
+ public List<RibEntry>
+ ribList() throws Exception
+ {
+ return Nfdc.getRouteList(m_face);
+ }
+
+ /**
+ * Creates new face
+ * <p>
+ * This command allows creation of UDP unicast and TCP faces only
+ */
+ public int
+ faceCreate(String faceUri) throws ManagementException, FaceUri.Error, FaceUri.CanonizeError
+ {
+ return Nfdc.createFace(m_face, new FaceUri(faceUri).canonize().toString());
+ }
+
+ /**
+ * Destroys face
+ */
+ public void
+ faceDestroy(int faceId) throws Exception
+ {
+ Nfdc.destroyFace(m_face, faceId);
+ }
+
+ /**
+ * List all faces
+ */
+ public List<FaceStatus>
+ faceList() throws Exception
+ {
+ return Nfdc.getFaceList(m_face);
+ }
+
+// /**
+// * Sets the strategy for a namespace
+// */
+// public void
+// strategyChoiceSet(Name namespace, Name strategy)
+// {
+// }
+//
+// /**
+// * Unset the strategy for a namespace
+// */
+// public void
+// strategyChoiceUnset(Name namespace)
+// {
+// }
+
+ /////////////////////////////////////////////////////////////////////////////
+
+ private static KeyChain
+ configureKeyChain() {
+ final MemoryIdentityStorage identityStorage = new MemoryIdentityStorage();
+ final MemoryPrivateKeyStorage privateKeyStorage = new MemoryPrivateKeyStorage();
+ final KeyChain keyChain = new KeyChain(new IdentityManager(identityStorage, privateKeyStorage),
+ new SelfVerifyPolicyManager(identityStorage));
+
+ Name name = new Name("/tmp-identity");
+
+ try {
+ // create keys, certs if necessary
+ if (!identityStorage.doesIdentityExist(name)) {
+ keyChain.createIdentityAndCertificate(name);
+
+ // set default identity
+ keyChain.getIdentityManager().setDefaultIdentity(name);
+ }
+ }
+ catch (SecurityException e){
+ // shouldn't really happen
+ /// @todo add logging
+ }
+
+ return keyChain;
+ }
+
+ /////////////////////////////////////////////////////////////////////////////
+
+ final static KeyChain s_keyChain = configureKeyChain();
+ private Face m_face;
+}
diff --git a/app/src/main/res/layout/fragment_main.xml b/app/src/main/res/layout/fragment_main.xml
index 7a8c93a..2fb1d1f 100644
--- a/app/src/main/res/layout/fragment_main.xml
+++ b/app/src/main/res/layout/fragment_main.xml
@@ -126,6 +126,21 @@
style="@style/main_fragment_list_value" />
</LinearLayout>
+ <LinearLayout style="@style/main_fragment_linear_layout">
+ <TextView style="@style/main_fragment_list_title"
+ android:text="@string/in_nacks" />
+
+ <TextView android:id="@+id/in_nacks"
+ style="@style/main_fragment_list_value" />
+ </LinearLayout>
+
+ <LinearLayout style="@style/main_fragment_linear_layout">
+ <TextView style="@style/main_fragment_list_title"
+ android:text="@string/out_nacks" />
+
+ <TextView android:id="@+id/out_nacks"
+ style="@style/main_fragment_list_value" />
+ </LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 9f65d2d..5691bdd 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -48,10 +48,12 @@
<string name="out_data">Out data</string>
<string name="in_bytes">In bytes</string>
<string name="out_bytes">Out bytes</string>
+ <string name="in_nacks">In NACKs</string>
+ <string name="out_nacks">Out NACKs</string>
<string-array name="face_scopes">
- <item>Local</item>
<item>Non-local</item>
+ <item>Local</item>
</string-array>
<string-array name="face_persistency">