-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
every parts are wroking, implemented ndnsd-tool completly and also th… #2
base: test
Are you sure you want to change the base?
Changes from 43 commits
b02ecf0
1ba7c94
0303200
7c3ef04
a3582bd
3b4d0ba
dd62698
3180bc4
aede771
0f53005
b1747aa
cd5c9cb
d00eef9
73a74d3
77380a6
4554ddb
26a8ab2
60fb747
8c6f79a
7f76944
91fb52a
0db4156
58143fe
f24d81f
99862fc
b7e80b0
18562a7
36e8e75
442a5e5
77ebb31
3d6d745
3990f1b
7a4ecf7
86fbcc8
79ca75e
fb6b721
8a5ca07
d2870d0
b8588c2
3a9b494
818c485
1a9790b
40e9faa
8cc9bd6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# NDNSD | ||
NDN Service Discovery |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,10 +17,26 @@ | |
* NDNSD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. | ||
**/ | ||
|
||
#include<iostream> | ||
#include "ndnsd/discovery/service-discovery.hpp" | ||
#include <ndn-cxx/util/logger.hpp> | ||
|
||
#include<iostream> | ||
#include <list> | ||
|
||
#include <boost/program_options/options_description.hpp> | ||
#include <boost/program_options/variables_map.hpp> | ||
#include <boost/program_options/parsers.hpp> | ||
|
||
NDN_LOG_INIT(ndnsd.examples.ConsumerApp); | ||
|
||
static void | ||
usage(const boost::program_options::options_description& options) | ||
{ | ||
std::cout << "Usage: ndnsd-consumer [options] e.g. printer \n" | ||
<< options; | ||
exit(2); | ||
} | ||
|
||
class Consumer | ||
{ | ||
public: | ||
|
@@ -32,17 +48,18 @@ class Consumer | |
void | ||
execute () | ||
{ | ||
// process and handle request | ||
m_serviceDiscovery.consumerHandler(); | ||
} | ||
|
||
private: | ||
void | ||
processCallback(const ndnsd::discovery::Reply& callback) | ||
{ | ||
NDN_LOG_INFO("Service info received"); | ||
auto status = (callback.status == ndnsd::discovery::ACTIVE)? "ACTIVE": "EXPIRED"; | ||
|
||
std::cout << "Status: " << status << std::endl; | ||
for (auto& item : callback.serviceDetails) | ||
for (const auto& item : callback.serviceDetails) | ||
{ | ||
std::cout << item.first << ": " << item.second << std::endl; | ||
} | ||
|
@@ -56,15 +73,63 @@ class Consumer | |
int | ||
main(int argc, char* argv[]) | ||
{ | ||
if (argc != 2) { | ||
std::cout << "usage: " << argv[0] << " <service-name> " | ||
<< std::endl; | ||
return 1; | ||
} | ||
std::string serviceName; | ||
int contFlag = -1; | ||
|
||
namespace po = boost::program_options; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why use boost::program_options here instead of just usual c++? |
||
po::options_description visibleOptDesc("Options"); | ||
|
||
visibleOptDesc.add_options() | ||
("help,h", "print this message and exit") | ||
("serviceName,s", po::value<std::string>(&serviceName)->required(), "Service name to fetch service info") | ||
("continuous,c", po::value<int>(&contFlag), "continuous discovery, 1 for true 0 for false") | ||
; | ||
|
||
try | ||
{ | ||
po::variables_map optVm; | ||
po::store(po::parse_command_line(argc, argv, visibleOptDesc), optVm); | ||
po::notify(optVm); | ||
|
||
if (optVm.count("continuous")) { | ||
if (contFlag != ndnsd::discovery::OPTIONAL and contFlag != ndnsd::discovery::REQUIRED) | ||
{ | ||
std::cout << "'c' must be either '0' or '1', default i.e. '0' will be used" << std::endl; | ||
} | ||
} | ||
else | ||
contFlag = 0; | ||
|
||
if (optVm.count("serviceName")) { | ||
if (serviceName.empty()) | ||
{ | ||
std::cerr << "ERROR: serviceName cannot be empty" << std::endl; | ||
usage(visibleOptDesc); | ||
} | ||
} | ||
|
||
} | ||
catch (const po::error& e) { | ||
std::cerr << "ERROR: " << e.what() << std::endl; | ||
usage(visibleOptDesc); | ||
} | ||
// TODO: protocol shouldn't be hard-coded. | ||
std::map<char, uint8_t> flags; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems complicated for only two things? Maybe have an Options class. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is also TODO, my new changes however have the options class. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What I meant was to replay this std::map with an options class such that you pass that to your discovery stuff. Where are the new changes? |
||
flags.insert(std::pair<char, uint8_t>('p', ndnsd::SYNC_PROTOCOL_CHRONOSYNC)); //protocol choice | ||
flags.insert(std::pair<char, uint8_t>('t', ndnsd::discovery::CONSUMER)); //c: consumer - 0, p:producer - 1 | ||
flags.insert(std::pair<char, uint8_t>('p', ndnsd::SYNC_PROTOCOL_PSYNC)); //protocol choice | ||
flags.insert(std::pair<char, uint8_t>('t', ndnsd::discovery::CONSUMER)); //type producer: 1 | ||
flags.insert(std::pair<char, uint8_t>('c', contFlag)); | ||
|
||
try | ||
{ | ||
std::cout << "Fetching service info for: " << serviceName << std::endl; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Redundant? |
||
NDN_LOG_INFO("Fetching service info for: " << serviceName); | ||
Consumer consumer(serviceName, flags); | ||
consumer.execute(); | ||
} | ||
catch (const std::exception& e) { | ||
std::cerr << "ERROR: " << e.what() << std::endl; | ||
NDN_LOG_ERROR("Cannot execute consumer, try again later: " << e.what()); | ||
} | ||
|
||
try { | ||
Consumer consumer(argv[1], flags); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,10 +17,13 @@ | |
* NDNSD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. | ||
**/ | ||
|
||
#include<iostream> | ||
#include "ndnsd/discovery/service-discovery.hpp" | ||
#include <ndn-cxx/util/logger.hpp> | ||
|
||
#include<iostream> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Space before < |
||
#include <list> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where is list used? |
||
#include <boost/filesystem.hpp> | ||
|
||
NDN_LOG_INIT(ndnsd.examples.ProducerApp); | ||
|
||
inline bool | ||
isFile(const std::string& fileName) | ||
|
@@ -46,8 +49,8 @@ class Producer | |
void | ||
processCallback(const ndnsd::discovery::Reply& callback) | ||
{ | ||
NDN_LOG_INFO("Service publish callback received"); | ||
auto status = (callback.status == ndnsd::discovery::ACTIVE)? "ACTIVE": "EXPIRED"; | ||
|
||
std::cout << "\n Status: " << status << std::endl; | ||
for (auto& item : callback.serviceDetails) | ||
{ | ||
|
@@ -63,14 +66,16 @@ int | |
main(int argc, char* argv[]) | ||
{ | ||
std::map<char, uint8_t> flags; | ||
flags.insert(std::pair<char, uint8_t>('p', ndnsd::SYNC_PROTOCOL_CHRONOSYNC)); //protocol choice | ||
flags.insert(std::pair<char, uint8_t>('p', ndnsd::SYNC_PROTOCOL_PSYNC)); //protocol choice | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. still hard coded protocol choice? |
||
flags.insert(std::pair<char, uint8_t>('t', ndnsd::discovery::PRODUCER)); //type producer: 1 | ||
|
||
try { | ||
NDN_LOG_INFO("Starting producer application"); | ||
Producer producer(argv[1], flags); | ||
producer.execute(); | ||
} | ||
catch (const std::exception& e) { | ||
std::cout << "Exception: " << e.what() << std::endl; | ||
NDN_LOG_ERROR("Cannot execute producer, try again later: " << e.what()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,12 @@ | |
|
||
#include "file-processor.hpp" | ||
|
||
#include<iostream> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Space before < |
||
|
||
#include <ndn-cxx/util/logger.hpp> | ||
|
||
NDN_LOG_INIT(ndnsd.FileProcessor); | ||
|
||
namespace ndnsd { | ||
namespace discovery { | ||
|
||
|
@@ -28,12 +34,14 @@ ServiceInfoFileProcessor::ServiceInfoFileProcessor(const std::string filename) | |
processFile(); | ||
} | ||
|
||
// need to implement sanity check, 1. correct file is edited, required section is not modified | ||
// and so on | ||
void | ||
ServiceInfoFileProcessor::processFile() | ||
{ | ||
try | ||
{ | ||
NDNSD_LOG_INFO("FP: Reading file: "<< m_filename); | ||
NDN_LOG_INFO("Reading file: "<< m_filename); | ||
boost::property_tree::ptree pt; | ||
read_info(m_filename, pt); | ||
for (auto& block: pt) | ||
|
@@ -68,17 +76,17 @@ ServiceInfoFileProcessor::processFile() | |
const auto& key = details.first; //get_value<std::string >(); | ||
const auto& val = details.second.get_value<std::string >(); | ||
|
||
NDNSD_LOG_INFO("FP: Reading file: "<< val); | ||
|
||
NDN_LOG_INFO("Reading file: "<< val); | ||
m_serviceMetaInfo.insert(std::pair<std::string, std::string>(key, val)); | ||
} | ||
} | ||
} | ||
NDNSD_LOG_INFO("FP: Successfully updated the file content: "); | ||
NDN_LOG_INFO("Successfully updated the file content: "); | ||
} | ||
catch (std::exception const& e) | ||
{ | ||
std::cerr << e.what() << std::endl; | ||
NDN_LOG_INFO("Error reading file: " << m_filename); | ||
throw e; | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe use ndn-cxx logger here too? So you get logs only when you want to.