fixes: Remove sync scheduler; Use ndn::time; Passed all the test cases
Change-Id: I50e8cd94f71f463793e4d19d5bf65e190cac6e59
diff --git a/src/sync-logic.cc b/src/sync-logic.cc
index f9bbdca..6f3d21d 100644
--- a/src/sync-logic.cc
+++ b/src/sync-logic.cc
@@ -27,7 +27,6 @@
#include "sync-logging.h"
#include "sync-state.h"
-#include <boost/make_shared.hpp>
#include <boost/foreach.hpp>
#include <boost/lexical_cast.hpp>
#include <vector>
@@ -39,7 +38,7 @@
#ifdef _DEBUG
-#define _LOG_DEBUG_ID(v) _LOG_DEBUG(m_instanceId + v)
+#define _LOG_DEBUG_ID(v) _LOG_DEBUG(m_instanceId << " " << v)
#else
#define _LOG_DEBUG_ID(v) _LOG_DEBUG(v)
#endif
@@ -47,14 +46,14 @@
#define GET_RANDOM(var) var ()
#define TIME_SECONDS_WITH_JITTER(sec) \
- (TIME_SECONDS (sec) + TIME_MILLISECONDS (GET_RANDOM (m_reexpressionJitter)))
+ (time::seconds(sec) + time::milliseconds(GET_RANDOM (m_reexpressionJitter)))
#define TIME_MILLISECONDS_WITH_JITTER(ms) \
- (TIME_MILLISECONDS (ms) + TIME_MILLISECONDS (GET_RANDOM (m_reexpressionJitter)))
+ (time::seconds(ms) + time::milliseconds(GET_RANDOM (m_reexpressionJitter)))
+namespace Sync {
-namespace Sync
-{
+using ndn::shared_ptr;
int SyncLogic::m_instanceCounter = 0;
@@ -64,7 +63,7 @@
LogicUpdateCallback onUpdate,
LogicRemoveCallback onRemove)
: m_state (new FullState)
- , m_syncInterestTable (TIME_SECONDS (m_syncInterestReexpress))
+ , m_syncInterestTable (*face->ioService(), time::seconds(m_syncInterestReexpress))
, m_syncPrefix (syncPrefix)
, m_onUpdate (onUpdate)
, m_onRemove (onRemove)
@@ -73,7 +72,7 @@
, m_keyChain(new KeyChain())
, m_face(face)
, m_scheduler(*face->ioService())
- , m_randomGenerator (static_cast<unsigned int> (std::time (0)))
+ , m_randomGenerator (static_cast<unsigned int> (std::time (0)))
, m_rangeUniformRandom (m_randomGenerator, boost::uniform_int<> (200,1000))
, m_reexpressionJitter (m_randomGenerator, boost::uniform_int<> (100,500))
, m_recoveryRetransmissionInterval (m_defaultRecoveryRetransmitInterval)
@@ -94,7 +93,7 @@
shared_ptr<Face> face,
LogicPerBranchCallback onUpdateBranch)
: m_state (new FullState)
- , m_syncInterestTable (TIME_SECONDS (m_syncInterestReexpress))
+ , m_syncInterestTable (*face->ioService(), time::seconds (m_syncInterestReexpress))
, m_syncPrefix (syncPrefix)
, m_onUpdateBranch (onUpdateBranch)
, m_perBranch(true)
@@ -258,7 +257,6 @@
_LOG_DEBUG_ID("processSyncInterest");
DigestConstPtr rootDigest;
{
- boost::recursive_mutex::scoped_lock lock (m_stateMutex);
rootDigest = m_state->getDigest();
}
@@ -268,7 +266,6 @@
SyncStateMsg ssm;
{
- boost::recursive_mutex::scoped_lock lock (m_stateMutex);
ssm << (*m_state);
}
sendSyncData (name, digest, ssm);
@@ -302,7 +299,7 @@
}
uint32_t waitDelay = GET_RANDOM (m_rangeUniformRandom);
- _LOG_DEBUG_ID ("Digest is not in the log. Schedule processing after small delay: " << waitDelay << "ms");
+ _LOG_DEBUG_ID ("Digest is not in the log. Schedule processing after small delay: " << time::milliseconds (waitDelay));
m_delayedInterestProcessingId = m_scheduler.scheduleEvent (time::milliseconds (waitDelay),
bind (&SyncLogic::processSyncInterest, this, name, digest, true));
@@ -353,7 +350,6 @@
bool updated = false;
SeqNo oldSeq;
{
- boost::recursive_mutex::scoped_lock lock (m_stateMutex);
boost::tie (inserted, updated, oldSeq) = m_state->update (info, seq);
}
@@ -392,7 +388,6 @@
}
else if (diffLeaf->getOperation() == REMOVE)
{
- boost::recursive_mutex::scoped_lock lock (m_stateMutex);
if (m_state->remove (info))
{
diffLog->remove (info);
@@ -436,7 +431,7 @@
// if state has changed, then it is safe to express a new interest
time::Duration after = time::milliseconds(GET_RANDOM (m_reexpressionJitter));
- cout << "------------ reexpress interest after: " << after << " ms " << endl;
+ // cout << "------------ reexpress interest after: " << after << endl;
EventId eventId = m_scheduler.scheduleEvent (after,
bind (&SyncLogic::sendSyncInterest, this));
@@ -459,7 +454,6 @@
SyncStateMsg ssm;
{
- boost::recursive_mutex::scoped_lock lock (m_stateMutex);
ssm << (*m_state);
}
sendSyncData (name, digest, ssm);
@@ -470,7 +464,6 @@
{
DiffStatePtr fullStateLog = boost::make_shared<DiffState> ();
{
- boost::recursive_mutex::scoped_lock lock (m_stateMutex);
BOOST_FOREACH (LeafConstPtr leaf, m_state->getLeaves ()/*.get<timed> ()*/)
{
fullStateLog->update (leaf->getInfo (), leaf->getSeq ());
@@ -524,7 +517,6 @@
DiffStatePtr diff;
{
//cout << "Add local names" <<endl;
- boost::recursive_mutex::scoped_lock lock (m_stateMutex);
NameInfoConstPtr info = StdNameInfo::FindOrCreate(prefix.toUri());
_LOG_DEBUG_ID ("addLocalNames (): old state " << *m_state->getDigest ());
@@ -548,7 +540,6 @@
{
DiffStatePtr diff;
{
- boost::recursive_mutex::scoped_lock lock (m_stateMutex);
NameInfoConstPtr info = StdNameInfo::FindOrCreate(prefix.toUri());
m_state->remove(info);
@@ -580,7 +571,6 @@
_LOG_DEBUG_ID("sendSyncInterest");
{
- boost::recursive_mutex::scoped_lock lock (m_stateMutex);
m_outstandingInterestName = m_syncPrefix;
ostringstream os;
os << *m_state->getDigest();
@@ -667,7 +657,6 @@
// checking if our own interest got satisfied
bool satisfiedOwnInterest = false;
{
- boost::recursive_mutex::scoped_lock lock (m_stateMutex);
satisfiedOwnInterest = (m_outstandingInterestName == name);
}
@@ -676,7 +665,7 @@
_LOG_DEBUG_ID ("Satisfied our own Interest. Re-expressing (hopefully with a new digest)");
time::Duration after = time::milliseconds(GET_RANDOM (m_reexpressionJitter));
- cout << "------------ reexpress interest after: " << after << " ms " << endl;
+ // cout << "------------ reexpress interest after: " << after << endl;
EventId eventId = m_scheduler.scheduleEvent (after,
bind (&SyncLogic::sendSyncInterest, this));
m_scheduler.cancelEvent (m_reexpressingInterestId);
@@ -688,7 +677,6 @@
SyncLogic::getRootDigest()
{
ostringstream os;
- boost::recursive_mutex::scoped_lock lock (m_stateMutex);
os << *m_state->getDigest();
return os.str();
}
@@ -696,15 +684,12 @@
size_t
SyncLogic::getNumberOfBranches () const
{
- boost::recursive_mutex::scoped_lock lock (m_stateMutex);
return m_state->getLeaves ().size ();
}
void
SyncLogic::printState () const
{
- boost::recursive_mutex::scoped_lock lock (m_stateMutex);
-
BOOST_FOREACH (const boost::shared_ptr<Sync::Leaf> leaf, m_state->getLeaves ())
{
std::cout << *leaf << std::endl;
@@ -714,8 +699,6 @@
std::map<std::string, bool>
SyncLogic::getBranchPrefixes() const
{
- boost::recursive_mutex::scoped_lock lock (m_stateMutex);
-
std::map<std::string, bool> m;
BOOST_FOREACH (const boost::shared_ptr<Sync::Leaf> leaf, m_state->getLeaves ())