25 #include <ndn-cxx/mgmt/nfd/control-response.hpp> 26 #include <ndn-cxx/face.hpp> 27 #include <boost/algorithm/string.hpp> 41 static ndn::optional<std::string>
44 shared_ptr<SignerTag> signerTag = interest.getTag<
SignerTag>();
45 if (signerTag ==
nullptr) {
49 return signerTag->get().toUri();
54 ndn::security::ValidatorConfig& validator,
56 Lsdb& lsdb,
const std::string& configFileName)
58 , m_validator(validator)
59 , m_confFileNameDynamic(configFileName)
66 std::bind(&PrefixUpdateProcessor::validateParameters<AdvertisePrefixCommand>,
72 std::bind(&PrefixUpdateProcessor::validateParameters<WithdrawPrefixCommand>,
77 ndn::mgmt::Authorization
78 PrefixUpdateProcessor::makeAuthorization()
80 return [=] (
const ndn::Name& prefix,
const ndn::Interest& interest,
81 const ndn::mgmt::ControlParameters* params,
82 const ndn::mgmt::AcceptContinuation& accept,
83 const ndn::mgmt::RejectContinuation& reject) {
84 m_validator.validate(interest,
85 [accept] (
const ndn::Interest& request) {
88 std::string signer = signer1.value_or(
"*");
89 NLSR_LOG_DEBUG(
"accept " << request.getName() <<
" signer=" << signer);
92 [reject] (
const ndn::Interest& request,
const ndn::security::v2::ValidationError& error) {
95 reject(ndn::mgmt::RejectReply::STATUS403);
102 const std::string& filename)
104 m_validator.load(section, filename);
111 std::fstream fp(m_confFileNameDynamic);
112 if (!fp.good() || !fp.is_open()) {
118 if (line == prefix) {
129 std::string value =
" prefix " + prefix.toUri();;
130 std::string fileString;
132 std::string trimedLine;
133 std::fstream input(m_confFileNameDynamic, input.in);
134 if (!input.good() || !input.is_open()) {
142 NLSR_LOG_ERROR(
"Prefix already exists in the configuration file");
145 while (!input.eof()) {
146 getline(input, line);
148 fileString.append(line +
"\n");
149 if (line ==
"advertising") {
150 getline(input, line);
151 fileString.append(line +
"\n" + value +
"\n");
158 NLSR_LOG_ERROR(
"Prefix doesn't exists in the configuration file");
162 while (!input.eof()) {
163 getline(input, line);
165 std::string trimLine = line;
166 boost::trim(trimLine);
167 if (trimLine != value) {
168 fileString.append(line +
"\n");
174 std::ofstream output(m_confFileNameDynamic);
175 output << fileString;
ndn::SimpleTag< ndn::Name, 20 > SignerTag
an Interest tag to indicate command signer
void loadValidator(ConfigSection section, const std::string &filename)
Load the validator's configuration from a section of a configuration file.
#define NLSR_LOG_DEBUG(x)
void advertiseAndInsertPrefix(const ndn::Name &prefix, const ndn::Interest &interest, const ndn::mgmt::ControlParameters ¶meters, const ndn::mgmt::CommandContinuation &done)
add desired name prefix to the advertised name prefix list or insert a prefix into the FIB if paramet...
static const ndn::Name LOCALHOST_PREFIX
#define INIT_LOGGER(name)
ndn::optional< bool > afterAdvertise(const ndn::Name &prefix)
save an advertised prefix to the nlsr configuration file returns bool from the overridden function wh...
PrefixUpdateProcessor(ndn::mgmt::Dispatcher &dispatcher, ndn::security::ValidatorConfig &validator, NamePrefixList &namePrefixList, Lsdb &lsdb, const std::string &configFileName)
ndn::optional< bool > afterWithdraw(const ndn::Name &prefix)
save an advertised prefix to the nlsr configuration file returns bool from the overridden function wh...
bool addOrDeletePrefix(const ndn::Name &prefix, bool addPrefix)
Add or delete an advertise or withdrawn prefix to the nlsr configuration file.
#define NLSR_LOG_ERROR(x)
Copyright (c) 2014-2018, The University of Memphis, Regents of the University of California, Arizona Board of Regents.
bool checkForPrefixInFile(const std::string prefix)
Check if a prefix exists in the nlsr configuration file.
void withdrawAndRemovePrefix(const ndn::Name &prefix, const ndn::Interest &interest, const ndn::mgmt::ControlParameters ¶meters, const ndn::mgmt::CommandContinuation &done)
remove desired name prefix from the advertised name prefix list or remove a prefix from the FIB if pa...
static ndn::optional< std::string > getSignerFromTag(const ndn::Interest &interest)
obtain signer from SignerTag attached to Interest, if available
ndn::PartialName makeRelPrefix(const std::string &verb) const
generate the relative prefix for a handler by appending the verb name to the module name ...
ndn::mgmt::Dispatcher & m_dispatcher