27#include <boost/algorithm/string.hpp>
40static std::optional<std::string>
43 auto signerTag = interest.getTag<
SignerTag>();
44 if (signerTag ==
nullptr) {
48 return signerTag->get().toUri();
53 ndn::security::ValidatorConfig& validator,
55 Lsdb& lsdb,
const std::string& configFileName)
57 , m_validator(validator)
58 , m_confFileNameDynamic(configFileName)
71ndn::mgmt::Authorization
72PrefixUpdateProcessor::makeAuthorization()
74 return [=] (
const ndn::Name& prefix,
const ndn::Interest& interest,
75 const ndn::mgmt::ControlParametersBase* params,
76 const ndn::mgmt::AcceptContinuation& accept,
77 const ndn::mgmt::RejectContinuation& reject) {
78 m_validator.validate(interest,
79 [accept] (
const ndn::Interest& request) {
81 std::string signer = signer1.value_or(
"*");
82 NLSR_LOG_DEBUG(
"accept " << request.getName() <<
" signer=" << signer);
85 [reject] (
const ndn::Interest& request,
const ndn::security::ValidationError& error) {
88 reject(ndn::mgmt::RejectReply::STATUS403);
95 const std::string& filename)
97 m_validator.load(section, filename);
104 std::fstream fp(m_confFileNameDynamic);
105 if (!fp.good() || !fp.is_open()) {
111 if (line == prefix) {
118std::tuple<bool, std::string>
121 std::string section =
"advertising." + prefix.toUri();
122 std::string value =
" " + prefix.toUri() +
" " + std::to_string(
cost);
123 std::fstream input(m_confFileNameDynamic, input.in);
124 if (!input.good() || !input.is_open()) {
126 return {
false,
"Failed to open configuration file for parsing"};
132 NLSR_LOG_ERROR(
"Prefix already exists in the configuration file");
133 return {
false,
"Prefix already exists in the configuration file"};
137 return {
false,
"Unable to save changes to configuration file"};
142 NLSR_LOG_ERROR(
"Prefix doesn't exists in the configuration file");
143 return {
false,
"Prefix doesn't exists in the configuration file"};
147 return {
false,
"Unable to save changes to configuration file"};
154std::tuple<bool, std::string>
160std::tuple<bool, std::string>
ndn::mgmt::Dispatcher & m_dispatcher
void advertiseAndInsertPrefix(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...
void withdrawAndRemovePrefix(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...
std::tuple< bool, std::string > addOrDeletePrefix(const ndn::Name &prefix, uint64_t cost, bool addPrefix)
Add or delete an advertise or withdrawn prefix to the nlsr configuration file.
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)
std::tuple< bool, std::string > afterAdvertise(const ndn::Name &prefix, uint64_t cost) override
Save an advertised prefix to the nlsr configuration file.
std::tuple< bool, std::string > afterWithdraw(const ndn::Name &prefix) override
Remove an advertised prefix from the nlsr configuration file.
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)
static std::optional< std::string > getSignerFromTag(const ndn::Interest &interest)
obtain signer from SignerTag attached to Interest, if available
ndn::SimpleTag< ndn::Name, 20 > SignerTag
an Interest tag to indicate command signer
bool remove(const std::string &fileName, const std::string §ion)
bool put(const std::string &fileName, const std::string §ion, const std::string &value)