diff --git a/ndn-svs/core.cpp b/ndn-svs/core.cpp index 1881800..57fb0a3 100644 --- a/ndn-svs/core.cpp +++ b/ndn-svs/core.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #ifdef NDN_SVS_COMPRESSION #include @@ -120,6 +121,15 @@ SVSyncCore::onSyncInterestValidated(const Interest &interest) { const auto &n = interest.getName(); + // Get incoming face + uint64_t incomingFace = 0; + { + auto tag = interest.getTag(); + if (tag) { + incomingFace = tag->get(); + } + } + // Get state vector std::shared_ptr vvOther; try @@ -163,8 +173,18 @@ SVSyncCore::onSyncInterestValidated(const Interest &interest) } // Merge state vector - bool myVectorNew, otherVectorNew; - std::tie(myVectorNew, otherVectorNew) = mergeStateVector(*vvOther); + auto result = mergeStateVector(*vvOther); + + bool myVectorNew = std::get<0>(result); + auto missingData = std::get<2>(result); + + // Callback if missing data found + if (!missingData.empty()) + { + for (auto &e : missingData) + e.incomingFace = incomingFace; + m_onUpdate(missingData); + } // Try to record; the call will check if in suppression state if (recordVector(*vvOther)) @@ -203,7 +223,7 @@ SVSyncCore::retxSyncInterest(bool send, unsigned int delay) // Only send interest if in steady state or local vector has newer state // than recorded interests - if (!m_recordedVv || mergeStateVector(*m_recordedVv).first) + if (!m_recordedVv || std::get<0>(mergeStateVector(*m_recordedVv))) sendSyncInterest(); m_recordedVv = nullptr; } @@ -278,7 +298,7 @@ SVSyncCore::sendSyncInterest() m_face.expressInterest(interest, nullptr, nullptr, nullptr); } -std::pair +std::tuple> SVSyncCore::mergeStateVector(const VersionVector &vvOther) { std::lock_guard lock(m_vvMutex); @@ -287,7 +307,7 @@ SVSyncCore::mergeStateVector(const VersionVector &vvOther) otherVectorNew = false; // New data found in vvOther - std::vector v; + std::vector missingData; // Check if other vector has newer state for (const auto& entry : vvOther) @@ -301,18 +321,12 @@ SVSyncCore::mergeStateVector(const VersionVector &vvOther) otherVectorNew = true; SeqNo startSeq = m_vv.get(nidOther) + 1; - v.push_back({nidOther, startSeq, seqOther}); + missingData.push_back({nidOther, startSeq, seqOther, 0}); m_vv.set(nidOther, seqOther); } } - // Callback if missing data found - if (!v.empty()) - { - m_onUpdate(v); - } - // Check if I have newer state for (const auto& entry : m_vv) { @@ -327,7 +341,7 @@ SVSyncCore::mergeStateVector(const VersionVector &vvOther) } } - return {myVectorNew, otherVectorNew}; + return {myVectorNew, otherVectorNew, missingData}; } void diff --git a/ndn-svs/core.hpp b/ndn-svs/core.hpp index 4755dc2..9f23198 100644 --- a/ndn-svs/core.hpp +++ b/ndn-svs/core.hpp @@ -39,6 +39,8 @@ class MissingDataInfo SeqNo low; /// @brief the highest one of missing sequence numbers SeqNo high; + /// @brief ndn::lp::IncomingFaceIdTag + uint64_t incomingFace; }; /** @@ -196,10 +198,10 @@ class SVSyncCore : noncopyable * * @param vvOther state vector to merge in * - * @returns a pair of boolean representing: - * . + * @returns a tuple of representing: + * . */ - std::pair + std::tuple> mergeStateVector(const VersionVector& vvOther); /**