wait to be verified
diff --git a/src/app/name-caching-resolver.cpp b/src/app/name-caching-resolver.cpp
new file mode 100644
index 0000000..728d0b0
--- /dev/null
+++ b/src/app/name-caching-resolver.cpp
@@ -0,0 +1,194 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014, Regents of the University of California.
+ *
+ * This file is part of NDNS (Named Data Networking Domain Name Service).
+ * See AUTHORS.md for complete list of NDNS authors and contributors.
+ *
+ * NDNS is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * NDNS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * NDNS, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ */
+#include "name-caching-resolver.hpp"
+
+namespace ndn {
+namespace ndns {
+
+NameCachingResolver::NameCachingResolver(const char *programName, const char *prefix)
+: NDNApp(programName, prefix)
+//, m_resolverType(CachingResolver)
+{
+ this->setInterestLifetime(time::milliseconds(2000));
+}
+
+
+
+void
+NameCachingResolver::run()
+{
+ boost::asio::signal_set signalSet(m_ioService, SIGINT, SIGTERM);
+ signalSet.async_wait(boost::bind(&NDNApp::signalHandler, this));
+ // boost::bind(&NdnTlvPingServer::signalHandler, this)
+
+ Name name(m_prefix);
+ name.append(Query::toString(Query::QUERY_DNS_R));
+
+ m_face.setInterestFilter(name,
+ bind(&NameCachingResolver::onInterest,
+ this, _1, _2),
+ bind(&NDNApp::onRegisterFailed,
+ this, _1,_2));
+
+ std::cout << "\n=== NDNS Resolver "<<m_programName
+ <<" with routeble prefix "<< name.toUri()
+ << " starts===\n" << std::endl;
+
+ try {
+ m_face.processEvents();
+ }
+ catch (std::exception& e) {
+ std::cerr << "ERROR: " << e.what() << std::endl;
+ m_hasError = true;
+ m_ioService.stop();
+ }
+}
+
+
+
+void
+NameCachingResolver::onData(const Interest& interest, Data &data, IterativeQuery& iq)
+{
+ if (interest.getName() != iq.getLastInterest().getName())
+ {
+ std::cout<<iq<<std::endl;
+ std::cout<<"waiting for "<<iq.getLastInterest().getName().toUri()<<std::endl;
+ std::cout<<"coming data "<<data.getName().toUri()<<std::endl;
+ return;
+ }
+
+ iq.doData(data);
+
+ if (iq.getStep() == IterativeQuery::AnswerStub)
+ {
+ Data data = iq.getLastResponse().toData();
+ Name name = iq.getQuery().getAuthorityZone();
+ name.append(Query::toString(iq.getQuery().getQueryType()));
+ name.append(iq.getQuery().getRrLabel());
+ name.append(RR::toString(iq.getQuery().getRrType()));
+ name.appendVersion();
+ data.setName(name);
+ data.setFreshnessPeriod(iq.getLastResponse().getFreshness());
+
+ m_keyChain.sign(data);
+ m_face.put(data);
+ std::cout<<"[* <- *] answer Response ("
+ <<Response::toString(iq.getLastResponse().getResponseType())<<") to stub:"<<std::endl;
+ std::cout<<iq.getLastResponse()<<std::endl;
+ for (int i=0; i<15; i++)
+ {
+ std::cout<<"----";
+ }
+ std::cout<<std::endl<<std::endl;
+
+ } else if (iq.getStep() == IterativeQuery::NSQuery){
+ resolve(iq);
+ } else if (iq.getStep() == IterativeQuery::RRQuery) {
+ resolve(iq);
+ } else if (iq.getStep() == IterativeQuery::Abort) {
+ return;
+ } else {
+ std::cout<<"let me see the current step="<<IterativeQuery::toString(iq.getStep())<<std::endl;
+ std::cout<<iq<<std::endl;
+ }
+
+}
+
+
+void
+NameCachingResolver::answerRespNack(IterativeQuery& iq)
+{
+ Response re;
+
+ Name name = iq.getQuery().getAuthorityZone();
+ name.append(Query::toString(iq.getQuery().getQueryType()));
+ name.append(iq.getQuery().getRrLabel());
+ name.append(RR::toString(iq.getQuery().getRrType()));
+ name.appendVersion();
+
+ re.setResponseType(Response::NDNS_Nack);
+ re.setFreshness(this->getContentFreshness());
+ re.setQueryName(name);
+ Data data = re.toData();
+
+ m_keyChain.sign(data);
+ m_face.put(data);
+ std::cout<<"[* <- *] answer RRs to stub:"<<std::endl;
+ std::cout<<iq.getLastResponse().getStringRRs()<<std::endl;
+ for (int i=0; i<15; i++)
+ {
+ std::cout<<"----";
+ }
+ std::cout<<std::endl<<std::endl;
+}
+
+void
+NameCachingResolver::onInterest(const Name &name, const Interest &interest)
+{
+ Query query;
+ query.fromInterest(interest);
+ std::cout<<"[* -> *] receive Interest: "<<interest.getName().toUri()<<std::endl;
+ if (query.getQueryType() == Query::QUERY_DNS)
+ {
+ cout<<m_programName<<" is not in charge of Query_DNS"<<endl;
+ }
+
+ IterativeQuery iq(query);
+ //iq.setQuery(query);
+ resolve(iq);
+
+}
+
+
+void
+NameCachingResolver::onTimeout(const Interest& interest, IterativeQuery& iq)
+{
+ std::cout<<"[* !! *] timeout Interest "<<interest.getName().toUri()<<" timeouts"<<std::endl;
+
+ iq.doTimeout();
+ return;
+}
+
+void
+NameCachingResolver::resolve(IterativeQuery& iq) {
+
+ Interest interest = iq.toLatestInterest();
+
+ //must be set before express interest,since the call will back call iq
+ //if set after, then the iq in call of onData will return nothing
+ //be very careful here, as a new guy to c++
+
+ interest.setInterestLifetime(this->getInterestLifetime());
+ iq.setLastInterest(interest);
+ try {
+ m_face.expressInterest(interest,
+ boost::bind(&NameCachingResolver::onData, this, _1, _2, iq),
+ boost::bind(&NameCachingResolver::onTimeout, this, _1, iq)
+ );
+ }catch(std::exception& e) {
+ std::cerr << "ERROR: " << e.what() << std::endl;
+ }
+
+
+ std::cout<<"[* <- *] send Interest: "<<interest.getName().toUri()<<std::endl;
+ std::cout<<iq<<std::endl;
+}
+
+} /* namespace ndns */
+} /* namespace ndn */
diff --git a/src/app/name-caching-resolver.hpp b/src/app/name-caching-resolver.hpp
new file mode 100644
index 0000000..5f4fe53
--- /dev/null
+++ b/src/app/name-caching-resolver.hpp
@@ -0,0 +1,85 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014, Regents of the University of California.
+ *
+ * This file is part of NDNS (Named Data Networking Domain Name Service).
+ * See AUTHORS.md for complete list of NDNS authors and contributors.
+ *
+ * NDNS is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * NDNS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * NDNS, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef NAME_RESOLVER_HPP
+#define NAME_RESOLVER_HPP
+
+#include <boost/asio.hpp>
+#include <boost/noncopyable.hpp>
+
+#include <ndn-cxx/face.hpp>
+#include <ndn-cxx/name.hpp>
+#include <ndn-cxx/security/key-chain.hpp>
+
+#include "zone.hpp"
+#include "db/zone-mgr.hpp"
+#include "db/rr-mgr.hpp"
+#include "query.hpp"
+#include "response.hpp"
+#include "rr.hpp"
+#include "iterative-query.hpp"
+#include "ndn-app.hpp"
+
+using namespace std;
+
+namespace ndn {
+namespace ndns {
+
+
+class NameCachingResolver : public NDNApp{
+enum ResolverType
+{
+ StubResolver,
+ CachingResolver
+};
+
+public:
+
+NameCachingResolver(const char *programName, const char *prefix);
+
+
+void
+resolve(IterativeQuery& iq);
+
+void
+answerRespNack(IterativeQuery& iq);
+
+using NDNApp::onData;
+void
+onData(const Interest& interest, Data &data, IterativeQuery& iq);
+
+void
+onInterest(const Name &name, const Interest &interest);
+
+using NDNApp::onTimeout;
+
+void
+onTimeout(const Interest& interest, IterativeQuery& iq);
+
+void
+run();
+
+private:
+ //ResolverType m_resolverType;
+
+};
+
+} /* namespace ndns */
+} /* namespace ndn */
+
+#endif /* NAME_RESOLVER_HPP_ */
diff --git a/src/app/name-dig.cpp b/src/app/name-dig.cpp
new file mode 100644
index 0000000..6e64e31
--- /dev/null
+++ b/src/app/name-dig.cpp
@@ -0,0 +1,123 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014, Regents of the University of California.
+ *
+ * This file is part of NDNS (Named Data Networking Domain Name Service).
+ * See AUTHORS.md for complete list of NDNS authors and contributors.
+ *
+ * NDNS is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * NDNS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * NDNS, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ */
+#include "name-dig.hpp"
+
+namespace ndn {
+namespace ndns {
+
+NameDig::NameDig(const char *programName, const char *prefix)
+: NDNApp(programName, prefix)
+, m_resolverName(Name("/"))
+, m_dstLabel(Name(prefix)){
+ //prefix in this app is the m_dstLabel
+ this->setInterestLifetime(time::milliseconds(10000));
+}
+
+NameDig::~NameDig() {
+ // TODO Auto-generated destructor stub
+}
+
+void
+NameDig::onData(const Interest& interest, Data& data)
+{
+ Response re;
+ re.fromData(data);
+ cout<<"get data:->"<<data.getName()<<endl;
+ cout<<"get response:->"<<re<<endl;
+
+
+
+ m_rrs = re.getRrs();
+
+
+
+ vector<RR>::iterator iter = m_rrs.begin();
+
+ while (iter != m_rrs.end())
+ {
+ RR rr = *iter;
+ cout<<rr<<endl;
+ iter ++;
+ }
+
+ this->stop();
+}
+
+void
+NameDig::sendQuery()
+{
+ Query q;
+ q.setAuthorityZone(this->m_resolverName);
+ q.setRrLabel(m_dstLabel);
+ q.setQueryType(Query::QUERY_DNS_R);
+ q.setRrType(m_rrType);
+
+ Interest interest = q.toInterest();
+ interest.setInterestLifetime(this->m_interestLifetime);
+ try {
+ m_face.expressInterest(interest,
+ boost::bind(&NameDig::onData, this, _1, _2),
+ boost::bind(&NameDig::onTimeout, this, _1)
+ );
+ std::cout<<"[* <- *] send Interest: "<<interest.getName().toUri()<<std::endl;
+ }catch(std::exception& e) {
+ m_hasError = true;
+ m_error = e.what();
+ }
+ m_interestTriedNum += 1;
+}
+
+void
+NameDig::onTimeout(const Interest& interest)
+{
+ std::cout<<"[* !! *] timeout Interest"<<interest.getName()<<std::endl;
+
+ if (m_interestTriedNum >= m_interestTriedMax)
+ {
+ m_error = "All Interests timeout";
+ m_hasError = true;
+ this->stop();
+ } else
+ {
+ sendQuery();
+ }
+
+}
+
+void
+NameDig::run()
+{
+
+ this->sendQuery();
+
+ try
+ {
+ m_face.processEvents();
+ }
+ catch (std::exception& e)
+ {
+ m_error = e.what();
+ m_hasError = true;
+ this->stop();
+ }
+
+}
+
+} /* namespace ndns */
+} /* namespace ndn */
diff --git a/src/app/name-dig.hpp b/src/app/name-dig.hpp
new file mode 100644
index 0000000..475cf26
--- /dev/null
+++ b/src/app/name-dig.hpp
@@ -0,0 +1,92 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014, Regents of the University of California.
+ *
+ * This file is part of NDNS (Named Data Networking Domain Name Service).
+ * See AUTHORS.md for complete list of NDNS authors and contributors.
+ *
+ * NDNS is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * NDNS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * NDNS, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef NAME_DIG_HPP_
+#define NAME_DIG_HPP_
+
+#include "ndn-app.hpp"
+#include "rr.hpp"
+#include "response.hpp"
+#include "query.hpp"
+
+namespace ndn {
+namespace ndns {
+
+class NameDig: public NDNApp {
+public:
+ NameDig(const char *programName, const char *prefix);
+ virtual ~NameDig();
+
+ void
+ onData(const ndn::Interest& interest, Data& data);
+
+
+ void
+ onTimeout(const ndn::Interest& interest);
+
+ void
+ sendQuery();
+
+ void
+ run();
+
+ const vector<RR>& getRrs() const {
+ return m_rrs;
+ }
+
+ void setRrs(const vector<RR>& rrs) {
+ m_rrs = rrs;
+ }
+
+ const Name& getResolverName() const {
+ return m_resolverName;
+ }
+
+ void setResolverName(const Name& resolverName) {
+ m_resolverName = resolverName;
+ }
+
+
+
+ const Name& getDstLabel() const {
+ return m_dstLabel;
+ }
+
+ void setDstLabel(const Name& dstLabel) {
+ m_dstLabel = dstLabel;
+ }
+
+ RR::RRType getRrType() const {
+ return m_rrType;
+ }
+
+ void setRrType(RR::RRType rrType) {
+ m_rrType = rrType;
+ }
+
+private:
+ Name m_resolverName;
+ Name m_dstLabel;
+ RR::RRType m_rrType;
+ vector<RR> m_rrs;
+};
+
+} /* namespace ndns */
+} /* namespace ndn */
+
+#endif /* NAME_DIG_HPP_ */
diff --git a/src/app/name-server.cpp b/src/app/name-server.cpp
new file mode 100644
index 0000000..6e6428d
--- /dev/null
+++ b/src/app/name-server.cpp
@@ -0,0 +1,143 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014, Regents of the University of California.
+ *
+ * This file is part of NDNS (Named Data Networking Domain Name Service).
+ * See AUTHORS.md for complete list of NDNS authors and contributors.
+ *
+ * NDNS is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * NDNS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * NDNS, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ */
+#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)
+{
+ //m_zoneMgr.lookupId();
+}//NameServer Construction
+
+
+void
+NameServer::onInterest(const Name &name, const Interest &interest)
+{
+
+ cout<<"[* -> *] receive Interest: "<<interest.getName().toUri()<<std::endl;
+ Query query;
+ 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;
+ }
+ */
+
+ Response response;
+ Name name2 = interest.getName();
+ name2.appendVersion();
+ response.setQueryName(name2);
+ RRMgr mgr(m_zone, query, response);
+
+
+ if (mgr.lookup()<0)
+ {
+ cout<<"[* !! *] lookup error, then exit: "<<mgr.getErr()<<endl;
+ return;
+ }
+
+ 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;
+ return;
+ } else if (count > 0)
+ {
+ response.setResponseType(Response::NDNS_Auth);
+ } else{
+ response.setResponseType(Response::NDNS_Nack);
+ }
+ } else {
+ response.setResponseType(Response::NDNS_Nack);
+ }
+ }
+
+
+ Data data = response.toData();
+ data.setFreshnessPeriod(response.getFreshness());
+
+ m_keyChain.sign(data);
+ m_face.put(data);
+ cout<<"[* <- *] send response: "<<response<<": "<<data<<endl;
+}//onInterest
+
+
+void
+NameServer::run()
+{
+ //m_zoneMgr.lookupId();
+ if (m_zoneMgr.getZone().getId() == 0)
+ {
+ m_hasError = true;
+ 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)
+ 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 << "\n=== NDNS Server for Zone "
+ << m_zoneMgr.getZone().getAuthorizedName().toUri()
+ <<" with routable prefix "<< name.toUri()
+ << " starts===\n" << std::endl;
+
+ try {
+ m_face.processEvents();
+ }
+ catch (std::exception& e) {
+ m_hasError = true;
+ m_error = "ERROR: ";
+ m_error += e.what();
+ stop();
+ }
+
+}//run
+
+} //namespace ndns
+} /* namespace ndn */
+
diff --git a/src/app/name-server.hpp b/src/app/name-server.hpp
new file mode 100644
index 0000000..9d6f5cd
--- /dev/null
+++ b/src/app/name-server.hpp
@@ -0,0 +1,77 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014, Regents of the University of California.
+ *
+ * This file is part of NDNS (Named Data Networking Domain Name Service).
+ * See AUTHORS.md for complete list of NDNS authors and contributors.
+ *
+ * NDNS is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * NDNS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * NDNS, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef NDNS_NAME_SERVER_HPP
+#define NDNS_NAME_SERVER_HPP
+
+#include <boost/asio.hpp>
+#include <boost/noncopyable.hpp>
+
+#include <ndn-cxx/face.hpp>
+#include <ndn-cxx/name.hpp>
+#include <ndn-cxx/security/key-chain.hpp>
+
+#include "zone.hpp"
+#include "db/zone-mgr.hpp"
+#include "db/rr-mgr.hpp"
+#include "query.hpp"
+#include "response.hpp"
+#include "rr.hpp"
+
+#include "ndn-app.hpp"
+
+using namespace std;
+using namespace ndn;
+
+
+namespace ndn{
+namespace ndns{
+class NameServer : public NDNApp
+{
+
+public:
+explicit
+NameServer(const char *programName, const char *prefix, const char *nameZone);
+
+void
+onInterest(const Name &name, const Interest &interest);
+
+
+void
+run();
+
+public:
+ /*
+ * the name used by the server to provide routeable accessory.
+
+ Name m_name;
+ */
+ /*
+ * the zone the server is in charge of
+ */
+ Zone m_zone;
+
+ /*
+ * to manage the m_zone; m_zoneMgr.getZone() returns the referrence of m_zone
+ */
+ ZoneMgr m_zoneMgr;
+
+};//clcass NameServer
+}//namespace ndns
+}//namespace ndn
+#endif /* NAME_SERVER_HPP_ */
diff --git a/src/app/ndn-app.cpp b/src/app/ndn-app.cpp
new file mode 100644
index 0000000..b8f123a
--- /dev/null
+++ b/src/app/ndn-app.cpp
@@ -0,0 +1,47 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014, Regents of the University of California.
+ *
+ * This file is part of NDNS (Named Data Networking Domain Name Service).
+ * See AUTHORS.md for complete list of NDNS authors and contributors.
+ *
+ * NDNS is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * NDNS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * NDNS, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ */
+#include "ndn-app.hpp"
+
+namespace ndn {
+namespace ndns {
+
+NDNApp::NDNApp(const char *programName, const char *prefix)
+ : m_programName(programName)
+ , m_prefix(prefix)
+ , m_hasError(false)
+ , m_contentFreshness(time::milliseconds(40000))
+ , m_interestLifetime(time::milliseconds(4000))
+ , m_interestTriedMax(2)
+ , m_interestTriedNum(0)
+ , m_face(m_ioService)
+{
+}
+
+NDNApp::~NDNApp()
+{
+ m_programName = 0;
+ m_prefix = 0;
+}
+
+
+
+
+
+} //namespace ndns
+} /* namespace ndn */
diff --git a/src/app/ndn-app.hpp b/src/app/ndn-app.hpp
new file mode 100644
index 0000000..00595ea
--- /dev/null
+++ b/src/app/ndn-app.hpp
@@ -0,0 +1,170 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014, Regents of the University of California.
+ *
+ * This file is part of NDNS (Named Data Networking Domain Name Service).
+ * See AUTHORS.md for complete list of NDNS authors and contributors.
+ *
+ * NDNS is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * NDNS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * NDNS, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef NDNS_NDN_APP_HPP
+#define NDNS_NDN_APP_HPP
+
+#include <ndn-cxx/face.hpp>
+#include <ndn-cxx/name.hpp>
+#include <ndn-cxx/security/key-chain.hpp>
+
+#include <boost/asio.hpp>
+#include <boost/bind.hpp>
+#include <boost/date_time/posix_time/posix_time.hpp>
+#include <boost/noncopyable.hpp>
+
+using namespace std;
+
+namespace ndn {
+namespace ndns{
+
+class NDNApp {
+public:
+ NDNApp(const char *programName, const char *prefix);
+ virtual ~NDNApp();
+
+ virtual void
+ onData(const ndn::Interest& interest, Data& data)
+ {
+ }
+ virtual void
+ onTimeout(const ndn::Interest& interest)
+ {
+ std::cout<<"!- Interest Timeout"<<interest.getName()<<std::endl;
+ }
+
+ virtual void
+ onRegisterFailed(const ndn::Name& prefix, const std::string& reason)
+ {
+ m_error = "ERROR: Failed to register prefix in local hub's daemon";
+ m_error += " due to: ";
+ m_error += reason;
+ m_hasError = true;
+ this->stop();
+ }
+
+
+ virtual void
+ onInterest(const Name &name, const Interest& interest)
+ {
+
+ }
+
+ virtual void
+ signalHandler()
+ {
+ this->stop();
+ exit(1);
+ }
+
+
+ virtual void
+ stop()
+ {
+ std::cout<<m_programName<<" stops"<<std::endl;
+ m_ioService.stop();
+ m_face.shutdown();
+ if (hasError())
+ {
+ cout<<m_error<<endl;
+ }
+ }
+
+
+
+ bool hasError() const {
+ return m_hasError;
+ }
+
+ void setHasError(bool hasError) {
+ m_hasError = hasError;
+ }
+
+ const char* getPrefix() const {
+ return m_prefix;
+ }
+
+ void setPrefix(char* prefix) {
+ m_prefix = prefix;
+ }
+
+ const char* getProgramName() const {
+ return m_programName;
+ }
+
+ void setProgramName(char* programName) {
+ m_programName = programName;
+ }
+
+ const string& getErr() const {
+ return m_error;
+ }
+
+ void setErr(const string& err) {
+ m_error = err;
+ }
+
+ uint32_t getInterestTriedMax() const {
+ return m_interestTriedMax;
+ }
+
+ void setInterestTriedMax(uint32_t interestTriedMax) {
+ m_interestTriedMax = interestTriedMax;
+ }
+
+ time::milliseconds getContentFreshness() const {
+ return m_contentFreshness;
+ }
+
+ void setContentFreshness(time::milliseconds contentFreshness) {
+ m_contentFreshness = contentFreshness;
+ }
+
+ time::milliseconds getInterestLifetime() const {
+ return m_interestLifetime;
+ }
+
+ void setInterestLifetime(time::milliseconds interestLifetime) {
+ m_interestLifetime = interestLifetime;
+ }
+
+public:
+ const char* m_programName;
+ const char* m_prefix;
+ bool m_hasError;
+ string m_error;
+ time::milliseconds m_contentFreshness;
+ time::milliseconds m_interestLifetime;
+
+ uint32_t m_interestTriedMax;
+ uint32_t m_interestTriedNum;
+
+ //Name m_name;
+ boost::asio::io_service m_ioService;
+ //Zone m_zone;
+ //ZoneMgr m_zoneMgr;
+
+
+ Face m_face;
+ KeyChain m_keyChain;
+};
+
+} //namespace ndns
+} /* namespace ndn */
+
+#endif /* NDN_APP_HPP_ */