fixes: Remove sync scheduler; Use ndn::time; Passed all the test cases
Change-Id: I50e8cd94f71f463793e4d19d5bf65e190cac6e59
diff --git a/src/sync-full-state.cc b/src/sync-full-state.cc
index 25d01c6..eb9ca4c 100644
--- a/src/sync-full-state.cc
+++ b/src/sync-full-state.cc
@@ -22,10 +22,6 @@
#include "sync-full-state.h"
-#ifdef NS3_MODULE
-#include "ns3/simulator.h"
-#endif // NS3_MODULE
-
#include <boost/make_shared.hpp>
#include <boost/lambda/lambda.hpp>
#include <boost/lambda/bind.hpp>
@@ -49,14 +45,10 @@
{
}
-TimeDurationType
+ndn::time::Duration
FullState::getTimeFromLastUpdate () const
{
-#ifdef NS3_MODULE
- return ns3::Simulator::Now () - m_lastUpdated;
-#else
- return boost::posix_time::second_clock::universal_time () - m_lastUpdated;
-#endif // NS3_MODULE
+ return ndn::time::now() - m_lastUpdated;
}
DigestConstPtr
@@ -89,11 +81,8 @@
boost::tuple<bool/*inserted*/, bool/*updated*/, SeqNo/*oldSeqNo*/>
FullState::update (NameInfoConstPtr info, const SeqNo &seq)
{
-#ifdef NS3_MODULE
- m_lastUpdated = ns3::Simulator::Now ();
-#else
- m_lastUpdated = boost::posix_time::second_clock::universal_time ();
-#endif // NS3_MODULE
+ m_lastUpdated = ndn::time::now();
+
m_digest.reset ();
@@ -120,11 +109,7 @@
bool
FullState::remove (NameInfoConstPtr info)
{
-#ifdef NS3_MODULE
- m_lastUpdated = ns3::Simulator::Now ();
-#else
- m_lastUpdated = boost::posix_time::second_clock::universal_time ();
-#endif // NS3_MODULE
+ m_lastUpdated = ndn::time::now();
m_digest.reset ();
diff --git a/src/sync-full-state.h b/src/sync-full-state.h
index 44b9248..28e0078 100644
--- a/src/sync-full-state.h
+++ b/src/sync-full-state.h
@@ -23,16 +23,7 @@
#ifndef SYNC_FULL_STATE_H
#define SYNC_FULL_STATE_H
-#ifdef NS3_MODULE
-#include "ns3/nstime.h"
-typedef ns3::Time TimeType;
-typedef ns3::Time TimeDurationType;
-#else
-#include <boost/date_time/posix_time/posix_time_types.hpp>
-typedef boost::posix_time::ptime TimeType;
-typedef boost::posix_time::time_duration TimeDurationType;
-#endif // NS3_MODULE
-
+#include <ndn-cpp-dev/util/time.hpp>
#include "sync-state.h"
namespace Sync {
@@ -60,7 +51,7 @@
*
* This value can be used to randomize reconciliation waiting time in SyncApp
*/
- TimeDurationType
+ ndn::time::Duration
getTimeFromLastUpdate () const;
/**
@@ -79,7 +70,7 @@
remove (NameInfoConstPtr info);
private:
- TimeType m_lastUpdated; ///< @brief Time when state was updated last time
+ ndn::time::Point 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 b998b18..742f053 100644
--- a/src/sync-interest-container.h
+++ b/src/sync-interest-container.h
@@ -23,6 +23,8 @@
#ifndef SYNC_INTEREST_CONTAINER_H
#define SYNC_INTEREST_CONTAINER_H
+#include <ndn-cpp-dev/util/time.hpp>
+
#include "sync-digest.h"
#include <boost/multi_index_container.hpp>
@@ -45,15 +47,15 @@
Interest (DigestConstPtr digest, const std::string &name, bool unknown=false)
: m_digest (digest)
, m_name (name)
- , m_time (TIME_NOW)
+ , m_time (ndn::time::now())
, m_unknown (unknown)
{
}
- DigestConstPtr m_digest;
- std::string m_name;
- TimeAbsolute m_time;
- bool m_unknown;
+ DigestConstPtr m_digest;
+ std::string m_name;
+ ndn::time::Point m_time;
+ bool m_unknown;
};
/// @cond include_hidden
@@ -85,7 +87,7 @@
mi::ordered_non_unique<
mi::tag<timed>,
- BOOST_MULTI_INDEX_MEMBER(Interest, TimeAbsolute, m_time)
+ BOOST_MULTI_INDEX_MEMBER(Interest, ndn::time::Point, m_time)
>
>
>
diff --git a/src/sync-interest-table.cc b/src/sync-interest-table.cc
index d966d09..a378950 100644
--- a/src/sync-interest-table.cc
+++ b/src/sync-interest-table.cc
@@ -23,19 +23,18 @@
#include "sync-interest-table.h"
#include "sync-logging.h"
using namespace std;
-using namespace boost;
INIT_LOGGER ("SyncInterestTable");
namespace Sync
{
-SyncInterestTable::SyncInterestTable (TimeDuration lifetime)
+SyncInterestTable::SyncInterestTable (boost::asio::io_service& io, ndn::time::Duration lifetime)
: m_entryLifetime (lifetime)
+ , m_scheduler(io)
{
- m_scheduler.schedule (TIME_SECONDS (m_checkPeriod),
- bind (&SyncInterestTable::expireInterests, this),
- 0);
+ m_scheduler.schedulePeriodicEvent (ndn::time::seconds (4), ndn::time::seconds (4),
+ ndn::bind(&SyncInterestTable::expireInterests, this));
}
SyncInterestTable::~SyncInterestTable ()
@@ -45,8 +44,6 @@
Interest
SyncInterestTable::pop ()
{
- boost::recursive_mutex::scoped_lock lock (m_mutex);
-
if (m_table.size () == 0)
BOOST_THROW_EXCEPTION (Error::InterestTableIsEmpty ());
@@ -61,7 +58,6 @@
{
bool existent = false;
- boost::recursive_mutex::scoped_lock lock (m_mutex);
InterestContainer::index<named>::type::iterator it = m_table.get<named> ().find (name);
if (it != m_table.end())
{
@@ -76,15 +72,12 @@
uint32_t
SyncInterestTable::size () const
{
- boost::recursive_mutex::scoped_lock lock (m_mutex);
return m_table.size ();
}
bool
SyncInterestTable::remove (const string &name)
{
- boost::recursive_mutex::scoped_lock lock (m_mutex);
-
InterestContainer::index<named>::type::iterator item = m_table.get<named> ().find (name);
if (item != m_table.get<named> ().end ())
{
@@ -98,7 +91,6 @@
bool
SyncInterestTable::remove (DigestConstPtr digest)
{
- boost::recursive_mutex::scoped_lock lock (m_mutex);
InterestContainer::index<hashed>::type::iterator item = m_table.get<hashed> ().find (digest);
if (item != m_table.get<hashed> ().end ())
{
@@ -110,16 +102,14 @@
void SyncInterestTable::expireInterests ()
{
- boost::recursive_mutex::scoped_lock lock (m_mutex);
-
uint32_t count = 0;
- TimeAbsolute expireTime = TIME_NOW - m_entryLifetime;
+ ndn::time::Point expireTime = ndn::time::now() - m_entryLifetime;
while (m_table.size () > 0)
{
InterestContainer::index<timed>::type::iterator item = m_table.get<timed> ().begin ();
- if (item->m_time < expireTime)
+ if (item->m_time <= expireTime)
{
m_table.get<timed> ().erase (item);
count ++;
@@ -127,12 +117,6 @@
else
break;
}
-
- _LOG_DEBUG ("expireInterests (): expired " << count);
-
- m_scheduler.schedule (TIME_SECONDS (m_checkPeriod),
- bind (&SyncInterestTable::expireInterests, this),
- 0);
}
diff --git a/src/sync-interest-table.h b/src/sync-interest-table.h
index 824d1f9..9b7c46b 100644
--- a/src/sync-interest-table.h
+++ b/src/sync-interest-table.h
@@ -23,18 +23,16 @@
#ifndef SYNC_INTEREST_TABLE_H
#define SYNC_INTEREST_TABLE_H
+#include <ndn-cpp-dev/util/scheduler.hpp>
+
#include <string>
#include <vector>
-#include <boost/thread/recursive_mutex.hpp>
-#include <boost/thread/thread.hpp>
-#include <ctime>
-#include "sync-scheduler.h"
+
#include "sync-digest.h"
#include "sync-interest-container.h"
namespace Sync {
-
/**
* \ingroup sync
* @brief A table to keep unanswered Sync Interest
@@ -44,7 +42,7 @@
class SyncInterestTable
{
public:
- SyncInterestTable (TimeDuration lifetime);
+ SyncInterestTable (boost::asio::io_service& io, ndn::time::Duration lifetime);
~SyncInterestTable ();
/**
@@ -83,20 +81,16 @@
expireInterests ();
private:
- static const int m_checkPeriod = 4; // seconds
-
- TimeDuration m_entryLifetime;
+ ndn::time::Duration m_entryLifetime;
InterestContainer m_table;
- Scheduler m_scheduler;
- mutable boost::recursive_mutex m_mutex;
+ ndn::Scheduler m_scheduler;
};
namespace Error {
struct InterestTableIsEmpty : virtual boost::exception, virtual std::exception { };
}
-
} // Sync
#endif // SYNC_INTEREST_TABLE_H
diff --git a/src/sync-logging.h b/src/sync-logging.h
index ef84e75..865204a 100644
--- a/src/sync-logging.h
+++ b/src/sync-logging.h
@@ -59,7 +59,6 @@
#ifdef _DEBUG
-#include <boost/thread/thread.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <iostream>
diff --git a/src/sync-logic.cc b/src/sync-logic.cc
index f9bbdca..6f3d21d 100644
--- a/src/sync-logic.cc
+++ b/src/sync-logic.cc
@@ -27,7 +27,6 @@
#include "sync-logging.h"
#include "sync-state.h"
-#include <boost/make_shared.hpp>
#include <boost/foreach.hpp>
#include <boost/lexical_cast.hpp>
#include <vector>
@@ -39,7 +38,7 @@
#ifdef _DEBUG
-#define _LOG_DEBUG_ID(v) _LOG_DEBUG(m_instanceId + v)
+#define _LOG_DEBUG_ID(v) _LOG_DEBUG(m_instanceId << " " << v)
#else
#define _LOG_DEBUG_ID(v) _LOG_DEBUG(v)
#endif
@@ -47,14 +46,14 @@
#define GET_RANDOM(var) var ()
#define TIME_SECONDS_WITH_JITTER(sec) \
- (TIME_SECONDS (sec) + TIME_MILLISECONDS (GET_RANDOM (m_reexpressionJitter)))
+ (time::seconds(sec) + time::milliseconds(GET_RANDOM (m_reexpressionJitter)))
#define TIME_MILLISECONDS_WITH_JITTER(ms) \
- (TIME_MILLISECONDS (ms) + TIME_MILLISECONDS (GET_RANDOM (m_reexpressionJitter)))
+ (time::seconds(ms) + time::milliseconds(GET_RANDOM (m_reexpressionJitter)))
+namespace Sync {
-namespace Sync
-{
+using ndn::shared_ptr;
int SyncLogic::m_instanceCounter = 0;
@@ -64,7 +63,7 @@
LogicUpdateCallback onUpdate,
LogicRemoveCallback onRemove)
: m_state (new FullState)
- , m_syncInterestTable (TIME_SECONDS (m_syncInterestReexpress))
+ , m_syncInterestTable (*face->ioService(), time::seconds(m_syncInterestReexpress))
, m_syncPrefix (syncPrefix)
, m_onUpdate (onUpdate)
, m_onRemove (onRemove)
@@ -73,7 +72,7 @@
, m_keyChain(new KeyChain())
, m_face(face)
, m_scheduler(*face->ioService())
- , m_randomGenerator (static_cast<unsigned int> (std::time (0)))
+ , m_randomGenerator (static_cast<unsigned int> (std::time (0)))
, m_rangeUniformRandom (m_randomGenerator, boost::uniform_int<> (200,1000))
, m_reexpressionJitter (m_randomGenerator, boost::uniform_int<> (100,500))
, m_recoveryRetransmissionInterval (m_defaultRecoveryRetransmitInterval)
@@ -94,7 +93,7 @@
shared_ptr<Face> face,
LogicPerBranchCallback onUpdateBranch)
: m_state (new FullState)
- , m_syncInterestTable (TIME_SECONDS (m_syncInterestReexpress))
+ , m_syncInterestTable (*face->ioService(), time::seconds (m_syncInterestReexpress))
, m_syncPrefix (syncPrefix)
, m_onUpdateBranch (onUpdateBranch)
, m_perBranch(true)
@@ -258,7 +257,6 @@
_LOG_DEBUG_ID("processSyncInterest");
DigestConstPtr rootDigest;
{
- boost::recursive_mutex::scoped_lock lock (m_stateMutex);
rootDigest = m_state->getDigest();
}
@@ -268,7 +266,6 @@
SyncStateMsg ssm;
{
- boost::recursive_mutex::scoped_lock lock (m_stateMutex);
ssm << (*m_state);
}
sendSyncData (name, digest, ssm);
@@ -302,7 +299,7 @@
}
uint32_t waitDelay = GET_RANDOM (m_rangeUniformRandom);
- _LOG_DEBUG_ID ("Digest is not in the log. Schedule processing after small delay: " << waitDelay << "ms");
+ _LOG_DEBUG_ID ("Digest is not in the log. Schedule processing after small delay: " << time::milliseconds (waitDelay));
m_delayedInterestProcessingId = m_scheduler.scheduleEvent (time::milliseconds (waitDelay),
bind (&SyncLogic::processSyncInterest, this, name, digest, true));
@@ -353,7 +350,6 @@
bool updated = false;
SeqNo oldSeq;
{
- boost::recursive_mutex::scoped_lock lock (m_stateMutex);
boost::tie (inserted, updated, oldSeq) = m_state->update (info, seq);
}
@@ -392,7 +388,6 @@
}
else if (diffLeaf->getOperation() == REMOVE)
{
- boost::recursive_mutex::scoped_lock lock (m_stateMutex);
if (m_state->remove (info))
{
diffLog->remove (info);
@@ -436,7 +431,7 @@
// if state has changed, then it is safe to express a new interest
time::Duration after = time::milliseconds(GET_RANDOM (m_reexpressionJitter));
- cout << "------------ reexpress interest after: " << after << " ms " << endl;
+ // cout << "------------ reexpress interest after: " << after << endl;
EventId eventId = m_scheduler.scheduleEvent (after,
bind (&SyncLogic::sendSyncInterest, this));
@@ -459,7 +454,6 @@
SyncStateMsg ssm;
{
- boost::recursive_mutex::scoped_lock lock (m_stateMutex);
ssm << (*m_state);
}
sendSyncData (name, digest, ssm);
@@ -470,7 +464,6 @@
{
DiffStatePtr fullStateLog = boost::make_shared<DiffState> ();
{
- boost::recursive_mutex::scoped_lock lock (m_stateMutex);
BOOST_FOREACH (LeafConstPtr leaf, m_state->getLeaves ()/*.get<timed> ()*/)
{
fullStateLog->update (leaf->getInfo (), leaf->getSeq ());
@@ -524,7 +517,6 @@
DiffStatePtr diff;
{
//cout << "Add local names" <<endl;
- boost::recursive_mutex::scoped_lock lock (m_stateMutex);
NameInfoConstPtr info = StdNameInfo::FindOrCreate(prefix.toUri());
_LOG_DEBUG_ID ("addLocalNames (): old state " << *m_state->getDigest ());
@@ -548,7 +540,6 @@
{
DiffStatePtr diff;
{
- boost::recursive_mutex::scoped_lock lock (m_stateMutex);
NameInfoConstPtr info = StdNameInfo::FindOrCreate(prefix.toUri());
m_state->remove(info);
@@ -580,7 +571,6 @@
_LOG_DEBUG_ID("sendSyncInterest");
{
- boost::recursive_mutex::scoped_lock lock (m_stateMutex);
m_outstandingInterestName = m_syncPrefix;
ostringstream os;
os << *m_state->getDigest();
@@ -667,7 +657,6 @@
// checking if our own interest got satisfied
bool satisfiedOwnInterest = false;
{
- boost::recursive_mutex::scoped_lock lock (m_stateMutex);
satisfiedOwnInterest = (m_outstandingInterestName == name);
}
@@ -676,7 +665,7 @@
_LOG_DEBUG_ID ("Satisfied our own Interest. Re-expressing (hopefully with a new digest)");
time::Duration after = time::milliseconds(GET_RANDOM (m_reexpressionJitter));
- cout << "------------ reexpress interest after: " << after << " ms " << endl;
+ // cout << "------------ reexpress interest after: " << after << endl;
EventId eventId = m_scheduler.scheduleEvent (after,
bind (&SyncLogic::sendSyncInterest, this));
m_scheduler.cancelEvent (m_reexpressingInterestId);
@@ -688,7 +677,6 @@
SyncLogic::getRootDigest()
{
ostringstream os;
- boost::recursive_mutex::scoped_lock lock (m_stateMutex);
os << *m_state->getDigest();
return os.str();
}
@@ -696,15 +684,12 @@
size_t
SyncLogic::getNumberOfBranches () const
{
- boost::recursive_mutex::scoped_lock lock (m_stateMutex);
return m_state->getLeaves ().size ();
}
void
SyncLogic::printState () const
{
- boost::recursive_mutex::scoped_lock lock (m_stateMutex);
-
BOOST_FOREACH (const boost::shared_ptr<Sync::Leaf> leaf, m_state->getLeaves ())
{
std::cout << *leaf << std::endl;
@@ -714,8 +699,6 @@
std::map<std::string, bool>
SyncLogic::getBranchPrefixes() const
{
- boost::recursive_mutex::scoped_lock lock (m_stateMutex);
-
std::map<std::string, bool> m;
BOOST_FOREACH (const boost::shared_ptr<Sync::Leaf> leaf, m_state->getLeaves ())
diff --git a/src/sync-logic.h b/src/sync-logic.h
index 4e9e69b..5c3abe4 100644
--- a/src/sync-logic.h
+++ b/src/sync-logic.h
@@ -24,8 +24,6 @@
#ifndef SYNC_LOGIC_H
#define SYNC_LOGIC_H
-#include <boost/shared_ptr.hpp>
-#include <boost/thread/recursive_mutex.hpp>
#include <boost/random.hpp>
#include <memory>
#include <map>
@@ -198,7 +196,6 @@
private:
FullStatePtr m_state;
DiffStateContainer m_log;
- mutable boost::recursive_mutex m_stateMutex;
ndn::Name m_outstandingInterestName;
SyncInterestTable m_syncInterestTable;
@@ -220,8 +217,8 @@
boost::variate_generator<boost::mt19937&, boost::uniform_int<> > m_reexpressionJitter;
static const int m_unknownDigestStoreTime = 10; // seconds
- static const int m_syncResponseFreshness = 100;
- static const int m_syncInterestReexpress = 4;
+ static const int m_syncResponseFreshness = 1000; // MUST BE dividable by 1000!!!
+ static const int m_syncInterestReexpress = 4; // seconds
static const int m_defaultRecoveryRetransmitInterval = 200; // milliseconds
uint32_t m_recoveryRetransmissionInterval; // milliseconds
diff --git a/src/sync-name-info.cc b/src/sync-name-info.cc
index 056001b..30986cd 100644
--- a/src/sync-name-info.cc
+++ b/src/sync-name-info.cc
@@ -28,6 +28,5 @@
NameInfo::NameMap NameInfo::m_names;
size_t NameInfo::m_ids = 0;
-boost::mutex NameInfo::m_namesMutex;
} // Sync
diff --git a/src/sync-name-info.h b/src/sync-name-info.h
index 26bca67..2f7c165 100644
--- a/src/sync-name-info.h
+++ b/src/sync-name-info.h
@@ -25,7 +25,6 @@
#include <boost/shared_ptr.hpp>
#include <boost/weak_ptr.hpp>
-#include <boost/thread/mutex.hpp>
#include <map>
#include <string>
#include "sync-digest.h"
@@ -86,7 +85,6 @@
typedef std::map<std::string, const_weak_ptr> NameMap;
static size_t m_ids;
static NameMap m_names;
- static boost::mutex m_namesMutex;
};
typedef boost::shared_ptr<NameInfo> NameInfoPtr;
diff --git a/src/sync-scheduler.cc b/src/sync-scheduler.cc
deleted file mode 100644
index 5c19f76..0000000
--- a/src/sync-scheduler.cc
+++ /dev/null
@@ -1,133 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2012 University of California, Los Angeles
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu>
- * Chaoyi Bian <bcy@pku.edu.cn>
- * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
- */
-
-#include "sync-scheduler.h"
-#include "sync-logging.h"
-
-using namespace boost;
-using namespace std;
-
-INIT_LOGGER ("Scheduler");
-
-namespace Sync {
-
-Scheduler::Scheduler ()
- : m_threadRunning (true)
-{
- m_thread = thread (&Scheduler::threadLoop, this);
-}
-
-Scheduler::~Scheduler ()
-{
- m_threadRunning = false;
- // cout << "Requested stop" << this_thread::get_id () << endl;
- m_thread.interrupt ();
- m_thread.join ();
-}
-
-void
-Scheduler::threadLoop ()
-{
- _LOG_FUNCTION (this);
- while (m_threadRunning)
- {
- try
- {
- boost::system_time nextTime;
- {
- boost::unique_lock<boost::mutex> lock (m_eventsMutex);
- while (m_threadRunning && m_events.size () == 0)
- {
- m_eventsCondition.wait (lock);
- // cout << "Got something" << endl;
- }
-
- if (m_events.size () == 0) continue;
-
- nextTime = m_events.begin ()->time;
- }
-
- if (nextTime > get_system_time ())
- {
- this_thread::sleep (nextTime - get_system_time ());
-
- // sleeping
-
- if (nextTime > get_system_time ())
- {
- // cout << "expected here" << endl;
- continue; // something changes, try again
- }
- }
-
- if (!m_threadRunning) continue;
-
- Event event;
-
- {
- boost::lock_guard<boost::mutex> lock (m_eventsMutex);
-
- if (m_events.size () == 0)
- {
- // cout << "Here" << endl;
- continue;
- }
-
- event = m_events.begin ()->event;
- m_events.erase (m_events.begin ());
- }
-
- event (); // calling the event outside the locked mutex
- }
- catch (thread_interrupted &e)
- {
- // cout << "interrupted: " << this_thread::get_id () << endl;
- // do nothing
- }
- }
- // cout << "Exited...\n";
-}
-
-void
-Scheduler::schedule (const TimeDuration &reltime, Event event, uint32_t label)
-{
- boost::lock_guard<boost::mutex> lock (m_eventsMutex);
- m_events.insert (LogicEvent (boost::get_system_time () + reltime, event, label));
-
- m_eventsCondition.notify_one ();
- m_thread.interrupt (); // interrupt sleep, if currently sleeping
-}
-
-void
-Scheduler::cancel (uint32_t label)
-{
- // cout << "Canceling label " << label << " size: " << m_events.size () << endl;
- boost::lock_guard<boost::mutex> lock (m_eventsMutex);
- m_events.get<byLabel> ().erase (label);
- // cout << "Canceled label " << label << " size: " << m_events.size () << endl;
-
- m_eventsCondition.notify_one ();
- m_thread.interrupt (); // interrupt sleep, if currently sleeping
-}
-
-
-} // Sync
diff --git a/src/sync-scheduler.h b/src/sync-scheduler.h
deleted file mode 100644
index 155c6ba..0000000
--- a/src/sync-scheduler.h
+++ /dev/null
@@ -1,97 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2012 University of California, Los Angeles
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu>
- * Chaoyi Bian <bcy@pku.edu.cn>
- * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
- */
-
-#ifndef SYNC_SCHEDULER_H
-#define SYNC_SCHEDULER_H
-
-#include <boost/thread/thread.hpp>
-#include <boost/thread/mutex.hpp>
-
-#include "sync-logic-event-container.h"
-
-#define TIME_SECONDS(number) boost::posix_time::seconds (number)
-#define TIME_MILLISECONDS(number) boost::posix_time::milliseconds(number)
-#define TIME_NOW boost::get_system_time ()
-typedef boost::posix_time::time_duration TimeDuration;
-typedef boost::system_time TimeAbsolute;
-
-namespace Sync {
-
-/**
- * @ingroup sync
- * @brief General purpose event scheduler
- *
- * This class internally runs a thread and events can be scheduled by specifying an absolute or relative time of the event
- */
-class Scheduler
-{
-public:
- /**
- * @brief Default constructor. Thread will be created
- */
- Scheduler ();
- /**
- * @brief Destructor. Thread will be nicely stopped
- */
- ~Scheduler ();
-
- /**
- * @brief Schedule an event at relative time 'reltime'
- * @param reltime Relative time
- * @param event function to be called at the time
- * @param label Label for the event
- */
- void
- schedule (const TimeDuration &reltime, Event event, uint32_t label);
-
- /**
- * @brief Cancel all events for the label
- * @param label Label of the event that needs to be cancelled
- */
- void
- cancel (uint32_t label);
-
-#ifdef _DEBUG
- size_t
- getEventsSize ()
- {
- boost::lock_guard<boost::mutex> lock (m_eventsMutex);
- return m_events.size ();
- }
-#endif
-
-private:
- void
- threadLoop ();
-
-private:
- EventsContainer m_events;
- boost::condition_variable m_eventsCondition;
- boost::mutex m_eventsMutex;
-
- boost::thread m_thread;
- bool m_threadRunning;
-};
-
-}
-
-#endif // SYNC_SCHEDULER_H
diff --git a/src/sync-socket.cc b/src/sync-socket.cc
index 259e730..cb41b30 100644
--- a/src/sync-socket.cc
+++ b/src/sync-socket.cc
@@ -28,6 +28,8 @@
namespace Sync {
+using ndn::shared_ptr;
+
SyncSocket::SyncSocket (const Name &syncPrefix,
shared_ptr<Validator> validator,
shared_ptr<Face> face,
@@ -58,7 +60,7 @@
Data data(dataName);
data.setContent(reinterpret_cast<const uint8_t*>(buf), len);
- data.setFreshnessPeriod(freshness);
+ data.setFreshnessPeriod(1000*freshness);
m_keyChain->sign(data);
diff --git a/src/sync-socket.h b/src/sync-socket.h
index f1af423..35fd8ed 100644
--- a/src/sync-socket.h
+++ b/src/sync-socket.h
@@ -18,16 +18,16 @@
* Author: Yingdi Yu <yingdi@cs.ucla.edu>
*/
-#ifndef SYNC_SOCKET_H
-#define SYNC_SOCKET_H
-
-#include "sync-logic.h"
-#include "sync-seq-no.h"
+#ifndef _SYNC_SOCKET_H
+#define _SYNC_SOCKET_H
#include <ndn-cpp-dev/face.hpp>
#include <ndn-cpp-dev/security/validator.hpp>
#include <ndn-cpp-dev/security/key-chain.hpp>
+#include "sync-logic.h"
+#include "sync-seq-no.h"
+
#include <utility>
#include <map>
#include <vector>
diff --git a/src/sync-std-name-info.cc b/src/sync-std-name-info.cc
index 95169c4..2c0313d 100644
--- a/src/sync-std-name-info.cc
+++ b/src/sync-std-name-info.cc
@@ -21,7 +21,6 @@
*/
#include "sync-std-name-info.h"
-#include "boost/thread/locks.hpp"
// using namespace std;
using namespace boost;
@@ -32,8 +31,6 @@
NameInfoConstPtr
StdNameInfo::FindOrCreate (const std::string &key)
{
- mutex::scoped_lock namesLock (m_namesMutex);
-
// std::cout << "FindOrCreate: " << m_names.size () << "\n";
NameInfoConstPtr ret;
@@ -70,8 +67,6 @@
StdNameInfo::~StdNameInfo ()
{
- mutex::scoped_lock namesLock (m_namesMutex);
-
// cout << "Destructor for " << m_name << "\n";
m_names.erase (toString ());
}