Commenting out duplicate functionality with locators...
diff --git a/src/sync-core.cc b/src/sync-core.cc
index 4ddf47f..36b1fc7 100644
--- a/src/sync-core.cc
+++ b/src/sync-core.cc
@@ -73,7 +73,7 @@
m_rootHash = m_log->RememberStateInStateLog();
m_handle->setInterestFilter(m_syncPrefix, boost::bind(&SyncCore::handleInterest, this, _1));
- m_log->initYP(m_yp);
+ // m_log->initYP(m_yp);
m_scheduler->start();
sendSyncInterest();
}
@@ -83,29 +83,29 @@
// need to "deregister" closures
}
-Name
-SyncCore::yp(const Name &deviceName)
-{
- Name locator;
- ReadLock lock(m_ypMutex);
- if (m_yp.find(deviceName) != m_yp.end())
- {
- locator = m_yp[deviceName];
- }
- else
- {
- cout << "self: " << m_userName << ", deviceName: " << deviceName << " not found in yp " << endl;
- }
- return locator;
-}
+// Name
+// SyncCore::yp(const Name &deviceName)
+// {
+// Name locator;
+// ReadLock lock(m_ypMutex);
+// if (m_yp.find(deviceName) != m_yp.end())
+// {
+// locator = m_yp[deviceName];
+// }
+// else
+// {
+// cout << "self: " << m_userName << ", deviceName: " << deviceName << " not found in yp " << endl;
+// }
+// return locator;
+// }
-void
-SyncCore::updateLocalPrefix(const Name &localPrefix)
-{
- m_localPrefix = localPrefix;
- // optionally, we can have a sync action to announce the new prefix
- // we are not doing this for now
-}
+// void
+// SyncCore::updateLocalPrefix(const Name &localPrefix)
+// {
+// m_localPrefix = localPrefix;
+// // optionally, we can have a sync action to announce the new prefix
+// // we are not doing this for now
+// }
void
SyncCore::updateLocalState(sqlite3_int64 seqno)
@@ -113,10 +113,10 @@
m_log->UpdateDeviceSeqNo(m_userName, seqno);
// choose to update locator everytime
m_log->UpdateLocator(m_userName, m_localPrefix);
- {
- WriteLock lock(m_ypMutex);
- m_yp[m_userName] = m_localPrefix;
- }
+ // {
+ // WriteLock lock(m_ypMutex);
+ // m_yp[m_userName] = m_localPrefix;
+ // }
HashPtr oldHash = m_rootHash;
m_rootHash = m_log->RememberStateInStateLog();
@@ -308,8 +308,8 @@
Name locatorName((const unsigned char *)locStr.c_str(), locStr.size());
// cout << ", Got loc: " << locatorName << endl;
m_log->UpdateLocator(deviceName, locatorName);
- WriteLock lock(m_ypMutex);
- m_yp[deviceName] = locatorName;
+ // WriteLock lock(m_ypMutex);
+ // m_yp[deviceName] = locatorName;
cout << "self: " << m_userName << ", device: " << deviceName << " < == > " << locatorName << endl;
}
}
diff --git a/src/sync-core.h b/src/sync-core.h
index cb44398..b97596f 100644
--- a/src/sync-core.h
+++ b/src/sync-core.h
@@ -37,7 +37,7 @@
{
public:
typedef boost::function<void (const SyncStateMsgPtr & stateMsg) > StateMsgCallback;
- typedef map<Name, Name> YellowPage;
+ // typedef map<Name, Name> YellowPage;
typedef boost::shared_mutex Mutex;
typedef boost::shared_lock<Mutex> ReadLock;
typedef boost::unique_lock<Mutex> WriteLock;
@@ -59,14 +59,14 @@
// some other code should call this fuction when local prefix
// changes; e.g. when wake up in another network
- void
- updateLocalPrefix(const Name &localPrefix);
+ // void
+ // updateLocalPrefix(const Name &localPrefix);
void
updateLocalState(sqlite3_int64);
- Name
- yp(const Name &name);
+ // Name
+ // yp(const Name &name);
void
handleInterest(const Name &name);
@@ -123,7 +123,7 @@
Name m_localPrefix;
Name m_syncPrefix;
HashPtr m_rootHash;
- YellowPage m_yp;
+ // YellowPage m_yp;
Mutex m_ypMutex;
CcnxWrapperPtr m_handle;
Closure m_syncClosure;
diff --git a/src/sync-log.cc b/src/sync-log.cc
index eb421a9..058627f 100644
--- a/src/sync-log.cc
+++ b/src/sync-log.cc
@@ -59,25 +59,25 @@
sqlite3_finalize (stmt);
}
-void
-SyncLog::initYP(map<Name, Name> &yp)
-{
- sqlite3_stmt *stmt;
- sqlite3_prepare_v2(m_db, "SELECT device_name, last_known_locator FROM SyncNodes;", -1, &stmt, 0);
+// void
+// SyncLog::initYP(map<Name, Name> &yp)
+// {
+// sqlite3_stmt *stmt;
+// sqlite3_prepare_v2(m_db, "SELECT device_name, last_known_locator FROM SyncNodes;", -1, &stmt, 0);
- while (sqlite3_step(stmt) == SQLITE_ROW)
- {
- Name deviceName((const unsigned char *)sqlite3_column_blob(stmt, 0), sqlite3_column_bytes(stmt, 0));
- Name locator;
- if (sqlite3_column_type(stmt, 1) == SQLITE_BLOB)
- {
- locator = Name((const unsigned char *)sqlite3_column_blob(stmt, 1), sqlite3_column_bytes(stmt, 1));
- }
- yp.insert(make_pair(deviceName, locator));
- }
+// while (sqlite3_step(stmt) == SQLITE_ROW)
+// {
+// Name deviceName((const unsigned char *)sqlite3_column_blob(stmt, 0), sqlite3_column_bytes(stmt, 0));
+// Name locator;
+// if (sqlite3_column_type(stmt, 1) == SQLITE_BLOB)
+// {
+// locator = Name((const unsigned char *)sqlite3_column_blob(stmt, 1), sqlite3_column_bytes(stmt, 1));
+// }
+// yp.insert(make_pair(deviceName, locator));
+// }
- sqlite3_finalize(stmt);
-}
+// sqlite3_finalize(stmt);
+// }
sqlite3_int64
SyncLog::GetNextLocalSeqNo ()
@@ -91,12 +91,12 @@
BOOST_THROW_EXCEPTION (Error::Db ()
<< errmsg_info_str ("Impossible thing in ActionLog::AddActionUpdate"));
}
-
- sqlite3_int64 seq_no = sqlite3_column_int64 (stmt_seq, 0) + 1;
+
+ sqlite3_int64 seq_no = sqlite3_column_int64 (stmt_seq, 0) + 1;
sqlite3_finalize (stmt_seq);
UpdateDeviceSeqNo (m_localDeviceId, seq_no);
-
+
return seq_no;
}
@@ -123,9 +123,9 @@
BOOST_THROW_EXCEPTION (Error::Db ()
<< errmsg_info_str (sqlite3_errmsg(m_db)));
}
-
+
sqlite3_int64 rowId = sqlite3_last_insert_rowid (m_db);
-
+
sqlite3_stmt *insertStmt;
res += sqlite3_prepare (m_db, "\
INSERT INTO SyncStateNodes \
@@ -145,7 +145,7 @@
<< errmsg_info_str (sqlite3_errmsg(m_db)));
}
sqlite3_finalize (insertStmt);
-
+
sqlite3_stmt *getHashStmt;
res += sqlite3_prepare (m_db, "\
SELECT state_hash FROM SyncLog WHERE state_id = ?\
@@ -176,7 +176,7 @@
BOOST_THROW_EXCEPTION (Error::Db ()
<< errmsg_info_str ("Some error with rememberStateInStateLog"));
}
-
+
return retval;
}
@@ -192,7 +192,7 @@
sqlite3_stmt *stmt;
int res = sqlite3_prepare (m_db, "SELECT state_id FROM SyncLog WHERE state_hash = ?",
-1, &stmt, 0);
-
+
if (res != SQLITE_OK)
{
BOOST_THROW_EXCEPTION (Error::Db ()
@@ -223,14 +223,14 @@
{
sqlite3_stmt *stmt;
// update is performed using trigger
- int res = sqlite3_prepare (m_db, "INSERT INTO SyncNodes (device_name, seq_no) VALUES (?,?);",
+ int res = sqlite3_prepare (m_db, "INSERT INTO SyncNodes (device_name, seq_no) VALUES (?,?);",
-1, &stmt, 0);
Ccnx::CcnxCharbufPtr nameBuf = name;
res += sqlite3_bind_blob (stmt, 1, nameBuf->buf (), nameBuf->length (), SQLITE_STATIC);
res += sqlite3_bind_int64 (stmt, 2, seqNo);
sqlite3_step (stmt);
-
+
if (res != SQLITE_OK)
{
BOOST_THROW_EXCEPTION (Error::Db ()
@@ -244,13 +244,13 @@
{
sqlite3_stmt *stmt;
// update is performed using trigger
- int res = sqlite3_prepare (m_db, "UPDATE SyncNodes SET seq_no=MAX(seq_no,?) WHERE device_id=?;",
+ int res = sqlite3_prepare (m_db, "UPDATE SyncNodes SET seq_no=MAX(seq_no,?) WHERE device_id=?;",
-1, &stmt, 0);
res += sqlite3_bind_int64 (stmt, 1, seqNo);
res += sqlite3_bind_int64 (stmt, 2, deviceId);
sqlite3_step (stmt);
-
+
if (res != SQLITE_OK)
{
BOOST_THROW_EXCEPTION (Error::Db ()
@@ -303,6 +303,13 @@
sqlite3_finalize(stmt);
}
+void
+SyncLog::UpdateLocalLocator (const Ccnx::Name &locator)
+{
+ return UpdateLocator (m_localName, locator);
+}
+
+
SyncStateMsgPtr
SyncLog::FindStateDifferences (const std::string &oldHash, const std::string &newHash, bool includeOldSeq)
{
@@ -365,7 +372,7 @@
SyncStateMsgPtr msg = make_shared<SyncStateMsg> ();
// sqlite3_trace(m_db, xTrace, NULL);
-
+
while (sqlite3_step (stmt) == SQLITE_ROW)
{
SyncState *state = msg->add_state ();
diff --git a/src/sync-log.h b/src/sync-log.h
index 549d759..808d976 100644
--- a/src/sync-log.h
+++ b/src/sync-log.h
@@ -35,9 +35,9 @@
public:
SyncLog (const boost::filesystem::path &path, const std::string &localName);
- // fill in the map with device-name <-> locator pairs
- void
- initYP(map<Ccnx::Name, Ccnx::Name> &yp);
+ // // fill in the map with device-name <-> locator pairs
+ // void
+ // initYP(map<Ccnx::Name, Ccnx::Name> &yp);
sqlite3_int64
GetNextLocalSeqNo (); // side effect: local seq_no will be increased
@@ -52,6 +52,9 @@
void
UpdateLocator (const Ccnx::Name &deviceName, const Ccnx::Name &locator);
+ void
+ UpdateLocalLocator (const Ccnx::Name &locator);
+
// done
/**
* Create an entry in SyncLog and SyncStateNodes corresponding to the current state of SyncNodes
@@ -72,7 +75,7 @@
FindStateDifferences (const std::string &oldHash, const std::string &newHash, bool includeOldSeq = false);
SyncStateMsgPtr
- FindStateDifferences (const Hash &oldHash, const Hash &newHash, bool includeOldSeq = false);
+ FindStateDifferences (const Hash &oldHash, const Hash &newHash, bool includeOldSeq = false);
//-------- only used in test -----------------
sqlite3_int64
@@ -81,18 +84,17 @@
protected:
void
UpdateDeviceSeqNo (sqlite3_int64 deviceId, sqlite3_int64 seqNo);
-
+
protected:
- // std::string m_localName;
Ccnx::Name m_localName;
-
+
sqlite3_int64 m_localDeviceId;
typedef boost::mutex Mutex;
typedef boost::unique_lock<Mutex> WriteLock;
-
- Mutex m_stateUpdateMutex;
+
+ Mutex m_stateUpdateMutex;
};
typedef boost::shared_ptr<SyncLog> SyncLogPtr;