Revert "sync: remove check-for-self in sync updates"

This reverts commit b23f279353a14ce53a454d78ae8f069935187b86.

Change-Id: I8630be544195a01e09b3a2e4d85d102ac00cfc72
refs: #4134
diff --git a/src/communication/sync-logic-handler.cpp b/src/communication/sync-logic-handler.cpp
index acfeae9..c43a070 100644
--- a/src/communication/sync-logic-handler.cpp
+++ b/src/communication/sync-logic-handler.cpp
@@ -121,26 +121,30 @@
 {
   _LOG_DEBUG("Origin Router of update: " << originRouter);
 
-  std::string lsaType = updateName.get(updateName.size()-1).toUri();
+  // A router should not try to fetch its own LSA
+  if (originRouter != m_confParam.getRouterPrefix()) {
 
-  _LOG_DEBUG("Received sync update with higher " << lsaType
-             << " sequence number than entry in LSDB");
+    std::string lsaType = updateName.get(updateName.size()-1).toUri();
 
-  if (isLsaNew(originRouter, lsaType, seqNo)) {
-    if (lsaType == AdjLsa::TYPE_STRING && seqNo != 0 &&
-        m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_ON) {
-      _LOG_ERROR("Got an update for adjacency LSA when hyperbolic routing"
-                 << " is enabled. Not going to fetch.");
-      return;
+    _LOG_DEBUG("Received sync update with higher " << lsaType
+               << " sequence number than entry in LSDB");
+
+    if (isLsaNew(originRouter, lsaType, seqNo)) {
+      if (lsaType == AdjLsa::TYPE_STRING && seqNo != 0 &&
+          m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_ON) {
+        _LOG_ERROR("Got an update for adjacency LSA when hyperbolic routing"
+                   << " is enabled. Not going to fetch.");
+        return;
+      }
+
+      if (lsaType == CoordinateLsa::TYPE_STRING && seqNo != 0 &&
+          m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_OFF) {
+        _LOG_ERROR("Got an update for coordinate LSA when link-state"
+                   << " is enabled. Not going to fetch.");
+        return;
+      }
+      expressInterestForLsa(updateName, seqNo);
     }
-
-    if (lsaType == CoordinateLsa::TYPE_STRING && seqNo != 0 &&
-        m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_OFF) {
-      _LOG_ERROR("Got an update for coordinate LSA when link-state"
-                 << " is enabled. Not going to fetch.");
-      return;
-    }
-    expressInterestForLsa(updateName, seqNo);
   }
 }
 
diff --git a/tests/test-sync-logic-handler.cpp b/tests/test-sync-logic-handler.cpp
index a6b054a..76ca830 100644
--- a/tests/test-sync-logic-handler.cpp
+++ b/tests/test-sync-logic-handler.cpp
@@ -168,6 +168,19 @@
   }
 }
 
+BOOST_AUTO_TEST_CASE(NoUpdateForSelf)
+{
+  for (const std::string& lsaType : lsaTypes) {
+    std::string updateName = nlsr.getConfParameter().getLsaPrefix().toUri() +
+                             CONFIG_SITE + CONFIG_ROUTER_NAME + lsaType;
+
+    receiveUpdate(updateName, 1, sync);
+
+    std::vector<ndn::Interest>& interests = face->sentInterests;
+    BOOST_CHECK_EQUAL(interests.size(), 0);
+  }
+}
+
 BOOST_AUTO_TEST_CASE(MalformedUpdate)
 {
   for (const std::string& lsaType : lsaTypes) {