Skip to content

Commit

Permalink
refactor(core): remove tuple
Browse files Browse the repository at this point in the history
  • Loading branch information
pulsejet committed Mar 8, 2024
1 parent 8ea5442 commit 1290954
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 32 deletions.
35 changes: 14 additions & 21 deletions ndn-svs/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ suppressionCurve(int constFactor, int value)
// Increasing the curve factor makes the curve steeper =>
// better for more nodes, but worse for fewer nodes.

double c = constFactor;
double v = value;
double f = 10.0; // curve factor
float c = constFactor;
float v = value;
float f = 10.0; // curve factor

return static_cast<int>(c * (1.0 - std::exp((v - c) / (c / f))));
}
Expand Down Expand Up @@ -182,14 +182,11 @@ SVSyncCore::onSyncInterestValidated(const Interest& interest)
// Merge state vector
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)
if (!result.missingInfo.empty()) {
for (auto& e : result.missingInfo)
e.incomingFace = incomingFace;
m_onUpdate(missingData);
m_onUpdate(result.missingInfo);
}

// Try to record; the call will check if in suppression state
Expand All @@ -198,7 +195,7 @@ SVSyncCore::onSyncInterestValidated(const Interest& interest)

// If incoming state identical/newer to local vector, reset timer
// If incoming state is older, send sync interest immediately
if (!myVectorNew) {
if (!result.myVectorNew) {
retxSyncInterest(false, 0);
} else {
enterSuppressionState(*vvOther);
Expand All @@ -224,7 +221,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 || std::get<0>(mergeStateVector(*m_recordedVv)))
if (!m_recordedVv || mergeStateVector(*m_recordedVv).myVectorNew)
sendSyncInterest();
m_recordedVv = nullptr;
}
Expand Down Expand Up @@ -301,15 +298,11 @@ SVSyncCore::sendSyncInterest()
m_face.expressInterest(interest, nullptr, nullptr, nullptr);
}

std::tuple<bool, bool, std::vector<MissingDataInfo>>
SVSyncCore::MergeResult
SVSyncCore::mergeStateVector(const VersionVector& vvOther)
{
std::lock_guard<std::mutex> lock(m_vvMutex);

bool myVectorNew = false, otherVectorNew = false;

// New data found in vvOther
std::vector<MissingDataInfo> missingData;
SVSyncCore::MergeResult result;

// Check if other vector has newer state
for (const auto& entry : vvOther) {
Expand All @@ -318,10 +311,10 @@ SVSyncCore::mergeStateVector(const VersionVector& vvOther)
SeqNo seqCurrent = m_vv.get(nidOther);

if (seqCurrent < seqOther) {
otherVectorNew = true;
result.otherVectorNew = true;

SeqNo startSeq = m_vv.get(nidOther) + 1;
missingData.push_back({ nidOther, startSeq, seqOther, 0 });
result.missingInfo.push_back({ nidOther, startSeq, seqOther, 0 });

m_vv.set(nidOther, seqOther);
}
Expand All @@ -338,12 +331,12 @@ SVSyncCore::mergeStateVector(const VersionVector& vvOther)
continue;

if (seqOther < seq) {
myVectorNew = true;
result.myVectorNew = true;
break;
}
}

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

void
Expand Down
24 changes: 13 additions & 11 deletions ndn-svs/core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,31 +172,33 @@ class SVSyncCore : noncopyable
*/
void sendSyncInterest();

struct MergeResult
{
/// @brief If the local state vector has newer entries
bool myVectorNew;
/// @brief If the incoming state vector has newer entries
bool otherVectorNew;
/// @brief Newly learned missing information from incoming state vector
std::vector<MissingDataInfo> missingInfo;
};

/**
* @brief Merge state vector into the current
*
* Also adds missing data interests to data interest queue.
*
* @param vvOther state vector to merge in
*
* @returns a tuple of representing:
* <my vector new, other vector new, missinginfo>.
* @details Also adds missing data interests to data interest queue.
*/
std::tuple<bool, bool, std::vector<MissingDataInfo>> mergeStateVector(
const VersionVector& vvOther);
MergeResult mergeStateVector(const VersionVector& vvOther);

/**
* @brief Record vector by merging it into m_recordedVv
*
* @param vvOther state vector to merge in
* @returns if recorded successfully
*/
bool recordVector(const VersionVector& vvOther);

/**
* @brief Enter suppression state by setting
* m_recording to True and initializing m_recordedVv to vvOther
*
* m_recording to True and initializing m_recordedVv to vvOther.
* Does nothing if already in suppression state
*
* @param vvOther first vector to record
Expand Down

0 comments on commit 1290954

Please sign in to comment.