Skip to content

Instantly share code, notes, and snippets.

@anilj1
Created May 13, 2015 21:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anilj1/ebd1dbb6cf7d9a2582c9 to your computer and use it in GitHub Desktop.
Save anilj1/ebd1dbb6cf7d9a2582c9 to your computer and use it in GitHub Desktop.
Producer not receiving Interest, when starts a new thread.
void
Producer::run() {
// Read the database value for the sensor Id and update the serving router
// Id if the distance is less than the existing one.
std::string ldb_uri = getConfig().getLocationDb().getDbUri();
m_face.setInterestFilter("/",
bind(&Producer::onInterest, this, _1, _2),
RegisterPrefixSuccessCallback(),
bind(&Producer::onRegisterFailed, this, _1, _2));
sendInterest();
_LOG_DEBUG("WAITING FOR Events");
m_face.processEvents();
}
void
Producer::sendInterest() {
std::string servingRouter = m_ldb.getServingRouter(sensorId);
ndn::Name interestName;
interestName.append(servingRouter);
interestName.append(ndn::Name("/DATA"));
// Add parameter (content name)
interestName.append(ndn::Name("/$cname=/ndn/temp/s/2,rname="+thisRouter+"$"));
ndn::Interest i(interestName);
i.setInterestLifetime(ndn::time::seconds(3));
i.setMustBeFresh(true);
std::cout << "Pending Interest Notification: " << i << std::endl;
m_face.expressInterest(i,
ndn::bind(&Producer::onContent, this, _1, _2),
ndn::bind(&Producer::processInterestTimedOut, this, _1));
}
void
Producer::onInterest(const InterestFilter& filter,
const Interest& interest) {
std::cout << "<< I: " << interest << std::endl;
// Create new name, based on Interest's name
Name dataName(interest.getName());
dataName.append("testApp") // add "testApp" component to Interest name
.appendVersion(); // add "version" component (current UNIX timestamp in milliseconds)
static const std::string content = "HELLO KITTY";
// Create Data packet
ndn::shared_ptr<Data> data = ndn::make_shared<Data>();
data->setName(dataName);
data->setFreshnessPeriod(time::seconds(10));
data->setContent(reinterpret_cast<const uint8_t*>(content.c_str()),
content.size());
// Sign Data packet with default identity
m_keyChain.sign(*data);
// m_keyChain.sign(data, <identityName>);
// m_keyChain.sign(data, <certificate>);
// Return Data packet to the requester
std::cout << ">> D: " << *data << std::endl;
m_face.put(*data);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment