in process of writing sync-core
diff --git a/src/sync-core.h b/src/sync-core.h
index 7e787d3..b06b8b8 100644
--- a/src/sync-core.h
+++ b/src/sync-core.h
@@ -25,6 +25,8 @@
#include "sync-log.h"
#include <ccnx-wrapper.h>
#include <event-scheduler.h>
+#include <boost/function.hpp>
+#include <boost/thread/shared_mutex.hpp>
using namespace std;
using namespace Ccnx;
@@ -32,13 +34,71 @@
class SyncCore
{
public:
- SyncCore(const string &path, const Name &localName, CcnxWrapperPtr handle, SchedulerPtr scheduler);
+ typedef boost::function<void (const SyncStateMsgPtr & stateMsg) > StateMsgCallback;
+ typedef sqlite3_int64 seqno_t;
+ typedef Map<Name, Name> YellowPage;
+ typedef boost::shared_mutex Mutex;
+ typedef boost::shared_lock<Mutex> ReadLock;
+ typedef boost::unique_lock<Mutex> WriteLock;
+
+ static const int FRESHNESS = 2;
+
+public:
+ SyncCore(const string &path // path where SyncLog is stored
+ , const Name &userName // unique permanent name for local user
+ , const Name &localPrefix // routable name used by the local user
+ , const Name &syncPrefix // the prefix for the sync collection
+ , const StateMsgCallback &callback // callback when state change is detected
+ , CcnxWrapperPtr handle
+ , SchedulerPtr scheduler);
~SyncCore();
+ // 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
+ updateLocalState(seqno_t);
+
+ Name
+ yp(const Name &name);
+
+ void
+ handleSyncInterest(const Name &name);
+
+ Closure::TimeoutCallbackReturnValue
+ handleSyncInterestTimeout(const Name &name);
+
+ void
+ handleSyncData(const Name &name, const Bytes &content);
+
+ void
+ deregister();
+
+protected:
+ void
+ sendSyncInterest();
+
+ Name
+ constructSyncName(const HashPtr &hash);
+
+ static void
+ msgToBytes(const SyncStateMsgPtr &msg, Bytes &bytes);
+
protected:
SyncLog m_log;
- CcnxWrapperPtr m_handle;
SchedulerPtr m_scheduler;
+ StateMsgCallback m_stateMsgCallback;
+ Name m_userName;
+ Name m_localPrefix;
+ Name m_syncPrefix;
+ HashPtr m_rootHash;
+ YellowPage m_yp;
+ Mutex m_ypMutex;
+ CcnxWrapperPtr m_handle;
+ Closure *m_interestClosure;
+
};
#endif // SYNC_CORE_H