api: Use new callback interfaces

Change-Id: I1871df54c3061c0c8d5765ff69207b8307bc7569
This commit is contained in:
Yingdi Yu committed 2014-02-11 17:33:40 -08:00
1 parent 531803bae9
commit 51c802519a
5 files changed
+49 -70

No files matched your search

+15 -27
View File
@@ -79,7 +79,7 @@ SyncLogic::SyncLogic (const Name& syncPrefix,
{
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 @@ SyncLogic::SyncLogic (const Name& syncPrefix,
{
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 (const Name& syncPrefix,
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 @@ SyncLogic::convertNameToDigestAndType (const Name &name)
}
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 @@ SyncLogic::onSyncInterest (const shared_ptr<const Name>& prefix,
}
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 @@ SyncLogic::sendSyncInterest ()
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 @@ SyncLogic::sendSyncRecoveryInterests (DigestConstPtr digest)
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));
}
+4 -23
View File
@@ -94,19 +94,6 @@ public:
*/
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 @@ public:
ndn::Scheduler &
getScheduler () { return m_scheduler; }
#endif
void stop();
void
printState () const;
@@ -134,20 +119,16 @@ private:
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);
+20 -13
View File
@@ -39,6 +39,7 @@ SyncSocket::SyncSocket (const Name &syncPrefix,
, m_validator(validator)
, m_keyChain(new KeyChain())
, m_face(face)
, m_ioService(face->ioService())
, m_syncLogic (syncPrefix,
validator,
face,
@@ -52,24 +53,31 @@ SyncSocket::~SyncSocket()
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 @@ SyncSocket::fetchData(const Name &prefix, const SeqNo &seq, const OnDataValidate
}
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 @@ SyncSocket::onData(const shared_ptr<const ndn::Interest>& interest,
}
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,
+6 -3
View File
@@ -91,18 +91,20 @@ public:
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 @@ private:
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;
};
+4 -4
View File
@@ -138,14 +138,14 @@ public:
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 @@ public:
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