Now dispatcher uses CcnxDisovery to maintain localPrefix
diff --git a/src/dispatcher.cc b/src/dispatcher.cc
index ab2dc41..26e6e89 100644
--- a/src/dispatcher.cc
+++ b/src/dispatcher.cc
@@ -21,6 +21,7 @@
#include "dispatcher.h"
#include "logging.h"
+#include "ccnx-discovery.h"
#include <boost/make_shared.hpp>
#include <boost/lexical_cast.hpp>
@@ -34,7 +35,7 @@
static const string BROADCAST_DOMAIN = "/ndn/broadcast/chronoshare";
Dispatcher::Dispatcher(const filesystem::path &path, const std::string &localUserName,
- const Ccnx::Name &localPrefix, const std::string &sharedFolder,
+ const std::string &sharedFolder,
const filesystem::path &rootDir, Ccnx::CcnxWrapperPtr ccnx,
SchedulerPtr scheduler, int poolSize)
: m_ccnx(ccnx)
@@ -54,18 +55,22 @@
Name syncPrefix = Name(BROADCAST_DOMAIN)(sharedFolder);
m_server = new ContentServer(m_ccnx, m_actionLog, rootDir);
- m_server->registerPrefix(localPrefix);
+ m_server->registerPrefix(Name ("/"));
m_server->registerPrefix(syncPrefix);
- m_core = new SyncCore (m_syncLog, localUserName, localPrefix, syncPrefix,
+ m_core = new SyncCore (m_syncLog, localUserName, Name ("/"), syncPrefix,
bind(&Dispatcher::Did_SyncLog_StateChange, this, _1), ccnx, scheduler);
m_actionFetcher = make_shared<FetchManager> (m_ccnx, bind (&SyncLog::LookupLocator, &*m_syncLog, _1), 3);
m_fileFetcher = make_shared<FetchManager> (m_ccnx, bind (&SyncLog::LookupLocator, &*m_syncLog, _1), 3);
+
+ Ccnx::CcnxDiscovery::registerCallback (TaggedFunction (bind (&Dispatcher::Did_LocalPrefix_Updated, this, _1), "dispatcher"));
}
Dispatcher::~Dispatcher()
{
+ Ccnx::CcnxDiscovery::deregisterCallback (TaggedFunction (bind (&Dispatcher::Did_LocalPrefix_Updated, this, _1), "dispatcher"));
+
if (m_core != NULL)
{
delete m_core;
@@ -79,6 +84,17 @@
}
}
+void
+Dispatcher::Did_LocalPrefix_Updated (const Ccnx::Name &prefix)
+{
+ Name oldLocalPrefix = m_syncLog->LookupLocalLocator ();
+ _LOG_DEBUG ("LocalPrefix changed from: " << oldLocalPrefix << " to: " << prefix);
+
+ m_server->deregisterPrefix(prefix);
+ m_syncLog->UpdateLocalLocator (prefix);
+ m_server->deregisterPrefix(oldLocalPrefix);
+}
+
/////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/dispatcher.h b/src/dispatcher.h
index 3762f0c..3bb01b9 100644
--- a/src/dispatcher.h
+++ b/src/dispatcher.h
@@ -46,7 +46,7 @@
public:
// sharedFolder is the name to be used in NDN name;
// rootDir is the shared folder dir in local file system;
- Dispatcher(const boost::filesystem::path &path, const std::string &localUserName, const Ccnx::Name &localPrefix,
+ Dispatcher(const boost::filesystem::path &path, const std::string &localUserName,
const std::string &sharedFolder, const boost::filesystem::path &rootDir,
Ccnx::CcnxWrapperPtr ccnx, SchedulerPtr scheduler, int poolSize = 2);
~Dispatcher();
@@ -115,6 +115,9 @@
void
Did_FetchManager_FileFetchComplete_Execute (Ccnx::Name deviceName, Ccnx::Name fileBaseName);
+ void
+ Did_LocalPrefix_Updated (const Ccnx::Name &prefix);
+
private:
void
AssembleFile_Execute (const Ccnx::Name &deviceName, const Hash &filehash, const boost::filesystem::path &relativeFilepath);
diff --git a/src/sync-log.cc b/src/sync-log.cc
index 671162e..4298a9e 100644
--- a/src/sync-log.cc
+++ b/src/sync-log.cc
@@ -337,7 +337,7 @@
}
Name
-SyncLog::LookupLocator(const Name &deviceName)
+SyncLog::LookupLocator (const Name &deviceName)
{
sqlite3_stmt *stmt;
sqlite3_prepare_v2 (m_db, "SELECT last_known_locator FROM SyncNodes WHERE device_name=?;", -1, &stmt, 0);
@@ -361,6 +361,12 @@
return locator;
}
+Ccnx::Name
+SyncLog::LookupLocalLocator ()
+{
+ return LookupLocator (m_localName);
+}
+
void
SyncLog::UpdateLocator(const Name &deviceName, const Name &locator)
{
diff --git a/src/sync-log.h b/src/sync-log.h
index 7aed587..304afa7 100644
--- a/src/sync-log.h
+++ b/src/sync-log.h
@@ -54,6 +54,9 @@
Ccnx::Name
LookupLocator (const Ccnx::Name &deviceName);
+ Ccnx::Name
+ LookupLocalLocator ();
+
void
UpdateLocator (const Ccnx::Name &deviceName, const Ccnx::Name &locator);