Fix compilation with latest ndn-cxx

Change-Id: Iaf468a75466134d18ecbb1fef66e4cb401d781a4
diff --git a/src/boost-header.h b/src/boost-header.h
deleted file mode 100644
index aca4ba8..0000000
--- a/src/boost-header.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2012-2014 University of California, Los Angeles
- *
- * This file is part of ChronoSync, synchronization library for distributed realtime
- * applications for NDN.
- *
- * ChronoSync 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.
- *
- * ChronoSync 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
- * ChronoSync, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
- *
- * @author Yingdi Yu <yingdi@cs.ucla.edu>
- */
-
-#ifndef BOOST_HEADER_HPP
-#define BOOST_HEADER_HPP
-
-// suppress Boost warnings
-#pragma GCC system_header
-#pragma clang system_header
-
-#include <boost/random.hpp>
-
-#include <boost/assert.hpp>
-#include <boost/throw_exception.hpp>
-
-#include <boost/iterator/transform_iterator.hpp>
-#include <boost/archive/iterators/dataflow_exception.hpp>
-#include <boost/archive/iterators/transform_width.hpp>
-
-#endif // BOOST_HEADER_HPP
diff --git a/src/diff-state-container.hpp b/src/diff-state-container.hpp
index d20fbee..f03caf1 100644
--- a/src/diff-state-container.hpp
+++ b/src/diff-state-container.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
 /*
- * Copyright (c) 2012-2014 University of California, Los Angeles
+ * Copyright (c) 2012-2017 University of California, Los Angeles
  *
  * This file is part of ChronoSync, synchronization library for distributed realtime
  * applications for NDN.
@@ -42,7 +42,7 @@
 struct DigestPtrHash
 {
   std::size_t
-  operator()(ndn::ConstBufferPtr digest) const
+  operator()(ConstBufferPtr digest) const
   {
     BOOST_ASSERT(digest->size() > sizeof(std::size_t));
 
@@ -53,7 +53,7 @@
 struct DigestPtrEqual
 {
   bool
-  operator()(ndn::ConstBufferPtr digest1, ndn::ConstBufferPtr digest2) const
+  operator()(ConstBufferPtr digest1, ConstBufferPtr digest2) const
   {
     return *digest1 == *digest2;
   }
@@ -68,7 +68,7 @@
     // For fast access to elements using DiffState hashes
     mi::hashed_unique<
       mi::tag<hashed>,
-      mi::const_mem_fun<DiffState, ndn::ConstBufferPtr, &DiffState::getRootDigest>,
+      mi::const_mem_fun<DiffState, ConstBufferPtr, &DiffState::getRootDigest>,
       DigestPtrHash,
       DigestPtrEqual
       >,
diff --git a/src/diff-state.hpp b/src/diff-state.hpp
index 46ed412..7a59e3a 100644
--- a/src/diff-state.hpp
+++ b/src/diff-state.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
 /*
- * Copyright (c) 2012-2014 University of California, Los Angeles
+ * Copyright (c) 2012-2017 University of California, Los Angeles
  *
  * This file is part of ChronoSync, synchronization library for distributed realtime
  * applications for NDN.
@@ -30,8 +30,8 @@
 namespace chronosync {
 
 class DiffState;
-typedef shared_ptr<DiffState> DiffStatePtr;
-typedef shared_ptr<const DiffState> ConstDiffStatePtr;
+using DiffStatePtr = shared_ptr<DiffState>;
+using ConstDiffStatePtr = shared_ptr<const DiffState>;
 
 /**
  * @brief Contains the diff info between two states.
@@ -67,7 +67,7 @@
    * @param digest root digest of the full state
    */
   void
-  setRootDigest(ndn::ConstBufferPtr digest)
+  setRootDigest(ConstBufferPtr digest)
   {
     m_digest = digest;
   }
@@ -75,7 +75,7 @@
   /**
    * @brief Get root digest of the full state after applying the diff state
    */
-  ndn::ConstBufferPtr
+  ConstBufferPtr
   getRootDigest() const
   {
     return m_digest;
@@ -95,10 +95,10 @@
   diff() const;
 
 private:
-  ConstDiffStatePtr   m_next;
-  ndn::ConstBufferPtr m_digest;
+  ConstDiffStatePtr m_next;
+  ConstBufferPtr m_digest;
 };
 
-} // chronosync
+} // namespace chronosync
 
 #endif // CHRONOSYNC_DIFF_STATE_HPP
diff --git a/src/interest-container.cpp b/src/interest-container.cpp
index 4d42321..3a5e5f4 100644
--- a/src/interest-container.cpp
+++ b/src/interest-container.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
 /*
- * Copyright (c) 2012-2014 University of California, Los Angeles
+ * Copyright (c) 2012-2017 University of California, Los Angeles
  *
  * This file is part of ChronoSync, synchronization library for distributed realtime
  * applications for NDN.
@@ -26,8 +26,8 @@
 
 namespace chronosync {
 
-UnsatisfiedInterest::UnsatisfiedInterest(shared_ptr<const Interest> interest,
-                                         ndn::ConstBufferPtr digest,
+UnsatisfiedInterest::UnsatisfiedInterest(const Interest& interest,
+                                         ConstBufferPtr digest,
                                          bool isUnknown)
   : interest(interest)
   , digest(digest)
diff --git a/src/interest-container.hpp b/src/interest-container.hpp
index bf971eb..de7043a 100644
--- a/src/interest-container.hpp
+++ b/src/interest-container.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
 /*
- * Copyright (c) 2012-2014 University of California, Los Angeles
+ * Copyright (c) 2012-2017 University of California, Los Angeles
  *
  * This file is part of ChronoSync, synchronization library for distributed realtime
  * applications for NDN.
@@ -29,9 +29,6 @@
 #include "mi-tag.hpp"
 #include "diff-state-container.hpp"
 
-#include <ndn-cxx/util/time.hpp>
-#include <ndn-cxx/util/scheduler.hpp>
-
 #include <boost/multi_index_container.hpp>
 #include <boost/multi_index/tag.hpp>
 #include <boost/multi_index/hashed_index.hpp>
@@ -46,19 +43,19 @@
 class UnsatisfiedInterest : noncopyable
 {
 public:
-  UnsatisfiedInterest(shared_ptr<const Interest> interest,
-                      ndn::ConstBufferPtr digest,
+  UnsatisfiedInterest(const Interest& interest,
+                      ConstBufferPtr digest,
                       bool isUnknown = false);
 
 public:
-  shared_ptr<const Interest> interest;
-  ndn::ConstBufferPtr        digest;
-  bool                       isUnknown;
-  ndn::EventId               expirationEvent;
+  const Interest interest;
+  ConstBufferPtr digest;
+  bool           isUnknown;
+  ndn::EventId   expirationEvent;
 };
 
-typedef shared_ptr<UnsatisfiedInterest> UnsatisfiedInterestPtr;
-typedef shared_ptr<const UnsatisfiedInterest> ConstUnsatisfiedInterestPtr;
+using UnsatisfiedInterestPtr = shared_ptr<UnsatisfiedInterest>;
+using ConstUnsatisfiedInterestPtr = shared_ptr<const UnsatisfiedInterest>;
 
 /**
  * @brief Container for unsatisfied Sync Interests
@@ -68,7 +65,7 @@
   mi::indexed_by<
     mi::hashed_unique<
       mi::tag<hashed>,
-      mi::member<UnsatisfiedInterest, ndn::ConstBufferPtr, &UnsatisfiedInterest::digest>,
+      mi::member<UnsatisfiedInterest, ConstBufferPtr, &UnsatisfiedInterest::digest>,
       DigestPtrHash,
       DigestPtrEqual
       >
diff --git a/src/interest-table.cpp b/src/interest-table.cpp
index efe7fef..2b3c9d6 100644
--- a/src/interest-table.cpp
+++ b/src/interest-table.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
 /*
- * Copyright (c) 2012-2014 University of California, Los Angeles
+ * Copyright (c) 2012-2017 University of California, Los Angeles
  *
  * This file is part of ChronoSync, synchronization library for distributed realtime
  * applications for NDN.
@@ -37,38 +37,35 @@
 }
 
 void
-InterestTable::insert(shared_ptr<const Interest> interest,
-                      ndn::ConstBufferPtr digest,
-                      bool isKnown/*=false*/)
+InterestTable::insert(const Interest& interest, ConstBufferPtr digest, bool isKnown/*=false*/)
 {
   erase(digest);
 
-  UnsatisfiedInterestPtr request =
-    make_shared<UnsatisfiedInterest>(interest, digest, isKnown);
+  auto request = make_shared<UnsatisfiedInterest>(interest, digest, isKnown);
 
-  time::milliseconds entryLifetime = interest->getInterestLifetime();
+  time::milliseconds entryLifetime = interest.getInterestLifetime();
   if (entryLifetime < time::milliseconds::zero())
     entryLifetime = ndn::DEFAULT_INTEREST_LIFETIME;
 
-  request->expirationEvent =
-    m_scheduler.scheduleEvent(entryLifetime,
-                              [=] () { erase(digest); });
+  request->expirationEvent = m_scheduler.scheduleEvent(entryLifetime, [=] { erase(digest); });
 
   m_table.insert(request);
 }
 
 void
-InterestTable::erase(ndn::ConstBufferPtr digest)
+InterestTable::erase(ConstBufferPtr digest)
 {
-  InterestContainer::index<hashed>::type::iterator it = m_table.get<hashed>().find(digest);
-  if (it != m_table.get<hashed>().end()) {
+  auto it = m_table.get<hashed>().find(digest);
+  while (it != m_table.get<hashed>().end()) {
     m_scheduler.cancelEvent((*it)->expirationEvent);
     m_table.erase(it);
+
+    it = m_table.get<hashed>().find(digest);
   }
 }
 
 bool
-InterestTable::has(ndn::ConstBufferPtr digest)
+InterestTable::has(ConstBufferPtr digest)
 {
   if (m_table.get<hashed>().find(digest) != m_table.get<hashed>().end())
     return true;
@@ -85,12 +82,11 @@
 void
 InterestTable::clear()
 {
-  for (InterestContainer::iterator it = m_table.begin();
-       it != m_table.end(); it++) {
-    m_scheduler.cancelEvent((*it)->expirationEvent);
+  for (const auto& item : m_table) {
+    m_scheduler.cancelEvent(item->expirationEvent);
   }
 
   m_table.clear();
 }
 
-}
+} // namespace chronosync
diff --git a/src/interest-table.hpp b/src/interest-table.hpp
index 5292a69..bf5685b 100644
--- a/src/interest-table.hpp
+++ b/src/interest-table.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
 /*
- * Copyright (c) 2012-2014 University of California, Los Angeles
+ * Copyright (c) 2012-2017 University of California, Los Angeles
  *
  * This file is part of ChronoSync, synchronization library for distributed realtime
  * applications for NDN.
@@ -27,8 +27,6 @@
 
 #include "interest-container.hpp"
 
-#include <ndn-cxx/util/scheduler.hpp>
-
 namespace chronosync {
 
 /**
@@ -47,8 +45,8 @@
     }
   };
 
-  typedef InterestContainer::iterator iterator;
-  typedef InterestContainer::const_iterator const_iterator;
+  using iterator = InterestContainer::iterator;
+  using const_iterator = InterestContainer::const_iterator;
 
   explicit
   InterestTable(boost::asio::io_service& io);
@@ -69,17 +67,15 @@
    * @param isKnown  false if the digest is an unknown digest.
    */
   void
-  insert(shared_ptr<const Interest> interest,
-         ndn::ConstBufferPtr digest,
-         bool isKnown = false);
+  insert(const Interest& interest, ConstBufferPtr digest, bool isKnown = false);
 
   /// @brief check if an interest with the digest exists in the table
   bool
-  has(ndn::ConstBufferPtr digest);
+  has(ConstBufferPtr digest);
 
   /// @brief Delete interest by digest (e.g., when it was satisfied)
   void
-  erase(ndn::ConstBufferPtr digest);
+  erase(ConstBufferPtr digest);
 
   const_iterator
   begin() const
@@ -113,9 +109,6 @@
 
 private:
   ndn::Scheduler m_scheduler;
-  ndn::time::steady_clock::Duration m_entryLifetime;
-  ndn::time::steady_clock::Duration m_cleanPeriod;
-
   InterestContainer m_table;
 };
 
diff --git a/src/leaf-container.hpp b/src/leaf-container.hpp
index e1d30bd..f08f8f9 100644
--- a/src/leaf-container.hpp
+++ b/src/leaf-container.hpp
@@ -44,7 +44,7 @@
   std::size_t
   operator()(const Name& prefix) const
   {
-    ndn::ConstBufferPtr buffer =
+    ConstBufferPtr buffer =
       ndn::util::Sha256::computeDigest(prefix.wireEncode().wire(), prefix.wireEncode().size());
 
     BOOST_ASSERT(buffer->size() > sizeof(std::size_t));
diff --git a/src/leaf.cpp b/src/leaf.cpp
index 129b1ea..2bf6325 100644
--- a/src/leaf.cpp
+++ b/src/leaf.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
 /*
- * Copyright (c) 2012-2014 University of California, Los Angeles
+ * Copyright (c) 2012-2017 University of California, Los Angeles
  *
  * This file is part of ChronoSync, synchronization library for distributed realtime
  * applications for NDN.
@@ -44,7 +44,7 @@
 {
 }
 
-ndn::ConstBufferPtr
+ConstBufferPtr
 Leaf::getDigest() const
 {
   return m_digest.computeDigest();
diff --git a/src/leaf.hpp b/src/leaf.hpp
index 4c8223d..63284b8 100644
--- a/src/leaf.hpp
+++ b/src/leaf.hpp
@@ -26,11 +26,12 @@
 #define CHRONOSYNC_LEAF_HPP
 
 #include "common.hpp"
+
 #include <ndn-cxx/util/sha256.hpp>
 
 namespace chronosync {
 
-typedef uint64_t SeqNo;
+using SeqNo = uint64_t;
 
 /**
  * @brief Sync tree leaf
@@ -59,7 +60,7 @@
     return m_seq;
   }
 
-  ndn::ConstBufferPtr
+  ConstBufferPtr
   getDigest() const;
 
   /**
@@ -82,8 +83,8 @@
   mutable ndn::util::Sha256 m_digest;
 };
 
-typedef shared_ptr<Leaf> LeafPtr;
-typedef shared_ptr<const Leaf> ConstLeafPtr;
+using LeafPtr = shared_ptr<Leaf>;
+using ConstLeafPtr = shared_ptr<const Leaf>;
 
 std::ostream&
 operator<<(std::ostream& os, const Leaf& leaf);
diff --git a/src/logic.cpp b/src/logic.cpp
index d3e5f11..44115eb 100644
--- a/src/logic.cpp
+++ b/src/logic.cpp
@@ -38,7 +38,6 @@
 
 namespace chronosync {
 
-using ndn::ConstBufferPtr;
 using ndn::EventId;
 
 const uint8_t EMPTY_DIGEST_VALUE[] = {
@@ -49,12 +48,12 @@
 };
 
 #ifdef _DEBUG
-int Logic::m_instanceCounter = 0;
+int Logic::s_instanceCounter = 0;
 #endif
 
 const ndn::Name Logic::DEFAULT_NAME;
 const ndn::Name Logic::EMPTY_NAME;
-const std::shared_ptr<ndn::Validator> Logic::DEFAULT_VALIDATOR;
+const std::shared_ptr<Validator> Logic::DEFAULT_VALIDATOR;
 const time::steady_clock::Duration Logic::DEFAULT_RESET_TIMER = time::seconds(0);
 const time::steady_clock::Duration Logic::DEFAULT_CANCEL_RESET_TIMER = time::milliseconds(500);
 const time::milliseconds Logic::DEFAULT_RESET_INTEREST_LIFETIME(1000);
@@ -62,7 +61,7 @@
 const time::milliseconds Logic::DEFAULT_SYNC_REPLY_FRESHNESS(1000);
 const time::milliseconds Logic::DEFAULT_RECOVERY_INTEREST_LIFETIME(1000);
 
-const ndn::ConstBufferPtr Logic::EMPTY_DIGEST(new ndn::Buffer(EMPTY_DIGEST_VALUE, 32));
+const ConstBufferPtr Logic::EMPTY_DIGEST(new ndn::Buffer(EMPTY_DIGEST_VALUE, 32));
 const ndn::name::Component Logic::RESET_COMPONENT("reset");
 const ndn::name::Component Logic::RECOVERY_COMPONENT("recovery");
 
@@ -71,7 +70,7 @@
              const Name& defaultUserPrefix,
              const UpdateCallback& onUpdate,
              const Name& defaultSigningId,
-             std::shared_ptr<ndn::Validator> validator,
+             std::shared_ptr<Validator> validator,
              const time::steady_clock::Duration& resetTimer,
              const time::steady_clock::Duration& cancelResetTimer,
              const time::milliseconds& resetInterestLifetime,
@@ -99,7 +98,7 @@
   , m_validator(validator)
 {
 #ifdef _DEBUG
-  m_instanceId = m_instanceCounter++;
+  m_instanceId = s_instanceCounter++;
 #endif
 
   _LOG_DEBUG_ID(">> Logic::Logic");
@@ -251,7 +250,7 @@
 
     if (!m_isInReset) {
       _LOG_DEBUG_ID("updateSeqNo: not in Reset ");
-      ndn::ConstBufferPtr previousRoot = m_state.getRootDigest();
+      ConstBufferPtr previousRoot = m_state.getRootDigest();
       {
         std::string hash = ndn::toHex(previousRoot->buf(), previousRoot->size(), false);
         _LOG_DEBUG_ID("Hash: " << hash);
@@ -260,8 +259,7 @@
       bool isInserted = false;
       bool isUpdated = false;
       SeqNo oldSeq;
-      boost::tie(isInserted, isUpdated, oldSeq) = m_state.update(node.sessionName,
-                                                                 node.seqNo);
+      std::tie(isInserted, isUpdated, oldSeq) = m_state.update(node.sessionName, node.seqNo);
 
       _LOG_DEBUG_ID("Insert: " << std::boolalpha << isInserted);
       _LOG_DEBUG_ID("Updated: " << std::boolalpha << isUpdated);
@@ -322,7 +320,7 @@
   }
   // Do not process exclude interests, they should be answered by CS
   else if (interest.getExclude().empty()) {
-    processSyncInterest(interest.shared_from_this());
+    processSyncInterest(interest);
   }
 
   _LOG_DEBUG_ID("<< Logic::onSyncInterest");
@@ -344,15 +342,15 @@
   //                         bind(&Logic::onSyncDataValidated, this, _1),
   //                         bind(&Logic::onSyncDataValidationFailed, this, _1));
   // else
-  //   onSyncDataValidated(data.shared_from_this());
+  //   onSyncDataValidated(data);
 
   if (interest.getExclude().empty()) {
     _LOG_DEBUG_ID("First data");
-    onSyncDataValidated(data.shared_from_this());
+    onSyncDataValidated(data);
   }
   else {
     _LOG_DEBUG_ID("Data obtained using exclude filter");
-    onSyncDataValidated(data.shared_from_this(), false);
+    onSyncDataValidated(data, false);
   }
   sendExcludeInterest(interest, data);
 
@@ -375,29 +373,27 @@
 }
 
 void
-Logic::onSyncDataValidationFailed(const shared_ptr<const Data>& data)
+Logic::onSyncDataValidationFailed(const Data& data)
 {
   // SyncReply cannot be validated.
 }
 
 void
-Logic::onSyncDataValidated(const shared_ptr<const Data>& data, bool firstData)
+Logic::onSyncDataValidated(const Data& data, bool firstData)
 {
-  Name name = data->getName();
+  Name name = data.getName();
   ConstBufferPtr digest = make_shared<ndn::Buffer>(name.get(-1).value(), name.get(-1).value_size());
 
-  processSyncData(name, digest, data->getContent().blockFromValue(), firstData);
+  processSyncData(name, digest, data.getContent().blockFromValue(), firstData);
 }
 
 void
-Logic::processSyncInterest(const shared_ptr<const Interest>& interest,
-                           bool isTimedProcessing/*=false*/)
+Logic::processSyncInterest(const Interest& interest, bool isTimedProcessing/*=false*/)
 {
   _LOG_DEBUG_ID(">> Logic::processSyncInterest");
 
-  const Name& name = interest->getName();
-  ConstBufferPtr digest =
-      make_shared<ndn::Buffer>(name.get(-1).value(), name.get(-1).value_size());
+  Name name = interest.getName();
+  ConstBufferPtr digest = make_shared<ndn::Buffer>(name.get(-1).value(), name.get(-1).value_size());
 
   ConstBufferPtr rootDigest = m_state.getRootDigest();
 
@@ -480,13 +476,13 @@
 
 void
 Logic::processSyncData(const Name& name,
-                       ndn::ConstBufferPtr digest,
+                       ConstBufferPtr digest,
                        const Block& syncReplyBlock,
                        bool firstData)
 {
   _LOG_DEBUG_ID(">> Logic::processSyncData");
   DiffStatePtr commit = make_shared<DiffState>();
-  ndn::ConstBufferPtr previousRoot = m_state.getRootDigest();
+  ConstBufferPtr previousRoot = m_state.getRootDigest();
 
   try {
     m_interestTable.erase(digest); // Remove satisfied interest from PIT
@@ -505,7 +501,7 @@
         bool isInserted = false;
         bool isUpdated = false;
         SeqNo oldSeq;
-        boost::tie(isInserted, isUpdated, oldSeq) = m_state.update(info, seq);
+        std::tie(isInserted, isUpdated, oldSeq) = m_state.update(info, seq);
         if (isInserted || isUpdated) {
           commit->update(info, seq);
 
@@ -550,13 +546,14 @@
   _LOG_DEBUG_ID(">> Logic::satisfyPendingSyncInterests");
   try {
     _LOG_DEBUG_ID("InterestTable size: " << m_interestTable.size());
-    for (InterestTable::const_iterator it = m_interestTable.begin();
-         it != m_interestTable.end(); it++) {
+    auto it = m_interestTable.begin();
+    while (it != m_interestTable.end()) {
       ConstUnsatisfiedInterestPtr request = *it;
+      ++it;
       if (request->isUnknown)
-        sendSyncData(updatedPrefix, request->interest->getName(), m_state);
+        sendSyncData(updatedPrefix, request->interest.getName(), m_state);
       else
-        sendSyncData(updatedPrefix, request->interest->getName(), *commit);
+        sendSyncData(updatedPrefix, request->interest.getName(), *commit);
     }
     m_interestTable.clear();
   }
@@ -567,7 +564,7 @@
 }
 
 void
-Logic::insertToDiffLog(DiffStatePtr commit, ndn::ConstBufferPtr previousRoot)
+Logic::insertToDiffLog(DiffStatePtr commit, ConstBufferPtr previousRoot)
 {
   _LOG_DEBUG_ID(">> Logic::insertToDiffLog");
   // Connect to the history
@@ -646,17 +643,17 @@
 Logic::sendSyncData(const Name& nodePrefix, const Name& name, const State& state)
 {
   _LOG_DEBUG_ID(">> Logic::sendSyncData");
-  shared_ptr<Data> syncReply = make_shared<Data>(name);
-  syncReply->setContent(state.wireEncode());
-  syncReply->setFreshnessPeriod(m_syncReplyFreshness);
+  Data syncReply(name);
+  syncReply.setContent(state.wireEncode());
+  syncReply.setFreshnessPeriod(m_syncReplyFreshness);
   if (m_nodeList.find(nodePrefix) == m_nodeList.end())
     return;
   if (m_nodeList[nodePrefix].signingId.empty())
-    m_keyChain.sign(*syncReply);
+    m_keyChain.sign(syncReply);
   else
-    m_keyChain.sign(*syncReply, security::signingByIdentity(m_nodeList[nodePrefix].signingId));
+    m_keyChain.sign(syncReply, security::signingByIdentity(m_nodeList[nodePrefix].signingId));
 
-  m_face.put(*syncReply);
+  m_face.put(syncReply);
 
   // checking if our own interest got satisfied
   if (m_outstandingInterestName == name) {
@@ -692,14 +689,14 @@
 }
 
 void
-Logic::printDigest(ndn::ConstBufferPtr digest)
+Logic::printDigest(ConstBufferPtr digest)
 {
   std::string hash = ndn::toHex(digest->buf(), digest->size(), false);
   _LOG_DEBUG_ID("Hash: " << hash);
 }
 
 void
-Logic::sendRecoveryInterest(ndn::ConstBufferPtr digest)
+Logic::sendRecoveryInterest(ConstBufferPtr digest)
 {
   _LOG_DEBUG_ID(">> Logic::sendRecoveryInterest");
 
@@ -726,7 +723,7 @@
 {
   _LOG_DEBUG_ID(">> Logic::processRecoveryInterest");
 
-  const Name& name = interest.getName();
+  Name name = interest.getName();
   ConstBufferPtr digest = make_shared<ndn::Buffer>(name.get(-1).value(), name.get(-1).value_size());
 
   ConstBufferPtr rootDigest = m_state.getRootDigest();
@@ -745,7 +742,7 @@
 Logic::onRecoveryData(const Interest& interest, const Data& data)
 {
   _LOG_DEBUG_ID(">> Logic::onRecoveryData");
-  onSyncDataValidated(data.shared_from_this());
+  onSyncDataValidated(data);
   _LOG_DEBUG_ID("<< Logic::onRecoveryData");
 }
 
@@ -785,7 +782,7 @@
 }
 
 void
-Logic::formAndSendExcludeInterest(const Name& nodePrefix, const State& commit, ndn::ConstBufferPtr previousRoot)
+Logic::formAndSendExcludeInterest(const Name& nodePrefix, const State& commit, ConstBufferPtr previousRoot)
 {
   _LOG_DEBUG_ID(">> Logic::formAndSendExcludeInterest");
   Name interestName;
@@ -793,17 +790,17 @@
               .append(ndn::name::Component(*previousRoot));
   Interest interest(interestName);
 
-  shared_ptr<Data> data = make_shared<Data>(interestName);
-  data->setContent(commit.wireEncode());
-  data->setFreshnessPeriod(m_syncReplyFreshness);
+  Data data(interestName);
+  data.setContent(commit.wireEncode());
+  data.setFreshnessPeriod(m_syncReplyFreshness);
   if (m_nodeList.find(nodePrefix) == m_nodeList.end())
     return;
   if (m_nodeList[nodePrefix].signingId.empty())
-    m_keyChain.sign(*data);
+    m_keyChain.sign(data);
   else
-    m_keyChain.sign(*data, security::signingByIdentity(m_nodeList[nodePrefix].signingId));
+    m_keyChain.sign(data, security::signingByIdentity(m_nodeList[nodePrefix].signingId));
 
-  sendExcludeInterest(interest, *data);
+  sendExcludeInterest(interest, data);
 
   _LOG_DEBUG_ID("<< Logic::formAndSendExcludeInterest");
 }
diff --git a/src/logic.hpp b/src/logic.hpp
index 78080ae..453a843 100644
--- a/src/logic.hpp
+++ b/src/logic.hpp
@@ -26,19 +26,19 @@
 #ifndef CHRONOSYNC_LOGIC_HPP
 #define CHRONOSYNC_LOGIC_HPP
 
-#include "boost-header.h"
 #include "diff-state-container.hpp"
 #include "interest-table.hpp"
 
+#include <boost/archive/iterators/dataflow_exception.hpp>
+#include <boost/archive/iterators/transform_width.hpp>
+#include <boost/assert.hpp>
+#include <boost/iterator/transform_iterator.hpp>
+#include <boost/random.hpp>
+#include <boost/throw_exception.hpp>
+
 #include <memory>
 #include <unordered_map>
 
-#include <ndn-cxx/face.hpp>
-#include <ndn-cxx/util/scheduler.hpp>
-#include <ndn-cxx/security/key-chain.hpp>
-#include <ndn-cxx/security/signing-helpers.hpp>
-#include <ndn-cxx/security/validator.hpp>
-
 namespace chronosync {
 
 /**
@@ -76,7 +76,7 @@
  * The parameter is a set of MissingDataInfo, of which each corresponds to
  * a session that has changed its state.
  */
-typedef function<void(const std::vector<MissingDataInfo>&)> UpdateCallback;
+using UpdateCallback = function<void(const std::vector<MissingDataInfo>&)>;
 
 /**
  * @brief Logic of ChronoSync
@@ -123,7 +123,7 @@
         const Name& defaultUserPrefix,
         const UpdateCallback& onUpdate,
         const Name& defaultSigningId = DEFAULT_NAME,
-        std::shared_ptr<ndn::Validator> validator = DEFAULT_VALIDATOR,
+        std::shared_ptr<Validator> validator = DEFAULT_VALIDATOR,
         const time::steady_clock::Duration& resetTimer = DEFAULT_RESET_TIMER,
         const time::steady_clock::Duration& cancelResetTimer = DEFAULT_CANCEL_RESET_TIMER,
         const time::milliseconds& resetInterestLifetime = DEFAULT_RESET_INTEREST_LIFETIME,
@@ -207,7 +207,7 @@
   updateSeqNo(const SeqNo& seq, const Name& updatePrefix = EMPTY_NAME);
 
   /// @brief Get root digest of current sync tree
-  ndn::ConstBufferPtr
+  ConstBufferPtr
   getRootDigest() const;
 
   /// @brief Get the name of all sessions
@@ -297,7 +297,7 @@
    * @param data The invalid Sync Reply
    */
   void
-  onSyncDataValidationFailed(const shared_ptr<const Data>& data);
+  onSyncDataValidationFailed(const Data& data);
 
   /**
    * @brief Callback to valid Sync Reply.
@@ -308,7 +308,7 @@
    * @param firstData Whether the data is new or that obtained using exclude filter
    */
   void
-  onSyncDataValidated(const shared_ptr<const Data>& data, bool firstData = true);
+  onSyncDataValidated(const Data& data, bool firstData = true);
 
   /**
    * @brief Process normal Sync Interest
@@ -324,8 +324,7 @@
    *                          making a reply (to avoid unnecessary recovery)
    */
   void
-  processSyncInterest(const shared_ptr<const Interest>& interest,
-                      bool isTimedProcessing = false);
+  processSyncInterest(const Interest& interest, bool isTimedProcessing = false);
 
   /**
    * @brief Process reset Sync Interest
@@ -350,7 +349,7 @@
    */
   void
   processSyncData(const Name& name,
-                  ndn::ConstBufferPtr digest,
+                  ConstBufferPtr digest,
                   const Block& syncReplyBlock,
                   bool firstData);
 
@@ -362,7 +361,7 @@
    */
   void
   insertToDiffLog(DiffStatePtr diff,
-                  ndn::ConstBufferPtr previousRoot);
+                  ConstBufferPtr previousRoot);
 
   /**
    * @brief Reply to all pending Sync Interests with a particular commit (or diff)
@@ -394,7 +393,7 @@
   cancelReset();
 
   void
-  printDigest(ndn::ConstBufferPtr digest);
+  printDigest(ConstBufferPtr digest);
 
   /**
    * @brief Helper method to send Recovery Interest
@@ -402,7 +401,7 @@
    * @param digest    The digest to be included in the recovery interest
    */
   void
-  sendRecoveryInterest(ndn::ConstBufferPtr digest);
+  sendRecoveryInterest(ConstBufferPtr digest);
 
   /**
    * @brief Process Recovery Interest
@@ -458,17 +457,17 @@
   void
   formAndSendExcludeInterest(const Name& nodePrefix,
                              const State& commit,
-                             ndn::ConstBufferPtr previousRoot);
+                             ConstBufferPtr previousRoot);
 
 public:
   static const ndn::Name DEFAULT_NAME;
   static const ndn::Name EMPTY_NAME;
-  static const std::shared_ptr<ndn::Validator> DEFAULT_VALIDATOR;
+  static const std::shared_ptr<Validator> DEFAULT_VALIDATOR;
 
 private:
-  typedef std::unordered_map<ndn::Name, NodeInfo> NodeList;
+  using NodeList = std::unordered_map<ndn::Name, NodeInfo>;
 
-  static const ndn::ConstBufferPtr EMPTY_DIGEST;
+  static const ConstBufferPtr EMPTY_DIGEST;
   static const ndn::name::Component RESET_COMPONENT;
   static const ndn::name::Component RECOVERY_COMPONENT;
 
@@ -517,12 +516,12 @@
 
   // Security
   ndn::KeyChain m_keyChain;
-  std::shared_ptr<ndn::Validator> m_validator;
+  std::shared_ptr<Validator> m_validator;
 
 
 #ifdef _DEBUG
   int m_instanceId;
-  static int m_instanceCounter;
+  static int s_instanceCounter;
 #endif
 };
 
diff --git a/src/socket.cpp b/src/socket.cpp
index f70d900..d3184d2 100644
--- a/src/socket.cpp
+++ b/src/socket.cpp
@@ -27,19 +27,18 @@
 
 INIT_LOGGER(Socket);
 
-
 namespace chronosync {
 
 const ndn::Name Socket::DEFAULT_NAME;
 const ndn::Name Socket::DEFAULT_PREFIX;
-const std::shared_ptr<ndn::Validator> Socket::DEFAULT_VALIDATOR;
+const std::shared_ptr<Validator> Socket::DEFAULT_VALIDATOR;
 
 Socket::Socket(const Name& syncPrefix,
                const Name& userPrefix,
                ndn::Face& face,
                const UpdateCallback& updateCallback,
                const Name& signingId,
-               std::shared_ptr<ndn::Validator> validator)
+               std::shared_ptr<Validator> validator)
   : m_userPrefix(userPrefix)
   , m_face(face)
   , m_logic(face, syncPrefix, userPrefix, updateCallback)
@@ -161,7 +160,7 @@
 
 void
 Socket::fetchData(const Name& sessionName, const SeqNo& seqNo,
-                  const ndn::OnDataValidated& dataCallback,
+                  const DataValidatedCallback& dataCallback,
                   int nRetries)
 {
   Name interestName;
@@ -170,7 +169,7 @@
   Interest interest(interestName);
   interest.setMustBeFresh(true);
 
-  ndn::OnDataValidationFailed failureCallback =
+  DataValidationErrorCallback failureCallback =
     bind(&Socket::onDataValidationFailed, this, _1, _2);
 
   m_face.expressInterest(interest,
@@ -183,8 +182,8 @@
 
 void
 Socket::fetchData(const Name& sessionName, const SeqNo& seqNo,
-                  const ndn::OnDataValidated& dataCallback,
-                  const ndn::OnDataValidationFailed& failureCallback,
+                  const DataValidatedCallback& dataCallback,
+                  const DataValidationErrorCallback& failureCallback,
                   const ndn::TimeoutCallback& onTimeout,
                   int nRetries)
 {
@@ -214,21 +213,21 @@
 
 void
 Socket::onData(const Interest& interest, const Data& data,
-               const ndn::OnDataValidated& onValidated,
-               const ndn::OnDataValidationFailed& onFailed)
+               const DataValidatedCallback& onValidated,
+               const DataValidationErrorCallback& onFailed)
 {
   _LOG_DEBUG("Socket::onData");
 
   if (static_cast<bool>(m_validator))
     m_validator->validate(data, onValidated, onFailed);
   else
-    onValidated(data.shared_from_this());
+    onValidated(data);
 }
 
 void
 Socket::onDataTimeout(const Interest& interest, int nRetries,
-                      const ndn::OnDataValidated& onValidated,
-                      const ndn::OnDataValidationFailed& onFailed)
+                      const DataValidatedCallback& onValidated,
+                      const DataValidationErrorCallback& onFailed)
 {
   _LOG_DEBUG("Socket::onDataTimeout");
   if (nRetries <= 0)
@@ -246,12 +245,12 @@
 }
 
 void
-Socket::onDataValidationFailed(const shared_ptr<const Data>& data,
-                               const std::string& failureInfo)
+Socket::onDataValidationFailed(const Data& data,
+                               const ValidationError& error)
 {
 }
 
-ndn::ConstBufferPtr
+ConstBufferPtr
 Socket::getRootDigest() const
 {
   return m_logic.getRootDigest();
diff --git a/src/socket.hpp b/src/socket.hpp
index 6ec0aef..94ba109 100644
--- a/src/socket.hpp
+++ b/src/socket.hpp
@@ -27,10 +27,10 @@
 
 #include "logic.hpp"
 
-#include <ndn-cxx/face.hpp>
-#include <ndn-cxx/ims/in-memory-storage-persistent.hpp>
 #include <unordered_map>
 
+#include <ndn-cxx/ims/in-memory-storage-persistent.hpp>
+
 namespace chronosync {
 
 /**
@@ -64,10 +64,14 @@
          ndn::Face& face,
          const UpdateCallback& updateCallback,
          const Name& signingId = DEFAULT_NAME,
-         std::shared_ptr<ndn::Validator> validator = DEFAULT_VALIDATOR);
+         std::shared_ptr<Validator> validator = DEFAULT_VALIDATOR);
 
   ~Socket();
 
+  using DataValidatedCallback = function<void(const Data&)>;
+
+  using DataValidationErrorCallback = function<void(const Data&, const ValidationError& error)> ;
+
   /**
    * @brief Add a sync node under same logic
    *
@@ -175,7 +179,7 @@
    */
   void
   fetchData(const Name& sessionName, const SeqNo& seq,
-            const ndn::OnDataValidated& onValidated,
+            const DataValidatedCallback& onValidated,
             int nRetries = 0);
 
   /**
@@ -190,13 +194,13 @@
    */
   void
   fetchData(const Name& sessionName, const SeqNo& seq,
-            const ndn::OnDataValidated& onValidated,
-            const ndn::OnDataValidationFailed& onValidationFailed,
+            const DataValidatedCallback& onValidated,
+            const DataValidationErrorCallback& onValidationFailed,
             const ndn::TimeoutCallback& onTimeout,
             int nRetries = 0);
 
   /// @brief Get the root digest of current sync tree
-  ndn::ConstBufferPtr
+  ConstBufferPtr
   getRootDigest() const;
 
   Logic&
@@ -211,25 +215,25 @@
 
   void
   onData(const Interest& interest, const Data& data,
-         const ndn::OnDataValidated& dataCallback,
-         const ndn::OnDataValidationFailed& failCallback);
+         const DataValidatedCallback& dataCallback,
+         const DataValidationErrorCallback& failCallback);
 
   void
   onDataTimeout(const Interest& interest, int nRetries,
-                const ndn::OnDataValidated& dataCallback,
-                const ndn::OnDataValidationFailed& failCallback);
+                const DataValidatedCallback& dataCallback,
+                const DataValidationErrorCallback& failCallback);
 
   void
-  onDataValidationFailed(const shared_ptr<const Data>& data,
-                         const std::string& failureInfo);
+  onDataValidationFailed(const Data& data,
+                         const ValidationError& error);
 
 public:
   static const ndn::Name DEFAULT_NAME;
   static const ndn::Name DEFAULT_PREFIX;
-  static const std::shared_ptr<ndn::Validator> DEFAULT_VALIDATOR;
+  static const std::shared_ptr<Validator> DEFAULT_VALIDATOR;
 
 private:
-  typedef std::unordered_map<ndn::Name, const ndn::RegisteredPrefixId*> RegisteredPrefixList;
+  using RegisteredPrefixList = std::unordered_map<ndn::Name, const ndn::RegisteredPrefixId*>;
 
   Name m_userPrefix;
   ndn::Face& m_face;
@@ -237,7 +241,7 @@
 
   Name m_signingId;
   ndn::KeyChain m_keyChain;
-  std::shared_ptr<ndn::Validator> m_validator;
+  std::shared_ptr<Validator> m_validator;
 
   RegisteredPrefixList m_registeredPrefixList;
   ndn::InMemoryStoragePersistent m_ims;
diff --git a/src/state.cpp b/src/state.cpp
index 26a8944..b89509b 100644
--- a/src/state.cpp
+++ b/src/state.cpp
@@ -26,8 +26,6 @@
 
 namespace chronosync {
 
-using boost::make_tuple;
-
 State::~State()
 {
 }
@@ -39,7 +37,7 @@
  * @param seq  sequence number of the leaf
  * @return 3-tuple (isInserted, isUpdated, oldSeqNo)
  */
-boost::tuple<bool, bool, SeqNo>
+std::tuple<bool, bool, SeqNo>
 State::update(const Name& info, const SeqNo& seq)
 {
   m_wire.reset();
@@ -62,7 +60,7 @@
   }
 }
 
-ndn::ConstBufferPtr
+ConstBufferPtr
 State::getRootDigest() const
 {
   m_digest.reset();
@@ -95,9 +93,9 @@
   return *this;
 }
 
-template<bool T>
+template<encoding::Tag T>
 size_t
-State::wireEncode(ndn::EncodingImpl<T>& block) const
+State::wireEncode(encoding::EncodingImpl<T>& block) const
 {
   size_t totalLength = 0;
 
@@ -117,13 +115,7 @@
   return totalLength;
 }
 
-//! \relates State
-template size_t
-State::wireEncode<true>(ndn::EncodingImpl<true>& block) const;
-
-//! \relates State
-template size_t
-State::wireEncode<false>(ndn::EncodingImpl<false>& block) const;
+NDN_CXX_DEFINE_WIRE_ENCODE_INSTANTIATIONS(State);
 
 const Block&
 State::wireEncode() const
diff --git a/src/state.hpp b/src/state.hpp
index 8713552..e5d0de2 100644
--- a/src/state.hpp
+++ b/src/state.hpp
@@ -25,15 +25,16 @@
 #ifndef CHRONOSYNC_STATE_HPP
 #define CHRONOSYNC_STATE_HPP
 
-#include "tlv.hpp"
 #include "leaf-container.hpp"
+#include "tlv.hpp"
+
 #include <ndn-cxx/util/sha256.hpp>
 
 namespace chronosync {
 
 class State;
-typedef shared_ptr<State> StatePtr;
-typedef shared_ptr<const State> ConstStatePtr;
+using StatePtr = shared_ptr<State>;
+using ConstStatePtr = shared_ptr<const State>;
 
 /**
  * @brief Abstraction of state tree.
@@ -65,7 +66,7 @@
    * @param seq  sequence number of the leaf
    * @return 3-tuple (isInserted, isUpdated, oldSeqNo)
    */
-  boost::tuple<bool, bool, SeqNo>
+  std::tuple<bool, bool, SeqNo>
   update(const Name& info, const SeqNo& seq);
 
   /**
@@ -77,7 +78,7 @@
     return m_leaves;
   }
 
-  ndn::ConstBufferPtr
+  ConstBufferPtr
   getRootDigest() const;
 
   /**
@@ -111,9 +112,9 @@
   wireDecode(const Block& wire);
 
 protected:
-  template<bool T>
+  template<encoding::Tag T>
   size_t
-  wireEncode(ndn::EncodingImpl<T>& block) const;
+  wireEncode(encoding::EncodingImpl<T>& block) const;
 
 protected:
   LeafContainer m_leaves;
@@ -122,6 +123,8 @@
   mutable Block m_wire;
 };
 
+NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(State);
+
 } // namespace chronosync
 
 #endif // CHRONOSYNC_STATE_HPP