node+face-management-protocol: Finalizing prefix registration (selfreg)
Change-Id: I88aa15b785824a53fcc167b57fb1f0831b5aa9fa
diff --git a/include/ndn-cpp/data.hpp b/include/ndn-cpp/data.hpp
index cd6176f..8f97c87 100644
--- a/include/ndn-cpp/data.hpp
+++ b/include/ndn-cpp/data.hpp
@@ -236,10 +236,14 @@
inline void
Data::setContent(const Block& content)
-{
+{
onChanged();
- content_ = content;
+ if (content.type() == Tlv::Content)
+ content_ = content;
+ else {
+ content_ = Block(Tlv::Content, content);
+ }
}
inline const Signature&
diff --git a/include/ndn-cpp/forwarding-entry.hpp b/include/ndn-cpp/forwarding-entry.hpp
index 1de79ce..315f271 100644
--- a/include/ndn-cpp/forwarding-entry.hpp
+++ b/include/ndn-cpp/forwarding-entry.hpp
@@ -40,33 +40,33 @@
const std::string&
getAction() const { return action_; }
-
- Name&
- getPrefix() { return prefix_; }
-
+
+ void
+ setAction(const std::string& action) { action_ = action; wire_.reset(); }
+
const Name&
getPrefix() const { return prefix_; }
+ void
+ setPrefix(const Name &prefix) { prefix_ = prefix; wire_.reset(); }
+
int
getFaceId() const { return faceId_; }
+ void
+ setFaceId(int faceId) { faceId_ = faceId; wire_.reset(); }
+
const ForwardingFlags&
getForwardingFlags() const { return forwardingFlags_; }
+ void
+ setForwardingFlags(const ForwardingFlags& forwardingFlags) { forwardingFlags_ = forwardingFlags; wire_.reset(); }
+
int
getFreshnessPeriod() const { return freshnessPeriod_; }
void
- setAction(const std::string& action) { action_ = action; }
-
- void
- setFaceId(int faceId) { faceId_ = faceId; }
-
- void
- setForwardingFlags(const ForwardingFlags& forwardingFlags) { forwardingFlags_ = forwardingFlags; }
-
- void
- setFreshnessPeriod(int freshnessPeriod) { freshnessPeriod_ = freshnessPeriod; }
+ setFreshnessPeriod(int freshnessPeriod) { freshnessPeriod_ = freshnessPeriod; wire_.reset(); }
inline const Block&
wireEncode() const;
@@ -190,6 +190,42 @@
}
}
+inline std::ostream&
+operator << (std::ostream &os, const ForwardingEntry &entry)
+{
+ os << "ForwardingEntry(";
+
+ // Action
+ if (!entry.getAction().empty())
+ {
+ os << "Action:" << entry.getAction() << ", ";
+ }
+
+ // Name
+ if (!entry.getPrefix().empty())
+ {
+ os << "Prefix:" << entry.getPrefix() << ", ";
+ }
+
+ // FaceID
+ if (entry.getFaceId() >= 0)
+ {
+ os << "FaceID:" << entry.getFaceId() << ", ";
+ }
+
+ // ForwardingFlags
+ os << "ForwardingFlags:" << entry.getForwardingFlags() << ", ";
+
+ // FreshnessPeriod
+ if (entry.getFreshnessPeriod() >= 0)
+ {
+ os << "FreshnessPeriod:" << entry.getFreshnessPeriod() << ", ";
+ }
+
+ os << ")";
+ return os;
+}
+
}
#endif
diff --git a/src/data.cpp b/src/data.cpp
index 2bbe9a1..5a31e50 100644
--- a/src/data.cpp
+++ b/src/data.cpp
@@ -33,7 +33,7 @@
wire_.push_back(getMetaInfo().wireEncode());
// Content
- wire_.push_back(content_);
+ wire_.push_back(getContent());
if (!signature_) {
throw Error("Requested wire format, but data packet has not been signed yet");
diff --git a/src/node.cpp b/src/node.cpp
index b766718..3610344 100644
--- a/src/node.cpp
+++ b/src/node.cpp
@@ -152,25 +152,33 @@
return;
}
- switch(content.getAll().begin()->type())
+ Block::element_iterator val = content.getAll().begin();
+
+ switch(val->type())
{
case Tlv::FaceManagement::ForwardingEntry:
{
+ ForwardingEntry entry;
+ entry.wireDecode(*val);
+
+ // Save the onInterest callback and send the registration interest.
+ registeredPrefixTable_.push_back(ptr_lib::make_shared<RegisteredPrefix>(registeredPrefixId, prefix, onInterest));
+
+ /// @todo Notify user about successful registration
+
// succeeded
- break;
+ return;
}
case Tlv::FaceManagement::StatusResponse:
{
// failed :(
StatusResponse resp;
- resp.wireDecode(*content.getAll().begin());
+ resp.wireDecode(*val);
std::cerr << "StatusReponse: " << resp << std::endl;
onRegisterFailed(prefix);
return;
-
- break;
}
default:
{
@@ -178,16 +186,8 @@
onRegisterFailed(prefix);
return;
- break;
}
}
-
-
-
- // Save the onInterest callback and send the registration interest.
- registeredPrefixTable_.push_back(ptr_lib::make_shared<RegisteredPrefix>(registeredPrefixId, prefix, onInterest));
-
- /// @todo Notify user about successful registration
}
void