27 #include <ndn-cxx/face.hpp>
28 #include <ndn-cxx/mgmt/nfd/control-response.hpp>
30 #include <boost/algorithm/string.hpp>
45 static std::optional<std::string>
48 auto signerTag = interest.getTag<
SignerTag>();
49 if (signerTag ==
nullptr) {
53 return signerTag->get().toUri();
58 ndn::security::ValidatorConfig& validator,
60 Lsdb& lsdb,
const std::string& configFileName)
62 , m_validator(validator)
63 , m_confFileNameDynamic(configFileName)
70 std::bind(&PrefixUpdateProcessor::validateParameters<AdvertisePrefixCommand>,
76 std::bind(&PrefixUpdateProcessor::validateParameters<WithdrawPrefixCommand>,
81 ndn::mgmt::Authorization
82 PrefixUpdateProcessor::makeAuthorization()
84 return [=] (
const ndn::Name& prefix,
const ndn::Interest& interest,
85 const ndn::mgmt::ControlParameters* params,
86 const ndn::mgmt::AcceptContinuation& accept,
87 const ndn::mgmt::RejectContinuation& reject) {
88 m_validator.validate(interest,
89 [accept] (
const ndn::Interest& request) {
92 std::string signer = signer1.value_or(
"*");
93 NLSR_LOG_DEBUG(
"accept " << request.getName() <<
" signer=" << signer);
96 [reject] (
const ndn::Interest& request,
const ndn::security::ValidationError& error) {
99 reject(ndn::mgmt::RejectReply::STATUS403);
106 const std::string& filename)
108 m_validator.load(section, filename);
115 std::fstream fp(m_confFileNameDynamic);
116 if (!fp.good() || !fp.is_open()) {
122 if (line == prefix) {
133 std::string value =
" prefix " + prefix.toUri();
134 std::string fileString;
136 std::string trimedLine;
137 std::fstream input(m_confFileNameDynamic, input.in);
138 if (!input.good() || !input.is_open()) {
146 NLSR_LOG_ERROR(
"Prefix already exists in the configuration file");
149 while (!input.eof()) {
150 getline(input, line);
152 fileString.append(line +
"\n");
153 if (line ==
"advertising") {
154 getline(input, line);
155 fileString.append(line +
"\n" + value +
"\n");
162 NLSR_LOG_ERROR(
"Prefix doesn't exists in the configuration file");
166 while (!input.eof()) {
167 getline(input, line);
169 std::string trimLine = line;
170 boost::trim(trimLine);
171 if (trimLine != value) {
172 fileString.append(line +
"\n");
178 std::ofstream output(m_confFileNameDynamic);
179 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
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
Copyright (c) 2014-2020, The University of Memphis, Regents of the University of California.