communication: add SVS support

Change-Id: I74c5a091c8b1c05dd186a0c10849aa5bb4f39e50
Signed-off-by: Varun Patil <varunpatil@ucla.edu>
diff --git a/src/communication/sync-protocol-adapter.cpp b/src/communication/sync-protocol-adapter.cpp
index 2e09d2b..7e2dc92 100644
--- a/src/communication/sync-protocol-adapter.cpp
+++ b/src/communication/sync-protocol-adapter.cpp
@@ -58,7 +58,8 @@
                           chronosync::Logic::DEFAULT_RECOVERY_INTEREST_LIFETIME,
                           FIXED_SESSION);
     break;
-#endif
+#endif // HAVE_CHRONOSYNC
+#ifdef HAVE_PSYNC
   case SyncProtocol::PSYNC:
     NDN_LOG_DEBUG("Using PSync");
     m_psyncLogic = std::make_shared<psync::FullProducer>(face,
@@ -69,6 +70,15 @@
                      [this] (auto&&... args) { onPSyncUpdate(std::forward<decltype(args)>(args)...); },
                      syncInterestLifetime);
     break;
+#endif // HAVE_PSYNC
+#ifdef HAVE_SVS
+  case SyncProtocol::SVS:
+    NDN_LOG_DEBUG("Using SVS");
+    m_svsCore = std::make_shared<ndn::svs::SVSyncCore>(face,
+                    syncPrefix,
+                    [this] (auto&&... args) { onSvsUpdate(std::forward<decltype(args)>(args)...); });
+    break;
+#endif // HAVE_SVS
   default:
     NDN_CXX_UNREACHABLE;
   }
@@ -82,10 +92,16 @@
   case SyncProtocol::CHRONOSYNC:
     m_chronoSyncLogic->addUserNode(userPrefix, chronosync::Logic::DEFAULT_NAME, FIXED_SESSION);
     break;
-#endif
+#endif // HAVE_CHRONOSYNC
+#ifdef HAVE_PSYNC
   case SyncProtocol::PSYNC:
     m_psyncLogic->addUserNode(userPrefix);
     break;
+#endif // HAVE_PSYNC
+#ifdef HAVE_SVS
+  case SyncProtocol::SVS:
+    break;
+#endif // HAVE_SVS
   default:
     NDN_CXX_UNREACHABLE;
   }
@@ -99,10 +115,17 @@
   case SyncProtocol::CHRONOSYNC:
     m_chronoSyncLogic->updateSeqNo(seq, userPrefix);
     break;
-#endif
+#endif // HAVE_CHRONOSYNC
+#ifdef HAVE_PSYNC
   case SyncProtocol::PSYNC:
     m_psyncLogic->publishName(userPrefix, seq);
     break;
+#endif // HAVE_PSYNC
+#ifdef HAVE_SVS
+  case SyncProtocol::SVS:
+    m_svsCore->updateSeqNo(seq, userPrefix);
+    break;
+#endif // HAVE_SVS
   default:
     NDN_CXX_UNREACHABLE;
   }
@@ -119,8 +142,9 @@
     m_syncUpdateCallback(update.session.getPrefix(-1), update.high, 0);
   }
 }
-#endif
+#endif // HAVE_CHRONOSYNC
 
+#ifdef HAVE_PSYNC
 void
 SyncProtocolAdapter::onPSyncUpdate(const std::vector<psync::MissingDataInfo>& updates)
 {
@@ -130,5 +154,18 @@
     m_syncUpdateCallback(update.prefix, update.highSeq, update.incomingFace);
   }
 }
+#endif // HAVE_PSYNC
+
+#ifdef HAVE_SVS
+void
+SyncProtocolAdapter::onSvsUpdate(const std::vector<ndn::svs::MissingDataInfo>& updates)
+{
+  NLSR_LOG_TRACE("Received SVS update event");
+
+  for (const auto& update : updates) {
+    m_syncUpdateCallback(update.nodeId, update.high, 0);
+  }
+}
+#endif // HAVE_SVS
 
 } // namespace nlsr
diff --git a/src/communication/sync-protocol-adapter.hpp b/src/communication/sync-protocol-adapter.hpp
index fb5cdbe..e98fa53 100644
--- a/src/communication/sync-protocol-adapter.hpp
+++ b/src/communication/sync-protocol-adapter.hpp
@@ -30,7 +30,12 @@
 #ifdef HAVE_CHRONOSYNC
 #include <ChronoSync/logic.hpp>
 #endif
+#ifdef HAVE_PSYNC
 #include <PSync/full-producer.hpp>
+#endif
+#ifdef HAVE_SVS
+#include <ndn-svs/core.hpp>
+#endif
 
 namespace nlsr {
 
@@ -48,14 +53,14 @@
                       ndn::time::milliseconds syncInterestLifetime,
                       SyncUpdateCallback syncUpdateCallback);
 
-  /*! \brief Add user node to ChronoSync or PSync
+  /*! \brief Add user node to Sync
    *
    * \param userPrefix the Name under which the application will publishData
    */
   void
   addUserNode(const ndn::Name& userPrefix);
 
-  /*! \brief Publish update to ChronoSync or PSync
+  /*! \brief Publish update to Sync
    *
    * NLSR forces sequences number on the sync protocol
    * as it manages is its own sequence number by storing it in a file.
@@ -72,24 +77,36 @@
    *
    * This function packages the sync information into discrete updates
    * and passes those off to another function, m_syncUpdateCallback.
-   * \sa m_syncUpdateCallback
    *
-   * \param v A container with the new information sync has received
+   * \param updates A container with the new information sync has received
    */
   void
   onChronoSyncUpdate(const std::vector<chronosync::MissingDataInfo>& updates);
-#endif
+#endif // HAVE_CHRONOSYNC
 
+#ifdef HAVE_PSYNC
    /*! \brief Hook function to call whenever PSync detects new data.
    *
    * This function packages the sync information into discrete updates
    * and passes those off to another function, m_syncUpdateCallback.
-   * \sa m_syncUpdateCallback
    *
-   * \param v A container with the new information sync has received
+   * \param updates A container with the new information sync has received
    */
   void
   onPSyncUpdate(const std::vector<psync::MissingDataInfo>& updates);
+#endif // HAVE_PSYNC
+
+#ifdef HAVE_SVS
+  /*! \brief Hook function to call whenever SVS detects new data.
+   *
+   * This function packages the sync information into discrete updates
+   * and passes those off to another function, m_syncUpdateCallback.
+   *
+   * \param updates A container with the new information sync has received
+   */
+  void
+  onSvsUpdate(const std::vector<ndn::svs::MissingDataInfo>& updates);
+#endif // HAVE_SVS
 
 private:
   SyncProtocol m_syncProtocol;
@@ -98,7 +115,12 @@
 #ifdef HAVE_CHRONOSYNC
   std::shared_ptr<chronosync::Logic> m_chronoSyncLogic;
 #endif
+#ifdef HAVE_PSYNC
   std::shared_ptr<psync::FullProducer> m_psyncLogic;
+#endif
+#ifdef HAVE_SVS
+  std::shared_ptr<ndn::svs::SVSyncCore> m_svsCore;
+#endif
 };
 
 } // namespace nlsr
diff --git a/src/conf-file-processor.cpp b/src/conf-file-processor.cpp
index bd7dceb..b9ab454 100644
--- a/src/conf-file-processor.cpp
+++ b/src/conf-file-processor.cpp
@@ -289,17 +289,29 @@
 #ifdef HAVE_CHRONOSYNC
     m_confParam.setSyncProtocol(SyncProtocol::CHRONOSYNC);
 #else
-    std::cerr << "NLSR was compiled without ChronoSync support!\n"
-              << "Only PSync support is currently available ('sync-protocol psync')\n";
+    std::cerr << "NLSR was compiled without ChronoSync support!\n";
     return false;
 #endif
   }
   else if (syncProtocol == "psync") {
+#ifdef HAVE_PSYNC
     m_confParam.setSyncProtocol(SyncProtocol::PSYNC);
+#else
+    std::cerr << "NLSR was compiled without PSync support!\n";
+    return false;
+#endif
+  }
+  else if (syncProtocol == "svs") {
+#ifdef HAVE_SVS
+    m_confParam.setSyncProtocol(SyncProtocol::SVS);
+#else
+    std::cerr << "NLSR was compiled without SVS support!\n";
+    return false;
+#endif
   }
   else {
     std::cerr << "Sync protocol '" << syncProtocol << "' is not supported!\n"
-              << "Use either 'chronosync' or 'psync'\n";
+              << "Use 'chronosync' or 'psync' or 'svs'\n";
     return false;
   }
 
diff --git a/src/conf-parameter.hpp b/src/conf-parameter.hpp
index 32b343c..1bcf64c 100644
--- a/src/conf-parameter.hpp
+++ b/src/conf-parameter.hpp
@@ -38,6 +38,7 @@
 enum class SyncProtocol {
   CHRONOSYNC,
   PSYNC,
+  SVS,
 };
 
 enum {