api: Use new callback interfaces
Change-Id: I1871df54c3061c0c8d5765ff69207b8307bc7569
diff --git a/src/sync-logic.cc b/src/sync-logic.cc
index 6f3d21d..ec4d63e 100644
--- a/src/sync-logic.cc
+++ b/src/sync-logic.cc
@@ -79,7 +79,7 @@
{
m_syncRegisteredPrefixId = m_face->setInterestFilter (m_syncPrefix,
bind(&SyncLogic::onSyncInterest, this, _1, _2),
- bind(&SyncLogic::onSyncRegisterFailed, this, _1));
+ bind(&SyncLogic::onSyncRegisterFailed, this, _1, _2));
m_reexpressingInterestId = m_scheduler.scheduleEvent (time::seconds (0), // no need to add jitter
@@ -108,7 +108,7 @@
{
m_syncRegisteredPrefixId = m_face->setInterestFilter (m_syncPrefix,
bind(&SyncLogic::onSyncInterest, this, _1, _2),
- bind(&SyncLogic::onSyncRegisterFailed, this, _1));
+ bind(&SyncLogic::onSyncRegisterFailed, this, _1, _2));
m_reexpressingInterestId = m_scheduler.scheduleEvent (time::seconds (0), // no need to add jitter
bind (&SyncLogic::sendSyncInterest, this));
@@ -117,12 +117,6 @@
SyncLogic::~SyncLogic ()
{
m_face->unsetInterestFilter(m_syncRegisteredPrefixId);
-}
-
-void
-SyncLogic::stop()
-{
- m_face->unsetInterestFilter(m_syncRegisteredPrefixId);
m_scheduler.cancelEvent (m_reexpressingInterestId);
m_scheduler.cancelEvent (m_delayedInterestProcessingId);
}
@@ -160,10 +154,9 @@
}
void
-SyncLogic::onSyncInterest (const shared_ptr<const Name>& prefix,
- const shared_ptr<const ndn::Interest>& interest)
+SyncLogic::onSyncInterest (const Name& prefix, const ndn::Interest& interest)
{
- Name name = interest->getName();
+ Name name = interest.getName();
_LOG_DEBUG_ID("respondSyncInterest: " << name);
@@ -193,20 +186,21 @@
}
void
-SyncLogic::onSyncRegisterFailed(const shared_ptr<const Name>& prefix)
+SyncLogic::onSyncRegisterFailed(const Name& prefix, const string& msg)
{
- _LOG_DEBUG_ID("Sync prefix registration failed!");
+ _LOG_DEBUG_ID("Sync prefix registration failed! " << msg);
}
void
-SyncLogic::onSyncData(const shared_ptr<const ndn::Interest>& interest,
- const shared_ptr<Data>& data,
- const OnDataValidated& onValidated,
- const OnDataValidationFailed& onValidationFailed)
-{ m_validator->validate(data, onValidated, onValidationFailed); }
+SyncLogic::onSyncData(const ndn::Interest& interest, Data& data)
+{
+ OnDataValidated onValidated = bind(&SyncLogic::onSyncDataValidated, this, _1);
+ OnDataValidationFailed onValidationFailed = bind(&SyncLogic::onSyncDataValidationFailed, this, _1);
+ m_validator->validate(data, onValidated, onValidationFailed);
+}
void
-SyncLogic::onSyncTimeout(const shared_ptr<const ndn::Interest>& interest)
+SyncLogic::onSyncTimeout(const ndn::Interest& interest)
{
// It is OK. Others will handle the time out situation.
}
@@ -588,11 +582,8 @@
ndn::Interest interest(m_outstandingInterestName);
interest.setMustBeFresh(true);
- OnDataValidated onValidated = bind(&SyncLogic::onSyncDataValidated, this, _1);
- OnDataValidationFailed onValidationFailed = bind(&SyncLogic::onSyncDataValidationFailed, this, _1);
-
m_face->expressInterest(interest,
- bind(&SyncLogic::onSyncData, this, _1, _2, onValidated, onValidationFailed),
+ bind(&SyncLogic::onSyncData, this, _1, _2),
bind(&SyncLogic::onSyncTimeout, this, _1));
}
@@ -617,11 +608,8 @@
ndn::Interest interest(interestName);
interest.setMustBeFresh(true);
- OnDataValidated onValidated = bind(&SyncLogic::onSyncDataValidated, this, _1);
- OnDataValidationFailed onValidationFailed = bind(&SyncLogic::onSyncDataValidationFailed, this, _1);
-
m_face->expressInterest(interest,
- bind(&SyncLogic::onSyncData, this, _1, _2, onValidated, onValidationFailed),
+ bind(&SyncLogic::onSyncData, this, _1, _2),
bind(&SyncLogic::onSyncTimeout, this, _1));
}
diff --git a/src/sync-logic.h b/src/sync-logic.h
index 5c3abe4..fc63fca 100644
--- a/src/sync-logic.h
+++ b/src/sync-logic.h
@@ -95,19 +95,6 @@
void addLocalNames (const ndn::Name &prefix, uint64_t session, uint64_t seq);
/**
- * @brief respond to the Sync Interest; a lot of logic needs to go in here
- * @param interest the Sync Interest in string format
- */
- void respondSyncInterest (ndn::shared_ptr<ndn::Interest> interest);
-
- /**
- * @brief process the fetched sync data
- * @param name the data name
- * @param dataBuffer the sync data
- */
- void respondSyncData (ndn::shared_ptr<ndn::Data> data);
-
- /**
* @brief remove a participant's subtree from the sync tree
* @param prefix the name prefix for the participant
*/
@@ -120,8 +107,6 @@
ndn::Scheduler &
getScheduler () { return m_scheduler; }
#endif
-
- void stop();
void
printState () const;
@@ -134,20 +119,16 @@
delayedChecksLoop ();
void
- onSyncInterest (const ndn::shared_ptr<const ndn::Name>& prefix,
- const ndn::shared_ptr<const ndn::Interest>& interest);
+ onSyncInterest (const ndn::Name& prefix, const ndn::Interest& interest);
void
- onSyncRegisterFailed(const ndn::shared_ptr<const ndn::Name>& prefix);
+ onSyncRegisterFailed(const ndn::Name& prefix, const std::string& msg);
void
- onSyncData(const ndn::shared_ptr<const ndn::Interest>& interest,
- const ndn::shared_ptr<ndn::Data>& data,
- const ndn::OnDataValidated& onValidated,
- const ndn::OnDataValidationFailed& onValidationFailed);
+ onSyncData(const ndn::Interest& interest, ndn::Data& data);
void
- onSyncTimeout(const ndn::shared_ptr<const ndn::Interest>& interest);
+ onSyncTimeout(const ndn::Interest& interest);
void
onSyncDataValidationFailed(const ndn::shared_ptr<const ndn::Data>& data);
diff --git a/src/sync-socket.cc b/src/sync-socket.cc
index cb41b30..f590338 100644
--- a/src/sync-socket.cc
+++ b/src/sync-socket.cc
@@ -39,6 +39,7 @@
, m_validator(validator)
, m_keyChain(new KeyChain())
, m_face(face)
+ , m_ioService(face->ioService())
, m_syncLogic (syncPrefix,
validator,
face,
@@ -53,23 +54,30 @@
bool
SyncSocket::publishData(const Name &prefix, uint64_t session, const char *buf, size_t len, int freshness)
{
+ shared_ptr<Data> data = make_shared<Data>();
+ data->setContent(reinterpret_cast<const uint8_t*>(buf), len);
+ data->setFreshnessPeriod(1000*freshness);
+
+ m_ioService->post(bind(&SyncSocket::publishDataInternal, this, data, prefix, session));
+
+ return true;
+}
+
+void
+SyncSocket::publishDataInternal(shared_ptr<Data> data, const Name &prefix, uint64_t session)
+{
uint64_t sequence = getNextSeq(prefix, session);
-
Name dataName = prefix;
dataName.append(boost::lexical_cast<string>(session)).append(boost::lexical_cast<string>(sequence));
+ data->setName(dataName);
- Data data(dataName);
- data.setContent(reinterpret_cast<const uint8_t*>(buf), len);
- data.setFreshnessPeriod(1000*freshness);
+ m_keyChain->sign(*data);
+ m_face->put(*data);
- m_keyChain->sign(data);
-
- m_face->put(data);
-
SeqNo s(session, sequence + 1);
+
m_sequenceLog[prefix] = s;
m_syncLogic.addLocalNames (prefix, session, sequence);
- return true;
}
void
@@ -89,8 +97,7 @@
}
void
-SyncSocket::onData(const shared_ptr<const ndn::Interest>& interest,
- const shared_ptr<Data>& data,
+SyncSocket::onData(const ndn::Interest& interest, Data& data,
const OnDataValidated& onValidated,
const OnDataValidationFailed& onValidationFailed)
{
@@ -98,14 +105,14 @@
}
void
-SyncSocket::onDataTimeout(const shared_ptr<const ndn::Interest>& interest,
+SyncSocket::onDataTimeout(const ndn::Interest& interest,
int retry,
const OnDataValidated& onValidated,
const OnDataValidationFailed& onValidationFailed)
{
if(retry > 0)
{
- m_face->expressInterest(*interest,
+ m_face->expressInterest(interest,
bind(&SyncSocket::onData,
this,
_1,
diff --git a/src/sync-socket.h b/src/sync-socket.h
index 35fd8ed..ee02ae8 100644
--- a/src/sync-socket.h
+++ b/src/sync-socket.h
@@ -91,18 +91,20 @@
GetLocalPrefix ();
private:
+ void
+ publishDataInternal(ndn::shared_ptr<ndn::Data> data, const ndn::Name &prefix, uint64_t session);
+
void
passCallback(const std::vector<MissingDataInfo> &v)
{ m_newDataCallback(v, this); }
void
- onData(const ndn::shared_ptr<const ndn::Interest>& interest,
- const ndn::shared_ptr<ndn::Data>& data,
+ onData(const ndn::Interest& interest, ndn::Data& data,
const ndn::OnDataValidated& onValidated,
const ndn::OnDataValidationFailed& onValidationFailed);
void
- onDataTimeout(const ndn::shared_ptr<const ndn::Interest>& interest,
+ onDataTimeout(const ndn::Interest& interest,
int retry,
const ndn::OnDataValidated& onValidated,
const ndn::OnDataValidationFailed& onValidationFailed);
@@ -117,6 +119,7 @@
ndn::shared_ptr<ndn::Validator> m_validator;
ndn::shared_ptr<ndn::KeyChain> m_keyChain;
ndn::shared_ptr<ndn::Face> m_face;
+ ndn::shared_ptr<boost::asio::io_service> m_ioService;
SyncLogic m_syncLogic;
};
diff --git a/tests/test_socket.cc b/tests/test_socket.cc
index fd17c44..60a87f3 100644
--- a/tests/test_socket.cc
+++ b/tests/test_socket.cc
@@ -138,14 +138,14 @@
class TestSet1{
public:
TestSet1(ndn::shared_ptr<boost::asio::io_service> ioService)
- : m_syncPrefix("/let/us/sync")
- , m_validator(new ndn::ValidatorNull())
+ : m_validator(new ndn::ValidatorNull())
, m_face1(new ndn::Face(ioService))
, m_face2(new ndn::Face(ioService))
, m_face3(new ndn::Face(ioService))
, m_p1("/irl.cs.ucla.edu")
, m_p2("/yakshi.org")
, m_p3("/google.com")
+ , m_syncPrefix("/let/us/sync")
{}
void
@@ -250,12 +250,12 @@
class TestSet2{
public:
TestSet2(ndn::shared_ptr<boost::asio::io_service> ioService)
- : m_syncPrefix("/this/is/the/prefix")
- , m_validator(new ndn::ValidatorNull())
+ : m_validator(new ndn::ValidatorNull())
, m_face1(new ndn::Face(ioService))
, m_face2(new ndn::Face(ioService))
, m_p1("/xiaonei.com")
, m_p2("/mitbbs.com")
+ , m_syncPrefix("/this/is/the/prefix")
{}
void