face+transport: Cleanup and preparation for implementation of fully async Face operations

Change-Id: I7816b6a9c99a0cf4825459b9652372d6585a5191
diff --git a/src/util/ndnd-id-fetcher.hpp b/src/util/ndnd-id-fetcher.hpp
new file mode 100644
index 0000000..1a938f9
--- /dev/null
+++ b/src/util/ndnd-id-fetcher.hpp
@@ -0,0 +1,77 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+/**
+ * Copyright (C) 2013 Regents of the University of California.
+ * @author: Jeff Thompson <jefft0@remap.ucla.edu>
+ * See COPYING for copyright and distribution information.
+ */
+
+#ifndef NDN_NDND_ID_FETCHER_HPP
+#define NDN_NDND_ID_FETCHER_HPP
+
+#include <ndn-cpp/common.hpp>
+#include "../c/util/crypto.h"
+
+namespace ndn {
+
+/**
+ * An NdndIdFetcher receives the Data packet with the publisher public key digest for the connected NDN hub.
+ * This class is a function object for the callbacks. It only holds a pointer to an Info object, so it is OK to copy the pointer.
+ */
+class NdndIdFetcher {
+public:
+  typedef func_lib::function<void (void)> OnSuccess;
+  typedef func_lib::function<void (void)> OnFailure;
+  
+  
+  class Info;
+  NdndIdFetcher(Buffer &ndndId, const OnSuccess& onSuccess, const OnFailure& onFailure)
+    : ndndId_(ndndId)
+    , onSuccess_(onSuccess)
+    , onFailure_(onFailure)
+  {
+  }
+    
+  /**
+   * We received the ndnd ID.
+   * @param interest
+   * @param data
+   */
+  inline void 
+  operator()(const ptr_lib::shared_ptr<const Interest>& interest, const ptr_lib::shared_ptr<Data>& ndndIdData);
+
+  /**
+   * We timed out fetching the ndnd ID.
+   * @param interest
+   */
+  inline void 
+  operator()(const ptr_lib::shared_ptr<const Interest>& timedOutInterest);
+
+private:
+  Buffer &ndndId_;
+  OnSuccess onSuccess_;
+  OnFailure onFailure_;
+};
+
+void 
+NdndIdFetcher::operator()(const ptr_lib::shared_ptr<const Interest>& interest, const ptr_lib::shared_ptr<Data>& ndndIdData)
+{
+  if (ndndIdData->getSignature().getType() == Signature::SignatureSha256WithRsa)
+    {
+      ndndId_.resize(32);
+      ndn_digestSha256(ndndIdData->getSignature().getValue().value(), ndndIdData->getSignature().getValue().value_size(), ndndId_.buf());
+      onSuccess_();
+    }
+  else
+    onFailure_();
+}
+
+void 
+NdndIdFetcher::operator()(const ptr_lib::shared_ptr<const Interest>& timedOutInterest)
+{
+  onFailure_();
+}
+
+
+} // namespace ndn
+
+#endif // NDN_NDND_ID_FETCHER_HPP