API change for closure. Return ParsedContentObject, not just content
Fixed bug in test/test-sync-core.cc: there should have been two independent schedulers
diff --git a/src/sync-core.cc b/src/sync-core.cc
index 14f4110..9861c44 100644
--- a/src/sync-core.cc
+++ b/src/sync-core.cc
@@ -32,7 +32,7 @@
static void
printMsg(SyncStateMsgPtr &msg)
{
- cout << " ===== start Msg ======" << endl;
+ cerr << " ===== start Msg ======" << endl;
int size = msg->state_size();
if (size > 0)
{
@@ -43,17 +43,17 @@
string strName = state.name();
string strLocator = state.locator();
sqlite3_int64 seq = state.seq();
- cout << "Name: " << Name((const unsigned char *)strName.c_str(), strName.size());
- cout << ", Locator: " << Name((const unsigned char *)strLocator.c_str(), strLocator.size());
- cout << ", seq: " << seq << endl;
+ cerr << "Name: " << Name((const unsigned char *)strName.c_str(), strName.size());
+ cerr << ", Locator: " << Name((const unsigned char *)strLocator.c_str(), strLocator.size());
+ cerr << ", seq: " << seq << endl;
index ++;
}
}
else
{
- cout << "Msg size 0" << endl;
+ cerr << "Msg size 0" << endl;
}
- cout << " ++++++++ end Msg ++++++++ \n\n" << endl;
+ cerr << " ++++++++ end Msg ++++++++ \n\n" << endl;
}
SyncCore::SyncCore(SyncLogPtr syncLog, const Name &userName, const Name &localPrefix, const Name &syncPrefix, const StateMsgCallback &callback, const CcnxWrapperPtr &handle, const SchedulerPtr &scheduler)
@@ -128,7 +128,7 @@
Bytes syncData;
msgToBytes(msg, syncData);
m_handle->publishData(syncName, syncData, FRESHNESS);
- cout << m_log->GetLocalName () << " publishes: " << *oldHash << endl;
+ cerr << m_log->GetLocalName () << " publishes: " << *oldHash << endl;
printMsg(msg);
// no hurry in sending out new Sync Interest; if others send the new Sync Interest first, no problem, we know the new root hash already;
@@ -172,7 +172,7 @@
assert(msg->state_size() > 0);
int size = msg->state_size();
int index = 0;
- cout << "Reply recover interest with: " << endl;
+ cerr << "Reply recover interest with: " << endl;
while (index < size)
{
SyncState state = msg->state(index);
@@ -194,7 +194,7 @@
Bytes syncData;
msgToBytes(msg, syncData);
m_handle->publishData(name, syncData, FRESHNESS);
- cout << m_log->GetLocalName () << " publishes " << hash << endl;
+ cerr << m_log->GetLocalName () << " publishes " << hash << endl;
printMsg(msg);
}
else
@@ -211,29 +211,29 @@
if (*hash == *m_rootHash)
{
// we have the same hash; nothing needs to be done
- cout << "same as root hash: " << *hash << endl;
+ cerr << "same as root hash: " << *hash << endl;
return;
}
else if (m_log->LookupSyncLog(*hash) > 0)
{
// we know something more
- cout << "found hash in sync log" << endl;
+ cerr << "found hash in sync log" << endl;
SyncStateMsgPtr msg = m_log->FindStateDifferences(*hash, *m_rootHash);
Bytes syncData;
msgToBytes(msg, syncData);
m_handle->publishData(name, syncData, FRESHNESS);
- cout << m_log->GetLocalName () << " publishes: " << *hash << endl;
+ cerr << m_log->GetLocalName () << " publishes: " << *hash << endl;
printMsg(msg);
}
else
{
// we don't recognize the hash, send recover Interest if still don't know the hash after a randomized wait period
ostringstream ss;
- ss << *hash;
+ ss << "r-" << *hash;
double wait = m_recoverWaitGenerator->nextInterval();
- cout << m_log->GetLocalName () << ", rootHash: " << *m_rootHash << ", hash: " << *hash << endl;
- cout << "recover task scheduled after wait: " << wait << endl;
+ cerr << m_log->GetLocalName () << ", rootHash: " << *m_rootHash << ", hash: " << *hash << endl;
+ cerr << "recover task scheduled after wait: " << wait << endl;
TaskPtr task(new OneTimeTask(boost::bind(&SyncCore::recover, this, hash), ss.str(), m_scheduler, wait));
m_scheduler->addTask(task);
@@ -259,18 +259,18 @@
}
void
-SyncCore::handleRecoverData(const Name &name, const Bytes &content)
+SyncCore::handleRecoverData(const Name &name, PcoPtr content)
{
//cout << "handle recover data" << endl;
- handleStateData(content);
+ handleStateData(*content->contentPtr ());
sendSyncInterest();
}
void
-SyncCore::handleSyncData(const Name &name, const Bytes &content)
+SyncCore::handleSyncData(const Name &name, PcoPtr content)
{
// suppress recover in interest - data out of order case
- handleStateData(content);
+ handleStateData(*content->contentPtr ());
// resume outstanding sync interest
sendSyncInterest();
@@ -288,7 +288,7 @@
return;
}
- cout << m_log->GetLocalName () << " receives Msg " << endl;
+ cerr << m_log->GetLocalName () << " receives Msg " << endl;
printMsg (msg);
int size = msg->state_size();
int index = 0;
@@ -311,12 +311,12 @@
m_log->UpdateLocator(deviceName, locatorName);
// WriteLock lock(m_ypMutex);
// m_yp[deviceName] = locatorName;
- cout << "self: " << m_log->GetLocalName () << ", device: " << deviceName << " < == > " << locatorName << endl;
+ cerr << "self: " << m_log->GetLocalName () << ", device: " << deviceName << " < == > " << locatorName << endl;
}
}
else
{
- cout << "nani" << endl;
+ cerr << "nani" << endl;
deregister(deviceName);
}
index++;
@@ -339,7 +339,7 @@
{
Name syncInterest = constructSyncName(m_rootHash);
m_handle->sendInterest(syncInterest, m_syncClosure);
- cout << m_log->GetLocalName () << " send SYNC interest: " << *m_rootHash << endl;
+ cerr << m_log->GetLocalName () << " send SYNC interest: " << *m_rootHash << endl;
}
void
@@ -347,7 +347,7 @@
{
if (!(*hash == *m_rootHash) && m_log->LookupSyncLog(*hash) <= 0)
{
- cout << m_log->GetLocalName () << ", Recover for: " << *hash << endl;
+ cerr << m_log->GetLocalName () << ", Recover for: " << *hash << endl;
// unfortunately we still don't recognize this hash
Bytes bytes;
readRaw(bytes, (const unsigned char *)hash->GetHash(), hash->GetHashBytes());
@@ -356,7 +356,7 @@
// append the unknown hash
recoverInterest.appendComp(bytes);
m_handle->sendInterest(recoverInterest, m_recoverClosure);
- cout << m_log->GetLocalName () << " send RECOVER Interest: " << *hash << endl;
+ cerr << m_log->GetLocalName () << " send RECOVER Interest: " << *hash << endl;
}
else
{