Fix recurring sync prefix registration on every hello data

refs: #5157

Change-Id: Id0f77789976bd84720d2f96b549013b285e58978
diff --git a/src/hello-protocol.cpp b/src/hello-protocol.cpp
index 9585255..e11f0e4 100644
--- a/src/hello-protocol.cpp
+++ b/src/hello-protocol.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2020,  The University of Memphis,
+ * Copyright (c) 2014-2021,  The University of Memphis,
  *                           Regents of the University of California
  *
  * This file is part of NLSR (Named-data Link State Routing).
@@ -246,9 +246,8 @@
       else {
         m_lsdb.scheduleAdjLsaBuild();
       }
+      onInitialHelloDataValidated(neighbor);
     }
-
-    onHelloDataValidated(neighbor);
   }
   // increment RCV_HELLO_DATA
   hpIncrementSignal(Statistics::PacketType::RCV_HELLO_DATA);
diff --git a/src/hello-protocol.hpp b/src/hello-protocol.hpp
index 9ff5924..a42a4de 100644
--- a/src/hello-protocol.hpp
+++ b/src/hello-protocol.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2020,  The University of Memphis,
+ * Copyright (c) 2014-2021,  The University of Memphis,
  *                           Regents of the University of California,
  *                           Arizona Board of Regents.
  *
@@ -126,7 +126,7 @@
                             const ndn::security::ValidationError& ve);
 
 public:
-  ndn::util::Signal<HelloProtocol, const ndn::Name&> onHelloDataValidated;
+  ndn::util::Signal<HelloProtocol, const ndn::Name&> onInitialHelloDataValidated;
 
 private:
   ndn::Face& m_face;
@@ -138,6 +138,7 @@
   Lsdb& m_lsdb;
   AdjacencyList& m_adjacencyList;
 
+PUBLIC_WITH_TESTS_ELSE_PRIVATE:
   static const std::string INFO_COMPONENT;
   static const std::string NLSR_COMPONENT;
 };
diff --git a/src/nlsr.cpp b/src/nlsr.cpp
index cb24559..abf5c5f 100644
--- a/src/nlsr.cpp
+++ b/src/nlsr.cpp
@@ -56,7 +56,7 @@
       [this] (const ndn::Name& name) {
         m_helloProtocol.sendHelloInterest(name);
       }))
-  , m_onHelloDataValidated(m_helloProtocol.onHelloDataValidated.connect(
+  , m_onInitialHelloDataValidated(m_helloProtocol.onInitialHelloDataValidated.connect(
       [this] (const ndn::Name& neighbor) {
         auto it = m_adjacencyList.findAdjacent(neighbor);
         if (it != m_adjacencyList.end()) {
diff --git a/src/nlsr.hpp b/src/nlsr.hpp
index 3e22874..4c97401 100644
--- a/src/nlsr.hpp
+++ b/src/nlsr.hpp
@@ -179,7 +179,7 @@
 private:
   ndn::util::signal::ScopedConnection m_onNewLsaConnection;
   ndn::util::signal::ScopedConnection m_onPrefixRegistrationSuccess;
-  ndn::util::signal::ScopedConnection m_onHelloDataValidated;
+  ndn::util::signal::ScopedConnection m_onInitialHelloDataValidated;
 
 PUBLIC_WITH_TESTS_ELSE_PRIVATE:
   ndn::mgmt::Dispatcher m_dispatcher;
diff --git a/tests/test-hello-protocol.cpp b/tests/test-hello-protocol.cpp
index f5aee2b..742d129 100644
--- a/tests/test-hello-protocol.cpp
+++ b/tests/test-hello-protocol.cpp
@@ -115,6 +115,38 @@
   checkHelloInterestTimeout();
 }
 
+BOOST_AUTO_TEST_CASE(CheckHelloDataValidatedSignal) // # 5157
+{
+  int numOnInitialHelloDataValidates = 0;
+  helloProtocol.onInitialHelloDataValidated.connect(
+    [&] (const ndn::Name& neighbor) {
+      ++numOnInitialHelloDataValidates;
+    }
+  );
+
+  ndn::FaceUri faceUri("udp4://10.0.0.2:6363");
+  Adjacent adj1("/ndn/site/%C1.Router/router-other", faceUri, 10,
+                Adjacent::STATUS_INACTIVE, 0, 300);
+  adjList.insert(adj1);
+
+  ndn::Name dataName = adj1.getName() ;
+  dataName.append(nlsr::HelloProtocol::NLSR_COMPONENT);
+  dataName.append(nlsr::HelloProtocol::INFO_COMPONENT);
+  dataName.append(conf.getRouterPrefix().wireEncode());
+
+  ndn::Data data(ndn::Name(dataName).appendVersion());
+  BOOST_CHECK_EQUAL(numOnInitialHelloDataValidates, 0);
+  helloProtocol.onContentValidated(data);
+  BOOST_CHECK_EQUAL(numOnInitialHelloDataValidates, 1);
+  BOOST_CHECK_EQUAL(adjList.getStatusOfNeighbor(adj1.getName()), Adjacent::STATUS_ACTIVE);
+
+  // No state change of neighbor so no signal:
+  ndn::Data data2(ndn::Name(dataName).appendVersion());
+  helloProtocol.onContentValidated(data2);
+  BOOST_CHECK_EQUAL(numOnInitialHelloDataValidates, 1);
+  BOOST_CHECK_EQUAL(adjList.getStatusOfNeighbor(adj1.getName()), Adjacent::STATUS_ACTIVE);
+}
+
 BOOST_AUTO_TEST_SUITE_END()
 
 } // namespace test