time: adapt to the new API time structrue
diff --git a/src/sync-full-state.cc b/src/sync-full-state.cc
index eb9ca4c..7000606 100644
--- a/src/sync-full-state.cc
+++ b/src/sync-full-state.cc
@@ -45,10 +45,10 @@
{
}
-ndn::time::Duration
+ndn::time::system_clock::Duration
FullState::getTimeFromLastUpdate () const
{
- return ndn::time::now() - m_lastUpdated;
+ return ndn::time::system_clock::now() - m_lastUpdated;
}
DigestConstPtr
@@ -81,7 +81,7 @@
boost::tuple<bool/*inserted*/, bool/*updated*/, SeqNo/*oldSeqNo*/>
FullState::update (NameInfoConstPtr info, const SeqNo &seq)
{
- m_lastUpdated = ndn::time::now();
+ m_lastUpdated = ndn::time::system_clock::now();
m_digest.reset ();
@@ -109,7 +109,7 @@
bool
FullState::remove (NameInfoConstPtr info)
{
- m_lastUpdated = ndn::time::now();
+ m_lastUpdated = ndn::time::system_clock::now();
m_digest.reset ();
diff --git a/src/sync-full-state.h b/src/sync-full-state.h
index 28e0078..028c41e 100644
--- a/src/sync-full-state.h
+++ b/src/sync-full-state.h
@@ -51,7 +51,7 @@
*
* This value can be used to randomize reconciliation waiting time in SyncApp
*/
- ndn::time::Duration
+ ndn::time::system_clock::Duration
getTimeFromLastUpdate () const;
/**
@@ -70,7 +70,7 @@
remove (NameInfoConstPtr info);
private:
- ndn::time::Point m_lastUpdated; ///< @brief Time when state was updated last time
+ ndn::time::system_clock::TimePoint m_lastUpdated; ///< @brief Time when state was updated last time
DigestPtr m_digest;
};
diff --git a/src/sync-interest-container.h b/src/sync-interest-container.h
index 742f053..f674d05 100644
--- a/src/sync-interest-container.h
+++ b/src/sync-interest-container.h
@@ -47,14 +47,14 @@
Interest (DigestConstPtr digest, const std::string &name, bool unknown=false)
: m_digest (digest)
, m_name (name)
- , m_time (ndn::time::now())
+ , m_time (ndn::time::system_clock::now())
, m_unknown (unknown)
{
}
DigestConstPtr m_digest;
std::string m_name;
- ndn::time::Point m_time;
+ ndn::time::system_clock::TimePoint m_time;
bool m_unknown;
};
@@ -87,7 +87,7 @@
mi::ordered_non_unique<
mi::tag<timed>,
- BOOST_MULTI_INDEX_MEMBER(Interest, ndn::time::Point, m_time)
+ BOOST_MULTI_INDEX_MEMBER(Interest, ndn::time::system_clock::TimePoint, m_time)
>
>
>
diff --git a/src/sync-interest-table.cc b/src/sync-interest-table.cc
index a378950..415b641 100644
--- a/src/sync-interest-table.cc
+++ b/src/sync-interest-table.cc
@@ -29,7 +29,7 @@
namespace Sync
{
-SyncInterestTable::SyncInterestTable (boost::asio::io_service& io, ndn::time::Duration lifetime)
+SyncInterestTable::SyncInterestTable (boost::asio::io_service& io, ndn::time::system_clock::Duration lifetime)
: m_entryLifetime (lifetime)
, m_scheduler(io)
{
@@ -103,7 +103,7 @@
void SyncInterestTable::expireInterests ()
{
uint32_t count = 0;
- ndn::time::Point expireTime = ndn::time::now() - m_entryLifetime;
+ ndn::time::system_clock::TimePoint expireTime = ndn::time::system_clock::now() - m_entryLifetime;
while (m_table.size () > 0)
{
diff --git a/src/sync-interest-table.h b/src/sync-interest-table.h
index 9b7c46b..4810c41 100644
--- a/src/sync-interest-table.h
+++ b/src/sync-interest-table.h
@@ -42,7 +42,7 @@
class SyncInterestTable
{
public:
- SyncInterestTable (boost::asio::io_service& io, ndn::time::Duration lifetime);
+ SyncInterestTable (boost::asio::io_service& io, ndn::time::system_clock::Duration lifetime);
~SyncInterestTable ();
/**
@@ -81,7 +81,7 @@
expireInterests ();
private:
- ndn::time::Duration m_entryLifetime;
+ ndn::time::system_clock::Duration m_entryLifetime;
InterestContainer m_table;
ndn::Scheduler m_scheduler;
diff --git a/src/sync-logic.cc b/src/sync-logic.cc
index 5d20143..617830b 100644
--- a/src/sync-logic.cc
+++ b/src/sync-logic.cc
@@ -49,7 +49,7 @@
(time::seconds(sec) + time::milliseconds(GET_RANDOM (m_reexpressionJitter)))
#define TIME_MILLISECONDS_WITH_JITTER(ms) \
- (time::seconds(ms) + time::milliseconds(GET_RANDOM (m_reexpressionJitter)))
+ (time::milliseconds(ms) + time::milliseconds(GET_RANDOM (m_reexpressionJitter)))
namespace Sync {
@@ -57,6 +57,9 @@
int SyncLogic::m_instanceCounter = 0;
+const int SyncLogic::m_syncResponseFreshness = 1000; // MUST BE dividable by 1000!!!
+const int SyncLogic::m_syncInterestReexpress = 4; // seconds
+
SyncLogic::SyncLogic (const Name& syncPrefix,
const IdentityCertificate& myCertificate,
shared_ptr<Validator> validator,
@@ -430,7 +433,7 @@
// satisfyPendingSyncInterests (diffLog); // if there are interests in PIT, there is a point to satisfy them using new state
// if state has changed, then it is safe to express a new interest
- time::Duration after = time::milliseconds(GET_RANDOM (m_reexpressionJitter));
+ time::system_clock::Duration after = time::milliseconds(GET_RANDOM (m_reexpressionJitter));
// cout << "------------ reexpress interest after: " << after << endl;
EventId eventId = m_scheduler.scheduleEvent (after,
bind (&SyncLogic::sendSyncInterest, this));
@@ -602,7 +605,7 @@
Name interestName = m_syncPrefix;
interestName.append("recovery").append(os.str());
- time::Duration nextRetransmission = time::milliseconds (m_recoveryRetransmissionInterval + GET_RANDOM (m_reexpressionJitter));
+ time::system_clock::Duration nextRetransmission = time::milliseconds (m_recoveryRetransmissionInterval + GET_RANDOM (m_reexpressionJitter));
m_recoveryRetransmissionInterval <<= 1;
@@ -640,7 +643,7 @@
Data syncData(name);
syncData.setContent(reinterpret_cast<const uint8_t*>(wireData), size);
- syncData.setFreshnessPeriod(m_syncResponseFreshness);
+ syncData.setFreshnessPeriod(time::milliseconds(m_syncResponseFreshness));
m_keyChain.sign(syncData, m_myCertificate.getName());
@@ -658,7 +661,7 @@
{
_LOG_DEBUG_ID ("Satisfied our own Interest. Re-expressing (hopefully with a new digest)");
- time::Duration after = time::milliseconds(GET_RANDOM (m_reexpressionJitter));
+ time::system_clock::Duration after = time::milliseconds(GET_RANDOM (m_reexpressionJitter));
// cout << "------------ reexpress interest after: " << after << endl;
EventId eventId = m_scheduler.scheduleEvent (after,
bind (&SyncLogic::sendSyncInterest, this));
diff --git a/src/sync-logic.h b/src/sync-logic.h
index ec8fc29..98ab0aa 100644
--- a/src/sync-logic.h
+++ b/src/sync-logic.h
@@ -193,8 +193,8 @@
boost::variate_generator<boost::mt19937&, boost::uniform_int<> > m_reexpressionJitter;
static const int m_unknownDigestStoreTime = 10; // seconds
- static const int m_syncResponseFreshness = 1000; // MUST BE dividable by 1000!!!
- static const int m_syncInterestReexpress = 4; // seconds
+ static const int m_syncResponseFreshness; // MUST BE dividable by 1000!!!
+ static const int m_syncInterestReexpress; // seconds
static const int m_defaultRecoveryRetransmitInterval = 200; // milliseconds
uint32_t m_recoveryRetransmissionInterval; // milliseconds
diff --git a/src/sync-socket.cc b/src/sync-socket.cc
index ca015de..9c31f79 100644
--- a/src/sync-socket.cc
+++ b/src/sync-socket.cc
@@ -92,7 +92,7 @@
{
shared_ptr<Data> data = make_shared<Data>();
data->setContent(reinterpret_cast<const uint8_t*>(buf), len);
- data->setFreshnessPeriod(1000*freshness);
+ data->setFreshnessPeriod(time::milliseconds(1000*freshness));
m_ioService->post(bind(&SyncSocket::publishDataInternal, this,
data, isCert));
diff --git a/src/sync-validator.cc b/src/sync-validator.cc
index 2d86dbe..e1d40d8 100644
--- a/src/sync-validator.cc
+++ b/src/sync-validator.cc
@@ -130,7 +130,7 @@
Name interestName = m_prefix;
interestName.append("CHRONOS-INTRO-CERT").append(keyLocatorName.wireEncode());
Interest interest(interestName);
- interest.setInterestLifetime(500);
+ interest.setInterestLifetime(time::milliseconds(500));
OnDataValidated onKeyValidated = bind(&SyncValidator::onCertificateValidated, this,
_1, data.shared_from_this(), onValidated, onValidationFailed);
diff --git a/tests/test-socket.cc b/tests/test-socket.cc
index e25ef17..61519f8 100644
--- a/tests/test-socket.cc
+++ b/tests/test-socket.cc
@@ -142,9 +142,9 @@
: m_face1(new ndn::Face(ioService))
, m_face2(new ndn::Face(ioService))
, m_face3(new ndn::Face(ioService))
- , m_name1("/irl.cs.ucla.edu/" + boost::lexical_cast<std::string>(ndn::time::now()))
- , m_name2("/yakshi.org/" + boost::lexical_cast<std::string>(ndn::time::now()))
- , m_name3("/google.com/" + boost::lexical_cast<std::string>(ndn::time::now()))
+ , m_name1("/irl.cs.ucla.edu/" + boost::lexical_cast<std::string>(ndn::time::toUnixTimestamp(ndn::time::system_clock::now()).count()))
+ , m_name2("/yakshi.org/" + boost::lexical_cast<std::string>(ndn::time::toUnixTimestamp(ndn::time::system_clock::now()).count()))
+ , m_name3("/google.com/" + boost::lexical_cast<std::string>(ndn::time::toUnixTimestamp(ndn::time::system_clock::now()).count()))
{
m_id1 = m_keyChain.getCertificate(m_keyChain.createIdentity(m_name1));
m_id2 = m_keyChain.getCertificate(m_keyChain.createIdentity(m_name2));
@@ -272,7 +272,7 @@
}
void
- done()
+ done(ndn::shared_ptr<boost::asio::io_service> ioService)
{
m_s1.reset();
m_s2.reset();
@@ -282,6 +282,7 @@
m_keyChain.deleteIdentity(m_name2);
m_keyChain.deleteIdentity(m_name3);
+ ioService->stop();
}
ndn::KeyChain m_keyChain;
@@ -299,8 +300,8 @@
TestSet2(ndn::shared_ptr<boost::asio::io_service> ioService)
: m_face1(new ndn::Face(ioService))
, m_face2(new ndn::Face(ioService))
- , m_name1("/xiaonei.com/" + boost::lexical_cast<std::string>(ndn::time::now()))
- , m_name2("/mitbbs.com/" + boost::lexical_cast<std::string>(ndn::time::now()))
+ , m_name1("/xiaonei.com/" + boost::lexical_cast<std::string>(ndn::time::toUnixTimestamp(ndn::time::system_clock::now()).count()))
+ , m_name2("/mitbbs.com/" + boost::lexical_cast<std::string>(ndn::time::toUnixTimestamp(ndn::time::system_clock::now()).count()))
{
m_id1 = m_keyChain.getCertificate(m_keyChain.createIdentity(m_name1));
m_id2 = m_keyChain.getCertificate(m_keyChain.createIdentity(m_name2));
@@ -389,13 +390,15 @@
}
void
- done()
+ done(ndn::shared_ptr<boost::asio::io_service> ioService)
{
m_s1.reset();
m_s2.reset();
m_keyChain.deleteIdentity(m_name1);
m_keyChain.deleteIdentity(m_name2);
+
+ ioService->stop();
}
ndn::KeyChain m_keyChain;
@@ -415,8 +418,8 @@
TestSet3(ndn::shared_ptr<boost::asio::io_service> ioService)
: m_face1(new ndn::Face(ioService))
, m_face2(new ndn::Face(ioService))
- , m_name1("/xiaonei.com/" + boost::lexical_cast<std::string>(ndn::time::now()))
- , m_name2("/mitbbs.com/" + boost::lexical_cast<std::string>(ndn::time::now()))
+ , m_name1("/xiaonei.com/" + boost::lexical_cast<std::string>(ndn::time::toUnixTimestamp(ndn::time::system_clock::now()).count()))
+ , m_name2("/mitbbs.com/" + boost::lexical_cast<std::string>(ndn::time::toUnixTimestamp(ndn::time::system_clock::now()).count()))
{
m_id1 = m_keyChain.getCertificate(m_keyChain.createIdentity(m_name1));
m_id2 = m_keyChain.getCertificate(m_keyChain.createIdentity(m_name2));
@@ -505,13 +508,15 @@
}
void
- done()
+ done(ndn::shared_ptr<boost::asio::io_service> ioService)
{
m_s1.reset();
m_s2.reset();
m_keyChain.deleteIdentity(m_name1);
m_keyChain.deleteIdentity(m_name2);
+
+ ioService->stop();
}
ndn::KeyChain m_keyChain;
@@ -532,40 +537,40 @@
ndn::Scheduler scheduler(*ioService);
TestSet1 testSet1(ioService);
- scheduler.scheduleEvent(ndn::time::seconds(0.00), ndn::bind(&TestSet1::createSyncSocket1, &testSet1));
- scheduler.scheduleEvent(ndn::time::seconds(0.05), ndn::bind(&TestSet1::createSyncSocket2, &testSet1));
- scheduler.scheduleEvent(ndn::time::seconds(0.10), ndn::bind(&TestSet1::createSyncSocket3, &testSet1));
+ scheduler.scheduleEvent(ndn::time::milliseconds(0), ndn::bind(&TestSet1::createSyncSocket1, &testSet1));
+ scheduler.scheduleEvent(ndn::time::milliseconds(50), ndn::bind(&TestSet1::createSyncSocket2, &testSet1));
+ scheduler.scheduleEvent(ndn::time::milliseconds(100), ndn::bind(&TestSet1::createSyncSocket3, &testSet1));
string data0 = "Very funny Scotty, now beam down my clothes";
- scheduler.scheduleEvent(ndn::time::seconds(0.15), ndn::bind(&TestSet1::publishSocket1, &testSet1, data0));
- scheduler.scheduleEvent(ndn::time::seconds(1.15), ndn::bind(&TestSet1::setSocket1, &testSet1, "/0/1", data0));
- scheduler.scheduleEvent(ndn::time::seconds(1.16), ndn::bind(&TestSet1::check, &testSet1, 1));
+ scheduler.scheduleEvent(ndn::time::milliseconds(150), ndn::bind(&TestSet1::publishSocket1, &testSet1, data0));
+ scheduler.scheduleEvent(ndn::time::milliseconds(1150), ndn::bind(&TestSet1::setSocket1, &testSet1, "/0/1", data0));
+ scheduler.scheduleEvent(ndn::time::milliseconds(1160), ndn::bind(&TestSet1::check, &testSet1, 1));
string data1 = "Yes, give me that ketchup";
string data2 = "Don't look conspicuous, it draws fire";
- scheduler.scheduleEvent(ndn::time::seconds(1.17), ndn::bind(&TestSet1::publishSocket1, &testSet1, data1));
- scheduler.scheduleEvent(ndn::time::seconds(1.18), ndn::bind(&TestSet1::publishSocket1, &testSet1, data2));
- scheduler.scheduleEvent(ndn::time::seconds(2.15), ndn::bind(&TestSet1::setSocket1, &testSet1, "/0/2", data1));
- scheduler.scheduleEvent(ndn::time::seconds(2.16), ndn::bind(&TestSet1::setSocket1, &testSet1, "/0/3", data2));
- scheduler.scheduleEvent(ndn::time::seconds(2.17), ndn::bind(&TestSet1::check, &testSet1, 2));
+ scheduler.scheduleEvent(ndn::time::milliseconds(1170), ndn::bind(&TestSet1::publishSocket1, &testSet1, data1));
+ scheduler.scheduleEvent(ndn::time::milliseconds(1180), ndn::bind(&TestSet1::publishSocket1, &testSet1, data2));
+ scheduler.scheduleEvent(ndn::time::milliseconds(2150), ndn::bind(&TestSet1::setSocket1, &testSet1, "/0/2", data1));
+ scheduler.scheduleEvent(ndn::time::milliseconds(2160), ndn::bind(&TestSet1::setSocket1, &testSet1, "/0/3", data2));
+ scheduler.scheduleEvent(ndn::time::milliseconds(2170), ndn::bind(&TestSet1::check, &testSet1, 2));
string data3 = "You surf the Internet, I surf the real world";
string data4 = "I got a fortune cookie once that said 'You like Chinese food'";
string data5 = "Real men wear pink. Why? Because their wives make them";
- scheduler.scheduleEvent(ndn::time::seconds(3.18), ndn::bind(&TestSet1::publishSocket3, &testSet1, data3));
- scheduler.scheduleEvent(ndn::time::seconds(3.20), ndn::bind(&TestSet1::publishSocket2, &testSet1, data4));
- scheduler.scheduleEvent(ndn::time::seconds(3.21), ndn::bind(&TestSet1::publishSocket2, &testSet1, data5));
- scheduler.scheduleEvent(ndn::time::seconds(4.71), ndn::bind(&TestSet1::setSocket3, &testSet1, "/0/1", data3));
- scheduler.scheduleEvent(ndn::time::seconds(4.72), ndn::bind(&TestSet1::setSocket2, &testSet1, "/0/2", data4));
- scheduler.scheduleEvent(ndn::time::seconds(4.73), ndn::bind(&TestSet1::setSocket2, &testSet1, "/0/3", data5));
- scheduler.scheduleEvent(ndn::time::seconds(4.80), ndn::bind(&TestSet1::check, &testSet1, 3));
+ scheduler.scheduleEvent(ndn::time::milliseconds(3180), ndn::bind(&TestSet1::publishSocket3, &testSet1, data3));
+ scheduler.scheduleEvent(ndn::time::milliseconds(3200), ndn::bind(&TestSet1::publishSocket2, &testSet1, data4));
+ scheduler.scheduleEvent(ndn::time::milliseconds(3210), ndn::bind(&TestSet1::publishSocket2, &testSet1, data5));
+ scheduler.scheduleEvent(ndn::time::milliseconds(4710), ndn::bind(&TestSet1::setSocket3, &testSet1, "/0/1", data3));
+ scheduler.scheduleEvent(ndn::time::milliseconds(4720), ndn::bind(&TestSet1::setSocket2, &testSet1, "/0/2", data4));
+ scheduler.scheduleEvent(ndn::time::milliseconds(4730), ndn::bind(&TestSet1::setSocket2, &testSet1, "/0/3", data5));
+ scheduler.scheduleEvent(ndn::time::milliseconds(4800), ndn::bind(&TestSet1::check, &testSet1, 3));
// not sure weither this is simultanous data generation from multiple sources
_LOG_DEBUG ("Simultaneous publishing");
string data6 = "Shakespeare says: 'Prose before hos.'";
string data7 = "Pick good people, talent never wears out";
- scheduler.scheduleEvent(ndn::time::seconds(5.50), ndn::bind(&TestSet1::publishSocket1, &testSet1, data6));
- scheduler.scheduleEvent(ndn::time::seconds(5.50), ndn::bind(&TestSet1::publishSocket2, &testSet1, data7));
- scheduler.scheduleEvent(ndn::time::seconds(6.80), ndn::bind(&TestSet1::setSocket1, &testSet1, "/0/4", data6));
- scheduler.scheduleEvent(ndn::time::seconds(6.80), ndn::bind(&TestSet1::setSocket2, &testSet1, "/0/4", data7));
- scheduler.scheduleEvent(ndn::time::seconds(6.90), ndn::bind(&TestSet1::check, &testSet1, 4));
- scheduler.scheduleEvent(ndn::time::seconds(7.00), ndn::bind(&TestSet1::done, &testSet1));
+ scheduler.scheduleEvent(ndn::time::milliseconds(5500), ndn::bind(&TestSet1::publishSocket1, &testSet1, data6));
+ scheduler.scheduleEvent(ndn::time::milliseconds(5500), ndn::bind(&TestSet1::publishSocket2, &testSet1, data7));
+ scheduler.scheduleEvent(ndn::time::milliseconds(6800), ndn::bind(&TestSet1::setSocket1, &testSet1, "/0/4", data6));
+ scheduler.scheduleEvent(ndn::time::milliseconds(6800), ndn::bind(&TestSet1::setSocket2, &testSet1, "/0/4", data7));
+ scheduler.scheduleEvent(ndn::time::milliseconds(6900), ndn::bind(&TestSet1::check, &testSet1, 4));
+ scheduler.scheduleEvent(ndn::time::milliseconds(7000), ndn::bind(&TestSet1::done, &testSet1, ioService));
ioService->run();
}
@@ -576,19 +581,19 @@
ndn::Scheduler scheduler(*ioService);
TestSet2 testSet2(ioService);
- scheduler.scheduleEvent(ndn::time::seconds(0.00), ndn::bind(&TestSet2::createSyncSocket1, &testSet2));
- scheduler.scheduleEvent(ndn::time::seconds(0.05), ndn::bind(&TestSet2::createSyncSocket2, &testSet2));
+ scheduler.scheduleEvent(ndn::time::milliseconds(0), ndn::bind(&TestSet2::createSyncSocket1, &testSet2));
+ scheduler.scheduleEvent(ndn::time::milliseconds(50), ndn::bind(&TestSet2::createSyncSocket2, &testSet2));
uint32_t num[5] = {0, 1, 2, 3, 4};
string data0((const char *) num, sizeof(num));
- scheduler.scheduleEvent(ndn::time::seconds(0.10), ndn::bind(&TestSet2::publishSocket1, &testSet2, data0));
- scheduler.scheduleEvent(ndn::time::seconds(0.15), ndn::bind(&TestSet2::setSocket1, &testSet2, (const char *) num, sizeof (num)));
- scheduler.scheduleEvent(ndn::time::seconds(1.00), ndn::bind(&TestSet2::check, &testSet2, 10));
+ scheduler.scheduleEvent(ndn::time::milliseconds(100), ndn::bind(&TestSet2::publishSocket1, &testSet2, data0));
+ scheduler.scheduleEvent(ndn::time::milliseconds(150), ndn::bind(&TestSet2::setSocket1, &testSet2, (const char *) num, sizeof (num)));
+ scheduler.scheduleEvent(ndn::time::milliseconds(1000), ndn::bind(&TestSet2::check, &testSet2, 10));
uint32_t newNum[5] = {9, 7, 2, 1, 1};
string data1((const char *) newNum, sizeof(newNum));
- scheduler.scheduleEvent(ndn::time::seconds(1.10), ndn::bind(&TestSet2::publishSocket2, &testSet2, data1));
- scheduler.scheduleEvent(ndn::time::seconds(1.15), ndn::bind(&TestSet2::setSocket2, &testSet2, (const char *) newNum, sizeof (newNum)));
- scheduler.scheduleEvent(ndn::time::seconds(2.00), ndn::bind(&TestSet2::check, &testSet2, 30));
- scheduler.scheduleEvent(ndn::time::seconds(7.00), ndn::bind(&TestSet2::done, &testSet2));
+ scheduler.scheduleEvent(ndn::time::milliseconds(1100), ndn::bind(&TestSet2::publishSocket2, &testSet2, data1));
+ scheduler.scheduleEvent(ndn::time::milliseconds(1150), ndn::bind(&TestSet2::setSocket2, &testSet2, (const char *) newNum, sizeof (newNum)));
+ scheduler.scheduleEvent(ndn::time::milliseconds(2000), ndn::bind(&TestSet2::check, &testSet2, 30));
+ scheduler.scheduleEvent(ndn::time::milliseconds(7000), ndn::bind(&TestSet2::done, &testSet2, ioService));
ioService->run();
}
@@ -599,19 +604,19 @@
ndn::Scheduler scheduler(*ioService);
TestSet3 testSet3(ioService);
- scheduler.scheduleEvent(ndn::time::seconds(0.00), ndn::bind(&TestSet3::createSyncSocket1, &testSet3));
- scheduler.scheduleEvent(ndn::time::seconds(0.20), ndn::bind(&TestSet3::createSyncSocket2, &testSet3));
+ scheduler.scheduleEvent(ndn::time::milliseconds(0), ndn::bind(&TestSet3::createSyncSocket1, &testSet3));
+ scheduler.scheduleEvent(ndn::time::milliseconds(200), ndn::bind(&TestSet3::createSyncSocket2, &testSet3));
uint32_t num[5] = {0, 1, 2, 3, 4};
string data0((const char *) num, sizeof(num));
- scheduler.scheduleEvent(ndn::time::seconds(1.00), ndn::bind(&TestSet3::publishSocket1, &testSet3, data0));
- scheduler.scheduleEvent(ndn::time::seconds(1.50), ndn::bind(&TestSet3::setSocket1, &testSet3, (const char *) num, sizeof (num)));
- scheduler.scheduleEvent(ndn::time::seconds(2.00), ndn::bind(&TestSet3::check, &testSet3, 10));
+ scheduler.scheduleEvent(ndn::time::milliseconds(1000), ndn::bind(&TestSet3::publishSocket1, &testSet3, data0));
+ scheduler.scheduleEvent(ndn::time::milliseconds(1500), ndn::bind(&TestSet3::setSocket1, &testSet3, (const char *) num, sizeof (num)));
+ scheduler.scheduleEvent(ndn::time::milliseconds(2000), ndn::bind(&TestSet3::check, &testSet3, 10));
uint32_t newNum[5] = {9, 7, 2, 1, 1};
string data1((const char *) newNum, sizeof(newNum));
- scheduler.scheduleEvent(ndn::time::seconds(3.00), ndn::bind(&TestSet3::publishSocket2, &testSet3, data1));
- scheduler.scheduleEvent(ndn::time::seconds(3.50), ndn::bind(&TestSet3::setSocket2, &testSet3, (const char *) newNum, sizeof (newNum)));
- scheduler.scheduleEvent(ndn::time::seconds(5.00), ndn::bind(&TestSet3::check, &testSet3, 30));
- scheduler.scheduleEvent(ndn::time::seconds(7.00), ndn::bind(&TestSet3::done, &testSet3));
+ scheduler.scheduleEvent(ndn::time::milliseconds(3000), ndn::bind(&TestSet3::publishSocket2, &testSet3, data1));
+ scheduler.scheduleEvent(ndn::time::milliseconds(3500), ndn::bind(&TestSet3::setSocket2, &testSet3, (const char *) newNum, sizeof (newNum)));
+ scheduler.scheduleEvent(ndn::time::milliseconds(5000), ndn::bind(&TestSet3::check, &testSet3, 30));
+ scheduler.scheduleEvent(ndn::time::milliseconds(7000), ndn::bind(&TestSet3::done, &testSet3, ioService));
ioService->run();
}
diff --git a/tests/test-sync-logic.cc b/tests/test-sync-logic.cc
index ebce9c0..d430a46 100644
--- a/tests/test-sync-logic.cc
+++ b/tests/test-sync-logic.cc
@@ -93,15 +93,16 @@
}
void
- finish()
+ finish(ndn::shared_ptr<boost::asio::io_service> ioService)
{
+ ioService->stop();
}
void
createSyncLogic(int index,
ndn::shared_ptr<Handler> h)
{
- ndn::Name identity("/tmp-" + boost::lexical_cast<std::string>(ndn::time::now()));
+ ndn::Name identity("/tmp-" + boost::lexical_cast<std::string>(ndn::time::toUnixTimestamp(ndn::time::system_clock::now()).count()));
ndn::shared_ptr<ndn::IdentityCertificate> cert = m_keyChain.getCertificate(m_keyChain.createIdentity(identity));
m_faces[index] = ndn::make_shared<ndn::Face>(m_ioService);
m_l[index] = new SyncLogic(ndn::Name("/bcast"),
@@ -166,17 +167,17 @@
ndn::shared_ptr<Handler> h1 = ndn::make_shared<Handler>("1");
ndn::shared_ptr<Handler> h2 = ndn::make_shared<Handler>("2");
- scheduler.scheduleEvent(ndn::time::seconds(0), ndn::bind(&TestCore::createSyncLogic, &testCore, 0, h1));
- scheduler.scheduleEvent(ndn::time::seconds(0.1), ndn::bind(&TestCore::getOldDigestForOne, &testCore));
- scheduler.scheduleEvent(ndn::time::seconds(0.2), ndn::bind(&TestCore::addLocalNamesForOne, &testCore, "/one", 1, 2));
- scheduler.scheduleEvent(ndn::time::seconds(0.3), ndn::bind(&checkMapSize, h1, 0));
- scheduler.scheduleEvent(ndn::time::seconds(0.4), ndn::bind(&TestCore::createSyncLogic, &testCore, 1, h2));
- scheduler.scheduleEvent(ndn::time::seconds(0.5), ndn::bind(&checkMapSize, h1, 0));
- scheduler.scheduleEvent(ndn::time::seconds(0.6), ndn::bind(&checkMapSize, h2, 1));
- scheduler.scheduleEvent(ndn::time::seconds(0.7), ndn::bind(&TestCore::removeForOne, &testCore, "/one"));
- scheduler.scheduleEvent(ndn::time::seconds(0.8), ndn::bind(&TestCore::getNewDigestForOne, &testCore));
- scheduler.scheduleEvent(ndn::time::seconds(0.9), ndn::bind(&TestCore::checkDigest, &testCore));
- scheduler.scheduleEvent(ndn::time::seconds(1.0), ndn::bind(&TestCore::finish, &testCore));
+ scheduler.scheduleEvent(ndn::time::milliseconds(0), ndn::bind(&TestCore::createSyncLogic, &testCore, 0, h1));
+ scheduler.scheduleEvent(ndn::time::milliseconds(100), ndn::bind(&TestCore::getOldDigestForOne, &testCore));
+ scheduler.scheduleEvent(ndn::time::milliseconds(200), ndn::bind(&TestCore::addLocalNamesForOne, &testCore, "/one", 1, 2));
+ scheduler.scheduleEvent(ndn::time::milliseconds(300), ndn::bind(&checkMapSize, h1, 0));
+ scheduler.scheduleEvent(ndn::time::milliseconds(400), ndn::bind(&TestCore::createSyncLogic, &testCore, 1, h2));
+ scheduler.scheduleEvent(ndn::time::milliseconds(500), ndn::bind(&checkMapSize, h1, 0));
+ scheduler.scheduleEvent(ndn::time::milliseconds(600), ndn::bind(&checkMapSize, h2, 1));
+ scheduler.scheduleEvent(ndn::time::milliseconds(700), ndn::bind(&TestCore::removeForOne, &testCore, "/one"));
+ scheduler.scheduleEvent(ndn::time::milliseconds(800), ndn::bind(&TestCore::getNewDigestForOne, &testCore));
+ scheduler.scheduleEvent(ndn::time::milliseconds(900), ndn::bind(&TestCore::checkDigest, &testCore));
+ scheduler.scheduleEvent(ndn::time::milliseconds(1000), ndn::bind(&TestCore::finish, &testCore, ioService));
ioService->run();
diff --git a/tests/test-sync-validator.cc b/tests/test-sync-validator.cc
index 9049edc..6f77f86 100644
--- a/tests/test-sync-validator.cc
+++ b/tests/test-sync-validator.cc
@@ -47,23 +47,23 @@
Name prefix("/Sync/TestSyncValidator/AddEdge");
KeyChain keychain;
- Name identity1("/TestSyncValidator/AddEdge-1/" + boost::lexical_cast<std::string>(time::now()));
+ Name identity1("/TestSyncValidator/AddEdge-1/" + boost::lexical_cast<std::string>(ndn::time::toUnixTimestamp(ndn::time::system_clock::now()).count()));
Name certName1 = keychain.createIdentity(identity1);
shared_ptr<IdentityCertificate> anchor = keychain.getCertificate(certName1);
- Name identity2("/TestSyncValidator/AddEdge-2/" + boost::lexical_cast<std::string>(time::now()));
+ Name identity2("/TestSyncValidator/AddEdge-2/" + boost::lexical_cast<std::string>(ndn::time::toUnixTimestamp(ndn::time::system_clock::now()).count()));
Name certName2 = keychain.createIdentity(identity2);
shared_ptr<IdentityCertificate> introducer = keychain.getCertificate(certName2);
- Name identity3("/TestSyncValidator/AddEdge-3/" + boost::lexical_cast<std::string>(time::now()));
+ Name identity3("/TestSyncValidator/AddEdge-3/" + boost::lexical_cast<std::string>(ndn::time::toUnixTimestamp(ndn::time::system_clock::now()).count()));
Name certName3 = keychain.createIdentity(identity3);
shared_ptr<IdentityCertificate> introducee = keychain.getCertificate(certName3);
- Name identity4("/TestSyncValidator/AddEdge-4/" + boost::lexical_cast<std::string>(time::now()));
+ Name identity4("/TestSyncValidator/AddEdge-4/" + boost::lexical_cast<std::string>(ndn::time::toUnixTimestamp(ndn::time::system_clock::now()).count()));
Name certName4 = keychain.createIdentity(identity4);
shared_ptr<IdentityCertificate> introducer2 = keychain.getCertificate(certName4);
- Name identity5("/TestSyncValidator/AddEdge-5/" + boost::lexical_cast<std::string>(time::now()));
+ Name identity5("/TestSyncValidator/AddEdge-5/" + boost::lexical_cast<std::string>(ndn::time::toUnixTimestamp(ndn::time::system_clock::now()).count()));
Name certName5 = keychain.createIdentity(identity5);
shared_ptr<IdentityCertificate> introducee2 = keychain.getCertificate(certName5);
@@ -125,23 +125,28 @@
Name prefix("/Sync/TestSyncValidator/OfflineValidate");
KeyChain keychain;
- Name identity1("/TestSyncValidator/OfflineValidate-1/" + boost::lexical_cast<std::string>(time::now()));
+ Name identity1("/TestSyncValidator/OfflineValidate-1/"
+ + boost::lexical_cast<std::string>(ndn::time::toUnixTimestamp(ndn::time::system_clock::now()).count()));
Name certName1 = keychain.createIdentity(identity1);
shared_ptr<IdentityCertificate> anchor = keychain.getCertificate(certName1);
- Name identity2("/TestSyncValidator/OfflineValidate-2/" + boost::lexical_cast<std::string>(time::now()));
+ Name identity2("/TestSyncValidator/OfflineValidate-2/"
+ + boost::lexical_cast<std::string>(ndn::time::toUnixTimestamp(ndn::time::system_clock::now()).count()));
Name certName2 = keychain.createIdentity(identity2);
shared_ptr<IdentityCertificate> introducer = keychain.getCertificate(certName2);
- Name identity3("/TestSyncValidator/OfflineValidate-3/" + boost::lexical_cast<std::string>(time::now()));
+ Name identity3("/TestSyncValidator/OfflineValidate-3/"
+ + boost::lexical_cast<std::string>(ndn::time::toUnixTimestamp(ndn::time::system_clock::now()).count()));
Name certName3 = keychain.createIdentity(identity3);
shared_ptr<IdentityCertificate> introducee = keychain.getCertificate(certName3);
- Name identity4("/TestSyncValidator/OfflineValidate-4/" + boost::lexical_cast<std::string>(time::now()));
+ Name identity4("/TestSyncValidator/OfflineValidate-4/"
+ + boost::lexical_cast<std::string>(ndn::time::toUnixTimestamp(ndn::time::system_clock::now()).count()));
Name certName4 = keychain.createIdentity(identity4);
shared_ptr<IdentityCertificate> introducer2 = keychain.getCertificate(certName4);
- Name identity5("/TestSyncValidator/OfflineValidate-5/" + boost::lexical_cast<std::string>(time::now()));
+ Name identity5("/TestSyncValidator/OfflineValidate-5/"
+ + boost::lexical_cast<std::string>(ndn::time::toUnixTimestamp(ndn::time::system_clock::now()).count()));
Name certName5 = keychain.createIdentity(identity5);
shared_ptr<IdentityCertificate> introducee2 = keychain.getCertificate(certName5);
@@ -191,7 +196,7 @@
bind(&onValidated2, _1),
bind(&onValidationFailed2, _1, _2));
- ioService->run();
+ // ioService->run();
keychain.deleteIdentity(identity1);
keychain.deleteIdentity(identity2);
@@ -200,7 +205,55 @@
keychain.deleteIdentity(identity5);
}
-BOOST_AUTO_TEST_CASE (OnlineValidate)
+struct FacesFixture
+{
+ FacesFixture()
+ : regPrefixId(0)
+ , regPrefixId2(0)
+ {}
+
+ void
+ onInterest(ndn::shared_ptr<ndn::Face> face, ndn::shared_ptr<ndn::Data> data)
+ {
+ face->put(*data);
+ face->unsetInterestFilter(regPrefixId);
+ }
+
+ void
+ onInterest2(ndn::shared_ptr<ndn::Face> face, ndn::shared_ptr<ndn::Data> data)
+ {
+ face->put(*data);
+ face->unsetInterestFilter(regPrefixId2);
+ }
+
+ void
+ onRegFailed()
+ {}
+
+ void
+ validate(ndn::shared_ptr<Sync::SyncValidator> validator, ndn::shared_ptr<ndn::Data> data,
+ const ndn::Name& certName3, const ndn::Name& certName4)
+ {
+ validator->validate(*data,
+ bind(&onValidated, _1),
+ bind(&onValidationFailed, _1, _2));
+
+
+ BOOST_CHECK(validator->canTrust(certName3));
+ BOOST_CHECK(validator->canTrust(certName4));
+ }
+
+ void
+ terminate(ndn::shared_ptr<ndn::Face> face)
+ {
+ face->ioService()->stop();
+ }
+
+ const ndn::RegisteredPrefixId* regPrefixId;
+ const ndn::RegisteredPrefixId* regPrefixId2;
+};
+
+BOOST_FIXTURE_TEST_CASE(OnlineValidate, FacesFixture)
{
using namespace Sync;
using namespace ndn;
@@ -208,55 +261,66 @@
Name prefix("/Sync/TestSyncValidator/OnlineValidate");
KeyChain keychain;
- Name identity1("/TestSyncValidator/OnlineValidate-1/" + boost::lexical_cast<std::string>(time::now()));
+ Name identity1("/TestSyncValidator/OnlineValidate-1/"
+ + boost::lexical_cast<std::string>(ndn::time::toUnixTimestamp(ndn::time::system_clock::now()).count()));
Name certName1 = keychain.createIdentity(identity1);
shared_ptr<IdentityCertificate> anchor = keychain.getCertificate(certName1);
- Name identity2("/TestSyncValidator/OnlineValidate-2/" + boost::lexical_cast<std::string>(time::now()));
+ Name identity2("/TestSyncValidator/OnlineValidate-2/"
+ + boost::lexical_cast<std::string>(ndn::time::toUnixTimestamp(ndn::time::system_clock::now()).count()));
Name certName2 = keychain.createIdentity(identity2);
shared_ptr<IdentityCertificate> introducer = keychain.getCertificate(certName2);
- Name identity3("/TestSyncValidator/OnlineValidate-3/" + boost::lexical_cast<std::string>(time::now()));
+ Name identity3("/TestSyncValidator/OnlineValidate-3/"
+ + boost::lexical_cast<std::string>(ndn::time::toUnixTimestamp(ndn::time::system_clock::now()).count()));
Name certName3 = keychain.createIdentity(identity3);
shared_ptr<IdentityCertificate> introducee = keychain.getCertificate(certName3);
- Name identity4("/TestSyncValidator/OfflineValidate-4/" + boost::lexical_cast<std::string>(time::now()));
+ Name identity4("/TestSyncValidator/OnlineValidate-4/"
+ + boost::lexical_cast<std::string>(ndn::time::toUnixTimestamp(ndn::time::system_clock::now()).count()));
Name certName4 = keychain.createIdentity(identity4);
shared_ptr<IdentityCertificate> introducee2 = keychain.getCertificate(certName4);
shared_ptr<boost::asio::io_service> ioService = make_shared<boost::asio::io_service>();
shared_ptr<Face> face = make_shared<Face>(ioService);
+ shared_ptr<Face> face2 = make_shared<Face>(ioService);
+
shared_ptr<SecRuleRelative> rule;
- SyncValidator validator(prefix, *anchor, face,
- bind(&publishData, _1, _2, _3),
- rule);
+ shared_ptr<SyncValidator> validator = shared_ptr<SyncValidator>
+ (new SyncValidator(prefix, *anchor, face2, bind(&publishData, _1, _2, _3), rule));
- validator.addParticipant(*introducer);
- BOOST_CHECK(validator.canTrust(certName2));
+ validator->addParticipant(*introducer);
+ BOOST_CHECK(validator->canTrust(certName2));
- IntroCertificate introCert(prefix, *introducee, certName2.getPrefix(-1));
- keychain.sign(introCert, certName2);
- face->put(introCert);
- BOOST_CHECK(validator.canTrust(certName3) == false);
+ shared_ptr<IntroCertificate> introCert = shared_ptr<IntroCertificate>(new IntroCertificate(prefix, *introducee, certName2.getPrefix(-1)));
+ keychain.sign(*introCert, certName2);
+ BOOST_CHECK(validator->canTrust(certName3) == false);
- IntroCertificate introCert2(prefix, *introducee2, certName3.getPrefix(-1));
- keychain.sign(introCert2, certName3);
- face->put(introCert2);
- BOOST_CHECK(validator.canTrust(certName4) == false);
+ shared_ptr<IntroCertificate> introCert2 = shared_ptr<IntroCertificate>(new IntroCertificate(prefix, *introducee2, certName3.getPrefix(-1)));
+ keychain.sign(*introCert2, certName3);
+ BOOST_CHECK(validator->canTrust(certName4) == false);
Name dataName1 = prefix;
dataName1.append("data-1");
shared_ptr<Data> data1 = make_shared<Data>(dataName1);
keychain.sign(*data1, certName4);
- validator.validate(*data1,
- bind(&onValidated, _1),
- bind(&onValidationFailed, _1, _2));
+ ndn::Scheduler scheduler(*ioService);
- ioService->run();
+ scheduler.scheduleEvent(time::seconds(1),
+ bind(&FacesFixture::terminate, this, face));
- BOOST_CHECK(validator.canTrust(certName3));
- BOOST_CHECK(validator.canTrust(certName4));
+ regPrefixId = face->setInterestFilter(introCert->getName().getPrefix(-1),
+ bind(&FacesFixture::onInterest, this, face, introCert),
+ bind(&FacesFixture::onRegFailed, this));
+
+ regPrefixId2 = face->setInterestFilter(introCert2->getName().getPrefix(-1),
+ bind(&FacesFixture::onInterest2, this, face, introCert2),
+ bind(&FacesFixture::onRegFailed, this));
+
+ scheduler.scheduleEvent(time::milliseconds(200),
+ bind(&FacesFixture::validate, this,
+ validator, data1, certName3, certName4));
keychain.deleteIdentity(identity1);
keychain.deleteIdentity(identity2);