Merge remote-tracking branch 'git.irl/master'
diff --git a/model/sync-app-socket.h b/model/sync-app-socket.h
index 38a2657..fb2d271 100644
--- a/model/sync-app-socket.h
+++ b/model/sync-app-socket.h
@@ -62,6 +62,14 @@
*/
bool publish (const std::string &prefix, uint32_t session, const std::string &dataBuffer, int freshness);
+ /**
+ * @brief delete a participant's subtree from the sync tree; SyncLogic will do the work
+ * this is just a wrapper
+ *
+ * @param the prefix for the participant
+ */
+ void remove (const std::string &prefix) {m_syncLogic.remove(prefix);}
+
private:
CcnxWrapperPtr m_ccnxHandle;
diff --git a/model/sync-logic.cc b/model/sync-logic.cc
index 3102c4e..f9f8537 100644
--- a/model/sync-logic.cc
+++ b/model/sync-logic.cc
@@ -181,55 +181,55 @@
{
recursive_mutex::scoped_lock lock (m_stateMutex);
- string last = name.substr(name.find_last_of("/") + 1);
- istringstream ss (dataBuffer);
+ string last = name.substr(name.find_last_of("/") + 1);
+ istringstream ss (dataBuffer);
- if (last == "state")
- {
- FullState full;
- ss >> full;
+ if (last == "state")
+ {
+ FullState full;
+ ss >> full;
BOOST_FOREACH (LeafConstPtr leaf, full.getLeaves()) // order doesn't matter
- {
- NameInfoConstPtr info = leaf->getInfo ();
- SeqNo seq = leaf->getSeq ();
+ {
+ NameInfoConstPtr info = leaf->getInfo ();
+ SeqNo seq = leaf->getSeq ();
bool inserted = false;
bool updated = false;
SeqNo oldSeq;
tie (inserted, updated, oldSeq) = m_state.update (info, seq);
-
+
if (updated)
{
diffLog->update (info, seq);
m_onUpdate (info->toString (), seq.getSeq(), oldSeq);
- }
- }
+ }
+ }
}
- else
- {
- DiffState diff;
- ss >> diff;
- BOOST_FOREACH (LeafConstPtr leaf, diff.getLeaves().get<ordered>())
- {
+ else
+ {
+ DiffState diff;
+ ss >> diff;
+ BOOST_FOREACH (LeafConstPtr leaf, diff.getLeaves().get<ordered>())
+ {
DiffLeafConstPtr diffLeaf = dynamic_pointer_cast<const DiffLeaf> (leaf);
BOOST_ASSERT (diffLeaf != 0);
- NameInfoConstPtr info = diffLeaf->getInfo ();
+ NameInfoConstPtr info = diffLeaf->getInfo();
if (diffLeaf->getOperation() == UPDATE)
{
- SeqNo seq = diffLeaf->getSeq ();
-
+ SeqNo seq = diffLeaf->getSeq();
+
bool inserted = false;
bool updated = false;
SeqNo oldSeq;
tie (inserted, updated, oldSeq) = m_state.update (info, seq);
-
+
if (updated)
{
diffLog->update (info, seq);
m_onUpdate (info->toString (), seq.getSeq(), oldSeq);
- }
- }
+ }
+ }
else if (diffLeaf->getOperation() == REMOVE)
{
if (m_state.remove (info))
@@ -245,8 +245,8 @@
}
}
- diffLog->setDigest(m_state.getDigest());
- m_log.insert (diffLog);
+ diffLog->setDigest(m_state.getDigest());
+ m_log.insert (diffLog);
}
catch (Error::SyncXmlDecodingFailure &e)
{
@@ -256,29 +256,37 @@
if (diffLog->getLeaves ().size () > 0)
{
- // notify upper layer
- BOOST_FOREACH (LeafConstPtr leaf, diffLog->getLeaves ())
- {
+ // notify upper layer
+ BOOST_FOREACH (LeafConstPtr leaf, diffLog->getLeaves ())
+ {
DiffLeafConstPtr diffLeaf = dynamic_pointer_cast<const DiffLeaf> (leaf);
BOOST_ASSERT (diffLeaf != 0);
// m_fetchCallback (prefix, 1, seq.getSeq());
- }
-
- sendSyncInterest ();
}
+
+ sendSyncInterest();
+}
}
void
-SyncLogic::addLocalNames (const string &prefix, uint32_t session, uint32_t seq)
+SyncLogic::processPendingSyncInterests(DiffStatePtr &diff) {
+ diff->setDigest(m_state.getDigest());
+ m_log.insert(diff);
+
+ vector<string> pis = m_syncInterestTable.fetchAll ();
+ stringstream ss;
+ ss << *diff;
+ for (vector<string>::iterator ii = pis.begin(); ii != pis.end(); ++ii)
+ {
+ m_ccnxHandle->publishData (*ii, ss.str(), m_syncResponseFreshness);
+ }
+}
+
+void
+SyncLogic::processPendingSyncInterests(DiffStatePtr &diff)
{
recursive_mutex::scoped_lock lock (m_stateMutex);
-
- NameInfoConstPtr info = StdNameInfo::FindOrCreate (prefix);
- SeqNo seqN(session, seq);
- DiffStatePtr diff = make_shared<DiffState>();
- diff->update(info, seqN);
- m_state.update(info, seqN);
diff->setDigest(m_state.getDigest());
m_log.insert(diff);
@@ -292,6 +300,33 @@
}
void
+SyncLogic::addLocalNames (const string &prefix, uint32_t session, uint32_t seq)
+{
+ recursive_mutex::scoped_lock lock (m_stateMutex);
+ NameInfoConstPtr info = StdNameInfo::FindOrCreate(prefix);
+ SeqNo seqN(session, seq);
+ m_state.update(info, seqN);
+
+ DiffStatePtr diff = make_shared<DiffState>();
+ diff->update(info, seqN);
+
+ processPendingSyncInterests(diff);
+}
+
+void
+SyncLogic::remove(const string &prefix)
+{
+ recursive_mutex::scoped_lock lock (m_stateMutex);
+ NameInfoConstPtr info = StdNameInfo::FindOrCreate(prefix);
+ m_state.remove(info);
+
+ DiffStatePtr diff = make_shared<DiffState>();
+ diff->remove(info);
+
+ processPendingSyncInterests(diff);
+}
+
+void
SyncLogic::sendSyncInterest ()
{
recursive_mutex::scoped_lock lock (m_stateMutex);
diff --git a/model/sync-logic.h b/model/sync-logic.h
index d2d9f0f..6c112dd 100644
--- a/model/sync-logic.h
+++ b/model/sync-logic.h
@@ -80,6 +80,12 @@
*/
void processSyncData (const std::string &name, const std::string &dataBuffer);
+ /**
+ * @brief remove a participant's subtree from the sync tree
+ * @param the name prefix for the participant
+ */
+ void remove(const std::string &prefix);
+
#ifdef _DEBUG
size_t
getListChecksSize ()
@@ -96,7 +102,9 @@
processSyncInterest (DigestConstPtr digest, const std::string &interestname, bool timedProcessing=false);
void sendSyncInterest ();
- // void checkAgain (const std::string &interest, DigestPtr digest);
+
+ void
+ processPendingSyncInterests(DiffStatePtr &diff);
private:
typedef std::list< boost::tuple< boost::system_time, boost::function< void ( ) > > > DelayedChecksList;