src: add SigningInfo and version number to SegmentPublisher
refs: #4783
Change-Id: Id5dc8d6096ff729be0b8d0f971004281e0c09eb1
diff --git a/src/consumer.cpp b/src/consumer.cpp
index 04f8b4a..84adc2a 100644
--- a/src/consumer.cpp
+++ b/src/consumer.cpp
@@ -101,7 +101,7 @@
m_helloFetcher->afterSegmentValidated.connect([this] (const ndn::Data& data) {
if (data.getFinalBlock()) {
- m_helloDataName = data.getName().getPrefix(-1);
+ m_helloDataName = data.getName().getPrefix(-2);
}
});
@@ -189,7 +189,7 @@
m_syncFetcher->afterSegmentValidated.connect([this] (const ndn::Data& data) {
if (data.getFinalBlock()) {
- m_syncDataName = data.getName().getPrefix(-1);
+ m_syncDataName = data.getName().getPrefix(-2);
m_syncDataContentType = data.getContentType();
}
diff --git a/src/full-producer.cpp b/src/full-producer.cpp
index 0953f93..133eebe 100644
--- a/src/full-producer.cpp
+++ b/src/full-producer.cpp
@@ -137,16 +137,14 @@
ndn::Name nameWithoutSyncPrefix = interest.getName().getSubName(prefixName.size());
ndn::Name interestName;
- uint64_t interestSeq = 0;
if (nameWithoutSyncPrefix.size() == 1) {
- // Get /IBF from /IBF
+ // Get /<prefix>/IBF from /<prefix>/IBF
interestName = interest.getName();
}
- else if (nameWithoutSyncPrefix.size() == 2) {
- // Get /IBF from /IBF/<seq-no>
- interestName = interest.getName().getPrefix(-1);
- interestSeq = interest.getName().get(-1).toSegment();
+ else if (nameWithoutSyncPrefix.size() == 3) {
+ // Get /<prefix>/IBF from /<prefix>/IBF/<version>/<segment-no>
+ interestName = interest.getName().getPrefix(-2);
}
else {
return;
@@ -207,9 +205,6 @@
if (!state.getContent().empty()) {
NDN_LOG_DEBUG("Sending sync content: " << state);
- if (interestSeq != 0) {
- interestName.appendSegment(interestSeq);
- }
sendSyncData(interestName, state.wireEncode());
return;
}
diff --git a/src/partial-producer.cpp b/src/partial-producer.cpp
index b0d29f1..e1570fe 100644
--- a/src/partial-producer.cpp
+++ b/src/partial-producer.cpp
@@ -74,14 +74,14 @@
void
PartialProducer::onHelloInterest(const ndn::Name& prefix, const ndn::Interest& interest)
{
- // Last component or third last component (in case of interest with IBF and segment)
- // needs to be hello
- if (interest.getName().get(interest.getName().size()-1).toUri() != "hello" &&
- interest.getName().get(interest.getName().size()-3).toUri() != "hello") {
+ if (m_segmentPublisher.replyFromStore(interest.getName())) {
return;
}
- if (m_segmentPublisher.replyFromStore(interest.getName())) {
+ // Last component or fourth last component (in case of interest with version and segment)
+ // needs to be hello
+ if (interest.getName().get(interest.getName().size()-1).toUri() != "hello" &&
+ interest.getName().get(interest.getName().size()-4).toUri() != "hello") {
return;
}
@@ -104,17 +104,25 @@
void
PartialProducer::onSyncInterest(const ndn::Name& prefix, const ndn::Interest& interest)
{
- NDN_LOG_DEBUG("Sync Interest Received, nonce: " << interest.getNonce() <<
- " hash: " << std::hash<std::string>{}(interest.getName().toUri()));
-
- ndn::Name interestName = interest.getName();
-
- if (interestName.get(interestName.size() - 5).toUri() != "sync" &&
- interestName.get(interestName.size() - 7).toUri() != "sync") {
+ if (m_segmentPublisher.replyFromStore(interest.getName())) {
return;
}
- if (m_segmentPublisher.replyFromStore(interest.getName())) {
+ NDN_LOG_DEBUG("Sync Interest Received, nonce: " << interest.getNonce() <<
+ " hash: " << std::hash<std::string>{}(interest.getName().toUri()));
+
+ ndn::Name nameWithoutSyncPrefix = interest.getName().getSubName(prefix.size());
+ ndn::Name interestName;
+
+ if (nameWithoutSyncPrefix.size() == 4) {
+ // Get /<prefix>/BF/IBF/ from /<prefix>/BF/IBF (3 components of BF + 1 for IBF)
+ interestName = interest.getName();
+ }
+ else if (nameWithoutSyncPrefix.size() == 6) {
+ // Get <prefix>/BF/IBF/ from /<prefix>/BF/IBF/<version>/<segment-no>
+ interestName = interest.getName().getPrefix(-2);
+ }
+ else {
return;
}
diff --git a/src/partial-producer.hpp b/src/partial-producer.hpp
index cb014fc..de12fb8 100644
--- a/src/partial-producer.hpp
+++ b/src/partial-producer.hpp
@@ -97,6 +97,7 @@
void
satisfyPendingSyncInterests(const ndn::Name& prefix);
+PUBLIC_WITH_TESTS_ELSE_PRIVATE:
/**
* @brief Receive hello interest from consumer and respond with hello data
*
@@ -105,7 +106,6 @@
void
onHelloInterest(const ndn::Name& prefix, const ndn::Interest& interest);
-PUBLIC_WITH_TESTS_ELSE_PRIVATE:
/**
* @brief Receive sync interest from consumer
*
diff --git a/src/segment-publisher.cpp b/src/segment-publisher.cpp
index d78d47f..394dfc5 100644
--- a/src/segment-publisher.cpp
+++ b/src/segment-publisher.cpp
@@ -34,7 +34,8 @@
void
SegmentPublisher::publish(const ndn::Name& interestName, const ndn::Name& dataName,
- const ndn::Block& block, ndn::time::milliseconds freshness)
+ const ndn::Block& block, ndn::time::milliseconds freshness,
+ const ndn::security::SigningInfo& signingInfo)
{
uint64_t interestSegment = 0;
if (interestName[-1].isSegment()) {
@@ -52,6 +53,9 @@
uint64_t totalSegments = buffer.size() / maxPacketSize;
+ ndn::Name segmentPrefix(dataName);
+ segmentPrefix.appendVersion();
+
uint64_t segmentNo = 0;
do {
const uint8_t* segmentEnd = segmentBegin + maxPacketSize;
@@ -59,7 +63,7 @@
segmentEnd = end;
}
- ndn::Name segmentName(dataName);
+ ndn::Name segmentName(segmentPrefix);
segmentName.appendSegment(segmentNo);
// We get a std::exception: bad_weak_ptr from m_ims if we don't use shared_ptr for data
@@ -70,7 +74,7 @@
segmentBegin = segmentEnd;
- m_keyChain.sign(*data);
+ m_keyChain.sign(*data, signingInfo);
// Put on face only the segment which has a pending interest
// otherwise the segment is unsolicited
diff --git a/src/segment-publisher.hpp b/src/segment-publisher.hpp
index b23ac52..8e00624 100644
--- a/src/segment-publisher.hpp
+++ b/src/segment-publisher.hpp
@@ -54,7 +54,9 @@
*/
void
publish(const ndn::Name& interestName, const ndn::Name& dataName,
- const ndn::Block& block, ndn::time::milliseconds freshness);
+ const ndn::Block& block, ndn::time::milliseconds freshness,
+ const ndn::security::SigningInfo& signingInfo =
+ ndn::security::v2::KeyChain::getDefaultSigningInfo());
/**
* @brief Try to reply from memory, return false if we cannot find the segment.