comm: Create SyncSocket on initialization

refs: #2649

Change-Id: I9e5891b8ad5de9a6ff6ac4edab4bab1564a309c8
diff --git a/src/communication/sync-logic-handler.cpp b/src/communication/sync-logic-handler.cpp
index 705a721..1434aa4 100644
--- a/src/communication/sync-logic-handler.cpp
+++ b/src/communication/sync-logic-handler.cpp
@@ -138,8 +138,18 @@
 }
 
 void
-SyncLogicHandler::createSyncSocket()
+SyncLogicHandler::createSyncSocket(const ndn::Name& syncPrefix)
 {
+  if (m_syncSocket != nullptr) {
+    _LOG_WARN("Trying to create Sync socket, but Sync socket already exists");
+    return;
+  }
+
+  m_syncPrefix = syncPrefix;
+
+  // Build LSA sync update prefix
+  buildUpdatePrefix();
+
   _LOG_DEBUG("Creating Sync socket. Sync Prefix: " << m_syncPrefix);
 
   // The face's lifetime is managed in main.cpp; SyncSocket should not manage the memory
@@ -254,6 +264,12 @@
 void
 SyncLogicHandler::publishRoutingUpdate()
 {
+  if (m_syncSocket == nullptr) {
+    _LOG_FATAL("Cannot publish routing update; SyncSocket does not exist");
+
+    throw SyncLogicHandler::Error("Cannot publish routing update; SyncSocket does not exist");
+  }
+
   m_sequencingManager.writeSeqNoToFile();
 
   publishSyncUpdate(m_updatePrefix, m_sequencingManager.getCombinedSeqNo());
diff --git a/src/communication/sync-logic-handler.hpp b/src/communication/sync-logic-handler.hpp
index 36caae7..7df3671 100644
--- a/src/communication/sync-logic-handler.hpp
+++ b/src/communication/sync-logic-handler.hpp
@@ -44,10 +44,17 @@
 class SyncLogicHandler
 {
 public:
-  SyncLogicHandler(ndn::Face& face, Lsdb& lsdb, ConfParameter& conf, SequencingManager& seqManager);
+  class Error : public std::runtime_error
+  {
+  public:
+    explicit
+    Error(const std::string& what)
+      : std::runtime_error(what)
+    {
+    }
+  };
 
-  void
-  createSyncSocket();
+  SyncLogicHandler(ndn::Face& face, Lsdb& lsdb, ConfParameter& conf, SequencingManager& seqManager);
 
   void
   onNsyncUpdate(const std::vector<Sync::MissingDataInfo>& v, Sync::SyncSocket* socket);
@@ -59,15 +66,12 @@
   publishRoutingUpdate();
 
   void
-  setSyncPrefix(const std::string& sp)
-  {
-    m_syncPrefix = sp;
-  }
+  createSyncSocket(const ndn::Name& syncPrefix);
 
+private:
   void
   buildUpdatePrefix();
 
-private:
   void
   processUpdateFromSync(const SyncUpdate& updateName);