26 #include <ndn-cxx/face.hpp>
27 #include <ndn-cxx/mgmt/nfd/control-response.hpp>
29 #include <boost/algorithm/string.hpp>
43 static ndn::optional<std::string>
46 auto signerTag = interest.getTag<
SignerTag>();
47 if (signerTag ==
nullptr) {
51 return signerTag->get().toUri();
56 ndn::security::ValidatorConfig& validator,
58 Lsdb& lsdb,
const std::string& configFileName)
60 , m_validator(validator)
61 , m_confFileNameDynamic(configFileName)
68 std::bind(&PrefixUpdateProcessor::validateParameters<AdvertisePrefixCommand>,
74 std::bind(&PrefixUpdateProcessor::validateParameters<WithdrawPrefixCommand>,
79 ndn::mgmt::Authorization
80 PrefixUpdateProcessor::makeAuthorization()
82 return [=] (
const ndn::Name& prefix,
const ndn::Interest& interest,
83 const ndn::mgmt::ControlParameters* params,
84 const ndn::mgmt::AcceptContinuation& accept,
85 const ndn::mgmt::RejectContinuation& reject) {
86 m_validator.validate(interest,
87 [accept] (
const ndn::Interest& request) {
90 std::string signer = signer1.value_or(
"*");
91 NLSR_LOG_DEBUG(
"accept " << request.getName() <<
" signer=" << signer);
94 [reject] (
const ndn::Interest& request,
const ndn::security::ValidationError& error) {
97 reject(ndn::mgmt::RejectReply::STATUS403);
104 const std::string& filename)
106 m_validator.load(section, filename);
113 std::fstream fp(m_confFileNameDynamic);
114 if (!fp.good() || !fp.is_open()) {
120 if (line == prefix) {
131 std::string value =
" prefix " + prefix.toUri();
132 std::string fileString;
134 std::string trimedLine;
135 std::fstream input(m_confFileNameDynamic, input.in);
136 if (!input.good() || !input.is_open()) {
144 NLSR_LOG_ERROR(
"Prefix already exists in the configuration file");
147 while (!input.eof()) {
148 getline(input, line);
150 fileString.append(line +
"\n");
151 if (line ==
"advertising") {
152 getline(input, line);
153 fileString.append(line +
"\n" + value +
"\n");
160 NLSR_LOG_ERROR(
"Prefix doesn't exists in the configuration file");
164 while (!input.eof()) {
165 getline(input, line);
167 std::string trimLine = line;
168 boost::trim(trimLine);
169 if (trimLine != value) {
170 fileString.append(line +
"\n");
176 std::ofstream output(m_confFileNameDynamic);
177 output << fileString;
static const ndn::Name LOCALHOST_PREFIX
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...
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...
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
ndn::optional< bool > afterWithdraw(const ndn::Name &prefix)
save an advertised prefix to the nlsr configuration file returns bool from the overridden function wh...
void loadValidator(ConfigSection section, const std::string &filename)
Load the validator's configuration from a section of a configuration file.
PrefixUpdateProcessor(ndn::mgmt::Dispatcher &dispatcher, ndn::security::ValidatorConfig &validator, NamePrefixList &namePrefixList, Lsdb &lsdb, const std::string &configFileName)
bool addOrDeletePrefix(const ndn::Name &prefix, bool addPrefix)
Add or delete an advertise or withdrawn prefix to the nlsr configuration file.
ndn::optional< bool > afterAdvertise(const ndn::Name &prefix)
save an advertised prefix to the nlsr configuration file returns bool from the overridden function wh...
bool checkForPrefixInFile(const std::string prefix)
Check if a prefix exists in the nlsr configuration file.
#define NLSR_LOG_DEBUG(x)
#define INIT_LOGGER(name)
#define NLSR_LOG_ERROR(x)
ndn::SimpleTag< ndn::Name, 20 > SignerTag
an Interest tag to indicate command signer
static ndn::optional< std::string > getSignerFromTag(const ndn::Interest &interest)
obtain signer from SignerTag attached to Interest, if available
Copyright (c) 2014-2020, The University of Memphis, Regents of the University of California,...