support for NS, TXT, NDNCERT, FH
diff --git a/src/app/name-server.cpp b/src/app/name-server.cpp
index 6e6428d..99ceb19 100644
--- a/src/app/name-server.cpp
+++ b/src/app/name-server.cpp
@@ -18,39 +18,38 @@
*/
#include "name-server.hpp"
-
-namespace ndn{
-namespace ndns{
-NameServer::NameServer(const char *programName, const char *prefix, const char *nameZone)
-: NDNApp(programName, prefix)
-, m_zone(Name(nameZone))
-, m_zoneMgr(m_zone)
+namespace ndn {
+namespace ndns {
+NameServer::NameServer(const char *programName, const char *prefix,
+ const char *nameZone, const string dbfile)
+ : NDNApp(programName, prefix)
+ , m_zone(Name(nameZone))
+ , m_zoneMgr(m_zone)
{
+ m_zoneMgr.setDbfile(dbfile);
//m_zoneMgr.lookupId();
-}//NameServer Construction
+} //NameServer Construction
-
-void
-NameServer::onInterest(const Name &name, const Interest &interest)
+void NameServer::onInterest(const Name &name, const Interest &interest)
{
- cout<<"[* -> *] receive Interest: "<<interest.getName().toUri()<<std::endl;
+ cout << "[* -> *] receive Interest: " << interest.getName().toUri()
+ << std::endl;
Query query;
- if (!query.fromInterest(interest))
- {
- cout<<"can resolve the Query from Interest: "<<endl;
+ if (!query.fromInterest(interest)) {
+ cout << "can resolve the Query from Interest: " << endl;
return;
}
/*
* query.getAuthorityZone is routable name, not the zone's service name
- if (query.getAuthorityZone() != m_zoneMgr.getZone().getAuthorizedName())
- {
- cout<<"Query is intent to zone: "<<query.getAuthorityZone()
- <<". This is "<<m_zoneMgr.getZone().getAuthorizedName()<<endl;
- return;
- }
- */
+ if (query.getAuthorityZone() != m_zoneMgr.getZone().getAuthorizedName())
+ {
+ cout<<"Query is intent to zone: "<<query.getAuthorityZone()
+ <<". This is "<<m_zoneMgr.getZone().getAuthorizedName()<<endl;
+ return;
+ }
+ */
Response response;
Name name2 = interest.getName();
@@ -58,28 +57,23 @@
response.setQueryName(name2);
RRMgr mgr(m_zone, query, response);
-
- if (mgr.lookup()<0)
- {
- cout<<"[* !! *] lookup error, then exit: "<<mgr.getErr()<<endl;
+ if (mgr.lookup() < 0) {
+ cout << "[* !! *] lookup error, then exit: " << mgr.getErr() << endl;
return;
}
- if (response.getRrs().size() >0)
- {
+ if (response.getRrs().size() > 0) {
response.setResponseType(Response::NDNS_Resp);
} else {
if (query.getRrType() == RR::NS) {
int count = mgr.count();
- if (count < 0)
- {
- cout<<"[* !! *] lookup error, then exit: "<<mgr.getErr()<<endl;
+ if (count < 0) {
+ cout << "[* !! *] lookup error, then exit: " << mgr.getErr() << endl;
return;
- } else if (count > 0)
- {
+ } else if (count > 0) {
response.setResponseType(Response::NDNS_Auth);
- } else{
+ } else {
response.setResponseType(Response::NDNS_Nack);
}
} else {
@@ -87,56 +81,63 @@
}
}
-
Data data = response.toData();
data.setFreshnessPeriod(response.getFreshness());
m_keyChain.sign(data);
m_face.put(data);
- cout<<"[* <- *] send response: "<<response<<": "<<data<<endl;
-}//onInterest
+ cout << "[* <- *] send response: " << response << ": " << data << endl;
+} //onInterest
-
-void
-NameServer::run()
+void NameServer::run()
{
//m_zoneMgr.lookupId();
- if (m_zoneMgr.getZone().getId() == 0)
- {
+ if (m_zoneMgr.getZone().getId() == 0) {
m_hasError = true;
- m_error = "cannot get Zone.id from database for name="+m_zone.getAuthorizedName().toUri();
+ m_error = "cannot get Zone.id from database for name="
+ + m_zone.getAuthorizedName().toUri();
stop();
}
boost::asio::signal_set signalSet(m_ioService, SIGINT, SIGTERM);
signalSet.async_wait(boost::bind(&NDNApp::signalHandler, this));
- // boost::bind(&NdnTlvPingServer::signalHandler, this)
+ // boost::bind(&NdnTlvPingServer::signalHandler, this)
Name name;
name.set(m_prefix);
name.append(Query::toString(Query::QUERY_DNS));
- m_face.setInterestFilter(name,
- bind(&NameServer::onInterest,
- this, _1, _2),
- bind(&NDNApp::onRegisterFailed,
- this, _1,_2));
+ std::cout<<"========= NDNS Name Server for Zone "
+ <<m_zoneMgr.getZone().getAuthorizedName().toUri()
+ <<" Starts with Prefix "<<m_prefix;
+ if (m_enableForwardingHint > 0) {
+ std::cout<<" & ForwardingHint "<<m_forwardingHint.toUri();
+ }
+ std::cout<<"============="<<std::endl;
- std::cout << "\n=== NDNS Server for Zone "
- << m_zoneMgr.getZone().getAuthorizedName().toUri()
- <<" with routable prefix "<< name.toUri()
- << " starts===\n" << std::endl;
+ m_face.setInterestFilter(name, bind(&NameServer::onInterest, this, _1, _2),
+ bind(&NDNApp::onRegisterFailed, this, _1, _2));
+ std::cout<<"Name Server Register Name Prefix: "<<name<<std::endl;
+
+ if (m_enableForwardingHint > 0) {
+ Name name2 = Name(m_forwardingHint);
+ name2.append(ndn::ndns::label::ForwardingHintLabel);
+ name2.append(name);
+ m_face.setInterestFilter(name2, bind(&NameServer::onInterest, this, _1, _2),
+ bind(&NDNApp::onRegisterFailed, this, _1, _2));
+ std::cout<<"Name Server Register Name Prefix: "<<name2<<std::endl;
+ }
+
try {
m_face.processEvents();
- }
- catch (std::exception& e) {
+ } catch (std::exception& e) {
m_hasError = true;
m_error = "ERROR: ";
m_error += e.what();
stop();
}
-}//run
+} //run
} //namespace ndns
} /* namespace ndn */