Skip to content

Commit

Permalink
core: pass incoming face to callback
Browse files Browse the repository at this point in the history
  • Loading branch information
pulsejet committed Jul 19, 2023
1 parent 87e5bc0 commit 1541167
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 16 deletions.
40 changes: 27 additions & 13 deletions ndn-svs/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <ndn-cxx/security/signing-helpers.hpp>
#include <ndn-cxx/security/verification-helpers.hpp>
#include <ndn-cxx/encoding/buffer-stream.hpp>
#include <ndn-cxx/lp/tags.hpp>

#ifdef NDN_SVS_COMPRESSION
#include <boost/iostreams/filter/lzma.hpp>
Expand Down Expand Up @@ -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<ndn::lp::IncomingFaceIdTag>();
if (tag) {
incomingFace = tag->get();
}
}

// Get state vector
std::shared_ptr<VersionVector> vvOther;
try
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -278,7 +298,7 @@ SVSyncCore::sendSyncInterest()
m_face.expressInterest(interest, nullptr, nullptr, nullptr);
}

std::pair<bool, bool>
std::tuple<bool, bool, std::vector<MissingDataInfo>>
SVSyncCore::mergeStateVector(const VersionVector &vvOther)
{
std::lock_guard<std::mutex> lock(m_vvMutex);
Expand All @@ -287,7 +307,7 @@ SVSyncCore::mergeStateVector(const VersionVector &vvOther)
otherVectorNew = false;

// New data found in vvOther
std::vector<MissingDataInfo> v;
std::vector<MissingDataInfo> missingData;

// Check if other vector has newer state
for (const auto& entry : vvOther)
Expand All @@ -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)
{
Expand All @@ -327,7 +341,7 @@ SVSyncCore::mergeStateVector(const VersionVector &vvOther)
}
}

return {myVectorNew, otherVectorNew};
return {myVectorNew, otherVectorNew, missingData};
}

void
Expand Down
8 changes: 5 additions & 3 deletions ndn-svs/core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

/**
Expand Down Expand Up @@ -196,10 +198,10 @@ class SVSyncCore : noncopyable
*
* @param vvOther state vector to merge in
*
* @returns a pair of boolean representing:
* <my vector new, other vector new>.
* @returns a tuple of representing:
* <my vector new, other vector new, missinginfo>.
*/
std::pair<bool, bool>
std::tuple<bool, bool, std::vector<MissingDataInfo>>
mergeStateVector(const VersionVector& vvOther);

/**
Expand Down

0 comments on commit 1541167

Please sign in to comment.