socket: add remove node function

Change-Id: I6d032be0b9ed7c09e7ca14b6edb03beed9eb61db
diff --git a/src/socket.cpp b/src/socket.cpp
index 7356f73..95a9045 100644
--- a/src/socket.cpp
+++ b/src/socket.cpp
@@ -53,6 +53,15 @@
                                [] (const Name& prefix, const std::string& msg) {});
 }
 
+Socket::~Socket()
+{
+  for(const auto& itr : m_registeredPrefixList) {
+    if (static_cast<bool>(itr.second))
+      m_face.unsetInterestFilter(itr.second);
+  }
+  m_ims.erase("/");
+}
+
 void
 Socket::addSyncNode(const Name& prefix, const Name& signingId)
 {
@@ -73,6 +82,24 @@
 }
 
 void
+Socket::removeSyncNode(const Name& prefix)
+{
+  if (prefix == DEFAULT_NAME)
+    return;
+
+  auto itr = m_registeredPrefixList.find(prefix);
+  if (itr != m_registeredPrefixList.end()) {
+    if (static_cast<bool>(itr->second))
+      m_face.unsetInterestFilter(itr->second);
+    m_registeredPrefixList.erase(itr);
+  }
+
+  m_ims.erase(prefix);
+  m_logic.removeUserNode(prefix);
+
+}
+
+void
 Socket::publishData(const uint8_t* buf, size_t len, const ndn::time::milliseconds& freshness,
                     const Name& prefix)
 {
diff --git a/src/socket.hpp b/src/socket.hpp
index 6987003..450dfeb 100644
--- a/src/socket.hpp
+++ b/src/socket.hpp
@@ -66,10 +66,34 @@
          const Name& signingId = DEFAULT_NAME,
          ndn::shared_ptr<ndn::Validator> validator = DEFAULT_VALIDATOR);
 
+  ~Socket();
+
+  /**
+   * @brief Add a sync node under same logic
+   *
+   * This method will add a new sync node in logic and then register this prefix.
+   * If pass an empty prefix, it will return directly without doing anything
+   * If the prefix is already registered, return directly
+   *
+   * @param prefix Prefix of the new node
+   * @param signingId Signing ID for the packet sent out by the new node
+   */
   void
   addSyncNode(const Name& prefix, const Name& signingId = DEFAULT_NAME);
 
   /**
+   * @brief Remove a sync node under same logic
+   *
+   * This method will remove a sync node in logic, unregister this prefix
+   * and then clear the in memory storage about this prefix.
+   * logic will be reset after removal of this node
+   *
+   * @param prefix Prefix of the node to remove
+   */
+  void
+  removeSyncNode(const Name& prefix);
+
+  /**
    * @brief Publish a data packet in the session and trigger synchronization updates
    *
    * This method will create a data packet with the supplied content.