28 #include <ndn-cxx/face.hpp>
29 #include <ndn-cxx/mgmt/nfd/control-response.hpp>
31 #include <boost/algorithm/string.hpp>
44 static std::optional<std::string>
47 auto signerTag = interest.getTag<
SignerTag>();
48 if (signerTag ==
nullptr) {
52 return signerTag->get().toUri();
57 ndn::security::ValidatorConfig& validator,
59 Lsdb& lsdb,
const std::string& configFileName)
61 , m_validator(validator)
62 , m_confFileNameDynamic(configFileName)
69 [] (
const auto& p) {
return validateParameters<AdvertisePrefixCommand>(p); },
74 [] (
const auto& p) {
return validateParameters<WithdrawPrefixCommand>(p); },
78 ndn::mgmt::Authorization
79 PrefixUpdateProcessor::makeAuthorization()
81 return [=] (
const ndn::Name& prefix,
const ndn::Interest& interest,
82 const ndn::mgmt::ControlParametersBase* params,
83 const ndn::mgmt::AcceptContinuation& accept,
84 const ndn::mgmt::RejectContinuation& reject) {
85 m_validator.validate(interest,
86 [accept] (
const ndn::Interest& request) {
89 std::string signer = signer1.value_or(
"*");
90 NLSR_LOG_DEBUG(
"accept " << request.getName() <<
" signer=" << signer);
93 [reject] (
const ndn::Interest& request,
const ndn::security::ValidationError& error) {
96 reject(ndn::mgmt::RejectReply::STATUS403);
103 const std::string& filename)
105 m_validator.load(section, filename);
112 std::fstream fp(m_confFileNameDynamic);
113 if (!fp.good() || !fp.is_open()) {
119 if (line == prefix) {
130 std::string value =
" prefix " + prefix.toUri();
131 std::string fileString;
133 std::string trimedLine;
134 std::fstream input(m_confFileNameDynamic, input.in);
135 if (!input.good() || !input.is_open()) {
143 NLSR_LOG_ERROR(
"Prefix already exists in the configuration file");
146 while (!input.eof()) {
147 getline(input, line);
149 fileString.append(line +
"\n");
150 if (line ==
"advertising") {
151 getline(input, line);
152 fileString.append(line +
"\n" + value +
"\n");
159 NLSR_LOG_ERROR(
"Prefix doesn't exists in the configuration file");
163 while (!input.eof()) {
164 getline(input, line);
166 std::string trimLine = line;
167 boost::trim(trimLine);
168 if (trimLine != value) {
169 fileString.append(line +
"\n");
175 std::ofstream output(m_confFileNameDynamic);
176 output << fileString;
static const ndn::Name LOCALHOST_PREFIX
void withdrawAndRemovePrefix(const ndn::Name &prefix, const ndn::Interest &interest, const ndn::mgmt::ControlParametersBase ¶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::ControlParametersBase ¶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
void loadValidator(ConfigSection section, const std::string &filename)
Load the validator's configuration from a section of a configuration file.
std::optional< bool > afterAdvertise(const ndn::Name &prefix) override
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)
bool addOrDeletePrefix(const ndn::Name &prefix, bool addPrefix)
Add or delete an advertise or withdrawn prefix to the nlsr configuration file.
std::optional< bool > afterWithdraw(const ndn::Name &prefix) override
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.
Copyright (c) 2014-2018, The University of Memphis, Regents of the University of California.
#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 std::optional< std::string > getSignerFromTag(const ndn::Interest &interest)
obtain signer from SignerTag attached to Interest, if available