Fix socket

Change-Id: I0076010933c0edd3f5a0960ca55e02e5fff809be
diff --git a/src/socket.cpp b/src/socket.cpp
new file mode 100644
index 0000000..55296ab
--- /dev/null
+++ b/src/socket.cpp
@@ -0,0 +1,150 @@
+/* -*- 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 Zhenkai Zhu <http://irl.cs.ucla.edu/~zhenkai/>
+ * @author Chaoyi Bian <bcy@pku.edu.cn>
+ * @author Alexander Afanasyev <http://lasr.cs.ucla.edu/afanasyev/index.html>
+ * @author Yingdi Yu <yingdi@cs.ucla.edu>
+ */
+
+#include "socket.hpp"
+#include "logger.hpp"
+
+INIT_LOGGER("Socket");
+
+
+namespace chronosync {
+
+Socket::Socket(const Name& syncPrefix,
+               const Name& userPrefix,
+               ndn::Face& face,
+               const UpdateCallback& updateCallback)
+  : m_userPrefix(userPrefix)
+  , m_face(face)
+  , m_logic(face,
+            syncPrefix,
+            userPrefix,
+            updateCallback)
+{
+}
+
+
+void
+Socket::publishData(const uint8_t* buf, size_t len, const ndn::time::milliseconds& freshness)
+{
+  publishData(ndn::dataBlock(ndn::tlv::Content, buf, len), freshness);
+}
+
+void
+Socket::publishData(const Block& content, const ndn::time::milliseconds& freshness)
+{
+  shared_ptr<Data> data = make_shared<Data>();
+  data->setContent(content);
+  data->setFreshnessPeriod(freshness);
+
+  SeqNo newSeq = m_logic.getSeqNo() + 1;
+  Name dataName;
+  dataName.append(m_logic.getSessionName()).appendNumber(newSeq);
+  data->setName(dataName);
+
+  m_keyChain.sign(*data);
+
+  m_face.put(*data);
+
+  m_logic.updateSeqNo(newSeq);
+}
+
+void
+Socket::fetchData(const Name& sessionName, const SeqNo& seqNo,
+                  const ndn::OnDataValidated& dataCallback,
+                  int nRetries)
+{
+  Name interestName;
+  interestName.append(sessionName).appendNumber(seqNo);
+
+  Interest interest(interestName);
+  interest.setMustBeFresh(true);
+
+  ndn::OnDataValidationFailed failureCallback =
+    bind(&Socket::onDataValidationFailed, this, _1, _2);
+
+  m_face.expressInterest(interest,
+                         bind(&Socket::onData, this, _1, _2, dataCallback, failureCallback),
+                         bind(&Socket::onDataTimeout, this, _1, nRetries,
+                              dataCallback, failureCallback));
+}
+
+void
+Socket::fetchData(const Name& sessionName, const SeqNo& seqNo,
+                  const ndn::OnDataValidated& dataCallback,
+                  const ndn::OnDataValidationFailed& failureCallback,
+                  const ndn::OnTimeout& onTimeout,
+                  int nRetries)
+{
+  _LOG_DEBUG(">> Socket::fetchData");
+  Name interestName;
+  interestName.append(sessionName).appendNumber(seqNo);
+
+  Interest interest(interestName);
+  interest.setMustBeFresh(true);
+
+  m_face.expressInterest(interest,
+                         bind(&Socket::onData, this, _1, _2, dataCallback, failureCallback),
+                         onTimeout);
+
+  _LOG_DEBUG("<< Socket::fetchData");
+}
+
+void
+Socket::onData(const Interest& interest, Data& data,
+               const ndn::OnDataValidated& onValidated,
+               const ndn::OnDataValidationFailed& onFailed)
+{
+  _LOG_DEBUG("Socket::onData");
+  // Placeholder for validator
+  onValidated(data.shared_from_this());
+}
+
+void
+Socket::onDataTimeout(const Interest& interest, int nRetries,
+                      const ndn::OnDataValidated& onValidated,
+                      const ndn::OnDataValidationFailed& onFailed)
+{
+  _LOG_DEBUG("Socket::onDataTimeout");
+  if (nRetries <= 0)
+    return;
+
+  m_face.expressInterest(interest,
+                         bind(&Socket::onData, this, _1, _2, onValidated, onFailed),
+                         bind(&Socket::onDataTimeout, this, _1, nRetries - 1,
+                              onValidated, onFailed));
+}
+
+void
+Socket::onDataValidationFailed(const shared_ptr<const Data>& data,
+                               const std::string& failureInfo)
+{
+}
+
+ndn::ConstBufferPtr
+Socket::getRootDigest() const
+{
+  return m_logic.getRootDigest();
+}
+
+} // namespace chronosync
diff --git a/src/socket.hpp b/src/socket.hpp
new file mode 100644
index 0000000..11dc684
--- /dev/null
+++ b/src/socket.hpp
@@ -0,0 +1,158 @@
+/* -*- 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 Zhenkai Zhu <http://irl.cs.ucla.edu/~zhenkai/>
+ * @author Chaoyi Bian <bcy@pku.edu.cn>
+ * @author Alexander Afanasyev <http://lasr.cs.ucla.edu/afanasyev/index.html>
+ * @author Yingdi Yu <yingdi@cs.ucla.edu>
+ */
+
+#ifndef CHRONOSYNC_SOCKET_HPP
+#define CHRONOSYNC_SOCKET_HPP
+
+#include <ndn-cxx/face.hpp>
+#include <ndn-cxx/security/validation-request.hpp>
+
+#include "logic.hpp"
+
+namespace chronosync {
+
+/**
+ * @brief A simple interface to interact with client code
+ *
+ * Though it is called Socket, it is not a real socket. It just trying to provide
+ * a simplified interface for data publishing and fetching.
+ *
+ * This interface simplify data publishing.  Client can simply dump raw data
+ * into this interface without handling the ChronoSync specific details, such
+ * as sequence number and session id.
+ *
+ * This interface also simplify data fetching.  Client only needs to provide a
+ * data fetching strategy (through a updateCallback).
+ */
+class Socket : noncopyable
+{
+public:
+  class Error : public std::runtime_error
+  {
+  public:
+    explicit
+    Error(const std::string& what)
+      : std::runtime_error(what)
+    {
+    }
+  };
+
+  Socket(const Name& syncPrefix,
+         const Name& userPrefix,
+         ndn::Face& face,
+         const UpdateCallback& updateCallback);
+
+  /**
+   * @brief Publish a data packet in the session and trigger synchronization updates
+   *
+   * This method will create a data packet with the supplied content.
+   * The packet name is the local session + seqNo.
+   * The seqNo is automatically maintained by internal Logic.
+   *
+   * @param buf Pointer to the bytes in content
+   * @param len size of the bytes in content
+   * @param freshness FreshnessPeriod of the data packet.
+   */
+  void
+  publishData(const uint8_t* buf, size_t len, const ndn::time::milliseconds& freshness);
+
+  /**
+   * @brief Publish a data packet in the session and trigger synchronization updates
+   *
+   * This method will create a data packet with the supplied content.
+   * The packet name is the local session + seqNo.
+   * The seqNo is automatically maintained by internal Logic.
+   *
+   * @param content Block that will be set as the content of the data packet.
+   * @param freshness FreshnessPeriod of the data packet.
+   */
+  void
+  publishData(const Block& content, const ndn::time::milliseconds& freshness);
+
+  /**
+   * @brief Retrive a data packet with a particular seqNo from a session
+   *
+   * @param sessionName The name of the target session.
+   * @param seq The seqNo of the data packet.
+   * @param onValidated The callback when the retrieved packet has been validated.
+   * @param nRetries The number of retries.
+   */
+  void
+  fetchData(const Name& sessionName, const SeqNo& seq,
+            const ndn::OnDataValidated& onValidated,
+            int nRetries = 0);
+
+  /**
+   * @brief Retrive a data packet with a particular seqNo from a session
+   *
+   * @param sessionName The name of the target session.
+   * @param seq The seqNo of the data packet.
+   * @param onValidated The callback when the retrieved packet has been validated.
+   * @param nRetries The number of retries.
+   */
+  void
+  fetchData(const Name& sessionName, const SeqNo& seq,
+            const ndn::OnDataValidated& onValidated,
+            const ndn::OnDataValidationFailed& onValidationFailed,
+            const ndn::OnTimeout& onTimeout,
+            int nRetries = 0);
+
+  /// @brief Get the root digest of current sync tree
+  ndn::ConstBufferPtr
+  getRootDigest() const;
+
+  Logic&
+  getLogic()
+  {
+    return m_logic;
+  }
+
+private:
+  void
+  onData(const Interest& interest, Data& data,
+         const ndn::OnDataValidated& dataCallback,
+         const ndn::OnDataValidationFailed& failCallback);
+
+  void
+  onDataTimeout(const Interest& interest, int nRetries,
+                const ndn::OnDataValidated& dataCallback,
+                const ndn::OnDataValidationFailed& failCallback);
+
+  void
+  onDataValidationFailed(const shared_ptr<const Data>& data,
+                         const std::string& failureInfo);
+
+private:
+
+  Name m_userPrefix;
+  ndn::Face& m_face;
+
+  Logic m_logic;
+
+  ndn::KeyChain m_keyChain;
+};
+
+} // namespace chronosync
+
+#endif // CHRONOSYNC_SOCKET_HPP
diff --git a/src/sync-socket.cc b/src/sync-socket.cc
deleted file mode 100644
index b344a3e..0000000
--- a/src/sync-socket.cc
+++ /dev/null
@@ -1,245 +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 <http://irl.cs.ucla.edu/~yingdi/web/index.html>
- * @author Zhenkai Zhu <http://irl.cs.ucla.edu/~zhenkai/>
- * @author Chaoyi Bian <bcy@pku.edu.cn>
- * @author Alexander Afanasyev <http://lasr.cs.ucla.edu/afanasyev/index.html>
- */
-
-#include "sync-socket.h"
-#include "sync-logging.h"
-
-using namespace ndn;
-
-INIT_LOGGER ("SyncSocket")
-
-namespace Sync {
-
-using ndn::shared_ptr;
-
-static const uint8_t ROUTING_PREFIX_SEPARATOR[2] = {0xF0, 0x2E};
-
-const Name SyncSocket::EMPTY_NAME = Name();
-
-SyncSocket::SyncSocket (const Name& syncPrefix,
-                        const Name& dataPrefix,
-                        uint64_t dataSession,
-                        bool withRoutingPrefix,
-                        const Name& routingPrefix,
-                        shared_ptr<Face> face,
-                        const IdentityCertificate& myCertificate,
-                        shared_ptr<SecRuleRelative> dataRule,
-                        NewDataCallback dataCallback,
-                        RemoveCallback rmCallback )
-  : m_dataPrefix(dataPrefix)
-  , m_dataSession(dataSession)
-  , m_withRoutingPrefix(false)
-  , m_newDataCallback(dataCallback)
-  , m_myCertificate(myCertificate)
-  , m_face(face)
-  , m_ioService(face->getIoService())
-{
-  if(withRoutingPrefix && !routingPrefix.isPrefixOf(m_dataPrefix))
-    {
-      m_withRoutingPrefix = true;
-      m_routableDataPrefix.append(routingPrefix).append(ROUTING_PREFIX_SEPARATOR, 2).append(m_dataPrefix);
-    }
-
-
-  if(static_cast<bool>(dataRule))
-    {
-      m_withSecurity = true;
-      m_syncValidator = shared_ptr<Validator>(new SyncValidator(syncPrefix,
-                                                                m_myCertificate,
-                                                                *m_face,
-                                                                bind(&SyncSocket::publishData, this, _1, _2, _3, true),
-                                                                dataRule));
-    }
-  else
-    {
-      m_withSecurity = false;
-      m_syncValidator = shared_ptr<Validator>(new ValidatorNull());
-    }
-
-
-  m_syncLogic = shared_ptr<SyncLogic>(new SyncLogic(syncPrefix,
-                                                    myCertificate,
-                                                    m_syncValidator,
-                                                    m_face,
-                                                    bind(&SyncSocket::passCallback, this, _1),
-                                                    rmCallback));
-}
-
-SyncSocket::~SyncSocket()
-{
-}
-
-void
-SyncSocket::publishData(const uint8_t* buf, size_t len, int freshness, bool isCert)
-{
-  shared_ptr<Data> data = make_shared<Data>();
-  data->setContent(reinterpret_cast<const uint8_t*>(buf), len);
-  data->setFreshnessPeriod(time::milliseconds(1000*freshness));
-
-  m_ioService.post(bind(&SyncSocket::publishDataInternal, this,
-                        data, isCert));
-}
-
-void
-SyncSocket::publishDataInternal(shared_ptr<Data> data, bool isCert)
-{
-  Name dataPrefix = (m_withRoutingPrefix ? m_routableDataPrefix : m_dataPrefix);
-
-  uint64_t sequence = getNextSeq();
-
-  Name dataName;
-  dataName.append(m_dataPrefix)
-    .append(boost::lexical_cast<std::string>(m_dataSession))
-    .append(boost::lexical_cast<std::string>(sequence));
-  if(isCert)
-    dataName.append("INTRO-CERT");
-  data->setName(dataName);
-  m_keyChain.sign(*data, m_myCertificate.getName());
-
-  if(m_withRoutingPrefix)
-    {
-      Name wrappedName;
-      wrappedName.append(m_routableDataPrefix)
-        .append(boost::lexical_cast<std::string>(m_dataSession))
-        .append(boost::lexical_cast<std::string>(sequence));
-
-      Data wrappedData(wrappedName);
-      wrappedData.setContent(data->wireEncode());
-      m_keyChain.sign(wrappedData, m_myCertificate.getName());
-
-      m_face->put(wrappedData);
-    }
-  else
-    {
-      m_face->put(*data);
-    }
-
-  SeqNo s(m_dataSession, sequence + 1);
-  m_sequenceLog[dataPrefix] = s;
-  m_syncLogic->addLocalNames (dataPrefix, m_dataSession, sequence); // If DNS works, we should use pure m_dataprefix rather than the one with routing prefix.
-}
-
-void
-SyncSocket::fetchData(const Name& prefix, const SeqNo& seq, const OnDataValidated& dataCallback, int retry)
-{
-  Name interestName = prefix;
-  interestName.append(boost::lexical_cast<std::string>(seq.getSession())).append(boost::lexical_cast<std::string>(seq.getSeq()));
-
-  ndn::Interest interest(interestName);
-  interest.setMustBeFresh(true);
-
-  m_face->expressInterest(interest,
-                          bind(&SyncSocket::onData, this, _1, _2, dataCallback),
-                          bind(&SyncSocket::onDataTimeout, this, _1, retry, dataCallback));
-
-}
-
-void
-SyncSocket::onData(const ndn::Interest& interest, Data& data, const OnDataValidated& dataCallback)
-{
-  bool encaped = false;
-
-  Name interestName = interest.getName();
-  Name::const_iterator it = interestName.begin();
-  Name::const_iterator end = interestName.end();
-
-  size_t offset = interestName.size();
-  for(; it != end; it++)
-    {
-      offset--;
-      if(it->toUri() == "%F0.")
-        {
-          encaped = true;
-          break;
-        }
-    }
-
-  if(!encaped)
-    offset = interestName.size();
-
-  const OnDataValidated& onValidated = bind(&SyncSocket::onDataValidated, this, _1, offset, dataCallback);
-  const OnDataValidationFailed& onValidationFailed = bind(&SyncSocket::onDataValidationFailed, this, _1, _2);
-
-  if(encaped)
-    {
-      shared_ptr<Data> innerData = make_shared<Data>();
-      innerData->wireDecode(data.getContent().blockFromValue());
-      m_syncValidator->validate(*innerData, onValidated, onValidationFailed);
-    }
-  else
-    m_syncValidator->validate(data, onValidated, onValidationFailed);
-}
-
-void
-SyncSocket::onDataTimeout(const ndn::Interest& interest, int retry, const OnDataValidated& dataCallback)
-{
-  if(retry > 0)
-    {
-      m_face->expressInterest(interest,
-                              bind(&SyncSocket::onData,
-                                   this,
-                                   _1,
-                                   _2,
-                                   dataCallback),
-                              bind(&SyncSocket::onDataTimeout,
-                                   this,
-                                   _1,
-                                   retry - 1,
-                                   dataCallback));
-
-    }
-  else
-    _LOG_DEBUG("interest eventually time out!");
-}
-
-void
-SyncSocket::onDataValidated(const shared_ptr<const Data>& data,
-                            size_t interestNameSize,
-                            const OnDataValidated& onValidated)
-{
-  if(data->getName().size() > interestNameSize
-     && data->getName().get(interestNameSize).toUri() == "INTRO-CERT")
-    {
-      if(!m_withSecurity)
-        return;
-
-      Data rawData;
-      rawData.wireDecode(data->getContent().blockFromValue());
-      IntroCertificate introCert(rawData);
-      dynamic_pointer_cast<SyncValidator>(m_syncValidator)->addParticipant(introCert);
-    }
-  else
-    {
-      onValidated(data);
-    }
-}
-
-void
-SyncSocket::onDataValidationFailed(const shared_ptr<const Data>& data,
-                                   const std::string& failureInfo)
-{
-  _LOG_DEBUG("data cannot be verified!: " << failureInfo);
-}
-
-}//Sync
diff --git a/src/sync-socket.h b/src/sync-socket.h
deleted file mode 100644
index 5e66ac6..0000000
--- a/src/sync-socket.h
+++ /dev/null
@@ -1,204 +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 <http://irl.cs.ucla.edu/~yingdi/web/index.html>
- * @author Zhenkai Zhu <http://irl.cs.ucla.edu/~zhenkai/>
- * @author Chaoyi Bian <bcy@pku.edu.cn>
- * @author Alexander Afanasyev <http://lasr.cs.ucla.edu/afanasyev/index.html>
- */
-
-#ifndef _SYNC_SOCKET_H
-#define _SYNC_SOCKET_H
-
-#include <ndn-cxx/face.hpp>
-#include <ndn-cxx/security/validator.hpp>
-#include <ndn-cxx/security/validator-null.hpp>
-#include <ndn-cxx/security/key-chain.hpp>
-
-#include "sync-logic.h"
-#include "sync-seq-no.h"
-#include "sync-validator.h"
-
-#include <utility>
-#include <map>
-#include <vector>
-#include <sstream>
-
-namespace Sync {
-
-/**
- * \ingroup sync
- * @brief A simple interface to interact with client code
- */
-class SyncSocket
-{
-public:
-  struct Error : public std::runtime_error { Error(const std::string &what) : std::runtime_error(what) {} };
-
-  typedef ndn::function< void (const std::vector<MissingDataInfo> &, SyncSocket * ) > NewDataCallback;
-  typedef ndn::function< void (const std::string &/*prefix*/ ) > RemoveCallback;
-
-  static const ndn::Name EMPTY_NAME;
-
-  SyncSocket(const ndn::Name& syncPrefix,
-             const ndn::Name& dataPrefix,
-             uint64_t dataSession,
-             bool withRoutingPrefix,
-             const ndn::Name& routingPrefix,
-             ndn::shared_ptr<ndn::Face> face,
-             const ndn::IdentityCertificate& myCertificate,
-             ndn::shared_ptr<ndn::SecRuleRelative> dataRule,
-             NewDataCallback dataCallback,
-             RemoveCallback rmCallback);
-
-  ~SyncSocket();
-
-  void
-  publishData(const uint8_t* buf, size_t len, int freshness, bool isCert = false);
-
-  void
-  leave()
-  {
-    m_syncLogic->remove(m_withRoutingPrefix ? m_routableDataPrefix : m_dataPrefix);
-  }
-
-  void
-  remove(const ndn::Name& prefix)
-  {
-    m_syncLogic->remove(prefix);
-  }
-
-  void
-  fetchData(const ndn::Name &prefix, const SeqNo &seq, const ndn::OnDataValidated& onValidated, int retry = 0);
-
-  std::string
-  getRootDigest()
-  {
-    return m_syncLogic->getRootDigest();
-  }
-
-  uint64_t
-  getNextSeq()
-  {
-    // If DNS works, we should use pure m_dataprefix rather than the one with routing prefix.
-    SequenceLog::iterator i = m_sequenceLog.find (m_withRoutingPrefix ? m_routableDataPrefix : m_dataPrefix);
-
-    if (i != m_sequenceLog.end ())
-      {
-        SeqNo s = i->second;
-        if (s.getSession() == m_dataSession)
-          return s.getSeq();
-      }
-    return 0;
-  }
-
-  SyncLogic &
-  getLogic()
-  {
-    return *m_syncLogic;
-  }
-
-  void
-  addParticipant(const ndn::IdentityCertificate& introducee)
-  {
-    if(m_withSecurity)
-      {
-        ndn::dynamic_pointer_cast<SyncValidator>(m_syncValidator)->addParticipant(introducee);
-      }
-  }
-
-  void
-  addParticipant(const IntroCertificate& introCert)
-  {
-    if(m_withSecurity)
-      {
-        ndn::dynamic_pointer_cast<SyncValidator>(m_syncValidator)->addParticipant(introCert);
-      }
-  }
-
-  void
-  getIntroCertNames(std::vector<ndn::Name>& list)
-  {
-    if(m_withSecurity)
-      {
-        ndn::dynamic_pointer_cast<SyncValidator>(m_syncValidator)->getIntroCertNames(list);
-      }
-  }
-
-  const IntroCertificate&
-  getIntroCertificate(const ndn::Name& name)
-  {
-    if(m_withSecurity)
-      {
-        return ndn::dynamic_pointer_cast<SyncValidator>(m_syncValidator)->getIntroCertificate(name);
-      }
-    throw Error("You are running SyncSocket without security!");
-  }
-
-  // // make this a static function so we don't have to create socket instance without
-  // // knowing the local prefix. it's a wrong place for this function anyway
-  // static std::string
-  // GetLocalPrefix ();
-
-private:
-  void
-  publishDataInternal(ndn::shared_ptr<ndn::Data> data, bool isCert);
-
-  void
-  passCallback(const std::vector<MissingDataInfo> &v)
-  {
-    m_newDataCallback(v, this);
-  }
-
-  void
-  onData(const ndn::Interest& interest, ndn::Data& data, const ndn::OnDataValidated& dataCallback);
-
-  void
-  onDataTimeout(const ndn::Interest& interest, int retry, const ndn::OnDataValidated& dataCallback);
-
-
-  void
-  onDataValidated(const ndn::shared_ptr<const ndn::Data>& data,
-                  size_t interestNameSize,
-                  const ndn::OnDataValidated& onValidated);
-
-  void
-  onDataValidationFailed(const ndn::shared_ptr<const ndn::Data>& data,
-                         const std::string& failureInfo);
-
-private:
-  typedef std::map<ndn::Name, SeqNo> SequenceLog;
-
-  ndn::Name m_dataPrefix;
-  uint64_t m_dataSession;
-  ndn::Name m_routableDataPrefix;
-  bool m_withRoutingPrefix;
-  NewDataCallback m_newDataCallback;
-  SequenceLog m_sequenceLog;
-  ndn::IdentityCertificate m_myCertificate;
-  ndn::KeyChain m_keyChain;
-  ndn::shared_ptr<ndn::Face> m_face;
-  boost::asio::io_service& m_ioService;
-  bool m_withSecurity;
-  ndn::shared_ptr<ndn::Validator> m_syncValidator;
-  ndn::shared_ptr<SyncLogic>      m_syncLogic;
-};
-
-} // Sync
-
-#endif // SYNC_SOCKET_H