src: Making shared_ptr<ndn::Data> to put to NFD
Change-Id: I2c8b0a322cbe2a848ba2be7d9e9639237a08878a
diff --git a/nsync/sync-logic.cc b/nsync/sync-logic.cc
index af864d3..2a748c3 100644
--- a/nsync/sync-logic.cc
+++ b/nsync/sync-logic.cc
@@ -665,13 +665,15 @@
char *wireData = new char[size];
ssm.SerializeToArray(wireData, size);
- Data syncData(name);
- syncData.setContent(reinterpret_cast<const uint8_t*>(wireData), size);
- syncData.setFreshnessPeriod(ndn::time::seconds(m_syncResponseFreshness));
+ //Data syncData(name);
+ ndn::shared_ptr<ndn::Data> syncData = ndn::make_shared<ndn::Data>();
+ syncData->setName(name);
+ syncData->setContent(reinterpret_cast<const uint8_t*>(wireData), size);
+ syncData->setFreshnessPeriod(ndn::time::seconds(m_syncResponseFreshness));
- m_keyChain->sign(syncData);
+ m_keyChain->sign(*syncData);
- m_face->put(syncData);
+ m_face->put(*syncData);
delete []wireData;
diff --git a/src/hello-protocol.cpp b/src/hello-protocol.cpp
index 41df359..ad6709c 100644
--- a/src/hello-protocol.cpp
+++ b/src/hello-protocol.cpp
@@ -93,13 +93,14 @@
neighbor.wireDecode(interestName.get(-1).blockFromValue());
_LOG_DEBUG("Neighbor: " << neighbor);
if (m_nlsr.getAdjacencyList().isNeighbor(neighbor)) {
- ndn::Data data(ndn::Name(interest.getName()).appendVersion());
- data.setFreshnessPeriod(ndn::time::seconds(10)); // 10 sec
- data.setContent(reinterpret_cast<const uint8_t*>(INFO_COMPONENT.c_str()),
+ ndn::shared_ptr<ndn::Data> data = ndn::make_shared<ndn::Data>();
+ data->setName(ndn::Name(interest.getName()).appendVersion());
+ data->setFreshnessPeriod(ndn::time::seconds(10)); // 10 sec
+ data->setContent(reinterpret_cast<const uint8_t*>(INFO_COMPONENT.c_str()),
INFO_COMPONENT.size());
- m_nlsr.getKeyChain().sign(data, m_nlsr.getDefaultCertName());
- _LOG_DEBUG("Sending out data for name: " << data.getName());
- m_nlsr.getNlsrFace().put(data);
+ m_nlsr.getKeyChain().sign(*data, m_nlsr.getDefaultCertName());
+ _LOG_DEBUG("Sending out data for name: " << interest.getName());
+ m_nlsr.getNlsrFace().put(*data);
Adjacent *adjacent = m_nlsr.getAdjacencyList().findAdjacent(neighbor);
if (adjacent->getStatus() == 0) {
if(adjacent->getFaceId() != 0){
diff --git a/src/lsdb.cpp b/src/lsdb.cpp
index c5e7756..5076f5e 100644
--- a/src/lsdb.cpp
+++ b/src/lsdb.cpp
@@ -804,6 +804,18 @@
}
void
+Lsdb::putLsaData(const ndn::Interest& interest, const std::string& content)
+{
+ ndn::shared_ptr<ndn::Data> data = ndn::make_shared<ndn::Data>();
+ data->setName(ndn::Name(interest.getName()).appendVersion());
+ data->setFreshnessPeriod(ndn::time::seconds(10));
+ data->setContent(reinterpret_cast<const uint8_t*>(content.c_str()), content.size());
+ m_nlsr.getKeyChain().sign(*data, m_nlsr.getDefaultCertName());
+ _LOG_DEBUG("Sending data for LSA(name): " << interest.getName());
+ m_nlsr.getNlsrFace().put(*data);
+}
+
+void
Lsdb::processInterestForNameLsa(const ndn::Interest& interest,
const ndn::Name& lsaKey,
uint32_t interestedlsSeqNo)
@@ -811,14 +823,8 @@
NameLsa* nameLsa = m_nlsr.getLsdb().findNameLsa(lsaKey);
if (nameLsa != 0) {
if (nameLsa->getLsSeqNo() >= interestedlsSeqNo) {
- ndn::Data data(ndn::Name(interest.getName()).appendVersion());
- _LOG_DEBUG("Sending data for LSA(name): " << interest.getName());
- data.setFreshnessPeriod(ndn::time::seconds(10)); // 10 sec
std::string content = nameLsa->getData();
- data.setContent(reinterpret_cast<const uint8_t*>(content.c_str()),
- content.size());
- m_nlsr.getKeyChain().sign(data, m_nlsr.getDefaultCertName());
- m_nlsr.getNlsrFace().put(data);
+ putLsaData(interest,content);
}
}
}
@@ -831,14 +837,8 @@
AdjLsa* adjLsa = m_nlsr.getLsdb().findAdjLsa(lsaKey);
if (adjLsa != 0) {
if (adjLsa->getLsSeqNo() >= interestedlsSeqNo) {
- ndn::Data data(ndn::Name(interest.getName()).appendVersion());
- _LOG_DEBUG("Sending data for LSA(name): " << interest.getName());
- data.setFreshnessPeriod(ndn::time::seconds(10)); // 10 sec
std::string content = adjLsa->getData();
- data.setContent(reinterpret_cast<const uint8_t*>(content.c_str()),
- content.size());
- m_nlsr.getKeyChain().sign(data, m_nlsr.getDefaultCertName());
- m_nlsr.getNlsrFace().put(data);
+ putLsaData(interest,content);
}
}
}
@@ -851,14 +851,8 @@
CoordinateLsa* corLsa = m_nlsr.getLsdb().findCoordinateLsa(lsaKey);
if (corLsa != 0) {
if (corLsa->getLsSeqNo() >= interestedlsSeqNo) {
- ndn::Data data(ndn::Name(interest.getName()).appendVersion());
- _LOG_DEBUG("Sending data for LSA(name): " << interest.getName());
- data.setFreshnessPeriod(ndn::time::seconds(10)); // 10 sec
std::string content = corLsa->getData();
- data.setContent(reinterpret_cast<const uint8_t*>(content.c_str()),
- content.size());
- m_nlsr.getKeyChain().sign(data, m_nlsr.getDefaultCertName());
- m_nlsr.getNlsrFace().put(data);
+ putLsaData(interest,content);
}
}
}
diff --git a/src/lsdb.hpp b/src/lsdb.hpp
index 7c6ceb1..64de8ec 100644
--- a/src/lsdb.hpp
+++ b/src/lsdb.hpp
@@ -165,6 +165,9 @@
private:
void
+ putLsaData(const ndn::Interest& interest, const std::string& content);
+
+ void
processInterestForNameLsa(const ndn::Interest& interest,
const ndn::Name& lsaKey,
uint32_t interestedlsSeqNo);
diff --git a/src/nlsr.cpp b/src/nlsr.cpp
index 2285d85..5fef3bf 100644
--- a/src/nlsr.cpp
+++ b/src/nlsr.cpp
@@ -164,11 +164,12 @@
if (!static_cast<bool>(cert))
return; // cert is not found
- Data data(interestName);
- data.setContent(cert->wireEncode());
- m_keyChain.signWithSha256(data);
+ ndn::shared_ptr<ndn::Data> data = ndn::make_shared<ndn::Data>();
+ data->setName(interestName);
+ data->setContent(cert->wireEncode());
+ m_keyChain.signWithSha256(*data);
- m_nlsrFace.put(data);
+ m_nlsrFace.put(*data);
}
void
diff --git a/src/route/routing-table-calculator.cpp b/src/route/routing-table-calculator.cpp
index 1c39d51..57bf6b2 100644
--- a/src/route/routing-table-calculator.cpp
+++ b/src/route/routing-table-calculator.cpp
@@ -242,7 +242,6 @@
RoutingTable& rt, Map& pMap, int sourceRouter)
{
_LOG_DEBUG("LinkStateRoutingTableCalculator::addAllNextHopsToRoutingTable Called");
- std::cout << std::endl;
int nextHopRouter = 0;
for (int i = 0; i < numOfRouter ; i++) {
if (i != sourceRouter) {