change dataCallback to have two parameters: name and content
diff --git a/model/sync-app-data-fetch.cc b/model/sync-app-data-fetch.cc
index af696e2..76b6119 100644
--- a/model/sync-app-data-fetch.cc
+++ b/model/sync-app-data-fetch.cc
@@ -32,6 +32,8 @@
{
for (uint32_t i = startSeq; i <= endSeq; i++)
{
+ if (i == 0)
+ continue;
string interestName = prefix;
interestName += i;
m_ccnxHandle->sendInterest(interestName, m_dataCallback);
diff --git a/model/sync-app-data-fetch.h b/model/sync-app-data-fetch.h
index 70b54cb..ae07679 100644
--- a/model/sync-app-data-fetch.h
+++ b/model/sync-app-data-fetch.h
@@ -40,10 +40,10 @@
* @param dataCallback the callback function to process data
*/
AppDataFetch(boost::shared_ptr<CcnxWrapper> ccnxHandle,
- boost::function<void (std::string)> dataCallback)
+ boost::function<void (std::string, std::string)> dataCallback)
{ m_ccnxHandle = ccnxHandle; m_dataCallback = dataCallback; }
- void setDataCallback(boost::function<void (std::string)> dataCallback)
+ void setDataCallback(boost::function<void (std::string, std::string)> dataCallback)
{ m_dataCallback = dataCallback; }
/**
@@ -57,7 +57,7 @@
private:
boost::shared_ptr<CcnxWrapper> m_ccnxHandle;
- boost::function<void (std::string)> m_dataCallback;
+ boost::function<void (std::string, std::string)> m_dataCallback;
};
diff --git a/model/sync-app-data-publish.cc b/model/sync-app-data-publish.cc
index a3347b8..d05bcbe 100644
--- a/model/sync-app-data-publish.cc
+++ b/model/sync-app-data-publish.cc
@@ -28,37 +28,42 @@
namespace Sync
{
-pair<string, string> AppDataPublish::getRecentData(string prefix)
+string AppDataPublish::getRecentData(string prefix, uint32_t session)
{
}
-uint32_t AppDataPublish::getHighestSeq(string prefix)
+uint32_t AppDataPublish::getHighestSeq(string prefix, uint32_t session)
{
- unordered_map<string, uint32_t>::iterator i = m_sequenceLog.find(prefix);
+ unordered_map<string, Seq>::iterator i = m_sequenceLog.find(prefix);
if (i != m_sequenceLog.end())
{
- return i->second;
- }
- else
- {
- m_sequenceLog[prefix] = 0;
- return 0;
+ Seq s = i->second;
+ if (s.session == session)
+ return s.seq;
}
+ return 0;
}
-bool AppDataPublish::publishData(string name, string dataBuffer, int freshness)
+bool AppDataPublish::publishData(string name, uint32_t session, string dataBuffer, int freshness)
{
- uint32_t seq = getHighestSeq(name) + 1;
+ uint32_t seq = getHighestSeq(name, session);
+ if (seq == 0)
+ m_sequenceLog.erase(name);
+
+ seq++;
+ if (seq == 0)
+ seq = 1;
+ Seq s;
+ s.session = session;
+ s.seq = seq;
+ m_sequenceLog[name] = s;
+
string contentName = name;
-
contentName += seq;
- m_sequenceLog[contentName] = seq;
- m_recentData[contentName] = dataBuffer;
-
m_ccnxHandle->publishData(contentName, dataBuffer, freshness);
return true;
diff --git a/model/sync-app-data-publish.h b/model/sync-app-data-publish.h
index f02a188..1082904 100644
--- a/model/sync-app-data-publish.h
+++ b/model/sync-app-data-publish.h
@@ -24,6 +24,7 @@
#define SYNC_APP_DATA_PUBLISH_H
#include <boost/shared_ptr.hpp>
#include <boost/unordered_map.hpp>
+#include "sync-seq-no.h"
#include "sync-ccnx-wrapper.h"
/**
@@ -33,6 +34,12 @@
*/
namespace Sync {
+struct Seq
+{
+ uint32_t session;
+ uint32_t seq;
+};
+
/**
* \ingroup sync
* @brief publishes application data using incrementing sequence number (for
@@ -53,12 +60,12 @@
* @param prefix the name prefix to look for
* @return the pair of name and content
*/
- std::pair<std::string, std::string> getRecentData(std::string prefix);
+ std::string getRecentData(std::string prefix, uint32_t session);
/**
* brief get the most recent sequence number for a name prefix
*/
- u_int32_t getHighestSeq(std::string prefix);
+ u_int32_t getHighestSeq(std::string prefix, uint32_t session);
/**
* @brief publish data for a name prefix, updates the corresponding
@@ -69,10 +76,10 @@
* @param freshness the freshness for the data object
* @return whether the publish succeeded
*/
- bool publishData(std::string name, std::string dataBuffer, int freshness);
+ bool publishData(std::string name, uint32_t session, std::string dataBuffer, int freshness);
private:
- boost::unordered_map<std::string, uint32_t> m_sequenceLog;
+ boost::unordered_map<std::string, Seq> m_sequenceLog;
boost::shared_ptr<CcnxWrapper> m_ccnxHandle;
boost::unordered_map<std::string, std::string> m_recentData;
};
diff --git a/model/sync-app-socket.cc b/model/sync-app-socket.cc
index 8f11c97..c349aeb 100644
--- a/model/sync-app-socket.cc
+++ b/model/sync-app-socket.cc
@@ -28,7 +28,7 @@
namespace Sync
{
-SyncAppSocket::SyncAppSocket(string syncPrefix, function<void (string)> dataCallback)
+SyncAppSocket::SyncAppSocket(string syncPrefix, function<void (string, string)> dataCallback)
{
m_ccnxHandle.reset(new CcnxWrapper());
m_fetcher = new AppDataFetch(m_ccnxHandle, dataCallback);
@@ -45,10 +45,10 @@
delete m_publisher;
}
-bool SyncAppSocket::publish(string prefix, string dataBuffer, int freshness)
+bool SyncAppSocket::publish(string prefix, uint32_t session, string dataBuffer, int freshness)
{
- m_publisher->publishData(prefix, dataBuffer, freshness);
- m_syncLogic->addLocalNames(prefix, m_publisher->getHighestSeq(prefix));
+ m_publisher->publishData(prefix, session, dataBuffer, freshness);
+ m_syncLogic->addLocalNames(prefix, session, m_publisher->getHighestSeq(prefix, session));
}
}
\ No newline at end of file
diff --git a/model/sync-app-socket.h b/model/sync-app-socket.h
index d94d4db..3b2c62c 100644
--- a/model/sync-app-socket.h
+++ b/model/sync-app-socket.h
@@ -48,7 +48,7 @@
* @param syncPrefix the name prefix for Sync Interest
* @param dataCallback the callback to process data
*/
- SyncAppSocket(std::string syncPrefix, boost::function<void (std::string)>
+ SyncAppSocket(std::string syncPrefix, boost::function<void (std::string, std::string)>
dataCallback);
~SyncAppSocket();
@@ -61,7 +61,7 @@
* @param dataBuffer the data itself
* @param freshness the freshness time for the data (in seconds)
*/
- bool publish(std::string prefix, std::string dataBuffer, int freshness);
+ bool publish(std::string prefix, uint32_t session, std::string dataBuffer, int freshness);
private:
AppDataFetch *m_fetcher;
diff --git a/model/sync-ccnx-wrapper.cc b/model/sync-ccnx-wrapper.cc
index 3755324..a4aea2e 100644
--- a/model/sync-ccnx-wrapper.cc
+++ b/model/sync-ccnx-wrapper.cc
@@ -177,7 +177,7 @@
ccn_upcall_kind kind,
ccn_upcall_info *info)
{
- function<void (string)> f = *(function<void (string)> *)selfp->data;
+ function<void (string, string)> f = *(function<void (string, string)> *)selfp->data;
switch (kind)
{
@@ -195,15 +195,24 @@
char *pcontent;
size_t len;
ccn_content_get_value(info->content_ccnb, info->pco->offset[CCN_PCO_E], info->pco, (const unsigned char **)&pcontent, &len);
- f((string)pcontent);
+ string name;
+ for (int i = 0; i < info->content_comps->n - 1; i++)
+ {
+ char *comp;
+ size_t size;
+ name += "/";
+ ccn_name_comp_get(info->content_ccnb, info->content_comps, i, (const unsigned char **)&comp, &size);
+ name += comp;
+ }
+ f(name, (string)pcontent);
return CCN_UPCALL_RESULT_OK;
}
-int CcnxWrapper::sendInterest(string strInterest, function<void (string)> dataCallback)
+int CcnxWrapper::sendInterest(string strInterest, function<void (string, string)> dataCallback)
{
ccn_charbuf *pname = ccn_charbuf_create();
ccn_closure *dataClosure = new ccn_closure;
- function<void (string)> *f = new function<void (string)>(dataCallback);
+ function<void (string, string)> *f = new function<void (string, string)>(dataCallback);
ccn_name_from_uri(pname, strInterest.c_str());
dataClosure->data = f;
diff --git a/model/sync-ccnx-wrapper.h b/model/sync-ccnx-wrapper.h
index 71ee321..c7f2336 100644
--- a/model/sync-ccnx-wrapper.h
+++ b/model/sync-ccnx-wrapper.h
@@ -68,8 +68,8 @@
* @return the return code of ccn_express_interest
*/
int
- sendInterest(std::string strInterest, boost::function<void (std::string)>
- dataCallback);
+ sendInterest(std::string strInterest, boost::function<void
+ (std::string, std::string)> dataCallback);
/**
* @brief set Interest filter (specify what interest you want to receive
diff --git a/model/sync-logic.cc b/model/sync-logic.cc
index 5d6703a..a565003 100644
--- a/model/sync-logic.cc
+++ b/model/sync-logic.cc
@@ -42,24 +42,39 @@
}
-void SyncLogic::processSyncData(string dataBuffer)
+void SyncLogic::processSyncData(string name, string dataBuffer)
{
}
-void SyncLogic::addLocalNames(string prefix, uint32_t seq)
+void SyncLogic::addLocalNames(string prefix, uint32_t session, uint32_t seq)
{
-
+ NameInfoConstPtr info = StdNameInfo::FindOrCreate(prefix);
+ SeqNo seqN(session, seq);
+ m_state.update(info, seqN);
}
void SyncLogic::respondSyncInterest(string interest)
{
+ string hash = interest.substr(interest.find_last_of("/") + 1);
+
+ Digest digest;
+
+ digest << hash;
}
void SyncLogic::sendSyncInterest()
{
-
+ function<void (string, string)> f = bind(&SyncLogic::processSyncData, this, _1, _2);
+ stringstream os;
+ os << m_syncPrefix;
+ os << "/";
+ DigestConstPtr digest = m_state.getDigest();
+ os << digest;
+ string name;
+ os >> name;
+ m_ccnxHandle->sendInterest(name, f);
}
}
\ No newline at end of file
diff --git a/model/sync-logic.h b/model/sync-logic.h
index 6fe589c..98adf17 100644
--- a/model/sync-logic.h
+++ b/model/sync-logic.h
@@ -28,7 +28,7 @@
#include "sync-interest-table.h"
#include "sync-diff-state.h"
#include "sync-full-state.h"
-#include "sync-app.h"
+#include "sync-std-name-info.h"
namespace Sync {
@@ -53,7 +53,7 @@
/**
* a wrapper for the same func in SyncApp
*/
- void addLocalNames(std::string prefix, uint32_t seq);
+ void addLocalNames(std::string prefix, uint32_t session, uint32_t seq);
/**
* @brief respond to the Sync Interest; a lot of logic needs to go in here
@@ -65,14 +65,14 @@
* @brief process the fetched sync data
* @param dataBuffer the sync data
*/
- void processSyncData(std::string dataBuffer);
+ void processSyncData(std::string name, std::string dataBuffer);
private:
void sendSyncInterest();
private:
boost::shared_ptr<CcnxWrapper> m_ccnxHandle;
- //boost::shared_ptr<SyncApp> m_syncApp;
+ FullState m_state;
boost::function<void (std::string, uint32_t, uint32_t)> m_fetch;
SyncInterestTable m_syncInterestTable;
std::string m_syncPrefix;