Remove legacy code and rename files to new naming convention
diff --git a/adhoc/adhoc.h b/adhoc/adhoc.hpp
similarity index 100%
rename from adhoc/adhoc.h
rename to adhoc/adhoc.hpp
diff --git a/cmd/csd.cc b/cmd/csd.cpp
similarity index 100%
rename from cmd/csd.cc
rename to cmd/csd.cpp
diff --git a/cmd/dump-db.cc b/cmd/dump-db.cpp
similarity index 100%
rename from cmd/dump-db.cc
rename to cmd/dump-db.cpp
diff --git a/disabled/ndnx-tunnel.cpp b/disabled/ndnx-tunnel.cpp
deleted file mode 100644
index 0984d26..0000000
--- a/disabled/ndnx-tunnel.cpp
+++ /dev/null
@@ -1,175 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2013 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>
- * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
- */
-
-#include "ndnx-tunnel.h"
-#include "ndnx-pco.h"
-
-namespace Ndnx
-{
-
-NdnxTunnel::NdnxTunnel()
- : NdnxWrapper()
- , m_localPrefix("/")
-{
- refreshLocalPrefix();
-}
-
-NdnxTunnel::~NdnxTunnel()
-{
-}
-
-void
-NdnxTunnel::refreshLocalPrefix()
-{
- Name newPrefix = getLocalPrefix();
- if (!newPrefix.toString().empty() && m_localPrefix != newPrefix)
- {
- NdnxWrapper::clearInterestFilter(m_localPrefix);
- NdnxWrapper::setInterestFilter(newPrefix, bind(&NdnxTunnel::handleTunneledInterest, this, _1));
- m_localPrefix = newPrefix;
- }
-}
-
-int
-NdnxTunnel::sendInterest (const Name &interest, const Closure &closure, const Selectors &selectors)
-{
- Name tunneledInterest = queryRoutableName(interest);
-
- NdnxWrapper::sendInterest(tunneledInterest,
- TunnelClosure(closure, *this, interest),
- selectors);
-
- return 0;
-}
-
-void
-NdnxTunnel::handleTunneledData(const Name &name, const Bytes &tunneledData, const Closure::DataCallback &originalDataCallback)
-{
- ParsedContentObject pco(tunneledData);
- originalDataCallback(pco.name(), pco.content());
-}
-
-int
-NdnxTunnel::publishData(const Name &name, const unsigned char *buf, size_t len, int freshness)
-{
- Bytes content = createContentObject(name, buf, len, freshness);
- storeContentObject(name, content);
-
- return publishContentObject(name, content, freshness);
-}
-
-int
-NdnxTunnel::publishContentObject(const Name &name, const Bytes &contentObject, int freshness)
-{
- Name tunneledName = m_localPrefix + name;
- Bytes tunneledCo = createContentObject(tunneledName, head(contentObject), contentObject.size(), freshness);
- return putToNdnd(tunneledCo);
-}
-
-void
-NdnxTunnel::handleTunneledInterest(const Name &tunneledInterest)
-{
- // The interest must have m_localPrefix as a prefix (component-wise), otherwise ndnd would not deliver it to us
- Name interest = tunneledInterest.getPartialName(m_localPrefix.size());
-
- ReadLock lock(m_ritLock);
-
- // This is linear scan, but should be acceptable under the assumption that the caller wouldn't be listening to a lot prefixes (as of now, most app listen to one or two prefixes)
- for (RitIter it = m_rit.begin(); it != m_rit.end(); it++)
- {
- // evoke callback for any prefix that is the prefix of the interest
- if (isPrefix(it->first, interest))
- {
- (it->second)(interest);
- }
- }
-}
-
-bool
-NdnxTunnel::isPrefix(const Name &prefix, const Name &name)
-{
- if (prefix.size() > name.size())
- {
- return false;
- }
-
- int size = prefix.size();
- for (int i = 0; i < size; i++)
- {
- if (prefix.getCompAsString(i) != name.getCompAsString(i))
- {
- return false;
- }
- }
-
- return true;
-}
-
-int
-NdnxTunnel::setInterestFilter(const Name &prefix, const InterestCallback &interestCallback)
-{
- WriteLock lock(m_ritLock);
- // make sure copy constructor for boost::function works properly
- m_rit.insert(make_pair(prefix, interestCallback));
- return 0;
-}
-
-void
-NdnxTunnel::clearInterestFilter(const Name &prefix)
-{
- WriteLock lock(m_ritLock);
- // remove all
- m_rit.erase(prefix);
-}
-
-TunnelClosure::TunnelClosure(const DataCallback &dataCallback, NdnxTunnel &tunnel,
- const Name &originalInterest, const TimeoutCallback &timeoutCallback)
- : Closure(dataCallback, timeoutCallback)
- , m_tunnel(tunnel)
- , m_originalInterest(originalInterest)
-{
-}
-
-TunnelClosure::TunnelClosure(const Closure &closure, NdnxTunnel &tunnel, const Name &originalInterest)
- : Closure(closure)
- , m_tunnel(tunnel)
-{
-}
-
-Closure *
-TunnelClosure::dup() const
-{
- return new TunnelClosure (*this);
-}
-
-void
-TunnelClosure::runDataCallback(const Name &name, const Bytes &content)
-{
- m_tunnel.handleTunneledData(name, content, m_dataCallback);
-}
-
-Closure::TimeoutCallbackReturnValue
-TunnelClosure::runTimeoutCallback(const Name &interest)
-{
- return Closure::runTimeoutCallback(m_originalInterest);
-}
-
-} // Ndnx
diff --git a/disabled/ndnx-tunnel.h b/disabled/ndnx-tunnel.h
deleted file mode 100644
index 1722eb1..0000000
--- a/disabled/ndnx-tunnel.h
+++ /dev/null
@@ -1,127 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2013 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>
- * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
- */
-
-#ifndef NDNX_TUNNEL_H
-#define NDNX_TUNNEL_H
-
-#include "ndnx-wrapper.h"
-
-#define _OVERRIDE
-#ifdef __GNUC__
-#if __GNUC_MAJOR >= 4 && __GNUC_MINOR__ >= 7
- #undef _OVERRIDE
- #define _OVERRIDE override
-#endif // __GNUC__ version
-#endif // __GNUC__
-
-// Eventually, Sync::NdnxWrapper should be moved to this namespace.
-// It has nothing to do with Sync.
-namespace Ndnx
-{
-
-class NdnxTunnel : public NdnxWrapper
-{
-public:
- typedef std::multimap<Name, InterestCallback> RegisteredInterestTable;
- typedef std::multimap<Name, InterestCallback>::iterator RitIter;
-
-
- NdnxTunnel();
- virtual ~NdnxTunnel();
-
- // name is topology-independent
- virtual int
- publishData(const Name &name, const unsigned char *buf, size_t len, int freshness) _OVERRIDE;
-
- int
- publishContentObject(const Name &name, const Bytes &contentObject, int freshness);
-
- virtual int
- sendInterest (const Name &interest, const Closure &closure, const Selectors &selectors = Selectors());
-
-
- // prefix is topology-independent
- virtual int
- setInterestFilter(const Name &prefix, const InterestCallback &interestCallback) _OVERRIDE;
-
- // prefix is topology-independent
- // this clears all entries with key equal to prefix
- virtual void
- clearInterestFilter(const Name &prefix) _OVERRIDE;
-
- // subclass should provide translation service from topology-independent name
- // to routable name
- virtual Name
- queryRoutableName(const Name &name) = 0;
-
- // subclass should implement the function to store ContentObject with topoloy-independent
- // name to the permanent storage; default does nothing
- virtual void
- storeContentObject(const Name &name, const Bytes &content) {}
-
- // should be called when connect to a different network
- void
- refreshLocalPrefix();
-
- static bool
- isPrefix(const Name &prefix, const Name &name);
-
- void
- handleTunneledInterest(const Name &tunneldInterest);
-
- void
- handleTunneledData(const Name &name, const Bytes &tunneledData, const Closure::DataCallback &originalDataCallback);
-
-private:
- NdnxTunnel(const NdnxTunnel &other) {}
-
-protected:
- // need a way to update local prefix, perhaps using macports trick, but eventually we need something more portable
- Name m_localPrefix;
- RegisteredInterestTable m_rit;
- Lock m_ritLock;
-};
-
-class TunnelClosure : public Closure
-{
-public:
- TunnelClosure(const DataCallback &dataCallback, NdnxTunnel &tunnel,
- const Name &originalInterest, const TimeoutCallback &timeoutCallback = TimeoutCallback());
-
- TunnelClosure(const Closure &closure, NdnxTunnel &tunnel, const Name &originalInterest);
-
- virtual void
- runDataCallback(const Name &name, const Bytes &content) _OVERRIDE;
-
- virtual TimeoutCallbackReturnValue
- runTimeoutCallback(const Name &interest) _OVERRIDE;
-
- virtual Closure *
- dup() const;
-
-private:
- NdnxTunnel &m_tunnel;
- Name m_originalInterest;
-};
-
-};
-
-#endif
diff --git a/disabled/test-ndnx-tunnel.cc b/disabled/test-ndnx-tunnel.cc
deleted file mode 100644
index baa3ec7..0000000
--- a/disabled/test-ndnx-tunnel.cc
+++ /dev/null
@@ -1,121 +0,0 @@
-#include "ndnx-tunnel.h"
-#include "ndnx-closure.h"
-#include "ndnx-name.h"
-#include "ndnx-pco.h"
-#include <unistd.h>
-
-#include <boost/test/unit_test.hpp>
-
-
-using namespace Ndnx;
-using namespace std;
-using namespace boost;
-
-BOOST_AUTO_TEST_SUITE(NdnxTunnelTests)
-
-class DummyTunnel : public NdnxTunnel
-{
-public:
- DummyTunnel();
- virtual ~DummyTunnel() {}
-
- virtual Name
- queryRoutableName(const Name &name);
-
- void
- overridePrefix();
-
-};
-
-DummyTunnel::DummyTunnel() : NdnxTunnel()
-{
- m_localPrefix = Name("/local");
-}
-
-void
-DummyTunnel::overridePrefix()
-{
- NdnxWrapper::setInterestFilter(m_localPrefix, bind(&DummyTunnel::handleTunneledInterest, this, _1));
-}
-
-Name
-DummyTunnel::queryRoutableName (const Name &name)
-{
- return Name("/local") + name;
-}
-
-NdnxWrapperPtr t1(new DummyTunnel());
-NdnxWrapperPtr t2(new DummyTunnel());
-NdnxWrapperPtr c1(new NdnxWrapper());
-
-DummyTunnel t3;
-
-// global data callback counter;
-int g_dc_i = 0;
-int g_dc_o = 0;
-int g_ic = 0;
-
-void innerCallback(const Name &name, const Bytes &content)
-{
- g_dc_i ++;
- string str((const char *)&content[0], content.size());
- BOOST_CHECK_EQUAL(name, str);
-}
-
-void outerCallback(const Name &name, const Bytes &content)
-{
- g_dc_o ++;
-}
-
-void interestCallback(const Name &name)
-{
- string strName = name.toString();
- t3.publishData(name, (const unsigned char *)strName.c_str(), strName.size(), 5);
- g_ic++;
-}
-
-BOOST_AUTO_TEST_CASE (NdnxTunnelTest)
-{
- // test publish
- string inner = "/hello";
-
- g_dc_o = 0;
- t1->publishData(Name(inner), (const unsigned char *)inner.c_str(), inner.size(), 5);
- usleep(100000);
-
- c1->sendInterest(Name("/local/hello"), Closure(bind(outerCallback, _1, _2)));
- usleep(100000);
- // it is indeed published as /local/hello
- BOOST_CHECK_EQUAL(g_dc_o, 1);
-
- g_dc_i = 0;
- t2->sendInterest(Name(inner), Closure(bind(innerCallback, _1, _2)));
- usleep(100000);
- BOOST_CHECK_EQUAL(g_dc_i, 1);
-}
-
-BOOST_AUTO_TEST_CASE (NdnxTunnelRegister)
-{
-
- g_ic = 0;
- g_dc_i = 0;
- t3.overridePrefix();
- t3.setInterestFilter(Name("/t3"), bind(interestCallback, _1));
- usleep(100000);
- Closure innerClosure (bind(innerCallback, _1, _2));
- t1->sendInterest(Name("/t3/hello"), innerClosure);
- usleep(100000);
- BOOST_CHECK_EQUAL(g_dc_i, 1);
- BOOST_CHECK_EQUAL(g_ic, 1);
-
- t3.clearInterestFilter(Name("/t3"));
- usleep(100000);
- t1->sendInterest(Name("/t3/hello-there"), innerClosure);
- usleep(100000);
- BOOST_CHECK_EQUAL(g_dc_i, 1);
- BOOST_CHECK_EQUAL(g_ic, 1);
-
-}
-
-
-BOOST_AUTO_TEST_SUITE_END()
diff --git a/executor/executor.cc b/executor/executor.cc
deleted file mode 100644
index d9f3893..0000000
--- a/executor/executor.cc
+++ /dev/null
@@ -1,138 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2013 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>
- * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
- */
-
-#include "executor.h"
-#include "logging.h"
-
-INIT_MEMBER_LOGGER(Executor,"Executor")
-
-using namespace std;
-using namespace boost;
-
-Executor::Executor (int poolSize)
- : m_needStop (true)
- , m_poolSize (poolSize)
-{
-}
-
-Executor::~Executor()
-{
- _LOG_DEBUG ("Enter destructor");
- shutdown ();
- _LOG_DEBUG ("Exit destructor");
-}
-
-void
-Executor::start ()
-{
- if (m_needStop)
- {
- m_needStop = false;
- for (int i = 0; i < m_poolSize; i++)
- {
- m_group.create_thread (bind(&Executor::run, this));
- }
- }
-}
-
-void
-Executor::shutdown ()
-{
- if (!m_needStop)
- {
- m_needStop = true;
- _LOG_DEBUG ("Iterrupting all");
- m_group.interrupt_all ();
- _LOG_DEBUG ("Join all");
- m_group.join_all ();
- }
-}
-
-
-void
-Executor::execute(const Job &job)
-{
- _LOG_DEBUG ("Add to job queue");
-
- Lock lock(m_mutex);
- bool queueWasEmpty = m_queue.empty ();
- m_queue.push_back(job);
-
- // notify working threads if the queue was empty
- if (queueWasEmpty)
- {
- m_cond.notify_one ();
- }
-}
-
-int
-Executor::poolSize()
-{
- return m_group.size();
-}
-
-int
-Executor::jobQueueSize()
-{
- Lock lock(m_mutex);
- return m_queue.size();
-}
-
-void
-Executor::run ()
-{
- _LOG_DEBUG ("Start thread");
-
- while(!m_needStop)
- {
- Job job = waitForJob();
-
- _LOG_DEBUG (">>> enter job");
- job (); // even if job is "null", nothing bad will happen
- _LOG_DEBUG ("<<< exit job");
- }
-
- _LOG_DEBUG ("Executor thread finished");
-}
-
-Executor::Job
-Executor::waitForJob()
-{
- Lock lock(m_mutex);
-
- // wait until job queue is not empty
- while (m_queue.empty())
- {
- _LOG_DEBUG ("Unlocking mutex for wait");
- m_cond.wait(lock);
- _LOG_DEBUG ("Re-locking mutex after wait");
- }
-
- _LOG_DEBUG ("Got signal on condition");
-
- Job job;
- if (!m_queue.empty ()) // this is not always guaranteed, especially after interruption from destructor
- {
- job = m_queue.front();
- m_queue.pop_front();
- }
- return job;
-}
diff --git a/executor/executor.h b/executor/executor.h
deleted file mode 100644
index 6ed3d62..0000000
--- a/executor/executor.h
+++ /dev/null
@@ -1,93 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2013 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>
- * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
- */
-
-#ifndef EXECUTOR_H
-#define EXECUTOR_H
-
-#include <boost/function.hpp>
-#include <boost/shared_ptr.hpp>
-#include <boost/thread/condition_variable.hpp>
-#include <boost/thread/mutex.hpp>
-#include <boost/thread/locks.hpp>
-#include <boost/thread/thread.hpp>
-#include <deque>
-
-#include "logging.h"
-
-/* A very simple executor to execute submitted tasks immediately or
- * in the future (depending on whether there is idle thread)
- * A fixed number of threads are created for executing tasks;
- * The policy is FIFO
- * No cancellation of submitted tasks
- */
-
-class Executor
-{
-public:
- typedef boost::function<void ()> Job;
-
- Executor(int poolSize);
- ~Executor();
-
- // execute the job immediately or sometime in the future
- void
- execute(const Job &job);
-
- int
- poolSize();
-
-// only for test
- int
- jobQueueSize();
-
- void
- start ();
-
- void
- shutdown ();
-
-private:
- void
- run();
-
- Job
- waitForJob();
-
-private:
- typedef std::deque<Job> JobQueue;
- typedef boost::mutex Mutex;
- typedef boost::unique_lock<Mutex> Lock;
- typedef boost::condition_variable Cond;
- typedef boost::thread Thread;
- typedef boost::thread_group ThreadGroup;
- JobQueue m_queue;
- Mutex m_mutex;
- Cond m_cond;
- ThreadGroup m_group;
-
- volatile bool m_needStop;
- int m_poolSize;
-
- MEMBER_LOGGER
-};
-
-typedef boost::shared_ptr<Executor> ExecutorPtr;
-#endif // EXECUTOR_H
diff --git a/fs-watcher/fs-watcher.cc b/fs-watcher/fs-watcher.cpp
similarity index 100%
rename from fs-watcher/fs-watcher.cc
rename to fs-watcher/fs-watcher.cpp
diff --git a/fs-watcher/fs-watcher.h b/fs-watcher/fs-watcher.hpp
similarity index 100%
rename from fs-watcher/fs-watcher.h
rename to fs-watcher/fs-watcher.hpp
diff --git a/gui/chronosharegui.h b/gui/chronosharegui.hpp
similarity index 100%
rename from gui/chronosharegui.h
rename to gui/chronosharegui.hpp
diff --git a/ndnx/ndnx-cert.cpp b/ndnx/ndnx-cert.cpp
deleted file mode 100644
index 8dacd60..0000000
--- a/ndnx/ndnx-cert.cpp
+++ /dev/null
@@ -1,127 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2013 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>
- * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
- */
-#include "ndnx-cert.h"
-#include <tinyxml.h>
-#include <boost/lexical_cast.hpp>
-#include "logging.h"
-
-INIT_LOGGER ("Ndnx.Cert");
-
-using namespace std;
-
-namespace Ndnx {
-
-Cert::Cert()
- : m_pkey(0)
- , m_meta("", "", 0, 0)
-{
-}
-
-Cert::Cert(const PcoPtr &keyObject, const PcoPtr &metaObject = PcoPtr())
- : m_pkey(0)
- , m_meta("", "", 0, 0)
-{
- m_name = keyObject->name();
- m_rawKeyBytes = keyObject->content();
- m_keyHash = *(Hash::FromBytes(m_rawKeyBytes));
- m_pkey = ndn_d2i_pubkey(head(m_rawKeyBytes), m_rawKeyBytes.size());
- updateMeta(metaObject);
-}
-
-Cert::~Cert()
-{
- if (m_pkey != 0)
- {
- ndn_pubkey_free(m_pkey);
- m_pkey = 0;
- }
-}
-
-void
-Cert::updateMeta(const PcoPtr &metaObject)
-{
- if (metaObject)
- {
- TiXmlDocument doc;
- Bytes xml = metaObject->content();
- // just make sure it's null terminated as it's required by TiXmlDocument::parse
- xml.push_back('\0');
- doc.Parse((const char *)(head(xml)));
- if (!doc.Error())
- {
- TiXmlElement *root = doc.RootElement();
- for (TiXmlElement *child = root->FirstChildElement(); child; child = child->NextSiblingElement())
- {
- string elemName = child->Value();
- string text = child->GetText();
- if (elemName == "Name")
- {
- m_meta.realworldID = text;
- }
- else if (elemName == "Affiliation")
- {
- m_meta.affiliation = text;
- }
- else if (elemName == "Valid_to")
- {
- m_meta.validTo = boost::lexical_cast<time_t>(text);
- }
- else if (elemName == "Valid_from")
- {
- // this is not included in the key meta yet
- // but it should eventually be there
- }
- else
- {
- // ignore known stuff
- }
- }
- }
- else
- {
- _LOG_ERROR("Cannot parse meta info:" << std::string((const char *)head(xml), xml.size()));
- }
- }
-}
-
-Cert::VALIDITY
-Cert::validity()
-{
- if (m_meta.validFrom == 0 && m_meta.validTo == 0)
- {
- return OTHER;
- }
-
- time_t now = time(NULL);
- if (now < m_meta.validFrom)
- {
- return NOT_YET_VALID;
- }
-
- if (now >= m_meta.validTo)
- {
- return EXPIRED;
- }
-
- return WITHIN_VALID_TIME_SPAN;
-}
-
-} // Ndnx
diff --git a/ndnx/ndnx-cert.h b/ndnx/ndnx-cert.h
deleted file mode 100644
index 17f06d5..0000000
--- a/ndnx/ndnx-cert.h
+++ /dev/null
@@ -1,99 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2013 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>
- * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
- */
-
-#ifndef NDNX_CERT_H
-#define NDNX_CERT_H
-
-#include "ndnx-common.h"
-#include "ndnx-name.h"
-#include "ndnx-pco.h"
-#include "hash-helper.h"
-#include <boost/shared_ptr.hpp>
-
-namespace Ndnx {
-
-class Cert
-{
-public:
- enum VALIDITY
- {
- NOT_YET_VALID,
- WITHIN_VALID_TIME_SPAN,
- EXPIRED,
- OTHER
- };
-
- Cert();
- Cert(const PcoPtr &keyObject, const PcoPtr &metaObject);
- ~Cert();
-
- void
- updateMeta(const PcoPtr &metaObject);
-
- Name
- name() { return m_name; }
-
- Bytes
- rawKeyBytes() { return m_rawKeyBytes; }
-
- Hash
- keyDigest() { return m_keyHash; }
-
- std::string
- realworldID() { return m_meta.realworldID; }
-
- std::string
- affilication() { return m_meta.affiliation; }
-
- ndn_pkey *
- pkey() { return m_pkey; }
-
- VALIDITY
- validity();
-
-private:
- struct Meta
- {
- Meta(std::string id, std::string affi, time_t from, time_t to)
- : realworldID(id)
- , affiliation(affi)
- , validFrom(from)
- , validTo(to)
- {
- }
- std::string realworldID;
- std::string affiliation;
- time_t validFrom;
- time_t validTo;
- };
-
- Name m_name;
- Hash m_keyHash; // publisherPublicKeyHash
- Bytes m_rawKeyBytes;
- ndn_pkey *m_pkey;
- Meta m_meta;
-};
-
-typedef boost::shared_ptr<Cert> CertPtr;
-
-}
-
-#endif // NDNX_CERT_H
diff --git a/ndnx/ndnx-charbuf.cc b/ndnx/ndnx-charbuf.cc
deleted file mode 100644
index 842c840..0000000
--- a/ndnx/ndnx-charbuf.cc
+++ /dev/null
@@ -1,71 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2013 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>
- * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
- */
-
-#include "ndnx-charbuf.h"
-
-using namespace std;
-
-namespace Ndnx {
-
-void
-NdnxCharbuf::init(ndn_charbuf *buf)
-{
- if (buf != NULL)
- {
- m_buf = ndn_charbuf_create();
- ndn_charbuf_reserve(m_buf, buf->length);
- memcpy(m_buf->buf, buf->buf, buf->length);
- m_buf->length = buf->length;
- }
-}
-
-NdnxCharbuf::NdnxCharbuf()
- : m_buf(NULL)
-{
- m_buf = ndn_charbuf_create();
-}
-
-NdnxCharbuf::NdnxCharbuf(ndn_charbuf *buf)
- : m_buf(NULL)
-{
- init(buf);
-}
-
-NdnxCharbuf::NdnxCharbuf(const NdnxCharbuf &other)
- : m_buf (NULL)
-{
- init(other.m_buf);
-}
-
-NdnxCharbuf::NdnxCharbuf(const void *buf, size_t length)
-{
- m_buf = ndn_charbuf_create ();
- ndn_charbuf_reserve (m_buf, length);
- memcpy (m_buf->buf, buf, length);
- m_buf->length = length;
-}
-
-NdnxCharbuf::~NdnxCharbuf()
-{
- ndn_charbuf_destroy(&m_buf);
-}
-
-}
diff --git a/ndnx/ndnx-charbuf.h b/ndnx/ndnx-charbuf.h
deleted file mode 100644
index 3007eee..0000000
--- a/ndnx/ndnx-charbuf.h
+++ /dev/null
@@ -1,68 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2012-2013 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>
- * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
- */
-
-#ifndef NDNX_NDNX_CHARBUF_H
-#define NDNX_NDNX_CHARBUF_H
-
-#include "ndnx-common.h"
-#include <boost/shared_ptr.hpp>
-
-namespace Ndnx {
-
-class NdnxCharbuf;
-typedef boost::shared_ptr<NdnxCharbuf> NdnxCharbufPtr;
-
-// This class is mostly used in NdnxWrapper; users should not be directly using this class
-// The main purpose of this class to is avoid manually create and destroy charbuf everytime
-class NdnxCharbuf
-{
-public:
- NdnxCharbuf();
- NdnxCharbuf(ndn_charbuf *buf);
- NdnxCharbuf(const NdnxCharbuf &other);
- NdnxCharbuf(const void *buf, size_t length);
- ~NdnxCharbuf();
-
- // expose internal data structure, use with caution!!
- ndn_charbuf *
- getBuf() { return m_buf; }
-
- const ndn_charbuf *
- getBuf() const { return m_buf; }
-
- const unsigned char *
- buf () const
- { return m_buf->buf; }
-
- size_t
- length () const
- { return m_buf->length; }
-
-private:
- void init(ndn_charbuf *buf);
-
-protected:
- ndn_charbuf *m_buf;
-};
-
-}
-
-#endif // NDNX_NDNX_CHARBUF_H
diff --git a/ndnx/ndnx-closure.cpp b/ndnx/ndnx-closure.cpp
deleted file mode 100644
index 1a96582..0000000
--- a/ndnx/ndnx-closure.cpp
+++ /dev/null
@@ -1,112 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2013 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>
- * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
- */
-
-#include "ndnx-closure.h"
-
-namespace Ndnx {
-
-Closure::Closure(const DataCallback &dataCallback, const TimeoutCallback &timeoutCallback)
- : m_timeoutCallback (timeoutCallback)
- , m_dataCallback (dataCallback)
-{
-}
-
-Closure::~Closure ()
-{
-}
-
-void
-Closure::runTimeoutCallback(Name interest, const Closure &closure, Selectors selectors)
-{
- if (!m_timeoutCallback.empty ())
- {
- m_timeoutCallback (interest, closure, selectors);
- }
-}
-
-
-void
-Closure::runDataCallback(Name name, PcoPtr content)
-{
- if (!m_dataCallback.empty ())
- {
- m_dataCallback (name, content);
- }
-}
-
-////////////////////////////////////////////////////////////////////////////////////////////////////////
-////////////////////////////////////////////////////////////////////////////////////////////////////////
-////////////////////////////////////////////////////////////////////////////////////////////////////////
-////////////////////////////////////////////////////////////////////////////////////////////////////////
-////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-// ExecutorClosure::ExecutorClosure(const Closure &closure, ExecutorPtr executor)
-// : Closure(closure.m_dataCallback, closure.m_timeoutCallback)
-// , m_executor(executor)
-// {
-// }
-
-// ExecutorClosure::~ExecutorClosure()
-// {
-// }
-
-// void
-// ExecutorClosure::runDataCallback(Name name, PcoPtr content)
-// {
-// m_executor->execute(boost::bind(&Closure::runDataCallback, this, name, content));
-// }
-
-// // void
-// // ExecutorClosure::execute(Name name, PcoPtr content)
-// // {
-// // Closure::runDataCallback(name, content);
-// // }
-
-
-////////////////////////////////////////////////////////////////////////////////////////////////////////
-////////////////////////////////////////////////////////////////////////////////////////////////////////
-////////////////////////////////////////////////////////////////////////////////////////////////////////
-////////////////////////////////////////////////////////////////////////////////////////////////////////
-////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-
-// ExecutorInterestClosure::ExecutorInterestClosure(const InterestCallback &callback, ExecutorPtr executor)
-// : m_callback(callback)
-// , m_executor(executor)
-// {
-// }
-
-// void
-// ExecutorInterestClosure::runInterestCallback(Name interest)
-// {
-// m_executor->execute(boost::bind(&ExecutorInterestClosure::execute, this, interest));
-// }
-
-// void
-// ExecutorInterestClosure::execute(Name interest)
-// {
-// if (!m_callback.empty())
-// {
-// m_callback(interest);
-// }
-// }
-
-} // Ndnx
diff --git a/ndnx/ndnx-closure.h b/ndnx/ndnx-closure.h
deleted file mode 100644
index 91e723a..0000000
--- a/ndnx/ndnx-closure.h
+++ /dev/null
@@ -1,96 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2013 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>
- * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
- */
-
-#ifndef NDNX_CLOSURE_H
-#define NDNX_CLOSURE_H
-
-#include "ndnx-common.h"
-#include "ndnx-name.h"
-#include "ndnx-selectors.h"
-#include "executor.h"
-
-namespace Ndnx {
-
-class ParsedContentObject;
-typedef boost::shared_ptr<ParsedContentObject> PcoPtr;
-
-class Closure
-{
-public:
- typedef boost::function<void (Name, PcoPtr pco)> DataCallback;
-
- typedef boost::function<void (Name, const Closure &, Selectors)> TimeoutCallback;
-
- Closure(const DataCallback &dataCallback, const TimeoutCallback &timeoutCallback = TimeoutCallback());
- virtual ~Closure();
-
- virtual void
- runDataCallback(Name name, Ndnx::PcoPtr pco);
-
- virtual void
- runTimeoutCallback(Name interest, const Closure &closure, Selectors selectors);
-
- virtual Closure *
- dup () const { return new Closure (*this); }
-
-public:
- TimeoutCallback m_timeoutCallback;
- DataCallback m_dataCallback;
-};
-
-// class ExecutorClosure : public Closure
-// {
-// public:
-// ExecutorClosure(const Closure &closure, ExecutorPtr executor);
-// virtual ~ExecutorClosure();
-
-// virtual void
-// runDataCallback(Name name, PcoPtr pco);
-
-// // private:
-// // void
-// // execute(Name nae, PcoPtr content);
-
-// private:
-// ExecutorPtr m_executor;
-// };
-
-// class ExecutorInterestClosure
-// {
-// public:
-// typedef boost::function<void (Name)> InterestCallback;
-// ExecutorInterestClosure(const InterestCallback &callback, ExecutorPtr executor);
-// virtual ~ExecutorInterestClosure() {}
-
-// void
-// runInterestCallback(Name interest);
-
-// void
-// execute(Name interest);
-
-// private:
-// InterestCallback m_callback;
-// ExecutorPtr m_executor;
-// };
-
-} // Ndnx
-
-#endif
diff --git a/ndnx/ndnx-common.h b/ndnx/ndnx-common.h
deleted file mode 100644
index fae1569..0000000
--- a/ndnx/ndnx-common.h
+++ /dev/null
@@ -1,176 +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>
- * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
- */
-
-#ifndef NDNX_COMMON_H
-#define NDNX_COMMON_H
-
-extern "C" {
-#include <ndn/ndn.h>
-#include <ndn/charbuf.h>
-#include <ndn/keystore.h>
-#include <ndn/uri.h>
-#include <ndn/bloom.h>
-#include <ndn/signing.h>
-}
-#include <vector>
-#include <boost/shared_ptr.hpp>
-#include <boost/exception/all.hpp>
-#include <boost/function.hpp>
-#include <string>
-#include <sstream>
-#include <map>
-#include <utility>
-#include <string.h>
-#include <boost/iostreams/filter/gzip.hpp>
-#include <boost/iostreams/filtering_stream.hpp>
-#include <boost/iostreams/device/back_inserter.hpp>
-#include <boost/range/iterator_range.hpp>
-#include <boost/make_shared.hpp>
-
-namespace io = boost::iostreams;
-
-namespace Ndnx {
-typedef std::vector<unsigned char> Bytes;
-typedef std::vector<std::string>Comps;
-
-typedef boost::shared_ptr<Bytes> BytesPtr;
-
-inline
-const unsigned char *
-head(const Bytes &bytes)
-{
- return &bytes[0];
-}
-
-inline
-unsigned char *
-head (Bytes &bytes)
-{
- return &bytes[0];
-}
-
-// --- Bytes operations start ---
-inline void
-readRaw(Bytes &bytes, const unsigned char *src, size_t len)
-{
- if (len > 0)
- {
- bytes.resize(len);
- memcpy (head (bytes), src, len);
- }
-}
-
-inline BytesPtr
-readRawPtr (const unsigned char *src, size_t len)
-{
- if (len > 0)
- {
- BytesPtr ret (new Bytes (len));
- memcpy (head (*ret), src, len);
-
- return ret;
- }
- else
- return BytesPtr ();
-}
-
-template<class Msg>
-BytesPtr
-serializeMsg(const Msg &msg)
-{
- int size = msg.ByteSize ();
- BytesPtr bytes (new Bytes (size));
- msg.SerializeToArray (head(*bytes), size);
- return bytes;
-}
-
-template<class Msg>
-boost::shared_ptr<Msg>
-deserializeMsg (const Bytes &bytes)
-{
- boost::shared_ptr<Msg> retval (new Msg ());
- if (!retval->ParseFromArray (head (bytes), bytes.size ()))
- {
- // to indicate an error
- return boost::shared_ptr<Msg> ();
- }
- return retval;
-}
-
-template<class Msg>
-boost::shared_ptr<Msg>
-deserializeMsg (const void *buf, size_t length)
-{
- boost::shared_ptr<Msg> retval (new Msg ());
- if (!retval->ParseFromArray (buf, length))
- {
- // to indicate an error
- return boost::shared_ptr<Msg> ();
- }
- return retval;
-}
-
-
-template<class Msg>
-BytesPtr
-serializeGZipMsg(const Msg &msg)
-{
- std::vector<char> bytes; // Bytes couldn't work
- {
- boost::iostreams::filtering_ostream out;
- out.push(boost::iostreams::gzip_compressor()); // gzip filter
- out.push(boost::iostreams::back_inserter(bytes)); // back_inserter sink
-
- msg.SerializeToOstream(&out);
- }
- BytesPtr uBytes = boost::make_shared<Bytes>(bytes.size());
- memcpy(&(*uBytes)[0], &bytes[0], bytes.size());
- return uBytes;
-}
-
-template<class Msg>
-boost::shared_ptr<Msg>
-deserializeGZipMsg(const Bytes &bytes)
-{
- std::vector<char> sBytes(bytes.size());
- memcpy(&sBytes[0], &bytes[0], bytes.size());
- boost::iostreams::filtering_istream in;
- in.push(boost::iostreams::gzip_decompressor()); // gzip filter
- in.push(boost::make_iterator_range(sBytes)); // source
-
- boost::shared_ptr<Msg> retval = boost::make_shared<Msg>();
- if (!retval->ParseFromIstream(&in))
- {
- // to indicate an error
- return boost::shared_ptr<Msg> ();
- }
-
- return retval;
-}
-
-
-// --- Bytes operations end ---
-
-// Exceptions
-typedef boost::error_info<struct tag_errmsg, std::string> error_info_str;
-
-} // Ndnx
-#endif // NDNX_COMMON_H
diff --git a/ndnx/ndnx-discovery.cpp b/ndnx/ndnx-discovery.cpp
deleted file mode 100644
index dce0d98..0000000
--- a/ndnx/ndnx-discovery.cpp
+++ /dev/null
@@ -1,139 +0,0 @@
-#include "ndnx-discovery.h"
-#include "simple-interval-generator.h"
-#include "task.h"
-#include "periodic-task.h"
-#include <sstream>
-#include <boost/make_shared.hpp>
-#include <boost/bind.hpp>
-
-using namespace Ndnx;
-using namespace std;
-
-const string
-TaggedFunction::CHAR_SET = string("abcdefghijklmnopqtrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
-
-TaggedFunction::TaggedFunction(const Callback &callback, const string &tag)
- : m_callback(callback)
- , m_tag(tag)
-{
-}
-
-string
-TaggedFunction::GetRandomTag()
-{
- //boost::random::random_device rng;
- //boost::random::uniform_int_distribution<> dist(0, CHAR_SET.size() - 1);
- ostringstream oss;
- //for (int i = 0; i < DEFAULT_TAG_SIZE; i++)
- //{
- //oss << CHAR_SET[dist(rng)];
- //}
- return oss.str();
-}
-
-void
-TaggedFunction::operator()(const Name &name)
-{
- if (!m_callback.empty())
- {
- m_callback(name);
- }
-}
-
-const double
-NdnxDiscovery::INTERVAL = 15.0;
-
-NdnxDiscovery *
-NdnxDiscovery::instance = NULL;
-
-boost::mutex
-NdnxDiscovery::mutex;
-
-NdnxDiscovery::NdnxDiscovery()
- : m_scheduler(new Scheduler())
- , m_localPrefix("/")
-{
- m_scheduler->start();
-
- Scheduler::scheduleOneTimeTask (m_scheduler, 0,
- boost::bind(&NdnxDiscovery::poll, this), "Initial-Local-Prefix-Check");
- Scheduler::schedulePeriodicTask (m_scheduler,
- boost::make_shared<SimpleIntervalGenerator>(INTERVAL),
- boost::bind(&NdnxDiscovery::poll, this), "Local-Prefix-Check");
-}
-
-NdnxDiscovery::~NdnxDiscovery()
-{
- m_scheduler->shutdown();
-}
-
-void
-NdnxDiscovery::addCallback(const TaggedFunction &callback)
-{
- m_callbacks.push_back(callback);
-}
-
-int
-NdnxDiscovery::deleteCallback(const TaggedFunction &callback)
-{
- List::iterator it = m_callbacks.begin();
- while (it != m_callbacks.end())
- {
- if ((*it) == callback)
- {
- it = m_callbacks.erase(it);
- }
- else
- {
- ++it;
- }
- }
- return m_callbacks.size();
-}
-
-void
-NdnxDiscovery::poll()
-{
- Name localPrefix = NdnxWrapper::getLocalPrefix();
- if (localPrefix != m_localPrefix)
- {
- Lock lock(mutex);
- for (List::iterator it = m_callbacks.begin(); it != m_callbacks.end(); ++it)
- {
- (*it)(localPrefix);
- }
- m_localPrefix = localPrefix;
- }
-}
-
-void
-NdnxDiscovery::registerCallback(const TaggedFunction &callback)
-{
- Lock lock(mutex);
- if (instance == NULL)
- {
- instance = new NdnxDiscovery();
- }
-
- instance->addCallback(callback);
-}
-
-void
-NdnxDiscovery::deregisterCallback(const TaggedFunction &callback)
-{
- Lock lock(mutex);
- if (instance == NULL)
- {
- cerr << "NdnxDiscovery::deregisterCallback called without instance" << endl;
- }
- else
- {
- int size = instance->deleteCallback(callback);
- if (size == 0)
- {
- delete instance;
- instance = NULL;
- }
- }
-}
-
diff --git a/ndnx/ndnx-discovery.h b/ndnx/ndnx-discovery.h
deleted file mode 100644
index e273364..0000000
--- a/ndnx/ndnx-discovery.h
+++ /dev/null
@@ -1,108 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2013 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>
- * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
- */
-
-#ifndef NDNX_DISCOVERY_H
-#define NDNX_DISCOVERY_H
-
-#include "ndnx-wrapper.h"
-#include "ndnx-common.h"
-#include "ndnx-name.h"
-#include "scheduler.h"
-#include <boost/shared_ptr.hpp>
-#include <boost/function.hpp>
-#include <boost/random.hpp>
-#include <boost/thread/mutex.hpp>
-#include <boost/thread/locks.hpp>
-#include <list>
-
-namespace Ndnx
-{
-
-class NdnxDiscovery;
-typedef boost::shared_ptr<NdnxDiscovery> NdnxDiscoveryPtr;
-
-class TaggedFunction
-{
-public:
- typedef boost::function<void (const Name &)> Callback;
- TaggedFunction(const Callback &callback, const string &tag = GetRandomTag());
- ~TaggedFunction(){};
-
- bool
- operator==(const TaggedFunction &other) { return m_tag == other.m_tag; }
-
- void
- operator()(const Name &name);
-
-private:
- static const std::string CHAR_SET;
- static const int DEFAULT_TAG_SIZE = 32;
-
- static std::string
- GetRandomTag();
-
-private:
- Callback m_callback;
- std::string m_tag;
-};
-
-class NdnxDiscovery
-{
-public:
- const static double INTERVAL;
- // Add a callback to be invoked when local prefix changes
- // you must remember to deregister the callback
- // otherwise you may have undefined behavior if the callback is
- // bind to a member function of an object and the object is deleted
- static void
- registerCallback(const TaggedFunction &callback);
-
- // remember to call this before you quit
- static void
- deregisterCallback(const TaggedFunction &callback);
-
-private:
- NdnxDiscovery();
- ~NdnxDiscovery();
-
- void
- poll();
-
- void
- addCallback(const TaggedFunction &callback);
-
- int
- deleteCallback(const TaggedFunction &callback);
-
-private:
- typedef boost::mutex Mutex;
- typedef boost::unique_lock<Mutex> Lock;
- typedef std::list<TaggedFunction> List;
-
- static NdnxDiscovery *instance;
- static Mutex mutex;
- List m_callbacks;
- SchedulerPtr m_scheduler;
- Name m_localPrefix;
-};
-
-} // Ndnx
-#endif // NDNX_DISCOVERY_H
diff --git a/ndnx/ndnx-name.cpp b/ndnx/ndnx-name.cpp
deleted file mode 100644
index dcf762e..0000000
--- a/ndnx/ndnx-name.cpp
+++ /dev/null
@@ -1,361 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2013 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>
- * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
- */
-
-#include "ndnx-name.h"
-#include <boost/lexical_cast.hpp>
-#include <ctype.h>
-#include <boost/algorithm/string/join.hpp>
-#include <boost/make_shared.hpp>
-
-using namespace std;
-
-namespace Ndnx{
-
-Name::Name()
-{
-}
-
-Name::Name(const string &name)
-{
- stringstream ss(name);
- string compStr;
- bool first = true;
- while(getline(ss, compStr, '/'))
- {
- // discard the first empty comp before the first '/'
- if (first)
- {
- first = false;
- continue;
- }
- Bytes comp(compStr.begin(), compStr.end());
- m_comps.push_back(comp);
- }
-}
-
-Name::Name(const vector<Bytes> &comps)
-{
- m_comps = comps;
-}
-
-Name::Name(const Name &other)
-{
- m_comps = other.m_comps;
-}
-
-Name::Name(const unsigned char *data, const ndn_indexbuf *comps)
-{
- for (unsigned int i = 0; i < comps->n - 1; i++)
- {
- const unsigned char *compPtr;
- size_t size;
- ndn_name_comp_get(data, comps, i, &compPtr, &size);
- Bytes comp;
- readRaw(comp, compPtr, size);
- m_comps.push_back(comp);
- }
-}
-
-Name::Name (const void *buf, const size_t length)
-{
- ndn_indexbuf *idx = ndn_indexbuf_create();
- const ndn_charbuf namebuf = { length, length, const_cast<unsigned char *> (reinterpret_cast<const unsigned char *> (buf)) };
- ndn_name_split (&namebuf, idx);
-
- const unsigned char *compPtr = NULL;
- size_t size = 0;
- int i = 0;
- while (ndn_name_comp_get(namebuf.buf, idx, i, &compPtr, &size) == 0)
- {
- Bytes comp;
- readRaw (comp, compPtr, size);
- m_comps.push_back(comp);
- i++;
- }
- ndn_indexbuf_destroy(&idx);
-}
-
-Name::Name (const NdnxCharbuf &buf)
-{
- ndn_indexbuf *idx = ndn_indexbuf_create();
- ndn_name_split (buf.getBuf (), idx);
-
- const unsigned char *compPtr = NULL;
- size_t size = 0;
- int i = 0;
- while (ndn_name_comp_get(buf.getBuf ()->buf, idx, i, &compPtr, &size) == 0)
- {
- Bytes comp;
- readRaw (comp, compPtr, size);
- m_comps.push_back(comp);
- i++;
- }
- ndn_indexbuf_destroy(&idx);
-}
-
-Name::Name (const ndn_charbuf *buf)
-{
- ndn_indexbuf *idx = ndn_indexbuf_create();
- ndn_name_split (buf, idx);
-
- const unsigned char *compPtr = NULL;
- size_t size = 0;
- int i = 0;
- while (ndn_name_comp_get(buf->buf, idx, i, &compPtr, &size) == 0)
- {
- Bytes comp;
- readRaw (comp, compPtr, size);
- m_comps.push_back(comp);
- i++;
- }
- ndn_indexbuf_destroy(&idx);
-}
-
-Name &
-Name::operator=(const Name &other)
-{
- m_comps = other.m_comps;
- return *this;
-}
-bool
-Name::operator==(const string &str) const
-{
- return this->toString() == str;
-}
-
-bool
-Name::operator!=(const string &str) const
-{
- return !(*this == str);
-}
-
-Name
-operator+(const Name &n1, const Name &n2)
-{
- vector<Bytes> comps = n1.m_comps;
- copy(n2.m_comps.begin(), n2.m_comps.end(), back_inserter(comps));
- return Name(comps);
-}
-
-string
-Name::toString() const
-{
- stringstream ss(stringstream::out);
- ss << *this;
- return ss.str();
-}
-
-NdnxCharbuf*
-Name::toNdnxCharbufRaw () const
-{
- NdnxCharbuf *ptr = new NdnxCharbuf ();
-
- ndn_charbuf *cbuf = ptr->getBuf();
- ndn_name_init(cbuf);
- int size = m_comps.size();
- for (int i = 0; i < size; i++)
- {
- ndn_name_append(cbuf, head(m_comps[i]), m_comps[i].size());
- }
- return ptr;
-}
-
-
-NdnxCharbufPtr
-Name::toNdnxCharbuf () const
-{
- return NdnxCharbufPtr (toNdnxCharbufRaw ());
-}
-
-Name &
-Name::appendComp(const Name &comp)
-{
- m_comps.insert (m_comps.end (),
- comp.m_comps.begin (), comp.m_comps.end ());
- return *this;
-}
-
-Name &
-Name::appendComp(const Bytes &comp)
-{
- m_comps.push_back(comp);
- return *this;
-}
-
-Name &
-Name::appendComp(const string &compStr)
-{
- Bytes comp(compStr.begin(), compStr.end());
- return appendComp(comp);
-}
-
-Name &
-Name::appendComp (const void *buf, size_t size)
-{
- Bytes comp (reinterpret_cast<const unsigned char*> (buf), reinterpret_cast<const unsigned char*> (buf) + size);
- return appendComp(comp);
-}
-
-Name &
-Name::appendComp(uint64_t number)
-{
- Bytes comp;
- comp.push_back (0);
-
- while (number > 0)
- {
- comp.push_back (static_cast<unsigned char> (number & 0xFF));
- number >>= 8;
- }
- return appendComp (comp);
-}
-
-uint64_t
-Name::getCompAsInt (int index) const
-{
- Bytes comp = getComp(index);
- if (comp.size () < 1 ||
- comp[0] != 0)
- {
- boost::throw_exception(NameException()
- << error_info_str("Non integer component: " + getCompAsString(index)));
- }
- uint64_t ret = 0;
- for (int i = comp.size () - 1; i >= 1; i--)
- {
- ret <<= 8;
- ret |= comp [i];
- }
- return ret;
-}
-
-const Bytes &
-Name::getComp(int index) const
-{
- if (index < 0)
- {
- boost::throw_exception(NameException() << error_info_str("Negative index: " + boost::lexical_cast<string>(index)));
- }
-
- if (static_cast<unsigned int> (index) >= m_comps.size())
- {
- boost::throw_exception(NameException() << error_info_str("Index out of range: " + boost::lexical_cast<string>(index)));
- }
- return m_comps[index];
-}
-
-string
-Name::getCompAsString(int index) const
-{
- Bytes comp = getComp(index);
- stringstream ss(stringstream::out);
- int size = comp.size();
- for (int i = 0; i < size; i++)
- {
- unsigned char ch = comp[i];
- if (isprint(ch))
- {
- ss << (char) ch;
- }
- else
- {
- ss << "%" << hex << setfill('0') << setw(2) << (unsigned int)ch;
- }
- }
-
- return ss.str();
-}
-
-Name
-Name::getPartialName(int start, int n) const
-{
- int size = m_comps.size();
- if (start < 0 || start >= size || (n > 0 && start + n > size))
- {
- stringstream ss(stringstream::out);
- ss << "getPartialName() parameter out of range! ";
- ss << "start = " << start;
- ss << "n = " << n;
- ss << "size = " << size;
- boost::throw_exception(NameException() << error_info_str(ss.str()));
- }
-
- vector<Bytes> comps;
- int end;
- if (n > 0)
- {
- end = start + n;
- }
- else
- {
- end = size;
- }
-
- for (int i = start; i < end; i++)
- {
- comps.push_back(m_comps[i]);
- }
-
- return Name(comps);
-}
-
-ostream &
-operator <<(ostream &os, const Name &name)
-{
- int size = name.size();
- vector<string> strComps;
- for (int i = 0; i < size; i++)
- {
- strComps.push_back(name.getCompAsString(i));
- }
- string joined = boost::algorithm::join(strComps, "/");
- os << "/" << joined;
- return os;
-}
-
-bool
-operator ==(const Name &n1, const Name &n2)
-{
- stringstream ss1(stringstream::out);
- stringstream ss2(stringstream::out);
- ss1 << n1;
- ss2 << n2;
- return ss1.str() == ss2.str();
-}
-
-bool
-operator !=(const Name &n1, const Name &n2)
-{
- return !(n1 == n2);
-}
-
-bool
-operator <(const Name &n1, const Name &n2)
-{
- stringstream ss1(stringstream::out);
- stringstream ss2(stringstream::out);
- ss1 << n1;
- ss2 << n2;
- return ss1.str() < ss2.str();
-}
-
-
-} // Ndnx
diff --git a/ndnx/ndnx-name.h b/ndnx/ndnx-name.h
deleted file mode 100644
index 2fde71b..0000000
--- a/ndnx/ndnx-name.h
+++ /dev/null
@@ -1,173 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2012-2013 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>
- * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
- */
-
-#ifndef NDNX_NAME_H
-#define NDNX_NAME_H
-#include <boost/shared_ptr.hpp>
-#include "ndnx-common.h"
-#include "ndnx-charbuf.h"
-
-namespace Ndnx {
-
-struct NameException:
- virtual boost::exception, virtual std::exception {};
-
-class Name
-{
-public:
- Name();
- Name(const std::string &name);
- Name(const std::vector<Bytes> &comps);
- Name(const Name &other);
- Name(const unsigned char *data, const ndn_indexbuf *comps);
- Name (const void *buf, const size_t length);
- Name (const NdnxCharbuf &buf);
- Name (const ndn_charbuf *buf);
- virtual ~Name() {}
-
- NdnxCharbufPtr
- toNdnxCharbuf() const;
-
- NdnxCharbuf*
- toNdnxCharbufRaw () const;
-
- operator NdnxCharbufPtr () const { return toNdnxCharbuf (); }
-
- Name &
- appendComp(const Name &comp);
-
- Name &
- appendComp(const Bytes &comp);
-
- Name &
- appendComp(const std::string &compStr);
-
- Name &
- appendComp(const void *buf, size_t size);
-
- /**
- * Append int component
- *
- * Difference between this and appendComp call is that data is appended in network order
- *
- * Also, this function honors naming convention (%00 prefix is added)
- */
- Name &
- appendComp(uint64_t number);
-
- template<class T>
- Name &
- operator ()(const T &comp) { return appendComp (comp); }
-
- Name &
- operator ()(const void *buf, size_t size) { return appendComp (buf, size); }
-
- int
- size() const {return m_comps.size();}
-
- const Bytes &
- getComp (int index) const;
-
- inline const Bytes &
- getCompFromBack (int index) const;
-
- // return std::string format of the comp
- // if all characters are printable, simply returns the string
- // if not, print the bytes in hex string format
- std::string
- getCompAsString(int index) const;
-
- uint64_t
- getCompAsInt (int index) const;
-
- inline std::string
- getCompFromBackAsString(int index) const;
-
- inline uint64_t
- getCompFromBackAsInt (int index) const;
-
- Name
- getPartialName(int start, int n = -1) const;
-
- inline Name
- getPartialNameFromBack(int start, int n = -1) const;
-
- std::string
- toString() const;
-
- Name &
- operator=(const Name &other);
-
- bool
- operator==(const std::string &str) const;
-
- bool
- operator!=(const std::string &str) const;
-
- friend Name
- operator+(const Name &n1, const Name &n2);
-
-private:
- std::vector<Bytes> m_comps;
-};
-
-typedef boost::shared_ptr<Name> NamePtr;
-
-std::ostream&
-operator <<(std::ostream &os, const Name &name);
-
-bool
-operator ==(const Name &n1, const Name &n2);
-
-bool
-operator !=(const Name &n1, const Name &n2);
-
-bool
-operator <(const Name &n1, const Name &n2);
-
-
-std::string
-Name::getCompFromBackAsString(int index) const
-{
- return getCompAsString (m_comps.size () - 1 - index);
-}
-
-uint64_t
-Name::getCompFromBackAsInt (int index) const
-{
- return getCompAsInt (m_comps.size () - 1 - index);
-}
-
-Name
-Name::getPartialNameFromBack(int start, int n/* = -1*/) const
-{
- return getPartialName (m_comps.size () - 1 - start, n);
-}
-
-const Bytes &
-Name::getCompFromBack (int index) const
-{
- return getComp (m_comps.size () - 1 - index);
-}
-
-
-} // Ndnx
-#endif
diff --git a/ndnx/ndnx-pco.cpp b/ndnx/ndnx-pco.cpp
deleted file mode 100644
index 01c78da..0000000
--- a/ndnx/ndnx-pco.cpp
+++ /dev/null
@@ -1,149 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2013 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>
- * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
- */
-
-#include "ndnx-pco.h"
-#include "ndnx-cert.h"
-#include "hash-helper.h"
-
-namespace Ndnx {
-
-void
-ParsedContentObject::init(const unsigned char *data, size_t len)
-{
- readRaw(m_bytes, data, len);
-
- m_comps = ndn_indexbuf_create();
- int res = ndn_parse_ContentObject(head (m_bytes), len, &m_pco, m_comps);
- if (res < 0)
- {
- boost::throw_exception(MisformedContentObjectException());
- }
-
-}
-
-ParsedContentObject::ParsedContentObject(const unsigned char *data, size_t len, bool verified)
- : m_comps(NULL)
- , m_verified(verified)
-{
- init(data, len);
-}
-
-ParsedContentObject::ParsedContentObject(const Bytes &bytes, bool verified)
- : m_comps(NULL)
- , m_verified(verified)
-{
- init(head(bytes), bytes.size());
-}
-
-ParsedContentObject::ParsedContentObject(const ParsedContentObject &other, bool verified)
- : m_comps(NULL)
- , m_verified(verified)
-{
- init(head(other.m_bytes), other.m_bytes.size());
-}
-
-ParsedContentObject::~ParsedContentObject()
-{
- ndn_indexbuf_destroy(&m_comps);
- m_comps = NULL;
-}
-
-Bytes
-ParsedContentObject::content() const
-{
- const unsigned char *content;
- size_t len;
- int res = ndn_content_get_value(head(m_bytes), m_pco.offset[NDN_PCO_E], &m_pco, &content, &len);
- if (res < 0)
- {
- boost::throw_exception(MisformedContentObjectException());
- }
-
- Bytes bytes;
- readRaw(bytes, content, len);
- return bytes;
-}
-
-BytesPtr
-ParsedContentObject::contentPtr() const
-{
- const unsigned char *content;
- size_t len;
- int res = ndn_content_get_value(head(m_bytes), m_pco.offset[NDN_PCO_E], &m_pco, &content, &len);
- if (res < 0)
- {
- boost::throw_exception(MisformedContentObjectException());
- }
-
- return readRawPtr (content, len);
-}
-
-Name
-ParsedContentObject::name() const
-{
- return Name(head(m_bytes), m_comps);
-}
-
-Name
-ParsedContentObject::keyName() const
-{
- if (m_pco.offset[NDN_PCO_E_KeyName_Name] > m_pco.offset[NDN_PCO_B_KeyName_Name])
- {
- NdnxCharbufPtr ptr = boost::make_shared<NdnxCharbuf>();
- ndn_charbuf_append(ptr->getBuf(), head(m_bytes) + m_pco.offset[NDN_PCO_B_KeyName_Name], m_pco.offset[NDN_PCO_E_KeyName_Name] - m_pco.offset[NDN_PCO_B_KeyName_Name]);
-
- return Name(*ptr);
-}
- else
- {
- return Name();
- }
-}
-
-HashPtr
-ParsedContentObject::publisherPublicKeyDigest() const
-{
- const unsigned char *buf = NULL;
- size_t size = 0;
- ndn_ref_tagged_BLOB(NDN_DTAG_PublisherPublicKeyDigest, head(m_bytes), m_pco.offset[NDN_PCO_B_PublisherPublicKeyDigest], m_pco.offset[NDN_PCO_E_PublisherPublicKeyDigest], &buf, &size);
-
- return boost::make_shared<Hash>(buf, size);
-}
-
-ParsedContentObject::Type
-ParsedContentObject::type() const
-{
- switch (m_pco.type)
- {
- case NDN_CONTENT_DATA: return DATA;
- case NDN_CONTENT_KEY: return KEY;
- default: break;
- }
- return OTHER;
-}
-
-void
-ParsedContentObject::verifySignature(const CertPtr &cert)
-{
- m_verified = (ndn_verify_signature(head(m_bytes), m_pco.offset[NDN_PCO_E], &m_pco, cert->pkey()) == 1);
-}
-
-}
diff --git a/ndnx/ndnx-pco.h b/ndnx/ndnx-pco.h
deleted file mode 100644
index 6af0f73..0000000
--- a/ndnx/ndnx-pco.h
+++ /dev/null
@@ -1,110 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2013 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>
- * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
- */
-
-#ifndef NDNX_CONTENT_OBJECT_H
-#define NDNX_CONTENT_OBJECT_H
-
-#include "ndnx-wrapper.h"
-#include "ndnx-common.h"
-#include "ndnx-name.h"
-
-class Hash;
-typedef boost::shared_ptr<Hash> HashPtr;
-
-namespace Ndnx {
-
-struct MisformedContentObjectException : virtual boost::exception, virtual std::exception { };
-
-class Cert;
-typedef boost::shared_ptr<Cert> CertPtr;
-
-class ParsedContentObject
-{
-public:
- enum Type
- {
- DATA,
- KEY,
- OTHER
- };
- ParsedContentObject(const unsigned char *data, size_t len, bool verified = false);
- ParsedContentObject(const unsigned char *data, const ndn_parsed_ContentObject &pco, bool verified = false);
- ParsedContentObject(const Bytes &bytes, bool verified = false);
- ParsedContentObject(const ParsedContentObject &other, bool verified = false);
- virtual ~ParsedContentObject();
-
- Bytes
- content() const;
-
- BytesPtr
- contentPtr() const;
-
- Name
- name() const;
-
- Name
- keyName() const;
-
- HashPtr
- publisherPublicKeyDigest() const;
-
- Type
- type() const;
-
- inline const Bytes &
- buf () const;
-
- bool
- verified() const { return m_verified; }
-
- void
- verifySignature(const CertPtr &cert);
-
- const unsigned char *
- msg() const { return head(m_bytes); }
-
- const ndn_parsed_ContentObject *
- pco() const { return &m_pco; }
-
-private:
- void
- init(const unsigned char *data, size_t len);
-
-protected:
- ndn_parsed_ContentObject m_pco;
- ndn_indexbuf *m_comps;
- Bytes m_bytes;
- bool m_verified;
- bool m_integrityChecked;
-};
-
-const Bytes &
-ParsedContentObject::buf () const
-{
- return m_bytes;
-}
-
-
-typedef boost::shared_ptr<ParsedContentObject> PcoPtr;
-
-}
-
-#endif // NDNX_CONTENT_OBJECT_H
diff --git a/ndnx/ndnx-selectors.cpp b/ndnx/ndnx-selectors.cpp
deleted file mode 100644
index 3006d0e..0000000
--- a/ndnx/ndnx-selectors.cpp
+++ /dev/null
@@ -1,157 +0,0 @@
-#include "ndnx-selectors.h"
-#include "ndnx-common.h"
-#include <boost/lexical_cast.hpp>
-
-using namespace std;
-
-namespace Ndnx {
-
-Selectors::Selectors()
- : m_maxSuffixComps(-1)
- , m_minSuffixComps(-1)
- , m_answerOriginKind(AOK_DEFAULT)
- , m_interestLifetime(-1.0)
- , m_scope(NO_SCOPE)
- , m_childSelector(DEFAULT)
-{
-}
-
-Selectors::Selectors(const Selectors &other)
-{
- m_maxSuffixComps = other.m_maxSuffixComps;
- m_minSuffixComps = other.m_minSuffixComps;
- m_answerOriginKind = other.m_answerOriginKind;
- m_interestLifetime = other.m_interestLifetime;
- m_scope = other.m_scope;
- m_childSelector = other.m_childSelector;
- m_publisherPublicKeyDigest = other.m_publisherPublicKeyDigest;
-}
-
-Selectors::Selectors(const ndn_parsed_interest *pi)
- : m_maxSuffixComps(-1)
- , m_minSuffixComps(-1)
- , m_answerOriginKind(AOK_DEFAULT)
- , m_interestLifetime(-1.0)
- , m_scope(NO_SCOPE)
- , m_childSelector(DEFAULT)
-{
- if (pi != NULL)
- {
- m_maxSuffixComps = pi->max_suffix_comps;
- m_minSuffixComps = pi->min_suffix_comps;
- switch(pi->orderpref)
- {
- case 0: m_childSelector = LEFT; break;
- case 1: m_childSelector = RIGHT; break;
- default: break;
- }
- switch(pi->answerfrom)
- {
- case 0x1: m_answerOriginKind = AOK_CS; break;
- case 0x2: m_answerOriginKind = AOK_NEW; break;
- case 0x3: m_answerOriginKind = AOK_DEFAULT; break;
- case 0x4: m_answerOriginKind = AOK_STALE; break;
- case 0x10: m_answerOriginKind = AOK_EXPIRE; break;
- default: break;
- }
- m_scope = static_cast<Scope> (pi->scope);
- // scope and interest lifetime do not really matter to receiving application, it's only meaningful to routers
- }
-}
-
-bool
-Selectors::operator == (const Selectors &other)
-{
- return m_maxSuffixComps == other.m_maxSuffixComps
- && m_minSuffixComps == other.m_minSuffixComps
- && m_answerOriginKind == other.m_answerOriginKind
- && (m_interestLifetime - other.m_interestLifetime) < 10e-4
- && m_scope == other.m_scope
- && m_childSelector == other.m_childSelector;
-}
-
-bool
-Selectors::isEmpty() const
-{
- return m_maxSuffixComps == -1
- && m_minSuffixComps == -1
- && m_answerOriginKind == AOK_DEFAULT
- && (m_interestLifetime - (-1.0)) < 10e-4
- && m_scope == NO_SCOPE
- && m_childSelector == DEFAULT;
-}
-
-
-NdnxCharbufPtr
-Selectors::toNdnxCharbuf() const
-{
- if (isEmpty())
- {
- return NdnxCharbufPtr ();
- }
- NdnxCharbufPtr ptr(new NdnxCharbuf());
- ndn_charbuf *cbuf = ptr->getBuf();
- ndn_charbuf_append_tt(cbuf, NDN_DTAG_Interest, NDN_DTAG);
- ndn_charbuf_append_tt(cbuf, NDN_DTAG_Name, NDN_DTAG);
- ndn_charbuf_append_closer(cbuf); // </Name>
-
- if (m_maxSuffixComps < m_minSuffixComps)
- {
- boost::throw_exception(InterestSelectorException() << error_info_str("MaxSuffixComps = " + boost::lexical_cast<string>(m_maxSuffixComps) + " is smaller than MinSuffixComps = " + boost::lexical_cast<string>(m_minSuffixComps)));
- }
-
- if (m_minSuffixComps > 0)
- {
- ndnb_tagged_putf(cbuf, NDN_DTAG_MinSuffixComponents, "%d", m_minSuffixComps);
- }
-
- if (m_maxSuffixComps > 0)
- {
- ndnb_tagged_putf(cbuf, NDN_DTAG_MaxSuffixComponents, "%d", m_maxSuffixComps);
- }
-
- // publisher digest
-
- // exclude
-
- if (m_childSelector != DEFAULT)
- {
- ndnb_tagged_putf(cbuf, NDN_DTAG_MinSuffixComponents, "%d", (int)m_minSuffixComps);
- }
-
- if (m_answerOriginKind != AOK_DEFAULT)
- {
- // it was not using "ndnb_tagged_putf" in ndnx c code, no idea why
- ndn_charbuf_append_tt(cbuf, NDN_DTAG_AnswerOriginKind, NDN_DTAG);
- ndnb_append_number(cbuf, m_answerOriginKind);
- ndn_charbuf_append_closer(cbuf); // <AnswerOriginKind>
- }
-
- if (m_scope != NO_SCOPE)
- {
- ndnb_tagged_putf(cbuf, NDN_DTAG_Scope, "%d", m_scope);
- }
-
- if (m_interestLifetime > 0.0)
- {
- // Ndnx timestamp unit is weird 1/4096 second
- // this is from their code
- unsigned lifetime = 4096 * (m_interestLifetime + 1.0/8192.0);
- if (lifetime == 0 || lifetime > (30 << 12))
- {
- boost::throw_exception(InterestSelectorException() << error_info_str("Ndnx requires 0 < lifetime < 30.0. lifetime= " + boost::lexical_cast<string>(m_interestLifetime)));
- }
- unsigned char buf[3] = {0};
- for (int i = sizeof(buf) - 1; i >= 0; i--, lifetime >>= 8)
- {
- buf[i] = lifetime & 0xff;
- }
- ndnb_append_tagged_blob(cbuf, NDN_DTAG_InterestLifetime, buf, sizeof(buf));
- }
-
- ndn_charbuf_append_closer(cbuf); // </Interest>
-
- return ptr;
-}
-
-} // Ndnx
diff --git a/ndnx/ndnx-selectors.h b/ndnx/ndnx-selectors.h
deleted file mode 100644
index f75647d..0000000
--- a/ndnx/ndnx-selectors.h
+++ /dev/null
@@ -1,108 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2012-2013 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>
- * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
- */
-#ifndef NDNX_SELECTORS_H
-#define NDNX_SELECTORS_H
-
-#include "ndnx-common.h"
-#include "ndnx-name.h"
-
-namespace Ndnx {
-
-struct InterestSelectorException:
- virtual boost::exception, virtual std::exception {};
-
-class Selectors
-{
-public:
- Selectors();
- Selectors(const ndn_parsed_interest *);
- Selectors(const Selectors &other);
- ~Selectors(){};
-
- typedef enum
- {
- AOK_CS = 0x1,
- AOK_NEW = 0x2,
- AOK_DEFAULT = 0x3, // (AOK_CS | AOK_NEW)
- AOK_STALE = 0x4,
- AOK_EXPIRE = 0x10
- } AOK;
-
- typedef enum
- {
- LEFT = 0,
- RIGHT = 1,
- DEFAULT = 2
- } CHILD_SELECTOR;
-
- enum Scope
- {
- NO_SCOPE = -1,
- SCOPE_LOCAL_NDND = 0,
- SCOPE_LOCAL_HOST = 1,
- SCOPE_NEXT_HOST = 2
- };
-
- inline Selectors &
- maxSuffixComps(int maxSCs) {m_maxSuffixComps = maxSCs; return *this;}
-
- inline Selectors &
- minSuffixComps(int minSCs) {m_minSuffixComps = minSCs; return *this;}
-
- inline Selectors &
- answerOriginKind(AOK kind) {m_answerOriginKind = kind; return *this;}
-
- inline Selectors &
- interestLifetime(double lifetime) {m_interestLifetime = lifetime; return *this;}
-
- inline Selectors &
- scope(Scope scope) {m_scope = scope; return *this;}
-
- inline Selectors &
- childSelector(CHILD_SELECTOR child) {m_childSelector = child; return *this;}
-
- // this has no effect now
- inline Selectors &
- publisherPublicKeyDigest(const Bytes &digest) {m_publisherPublicKeyDigest = digest; return *this;}
-
- NdnxCharbufPtr
- toNdnxCharbuf() const;
-
- bool
- isEmpty() const;
-
- bool
- operator==(const Selectors &other);
-
-private:
- int m_maxSuffixComps;
- int m_minSuffixComps;
- AOK m_answerOriginKind;
- double m_interestLifetime;
- Scope m_scope;
- CHILD_SELECTOR m_childSelector;
- // not used now
- Bytes m_publisherPublicKeyDigest;
-};
-
-} // Ndnx
-
-#endif
diff --git a/ndnx/ndnx-verifier.cpp b/ndnx/ndnx-verifier.cpp
deleted file mode 100644
index 1bcfad0..0000000
--- a/ndnx/ndnx-verifier.cpp
+++ /dev/null
@@ -1,169 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2013 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>
- * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
- */
-
-#include "ndnx-verifier.h"
-#include "ndnx-wrapper.h"
-
-INIT_LOGGER ("Ndnx.Verifier");
-namespace Ndnx {
-
-static const size_t ROOT_KEY_DIGEST_LEN = 32; // SHA-256
-static const unsigned char ROOT_KEY_DIGEST[ROOT_KEY_DIGEST_LEN] = {0xa7, 0xd9, 0x8b, 0x81, 0xde, 0x13, 0xfc,
-0x56, 0xc5, 0xa6, 0x92, 0xb4, 0x44, 0x93, 0x6e, 0x56, 0x70, 0x9d, 0x52, 0x6f, 0x70,
-0xed, 0x39, 0xef, 0xb5, 0xe2, 0x3, 0x29, 0xa5, 0x53, 0x3e, 0x68};
-
-Verifier::Verifier(NdnxWrapper *ndnx)
- : m_ndnx(ndnx)
- , m_rootKeyDigest(ROOT_KEY_DIGEST, ROOT_KEY_DIGEST_LEN)
-{
-}
-
-Verifier::~Verifier()
-{
-}
-
-bool
-Verifier::verify(const PcoPtr &pco, double maxWait)
-{
- _LOG_TRACE("Verifying content [" << pco->name() << "]");
- HashPtr publisherPublicKeyDigest = pco->publisherPublicKeyDigest();
-
- {
- UniqueRecLock lock(m_cacheLock);
- CertCache::iterator it = m_certCache.find(*publisherPublicKeyDigest);
- if (it != m_certCache.end())
- {
- CertPtr cert = it->second;
- if (cert->validity() == Cert::WITHIN_VALID_TIME_SPAN)
- {
- pco->verifySignature(cert);
- return pco->verified();
- }
- else
- {
- // delete the invalid cert cache
- m_certCache.erase(it);
- }
- }
- }
-
- // keyName is the name specified in key locator, i.e. without version and segment
- Name keyName = pco->keyName();
- int keyNameSize = keyName.size();
-
- if (keyNameSize < 2)
- {
- _LOG_ERROR("Key name is empty or has too few components.");
- return false;
- }
-
- // for keys, we have to make sure key name is strictly prefix of the content name
- if (pco->type() == ParsedContentObject::KEY)
- {
- Name contentName = pco->name();
- // when checking for prefix, do not include the hash in the key name (which is the last component)
- Name keyNamePrefix = keyName.getPartialName(0, keyNameSize - 1);
- if (keyNamePrefix.size() >= contentName.size() || contentName.getPartialName(0, keyNamePrefix.size()) != keyNamePrefix)
- {
- _LOG_ERROR("Key name prefix [" << keyNamePrefix << "] is not the prefix of content name [" << contentName << "]");
- return false;
- }
- }
- else
- {
- // for now, user can assign any data using his key
- }
-
- Name metaName = keyName.getPartialName(0, keyNameSize - 1) + Name("/info") + keyName.getPartialName(keyNameSize - 1);
-
- Selectors selectors;
-
- selectors.childSelector(Selectors::RIGHT)
- .interestLifetime(maxWait);
-
- PcoPtr keyObject = m_ndnx->get(keyName, selectors, maxWait);
- PcoPtr metaObject = m_ndnx->get(metaName, selectors, maxWait);
- if (!keyObject || !metaObject )
- {
- _LOG_ERROR("can not fetch key or meta");
- return false;
- }
-
- HashPtr publisherKeyHashInKeyObject = keyObject->publisherPublicKeyDigest();
- HashPtr publisherKeyHashInMetaObject = metaObject->publisherPublicKeyDigest();
-
- // make sure key and meta are signed using the same key
- if (publisherKeyHashInKeyObject->IsZero() || ! (*publisherKeyHashInKeyObject == *publisherKeyHashInMetaObject))
- {
- _LOG_ERROR("Key and Meta not signed by the same publisher");
- return false;
- }
-
- CertPtr cert = boost::make_shared<Cert>(keyObject, metaObject);
- if (cert->validity() != Cert::WITHIN_VALID_TIME_SPAN)
- {
- _LOG_ERROR("Certificate is not valid, validity status is : " << cert->validity());
- return false;
- }
-
- // check pco is actually signed by this key (i.e. we don't trust the publisherPublicKeyDigest given by ndnx c lib)
- if (! (*pco->publisherPublicKeyDigest() == cert->keyDigest()))
- {
- _LOG_ERROR("key digest does not match the publisher public key digest of the content object");
- return false;
- }
-
- // now we only need to make sure the key is trustworthy
- if (cert->keyDigest() == m_rootKeyDigest)
- {
- // the key is the root key
- // do nothing now
- }
- else
- {
- // can not verify key or can not verify meta
- if (!verify(keyObject, maxWait) || !verify(metaObject, maxWait))
- {
- _LOG_ERROR("Can not verify key or meta");
- return false;
- }
- }
-
- // ok, keyObject verified, because metaObject is signed by the same parent key and integrity checked
- // so metaObject is also verified
- {
- UniqueRecLock lock(m_cacheLock);
- m_certCache.insert(std::make_pair(cert->keyDigest(), cert));
- }
-
- pco->verifySignature(cert);
- if (pco->verified())
- {
- _LOG_TRACE("[" << pco->name() << "] VERIFIED.");
- }
- else
- {
- _LOG_ERROR("[" << pco->name() << "] CANNOT BE VERIFIED.");
- }
- return pco->verified();
-}
-
-} // Ndnx
diff --git a/ndnx/ndnx-verifier.h b/ndnx/ndnx-verifier.h
deleted file mode 100644
index ce3d450..0000000
--- a/ndnx/ndnx-verifier.h
+++ /dev/null
@@ -1,60 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2013 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>
- * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
- */
-
-#ifndef NDNX_VERIFIER_H
-#define NDNX_VERIFIER_H
-
-#include "ndnx-common.h"
-#include "ndnx-name.h"
-#include "ndnx-cert.h"
-#include "ndnx-pco.h"
-#include <map>
-#include <boost/thread/locks.hpp>
-#include <boost/thread/recursive_mutex.hpp>
-#include <boost/thread/thread.hpp>
-
-namespace Ndnx {
-
-class NdnxWrapper;
-
-class Verifier
-{
-public:
- Verifier(NdnxWrapper *ndnx);
- ~Verifier();
-
- bool verify(const PcoPtr &pco, double maxWait);
-
-private:
-
-private:
- NdnxWrapper *m_ndnx;
- Hash m_rootKeyDigest;
- typedef std::map<Hash, CertPtr> CertCache;
- CertCache m_certCache;
- typedef boost::recursive_mutex RecLock;
- typedef boost::unique_lock<RecLock> UniqueRecLock;
- RecLock m_cacheLock;
-};
-
-} // Ndnx
-
-#endif // NDNX_VERIFIER_H
diff --git a/ndnx/ndnx-wrapper.cpp b/ndnx/ndnx-wrapper.cpp
deleted file mode 100644
index ab177ce..0000000
--- a/ndnx/ndnx-wrapper.cpp
+++ /dev/null
@@ -1,783 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2013 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>
- * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
- */
-
-#include "ndnx-wrapper.h"
-extern "C" {
-#include <ndn/fetch.h>
-}
-#include <poll.h>
-#include <boost/throw_exception.hpp>
-#include <boost/date_time/posix_time/posix_time.hpp>
-#include <boost/random.hpp>
-#include <boost/make_shared.hpp>
-#include <boost/algorithm/string.hpp>
-#include <sstream>
-
-#include "ndnx-verifier.h"
-#include "logging.h"
-
-INIT_LOGGER ("Ndnx.Wrapper");
-
-typedef boost::error_info<struct tag_errmsg, std::string> errmsg_info_str;
-typedef boost::error_info<struct tag_errmsg, int> errmsg_info_int;
-
-using namespace std;
-using namespace boost;
-
-namespace Ndnx {
-
-// hack to enable fake signatures
-// min length for signature field is 16, as defined in ndn_buf_decoder.c:728
-const int DEFAULT_SIGNATURE_SIZE = 16;
-
-// Although ndn_buf_decoder.c:745 defines minimum length 16, something else is checking and only 32-byte fake value is accepted by ndnd
-const int PUBLISHER_KEY_SIZE = 32;
-
-static int
-ndn_encode_garbage_Signature(struct ndn_charbuf *buf)
-{
- int res = 0;
-
- res |= ndn_charbuf_append_tt(buf, NDN_DTAG_Signature, NDN_DTAG);
-
- // Let's cheat more. Default signing algorithm in ndnd is SHA256, so we just need add 32 bytes of garbage
- static char garbage [DEFAULT_SIGNATURE_SIZE];
-
- // digest and witness fields are optional, so use default ones
-
- res |= ndn_charbuf_append_tt(buf, NDN_DTAG_SignatureBits, NDN_DTAG);
- res |= ndn_charbuf_append_tt(buf, DEFAULT_SIGNATURE_SIZE, NDN_BLOB);
- res |= ndn_charbuf_append(buf, garbage, DEFAULT_SIGNATURE_SIZE);
- res |= ndn_charbuf_append_closer(buf);
-
- res |= ndn_charbuf_append_closer(buf);
-
- return(res == 0 ? 0 : -1);
-}
-
-static int
-ndn_pack_unsigned_ContentObject(struct ndn_charbuf *buf,
- const struct ndn_charbuf *Name,
- const struct ndn_charbuf *SignedInfo,
- const void *data,
- size_t size)
-{
- int res = 0;
- struct ndn_charbuf *content_header;
- size_t closer_start;
-
- content_header = ndn_charbuf_create();
- res |= ndn_charbuf_append_tt(content_header, NDN_DTAG_Content, NDN_DTAG);
- if (size != 0)
- res |= ndn_charbuf_append_tt(content_header, size, NDN_BLOB);
- closer_start = content_header->length;
- res |= ndn_charbuf_append_closer(content_header);
- if (res < 0)
- return(-1);
-
- res |= ndn_charbuf_append_tt(buf, NDN_DTAG_ContentObject, NDN_DTAG);
-
- res |= ndn_encode_garbage_Signature(buf);
-
- res |= ndn_charbuf_append_charbuf(buf, Name);
- res |= ndn_charbuf_append_charbuf(buf, SignedInfo);
- res |= ndnb_append_tagged_blob(buf, NDN_DTAG_Content, data, size);
- res |= ndn_charbuf_append_closer(buf);
-
- ndn_charbuf_destroy(&content_header);
- return(res == 0 ? 0 : -1);
-}
-
-NdnxWrapper::NdnxWrapper()
- : m_handle (0)
- , m_running (true)
- , m_connected (false)
- , m_executor (new Executor(1))
- , m_verifier(new Verifier(this))
-{
- start ();
-}
-
-void
-NdnxWrapper::connectNdnd()
-{
- if (m_handle != 0) {
- ndn_disconnect (m_handle);
- //ndn_destroy (&m_handle);
- }
- else
- {
- m_handle = ndn_create ();
- }
-
- UniqueRecLock lock(m_mutex);
- if (ndn_connect(m_handle, NULL) < 0)
- {
- BOOST_THROW_EXCEPTION (NdnxOperationException() << errmsg_info_str("connection to ndnd failed"));
- }
- m_connected = true;
-
- if (!m_registeredInterests.empty())
- {
- for (map<Name, InterestCallback>::const_iterator it = m_registeredInterests.begin(); it != m_registeredInterests.end(); ++it)
- {
- clearInterestFilter(it->first, false);
- setInterestFilter(it->first, it->second, false);
- }
- }
-}
-
-NdnxWrapper::~NdnxWrapper()
-{
- shutdown ();
- if (m_verifier != 0)
- {
- delete m_verifier;
- m_verifier = 0;
-}
-}
-
-void
-NdnxWrapper::start () // called automatically in constructor
-{
- connectNdnd();
- m_thread = thread (&NdnxWrapper::ndnLoop, this);
- m_executor->start();
-}
-
-void
-NdnxWrapper::shutdown () // called in destructor, but can called manually
-{
- m_executor->shutdown();
-
- {
- UniqueRecLock lock(m_mutex);
- m_running = false;
- }
-
- _LOG_DEBUG ("+++++++++SHUTDOWN+++++++");
- if (m_connected)
- {
- m_thread.join ();
-
- ndn_disconnect (m_handle);
- //ndn_destroy (&m_handle);
- m_connected = false;
- }
-}
-
-void
-NdnxWrapper::ndnLoop ()
-{
- static boost::mt19937 randomGenerator (static_cast<unsigned int> (std::time (0)));
- static boost::variate_generator<boost::mt19937&, boost::uniform_int<> > rangeUniformRandom (randomGenerator, uniform_int<> (0,1000));
-
- while (m_running)
- {
- try
- {
- int res = 0;
- {
- UniqueRecLock lock(m_mutex);
- res = ndn_run (m_handle, 0);
- }
-
- if (!m_running) break;
-
- if (res < 0) {
- _LOG_ERROR ("ndn_run returned negative status: " << res);
-
- BOOST_THROW_EXCEPTION (NdnxOperationException()
- << errmsg_info_str("ndn_run returned error"));
- }
-
-
- pollfd pfds[1];
- {
- UniqueRecLock lock(m_mutex);
-
- pfds[0].fd = ndn_get_connection_fd (m_handle);
- pfds[0].events = POLLIN;
- if (ndn_output_is_pending (m_handle))
- pfds[0].events |= POLLOUT;
- }
-
- int ret = poll (pfds, 1, 1);
- if (ret < 0)
- {
- BOOST_THROW_EXCEPTION (NdnxOperationException() << errmsg_info_str("ndnd socket failed (probably ndnd got stopped)"));
- }
- }
- catch (NdnxOperationException &e)
- {
- m_connected = false;
- // probably ndnd has been stopped
- // try reconnect with sleep
- int interval = 1;
- int maxInterval = 32;
- while (m_running)
- {
- try
- {
- this_thread::sleep (boost::get_system_time () + boost::posix_time::seconds (interval) + boost::posix_time::milliseconds (rangeUniformRandom ()));
-
- connectNdnd ();
- _LOG_DEBUG("reconnect to ndnd succeeded");
- break;
- }
- catch (NdnxOperationException &e)
- {
- this_thread::sleep (boost::get_system_time () + boost::posix_time::seconds (interval) + boost::posix_time::milliseconds (rangeUniformRandom ()));
-
- // do exponential backup for reconnect interval
- if (interval < maxInterval)
- {
- interval *= 2;
- }
- }
- }
- }
- catch (const std::exception &exc)
- {
- // catch anything thrown within try block that derives from std::exception
- std::cerr << exc.what();
- }
- catch (...)
- {
- cout << "UNKNOWN EXCEPTION !!!" << endl;
- }
- }
-}
-
-Bytes
-NdnxWrapper::createContentObject(const Name &name, const void *buf, size_t len, int freshness, const Name &keyNameParam)
-{
- {
- UniqueRecLock lock(m_mutex);
- if (!m_running || !m_connected)
- {
- _LOG_TRACE ("<< not running or connected");
- return Bytes ();
- }
- }
-
- NdnxCharbufPtr ptr = name.toNdnxCharbuf();
- ndn_charbuf *pname = ptr->getBuf();
- ndn_charbuf *content = ndn_charbuf_create();
-
- struct ndn_signing_params sp = NDN_SIGNING_PARAMS_INIT;
- sp.freshness = freshness;
-
- Name keyName;
-
- if (keyNameParam.size() == 0)
- {
- // use default key name
- NdnxCharbufPtr defaultKeyNamePtr = boost::make_shared<NdnxCharbuf>();
- ndn_get_public_key_and_name(m_handle, &sp, NULL, NULL, defaultKeyNamePtr->getBuf());
- keyName = Name(*defaultKeyNamePtr);
- }
- else
- {
- keyName = keyNameParam;
- }
-
- if (sp.template_ndnb == NULL)
- {
- sp.template_ndnb = ndn_charbuf_create();
- ndn_charbuf_append_tt(sp.template_ndnb, NDN_DTAG_SignedInfo, NDN_DTAG);
- }
- // no idea what the following 3 lines do, but it was there
- else if (sp.template_ndnb->length > 0) {
- sp.template_ndnb->length--;
- }
- ndn_charbuf_append_tt(sp.template_ndnb, NDN_DTAG_KeyLocator, NDN_DTAG);
- ndn_charbuf_append_tt(sp.template_ndnb, NDN_DTAG_KeyName, NDN_DTAG);
- NdnxCharbufPtr keyPtr = keyName.toNdnxCharbuf();
- ndn_charbuf *keyBuf = keyPtr->getBuf();
- ndn_charbuf_append(sp.template_ndnb, keyBuf->buf, keyBuf->length);
- ndn_charbuf_append_closer(sp.template_ndnb); // </KeyName>
- ndn_charbuf_append_closer(sp.template_ndnb); // </KeyLocator>
- sp.sp_flags |= NDN_SP_TEMPL_KEY_LOCATOR;
- ndn_charbuf_append_closer(sp.template_ndnb); // </SignedInfo>
-
- if (ndn_sign_content(m_handle, content, pname, &sp, buf, len) != 0)
- {
- BOOST_THROW_EXCEPTION(NdnxOperationException() << errmsg_info_str("sign content failed"));
- }
-
- Bytes bytes;
- readRaw(bytes, content->buf, content->length);
-
- ndn_charbuf_destroy (&content);
- if (sp.template_ndnb != NULL)
- {
- ndn_charbuf_destroy (&sp.template_ndnb);
- }
-
- return bytes;
-}
-
-int
-NdnxWrapper::putToNdnd (const Bytes &contentObject)
-{
- _LOG_TRACE (">> putToNdnd");
- UniqueRecLock lock(m_mutex);
- if (!m_running || !m_connected)
- {
- _LOG_TRACE ("<< not running or connected");
- return -1;
- }
-
-
- if (ndn_put(m_handle, head(contentObject), contentObject.size()) < 0)
- {
- _LOG_ERROR ("ndn_put failed");
- // BOOST_THROW_EXCEPTION(NdnxOperationException() << errmsg_info_str("ndnput failed"));
- }
- else
- {
- _LOG_DEBUG ("<< putToNdnd");
- }
-
- return 0;
-}
-
-int
-NdnxWrapper::publishData (const Name &name, const unsigned char *buf, size_t len, int freshness, const Name &keyName)
-{
- Bytes co = createContentObject(name, buf, len, freshness, keyName);
- return putToNdnd(co);
-}
-
-int
-NdnxWrapper::publishUnsignedData(const Name &name, const unsigned char *buf, size_t len, int freshness)
-{
- {
- UniqueRecLock lock(m_mutex);
- if (!m_running || !m_connected)
- {
- _LOG_TRACE ("<< not running or connected");
- return -1;
- }
- }
-
- NdnxCharbufPtr ptr = name.toNdnxCharbuf();
- ndn_charbuf *pname = ptr->getBuf();
- ndn_charbuf *content = ndn_charbuf_create();
- ndn_charbuf *signed_info = ndn_charbuf_create();
-
- static char fakeKey[PUBLISHER_KEY_SIZE];
-
- int res = ndn_signed_info_create(signed_info,
- fakeKey, PUBLISHER_KEY_SIZE,
- NULL,
- NDN_CONTENT_DATA,
- freshness,
- NULL,
- NULL // ndnd is happy with absent key locator and key itself... ha ha
- );
- ndn_pack_unsigned_ContentObject(content, pname, signed_info, buf, len);
-
- Bytes bytes;
- readRaw(bytes, content->buf, content->length);
-
- ndn_charbuf_destroy (&content);
- ndn_charbuf_destroy (&signed_info);
-
- return putToNdnd (bytes);
-}
-
-
-static void
-deleterInInterestTuple (tuple<NdnxWrapper::InterestCallback *, ExecutorPtr> *tuple)
-{
- delete tuple->get<0> ();
- delete tuple;
-}
-
-static ndn_upcall_res
-incomingInterest(ndn_closure *selfp,
- ndn_upcall_kind kind,
- ndn_upcall_info *info)
-{
- NdnxWrapper::InterestCallback *f;
- ExecutorPtr executor;
- tuple<NdnxWrapper::InterestCallback *, ExecutorPtr> *realData = reinterpret_cast< tuple<NdnxWrapper::InterestCallback *, ExecutorPtr>* > (selfp->data);
- tie (f, executor) = *realData;
-
- switch (kind)
- {
- case NDN_UPCALL_FINAL: // effective in unit tests
- // delete closure;
- executor->execute (bind (deleterInInterestTuple, realData));
-
- delete selfp;
- _LOG_TRACE ("<< incomingInterest with NDN_UPCALL_FINAL");
- return NDN_UPCALL_RESULT_OK;
-
- case NDN_UPCALL_INTEREST:
- _LOG_TRACE (">> incomingInterest upcall: " << Name(info->interest_ndnb, info->interest_comps));
- break;
-
- default:
- _LOG_TRACE ("<< incomingInterest with NDN_UPCALL_RESULT_OK: " << Name(info->interest_ndnb, info->interest_comps));
- return NDN_UPCALL_RESULT_OK;
- }
-
- Name interest(info->interest_ndnb, info->interest_comps);
- Selectors selectors(info->pi);
-
- executor->execute (bind (*f, interest, selectors));
- // this will be run in executor
- // (*f) (interest);
- // closure->runInterestCallback(interest);
-
- return NDN_UPCALL_RESULT_OK;
-}
-
-static void
-deleterInDataTuple (tuple<Closure *, ExecutorPtr, Selectors> *tuple)
-{
- delete tuple->get<0> ();
- delete tuple;
-}
-
-static ndn_upcall_res
-incomingData(ndn_closure *selfp,
- ndn_upcall_kind kind,
- ndn_upcall_info *info)
-{
- // Closure *cp = static_cast<Closure *> (selfp->data);
- Closure *cp;
- ExecutorPtr executor;
- Selectors selectors;
- tuple<Closure *, ExecutorPtr, Selectors> *realData = reinterpret_cast< tuple<Closure*, ExecutorPtr, Selectors>* > (selfp->data);
- tie (cp, executor, selectors) = *realData;
-
- switch (kind)
- {
- case NDN_UPCALL_FINAL: // effecitve in unit tests
- executor->execute (bind (deleterInDataTuple, realData));
-
- cp = NULL;
- delete selfp;
- _LOG_TRACE ("<< incomingData with NDN_UPCALL_FINAL");
- return NDN_UPCALL_RESULT_OK;
-
- case NDN_UPCALL_CONTENT:
- _LOG_TRACE (">> incomingData content upcall: " << Name (info->content_ndnb, info->content_comps));
- break;
-
- // this is the case where the intentionally unsigned packets coming (in Encapsulation case)
- case NDN_UPCALL_CONTENT_BAD:
- _LOG_TRACE (">> incomingData content bad upcall: " << Name (info->content_ndnb, info->content_comps));
- break;
-
- // always ask ndnd to try to fetch the key
- case NDN_UPCALL_CONTENT_UNVERIFIED:
- _LOG_TRACE (">> incomingData content unverified upcall: " << Name (info->content_ndnb, info->content_comps));
- break;
-
- case NDN_UPCALL_INTEREST_TIMED_OUT: {
- if (cp != NULL)
- {
- Name interest(info->interest_ndnb, info->interest_comps);
- _LOG_TRACE ("<< incomingData timeout: " << Name (info->interest_ndnb, info->interest_comps));
- executor->execute (bind (&Closure::runTimeoutCallback, cp, interest, *cp, selectors));
- }
- else
- {
- _LOG_TRACE ("<< incomingData timeout, but callback is not set...: " << Name (info->interest_ndnb, info->interest_comps));
- }
- return NDN_UPCALL_RESULT_OK;
- }
-
- default:
- _LOG_TRACE(">> unknown upcall type");
- return NDN_UPCALL_RESULT_OK;
- }
-
- PcoPtr pco = make_shared<ParsedContentObject> (info->content_ndnb, info->pco->offset[NDN_PCO_E]);
-
- // this will be run in executor
- executor->execute (bind (&Closure::runDataCallback, cp, pco->name (), pco));
- _LOG_TRACE (">> incomingData");
-
- return NDN_UPCALL_RESULT_OK;
-}
-
-int NdnxWrapper::sendInterest (const Name &interest, const Closure &closure, const Selectors &selectors)
-{
- _LOG_TRACE (">> sendInterest: " << interest);
- {
- UniqueRecLock lock(m_mutex);
- if (!m_running || !m_connected)
- {
- _LOG_ERROR ("<< sendInterest: not running or connected");
- return -1;
- }
- }
-
- NdnxCharbufPtr namePtr = interest.toNdnxCharbuf();
- ndn_charbuf *pname = namePtr->getBuf();
- ndn_closure *dataClosure = new ndn_closure;
-
- // Closure *myClosure = new ExecutorClosure(closure, m_executor);
- Closure *myClosure = closure.dup ();
- dataClosure->data = new tuple<Closure*, ExecutorPtr, Selectors> (myClosure, m_executor, selectors);
-
- dataClosure->p = &incomingData;
-
- NdnxCharbufPtr selectorsPtr = selectors.toNdnxCharbuf();
- ndn_charbuf *templ = NULL;
- if (selectorsPtr)
- {
- templ = selectorsPtr->getBuf();
- }
-
- UniqueRecLock lock(m_mutex);
- if (ndn_express_interest (m_handle, pname, dataClosure, templ) < 0)
- {
- _LOG_ERROR ("<< sendInterest: ndn_express_interest FAILED!!!");
- }
-
- return 0;
-}
-
-int NdnxWrapper::setInterestFilter (const Name &prefix, const InterestCallback &interestCallback, bool record/* = true*/)
-{
- _LOG_TRACE (">> setInterestFilter");
- UniqueRecLock lock(m_mutex);
- if (!m_running || !m_connected)
- {
- return -1;
- }
-
- NdnxCharbufPtr ptr = prefix.toNdnxCharbuf();
- ndn_charbuf *pname = ptr->getBuf();
- ndn_closure *interestClosure = new ndn_closure;
-
- // interestClosure->data = new ExecutorInterestClosure(interestCallback, m_executor);
-
- interestClosure->data = new tuple<NdnxWrapper::InterestCallback *, ExecutorPtr> (new InterestCallback (interestCallback), m_executor); // should be removed when closure is removed
- interestClosure->p = &incomingInterest;
-
- int ret = ndn_set_interest_filter (m_handle, pname, interestClosure);
- if (ret < 0)
- {
- _LOG_ERROR ("<< setInterestFilter: ndn_set_interest_filter FAILED");
- }
-
- if (record)
- {
- m_registeredInterests.insert(pair<Name, InterestCallback>(prefix, interestCallback));
- }
-
- _LOG_TRACE ("<< setInterestFilter");
-
- return ret;
-}
-
-void
-NdnxWrapper::clearInterestFilter (const Name &prefix, bool record/* = true*/)
-{
- _LOG_TRACE (">> clearInterestFilter");
- UniqueRecLock lock(m_mutex);
- if (!m_running || !m_connected)
- return;
-
- NdnxCharbufPtr ptr = prefix.toNdnxCharbuf();
- ndn_charbuf *pname = ptr->getBuf();
-
- int ret = ndn_set_interest_filter (m_handle, pname, 0);
- if (ret < 0)
- {
- }
-
- if (record)
- {
- m_registeredInterests.erase(prefix);
- }
-
- _LOG_TRACE ("<< clearInterestFilter");
-}
-
-Name
-NdnxWrapper::getLocalPrefix ()
-{
- struct ndn * tmp_handle = ndn_create ();
- int res = ndn_connect (tmp_handle, NULL);
- if (res < 0)
- {
- return Name();
- }
-
- string retval = "";
-
- struct ndn_charbuf *templ = ndn_charbuf_create();
- ndn_charbuf_append_tt(templ, NDN_DTAG_Interest, NDN_DTAG);
- ndn_charbuf_append_tt(templ, NDN_DTAG_Name, NDN_DTAG);
- ndn_charbuf_append_closer(templ); /* </Name> */
- // XXX - use pubid if possible
- ndn_charbuf_append_tt(templ, NDN_DTAG_MaxSuffixComponents, NDN_DTAG);
- ndnb_append_number(templ, 1);
- ndn_charbuf_append_closer(templ); /* </MaxSuffixComponents> */
- ndnb_tagged_putf(templ, NDN_DTAG_Scope, "%d", 2);
- ndn_charbuf_append_closer(templ); /* </Interest> */
-
- struct ndn_charbuf *name = ndn_charbuf_create ();
- res = ndn_name_from_uri (name, "/local/ndn/prefix");
- if (res < 0) {
- }
- else
- {
- struct ndn_fetch *fetch = ndn_fetch_new (tmp_handle);
-
- struct ndn_fetch_stream *stream = ndn_fetch_open (fetch, name, "/local/ndn/prefix",
- NULL, 4, NDN_V_HIGHEST, 0);
- if (stream == NULL) {
- }
- else
- {
- ostringstream os;
-
- int counter = 0;
- char buf[256];
- while (true) {
- res = ndn_fetch_read (stream, buf, sizeof(buf));
-
- if (res == 0) {
- break;
- }
-
- if (res > 0) {
- os << string(buf, res);
- } else if (res == NDN_FETCH_READ_NONE) {
- if (counter < 2)
- {
- ndn_run(tmp_handle, 1000);
- counter ++;
- }
- else
- {
- break;
- }
- } else if (res == NDN_FETCH_READ_END) {
- break;
- } else if (res == NDN_FETCH_READ_TIMEOUT) {
- break;
- } else {
- break;
- }
- }
- retval = os.str ();
- stream = ndn_fetch_close(stream);
- }
- fetch = ndn_fetch_destroy(fetch);
- }
-
- ndn_charbuf_destroy (&name);
-
- ndn_disconnect (tmp_handle);
- ndn_destroy (&tmp_handle);
-
- boost::algorithm::trim(retval);
- return Name(retval);
-}
-
-bool
-NdnxWrapper::verify(PcoPtr &pco, double maxWait)
-{
- return m_verifier->verify(pco, maxWait);
-}
-
-// This is needed just for get function implementation
-struct GetState
-{
- GetState (double maxWait)
- {
- double intPart, fraction;
- fraction = modf (std::abs(maxWait), &intPart);
-
- m_maxWait = date_time::second_clock<boost::posix_time::ptime>::universal_time()
- + boost::posix_time::seconds (intPart)
- + boost::posix_time::microseconds (fraction * 1000000);
- }
-
- PcoPtr
- WaitForResult ()
- {
- //_LOG_TRACE("GetState::WaitForResult start");
- boost::unique_lock<boost::mutex> lock (m_mutex);
- m_cond.timed_wait (lock, m_maxWait);
- //_LOG_TRACE("GetState::WaitForResult finish");
-
- return m_retval;
- }
-
- void
- DataCallback (Name name, PcoPtr pco)
- {
- //_LOG_TRACE("GetState::DataCallback, Name [" << name << "]");
- boost::unique_lock<boost::mutex> lock (m_mutex);
- m_retval = pco;
- m_cond.notify_one ();
- }
-
- void
- TimeoutCallback (Name name)
- {
- boost::unique_lock<boost::mutex> lock (m_mutex);
- m_cond.notify_one ();
- }
-
-private:
- boost::posix_time::ptime m_maxWait;
-
- boost::mutex m_mutex;
- boost::condition_variable m_cond;
-
- PcoPtr m_retval;
-};
-
-
-PcoPtr
-NdnxWrapper::get(const Name &interest, const Selectors &selectors, double maxWait/* = 4.0*/)
-{
- _LOG_TRACE (">> get: " << interest);
- {
- UniqueRecLock lock(m_mutex);
- if (!m_running || !m_connected)
- {
- _LOG_ERROR ("<< get: not running or connected");
- return PcoPtr ();
- }
- }
-
- GetState state (maxWait);
- this->sendInterest (interest, Closure (boost::bind (&GetState::DataCallback, &state, _1, _2),
- boost::bind (&GetState::TimeoutCallback, &state, _1)),
- selectors);
- return state.WaitForResult ();
-}
-
-}
diff --git a/ndnx/ndnx-wrapper.h b/ndnx/ndnx-wrapper.h
deleted file mode 100644
index 9da54f6..0000000
--- a/ndnx/ndnx-wrapper.h
+++ /dev/null
@@ -1,162 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2013 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>
- * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
- */
-
-#ifndef NDNX_WRAPPER_H
-#define NDNX_WRAPPER_H
-
-#include <boost/thread/locks.hpp>
-#include <boost/thread/recursive_mutex.hpp>
-#include <boost/thread/thread.hpp>
-
-#include "ndnx-common.h"
-#include "ndnx-name.h"
-#include "ndnx-selectors.h"
-#include "ndnx-closure.h"
-#include "ndnx-pco.h"
-#include "executor.h"
-
-namespace Ndnx {
-
-struct NdnxOperationException : boost::exception, std::exception { };
-
-class Verifier;
-class NdnxWrapper
-{
-public:
- const static int MAX_FRESHNESS = 2147; // max value for ndnx
- const static int DEFAULT_FRESHNESS = 60;
- typedef boost::function<void (Name, Selectors)> InterestCallback;
-
- NdnxWrapper();
- ~NdnxWrapper();
-
- void
- start (); // called automatically in constructor
-
- /**
- * @brief Because of uncertainty with executor, in some case it is necessary to call shutdown explicitly (see test-server-and-fetch.cc)
- */
- void
- shutdown (); // called in destructor, but can called manually
-
- int
- setInterestFilter (const Name &prefix, const InterestCallback &interestCallback, bool record = true);
-
- void
- clearInterestFilter (const Name &prefix, bool record = true);
-
- int
- sendInterest (const Name &interest, const Closure &closure, const Selectors &selector = Selectors());
-
- int
- publishData (const Name &name, const unsigned char *buf, size_t len, int freshness = DEFAULT_FRESHNESS, const Name &keyName=Name());
-
- inline int
- publishData (const Name &name, const Bytes &content, int freshness = DEFAULT_FRESHNESS, const Name &keyName=Name());
-
- inline int
- publishData (const Name &name, const std::string &content, int freshness = DEFAULT_FRESHNESS, const Name &keyName=Name());
-
- int
- publishUnsignedData(const Name &name, const unsigned char *buf, size_t len, int freshness = DEFAULT_FRESHNESS);
-
- inline int
- publishUnsignedData(const Name &name, const Bytes &content, int freshness = DEFAULT_FRESHNESS);
-
- inline int
- publishUnsignedData(const Name &name, const std::string &content, int freshness = DEFAULT_FRESHNESS);
-
- static Name
- getLocalPrefix ();
-
- Bytes
- createContentObject(const Name &name, const void *buf, size_t len, int freshness = DEFAULT_FRESHNESS, const Name &keyNameParam=Name());
-
- int
- putToNdnd (const Bytes &contentObject);
-
- bool
- verify(PcoPtr &pco, double maxWait = 1 /*seconds*/);
-
- PcoPtr
- get (const Name &interest, const Selectors &selector = Selectors(), double maxWait = 4.0/*seconds*/);
-
-private:
- NdnxWrapper(const NdnxWrapper &other) {}
-
-protected:
- void
- connectNdnd();
-
- /// @cond include_hidden
- void
- ndnLoop ();
-
- /// @endcond
-
-protected:
- typedef boost::shared_mutex Lock;
- typedef boost::unique_lock<Lock> WriteLock;
- typedef boost::shared_lock<Lock> ReadLock;
-
- typedef boost::recursive_mutex RecLock;
- typedef boost::unique_lock<RecLock> UniqueRecLock;
-
- ndn* m_handle;
- RecLock m_mutex;
- boost::thread m_thread;
- bool m_running;
- bool m_connected;
- std::map<Name, InterestCallback> m_registeredInterests;
- ExecutorPtr m_executor;
- Verifier *m_verifier;
-};
-
-typedef boost::shared_ptr<NdnxWrapper> NdnxWrapperPtr;
-
-inline int
-NdnxWrapper::publishData (const Name &name, const Bytes &content, int freshness, const Name &keyName)
-{
- return publishData(name, head(content), content.size(), freshness, keyName);
-}
-
-inline int
-NdnxWrapper::publishData (const Name &name, const std::string &content, int freshness, const Name &keyName)
-{
- return publishData(name, reinterpret_cast<const unsigned char *> (content.c_str ()), content.size (), freshness, keyName);
-}
-
-inline int
-NdnxWrapper::publishUnsignedData(const Name &name, const Bytes &content, int freshness)
-{
- return publishUnsignedData(name, head(content), content.size(), freshness);
-}
-
-inline int
-NdnxWrapper::publishUnsignedData(const Name &name, const std::string &content, int freshness)
-{
- return publishUnsignedData(name, reinterpret_cast<const unsigned char *> (content.c_str ()), content.size (), freshness);
-}
-
-
-} // Ndnx
-
-#endif
diff --git a/osx/auto-update/auto-update.h b/osx/auto-update/auto-update.hpp
similarity index 100%
rename from osx/auto-update/auto-update.h
rename to osx/auto-update/auto-update.hpp
diff --git a/osx/auto-update/sparkle-auto-update.h b/osx/auto-update/sparkle-auto-update.h
deleted file mode 100644
index 1a19b9c..0000000
--- a/osx/auto-update/sparkle-auto-update.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2013 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>
- * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
- */
-
-#ifndef SPARKLE_AUTO_UPDATE_H
-#define SPARKLE_AUTO_UPDATE_H
-
-#include "auto-update.h"
-#include <QString>
-
-class SparkleAutoUpdate : public AutoUpdate
-{
-public:
- SparkleAutoUpdate (const QString &url);
- virtual ~SparkleAutoUpdate ();
- virtual void checkForUpdates();
-private:
- class Private;
- Private *d;
-};
-
-#endif
diff --git a/scheduler/interval-generator.h b/scheduler/interval-generator.h
deleted file mode 100644
index 027e6ab..0000000
--- a/scheduler/interval-generator.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2013 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>
- * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
- */
-
-#ifndef INTERVAL_GENERATOR_H
-#define INTERVAL_GENERATOR_H
-
-#include <boost/shared_ptr.hpp>
-
-using namespace std;
-
-class IntervalGenerator;
-typedef boost::shared_ptr<IntervalGenerator> IntervalGeneratorPtr;
-
-class IntervalGenerator
-{
-public:
- virtual ~IntervalGenerator () { }
-
- virtual double
- nextInterval() = 0;
-};
-
-
-#endif // INTERVAL_GENERATOR_H
diff --git a/scheduler/one-time-task.cc b/scheduler/one-time-task.cc
deleted file mode 100644
index e31c951..0000000
--- a/scheduler/one-time-task.cc
+++ /dev/null
@@ -1,52 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2013 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>
- * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
- */
-
-#include "one-time-task.h"
-#include "scheduler.h"
-
-OneTimeTask::OneTimeTask(const Callback &callback, const Tag &tag, const SchedulerPtr &scheduler, double delay)
- : Task(callback, tag, scheduler)
-{
- setTv(delay);
-}
-
-void
-OneTimeTask::run()
-{
- if (!m_invoked)
- {
- m_callback();
- m_invoked = true;
- deregisterSelf();
- }
-}
-
-void
-OneTimeTask::deregisterSelf()
-{
- m_scheduler->deleteTask(m_tag);
-}
-
-void
-OneTimeTask::reset()
-{
- m_invoked = false;
-}
diff --git a/scheduler/one-time-task.h b/scheduler/one-time-task.h
deleted file mode 100644
index 1b900e1..0000000
--- a/scheduler/one-time-task.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2013 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>
- * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
- */
-
-#ifndef ONE_TIME_TASK_H
-#define ONE_TIME_TASK_H
-
-#include "task.h"
-
-class OneTimeTask : public Task
-{
-public:
- OneTimeTask(const Callback &callback, const Tag &tag, const SchedulerPtr &scheduler, double delay);
- virtual ~OneTimeTask(){}
-
- // invoke callback and mark self as invoked and deregister self from scheduler
- virtual void
- run() _OVERRIDE;
-
- // after reset, the task is marked as un-invoked and can be add to scheduler again, with same delay
- // if not invoked yet, no effect
- virtual void
- reset() _OVERRIDE;
-
-private:
- // this is to deregister itself from scheduler automatically after invoke
- void
- deregisterSelf();
-};
-
-
-#endif // EVENT_SCHEDULER_H
diff --git a/scheduler/periodic-task.cc b/scheduler/periodic-task.cc
deleted file mode 100644
index 947107c..0000000
--- a/scheduler/periodic-task.cc
+++ /dev/null
@@ -1,57 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2013 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>
- * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
- */
-
-#include "periodic-task.h"
-#include "logging.h"
-#include <utility>
-
-INIT_LOGGER ("Scheduler.PeriodicTask");
-
-PeriodicTask::PeriodicTask(const Callback &callback, const Tag &tag, const SchedulerPtr &scheduler,
- IntervalGeneratorPtr generator)
- : Task(callback, tag, scheduler)
- , m_generator(generator)
-{
-}
-
-void
-PeriodicTask::run()
-{
- if (!m_invoked)
- {
- m_invoked = true;
- m_callback();
-
- if (m_invoked)
- {
- // m_invoked getting back if it is rescheduled inside the callback
- m_scheduler->rescheduleTask(m_tag);
- }
- }
-}
-
-void
-PeriodicTask::reset()
-{
- m_invoked = false;
- double interval = m_generator->nextInterval();
- setTv(interval);
-}
diff --git a/scheduler/periodic-task.h b/scheduler/periodic-task.h
deleted file mode 100644
index f36d71a..0000000
--- a/scheduler/periodic-task.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2013 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>
- * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
- */
-
-#ifndef PERIODIC_TASK_H
-#define PERIODIC_TASK_H
-
-#include "task.h"
-#include "scheduler.h"
-#include "interval-generator.h"
-
-class PeriodicTask : public Task
-{
-public:
- // generator is needed only when this is a periodic task
- // two simple generators implementation (SimpleIntervalGenerator and RandomIntervalGenerator) are provided;
- // if user needs more complex pattern in the intervals between calls, extend class IntervalGenerator
- PeriodicTask(const Callback &callback, const Tag &tag, const SchedulerPtr &scheduler, IntervalGeneratorPtr generator);
- virtual ~PeriodicTask(){}
-
- // invoke callback, reset self and ask scheduler to schedule self with the next delay interval
- virtual void
- run() _OVERRIDE;
-
- // set the next delay and mark as un-invoke
- virtual void
- reset() _OVERRIDE;
-
-private:
- IntervalGeneratorPtr m_generator;
-};
-
-#endif // PERIODIC_TASK_H
diff --git a/scheduler/random-interval-generator.h b/scheduler/random-interval-generator.h
deleted file mode 100644
index bd46214..0000000
--- a/scheduler/random-interval-generator.h
+++ /dev/null
@@ -1,89 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2013 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>
- * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
- */
-
-#ifndef RANDOM_INTERVAL_GENERATOR_H
-#define RANDOM_INTERVAL_GENERATOR_H
-
-#include "interval-generator.h"
-
-#include <boost/random/mersenne_twister.hpp>
-#include <boost/random/uniform_real.hpp>
-#include <boost/random/variate_generator.hpp>
-#include <boost/date_time/posix_time/posix_time_types.hpp>
-
-// generates intervals with uniform distribution
-class RandomIntervalGenerator : public IntervalGenerator
-{
-public:
- typedef enum
- {
- UP = 1,
- DOWN = 2,
- EVEN = 3
- } Direction;
-
-public:
- // percent is random-range/interval; e.g. if interval is 10 and you wish the random-range to be 2
- // e.g. 9 ~ 11, percent = 0.2
- // direction shifts the random range; e.g. in the above example, UP would produce a range of
- // 10 ~ 12, DOWN of 8 ~ 10, and EVEN of 9 ~ 11
- RandomIntervalGenerator(double interval, double percent, Direction direction = EVEN)
- // : m_rng(time(NULL))
- : m_rng (static_cast<int> (boost::posix_time::microsec_clock::local_time().time_of_day ().total_nanoseconds ()))
- , m_dist(0.0, fractional(percent))
- , m_random(m_rng, m_dist)
- , m_direction(direction)
- , m_percent(percent)
- , m_interval(interval)
- { }
-
- virtual ~RandomIntervalGenerator(){}
-
- virtual double
- nextInterval() _OVERRIDE
- {
- double percent = m_random();
- double interval = m_interval;
- switch (m_direction)
- {
- case UP: interval = m_interval * (1.0 + percent); break;
- case DOWN: interval = m_interval * (1.0 - percent); break;
- case EVEN: interval = m_interval * (1.0 - m_percent/2.0 + percent); break;
- default: break;
- }
-
- return interval;
- }
-
-private:
- inline double fractional(double x) { double dummy; return abs(modf(x, &dummy)); }
-
-private:
- typedef boost::mt19937 RNG_TYPE;
- RNG_TYPE m_rng;
- boost::uniform_real<> m_dist;
- boost::variate_generator<RNG_TYPE &, boost::uniform_real<> > m_random;
- Direction m_direction;
- double m_percent;
- double m_interval;
-
-};
-#endif // RANDOM_INTERVAL_GENERATOR_H
diff --git a/scheduler/scheduler.cc b/scheduler/scheduler.cc
deleted file mode 100644
index 209e3d1..0000000
--- a/scheduler/scheduler.cc
+++ /dev/null
@@ -1,361 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2013 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>
- * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
- */
-
-#include "scheduler.h"
-#include "one-time-task.h"
-#include "periodic-task.h"
-#include "logging.h"
-
-#include <utility>
-#include <boost/make_shared.hpp>
-
-INIT_LOGGER ("Scheduler");
-
-using namespace std;
-using namespace boost;
-
-#define EVLOOP_NO_EXIT_ON_EMPTY 0x04
-
-static void
-dummyCallback(evutil_socket_t fd, short what, void *arg)
-{
- // 1 year later, that was a long run for the app
- // let's wait for another year
- timeval tv;
- tv.tv_sec = 365 * 24 * 3600;
- tv.tv_usec = 0;
- event *ev = *(event **)arg;
- int res = evtimer_add(ev, &tv);
-}
-
-// IntervalGeneratorPtr
-// IntervalGenerator:: Null;
-
-void errorCallback(int err)
-{
- _LOG_ERROR ("Fatal error: " << err);
-}
-
-Scheduler::Scheduler()
- : m_running(false)
- , m_executor(1)
-{
- event_set_fatal_callback(errorCallback);
- evthread_use_pthreads();
- m_base = event_base_new();
-
- // This is a hack to prevent event_base_loop from exiting;
- // the flag EVLOOP_NO_EXIT_ON_EMPTY is somehow ignored, at least on Mac OS X
- // it's going to be scheduled to 10 years later
- timeval tv;
- tv.tv_sec = 365 * 24 * 3600;
- tv.tv_usec = 0;
- m_ev = evtimer_new(m_base, dummyCallback, &m_ev);
- int res = evtimer_add(m_ev, &tv);
- if (res < 0)
- {
- _LOG_ERROR("heck");
- }
-}
-
-Scheduler::~Scheduler()
-{
- shutdown ();
- evtimer_del(m_ev);
- event_free(m_ev);
- event_base_free(m_base);
-}
-
-void
-Scheduler::eventLoop()
-{
- while(true)
- {
- if (event_base_loop(m_base, EVLOOP_NO_EXIT_ON_EMPTY) < 0)
- {
- _LOG_DEBUG ("scheduler loop break error");
- }
- else
- {
- _LOG_DEBUG ("scheduler loop break normal");
- }
-
- {
- ScopedLock lock(m_mutex);
- if (!m_running)
- {
- _LOG_DEBUG ("scheduler loop break normal");
- break;
- }
- }
-
- // just to prevent craziness in CPU usage which supposedly should not happen
- // after adding the dummy event
- usleep(1000);
- }
-}
-
-void
-Scheduler::execute(Executor::Job job)
-{
- m_executor.execute(job);
-}
-
-void
-Scheduler::start()
-{
- ScopedLock lock(m_mutex);
- if (!m_running)
- {
- m_thread = boost::thread(&Scheduler::eventLoop, this);
- m_executor.start();
- m_running = true;
- }
-}
-
-void
-Scheduler::shutdown()
-{
- bool breakAndWait = false;
- {
- ScopedLock lock (m_mutex);
- if (m_running)
- {
- m_running = false;
- breakAndWait = true;
- }
- }
-
- if (breakAndWait)
- {
- event_base_loopbreak(m_base);
- m_executor.shutdown();
- m_thread.join();
- }
-}
-
-TaskPtr
-Scheduler::scheduleOneTimeTask (SchedulerPtr scheduler, double delay,
- const Task::Callback &callback, const Task::Tag &tag)
-{
- TaskPtr task = make_shared<OneTimeTask> (callback, tag, scheduler, delay);
- if (scheduler->addTask (task))
- return task;
- else
- return TaskPtr ();
-}
-
-TaskPtr
-Scheduler::schedulePeriodicTask (SchedulerPtr scheduler, IntervalGeneratorPtr delayGenerator,
- const Task::Callback &callback, const Task::Tag &tag)
-{
- TaskPtr task = make_shared<PeriodicTask> (callback, tag, scheduler, delayGenerator);
-
- if (scheduler->addTask (task))
- return task;
- else
- return TaskPtr ();
-}
-
-TaskPtr
-Scheduler::scheduleDelayOneTimeTask (SchedulerPtr scheduler, double delay,
- const Task::Callback &callback, const Task::Tag &tag)
-{
- TaskPtr task = make_shared<OneTimeTask> (callback, tag, scheduler, delay);
- if (scheduler->addTask (task))
- return task;
- else{
- _LOG_ERROR ("reschedule task for " << tag);
- scheduler->rescheduleTask(tag);
- return TaskPtr ();
- }
-}
-
-bool
-Scheduler::addTask(TaskPtr newTask, bool reset/* = true*/)
-{
- if (addToMap(newTask))
- {
- if (reset)
- {
- newTask->reset();
- }
- int res = evtimer_add(newTask->ev(), newTask->tv());
- if (res < 0)
- {
- _LOG_ERROR ("evtimer_add failed for " << newTask->tag());
- }
- return true;
- }
- else
- {
- _LOG_ERROR ("fail to add task: " << newTask->tag());
- }
-
- return false;
-}
-
-void
-Scheduler::deleteTask(TaskPtr task)
-{
- deleteTask (task->tag ());
-}
-
-void
-Scheduler::rescheduleTask(TaskPtr task)
-{
- ScopedLock lock(m_mutex);
- TaskMapIt it = m_taskMap.find(task->tag());
- if (it != m_taskMap.end())
- {
- TaskPtr task = it->second;
- task->reset();
- int res = evtimer_add(task->ev(), task->tv());
- if (res < 0)
- {
- _LOG_ERROR ("evtimer_add failed for " << task->tag());
- }
- }
- else
- {
- addTask(task);
- }
-}
-
-void
-Scheduler::rescheduleTask(const Task::Tag &tag)
-{
- ScopedLock lock(m_mutex);
- TaskMapIt it = m_taskMap.find(tag);
- if (it != m_taskMap.end())
- {
- TaskPtr task = it->second;
- task->reset();
- int res = evtimer_add(task->ev(), task->tv());
- if (res < 0)
- {
- cout << "evtimer_add failed for " << task->tag() << endl;
- }
- }
-}
-
-void
-Scheduler::rescheduleTaskAt (const Task::Tag &tag, double time)
-{
- ScopedLock lock(m_mutex);
- TaskMapIt it = m_taskMap.find (tag);
- if (it != m_taskMap.end())
- {
- TaskPtr task = it->second;
- task->reset();
- task->setTv (time);
-
- int res = evtimer_add(task->ev(), task->tv());
- if (res < 0)
- {
- _LOG_ERROR ("evtimer_add failed for " << task->tag());
- }
- }
- else
- {
- _LOG_ERROR ("Task for tag " << tag << " not found");
- }
-}
-
-void
-Scheduler::rescheduleTaskAt (TaskPtr task, double time)
-{
- ScopedLock lock(m_mutex);
- TaskMapIt it = m_taskMap.find(task->tag());
- if (it != m_taskMap.end())
- {
- TaskPtr task = it->second;
- task->reset();
- task->setTv (time);
-
- int res = evtimer_add(task->ev(), task->tv());
- if (res < 0)
- {
- _LOG_ERROR ("evtimer_add failed for " << task->tag());
- }
- }
- else
- {
- task->setTv (time); // force different time
- addTask (task, false);
- }
-}
-
-
-bool
-Scheduler::addToMap(TaskPtr task)
-{
- ScopedLock lock(m_mutex);
- if (m_taskMap.find(task->tag()) == m_taskMap.end())
- {
- m_taskMap.insert(make_pair(task->tag(), task));
- return true;
- }
- return false;
-}
-
-void
-Scheduler::deleteTask(const Task::Tag &tag)
-{
- ScopedLock lock(m_mutex);
- TaskMapIt it = m_taskMap.find(tag);
- if (it != m_taskMap.end())
- {
- TaskPtr task = it->second;
- evtimer_del(task->ev());
- m_taskMap.erase(it);
- }
-}
-
-void
-Scheduler::deleteTask(const Task::TaskMatcher &matcher)
-{
- ScopedLock lock(m_mutex);
- TaskMapIt it = m_taskMap.begin();
- while(it != m_taskMap.end())
- {
- TaskPtr task = it->second;
- if (matcher(task))
- {
- evtimer_del(task->ev());
- // Use post increment; map.erase invalidate the iterator that is beening erased,
- // but does not invalidate other iterators. This seems to be the convention to
- // erase something from C++ STL map while traversing.
- m_taskMap.erase(it++);
- }
- else
- {
- ++it;
- }
- }
-}
-
-int
-Scheduler::size()
-{
- ScopedLock lock(m_mutex);
- return m_taskMap.size();
-}
diff --git a/scheduler/scheduler.h b/scheduler/scheduler.h
deleted file mode 100644
index a52649a..0000000
--- a/scheduler/scheduler.h
+++ /dev/null
@@ -1,151 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2013 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>
- * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
- */
-
-#ifndef SCHEDULER_H
-#define SCHEDULER_H
-
-#include <event2/event.h>
-#include <event2/thread.h>
-#include <event2/event-config.h>
-#include <event2/util.h>
-
-#include <boost/function.hpp>
-#include <boost/shared_ptr.hpp>
-
-#include <boost/exception/all.hpp>
-#include <boost/thread/recursive_mutex.hpp>
-#include <boost/thread/thread.hpp>
-#include <math.h>
-#include <map>
-#include <sys/time.h>
-
-#include "task.h"
-#include "interval-generator.h"
-#include "executor.h"
-
-class Scheduler;
-typedef boost::shared_ptr<Scheduler> SchedulerPtr;
-
-/**
- * @brief Scheduler class
- */
-class Scheduler
-{
-public:
- Scheduler();
- virtual ~Scheduler();
-
- // start event scheduling
- virtual void
- start();
-
- // stop event scheduling
- virtual void
- shutdown();
-
- // helper method to schedule one-time task
- static TaskPtr
- scheduleOneTimeTask (SchedulerPtr scheduler, double delay, const Task::Callback &callback, const Task::Tag &tag);
-
- // helper method to schedule periodic task
- static TaskPtr
- schedulePeriodicTask (SchedulerPtr scheduler, IntervalGeneratorPtr delayGenerator,
- const Task::Callback &callback, const Task::Tag &tag);
-
- // helper method to schedule/reschedule one-time task
- static TaskPtr
- scheduleDelayOneTimeTask (SchedulerPtr scheduler, double delay, const Task::Callback &callback, const Task::Tag &tag);
-
- // if task with the same tag exists, the task is not added and return false
- virtual bool
- addTask(TaskPtr task, bool reset = true);
-
- // delete task by task->tag, regardless of whether it's invoked or not
- virtual void
- deleteTask(TaskPtr task);
-
- // delete task by tag, regardless of whether it's invoked or not
- // if no task is found, no effect
- virtual void
- deleteTask(const Task::Tag &tag);
-
- // delete tasks by matcher, regardless of whether it's invoked or not
- // this is flexiable in that you can use any form of criteria in finding tasks to delete
- // but keep in mind this is a linear scan
-
- // if no task is found, no effect
- virtual void
- deleteTask(const Task::TaskMatcher &matcher);
-
- // task must already have been added to the scheduler, otherwise this method has no effect
- // this is usually used by PeriodicTask
- virtual void
- rescheduleTask(const Task::Tag &tag);
-
- // if the task is not pending, it will be added to the schedule queue
- // if the task is pending, the delay is changed to the passed in delay
- // e.g. if at second 0 task A with delay 5 is originally going to run at second 5 and
- // rescheduleTask(A) is called at second 4, A will be reschedule to run
- // at second 9
- virtual void
- rescheduleTask(TaskPtr task);
-
- virtual void
- rescheduleTaskAt (const Task::Tag &tag, double time);
-
- virtual void
- rescheduleTaskAt (TaskPtr task, double time);
-
- void
- execute(Executor::Job);
-
- void
- eventLoop();
-
- event_base *
- base() { return m_base; }
-
- // used in test
- int
- size();
-
-protected:
- bool
- addToMap(TaskPtr task);
-
-protected:
- typedef std::map<Task::Tag, TaskPtr> TaskMap;
- typedef std::map<Task::Tag, TaskPtr>::iterator TaskMapIt;
- typedef boost::recursive_mutex Mutex;
- typedef boost::unique_lock<Mutex> ScopedLock;
-
- TaskMap m_taskMap;
- Mutex m_mutex;
- volatile bool m_running;
- event_base *m_base;
- event *m_ev;
- boost::thread m_thread;
- Executor m_executor;
-};
-
-struct SchedulerException : virtual boost::exception, virtual std::exception { };
-
-#endif // SCHEDULER_H
diff --git a/scheduler/simple-interval-generator.h b/scheduler/simple-interval-generator.h
deleted file mode 100644
index 06b1181..0000000
--- a/scheduler/simple-interval-generator.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2013 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>
- * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
- */
-
-#ifndef SIMPLE_INTERVAL_GENERATOR_H
-#define SIMPLE_INTERVAL_GENERATOR_H
-
-#include "interval-generator.h"
-
-class SimpleIntervalGenerator : public IntervalGenerator
-{
-public:
- SimpleIntervalGenerator(double interval) : m_interval (interval) {}
- virtual ~SimpleIntervalGenerator() {}
-
- virtual double
- nextInterval() _OVERRIDE { return m_interval; }
-
-private:
- double m_interval;
-};
-
-#endif // SIMPLE_INTERVAL_GENERATOR_H
diff --git a/scheduler/task.cc b/scheduler/task.cc
deleted file mode 100644
index 2f72f06..0000000
--- a/scheduler/task.cc
+++ /dev/null
@@ -1,83 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2013 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>
- * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
- */
-
-#include "task.h"
-#include "scheduler.h"
-
-static void
-eventCallback(evutil_socket_t fd, short what, void *arg)
-{
- Task *task = static_cast<Task *>(arg);
- task->execute();
- task = NULL;
-}
-
-Task::Task(const Callback &callback, const Tag &tag, const SchedulerPtr &scheduler)
- : m_callback(callback)
- , m_tag(tag)
- , m_scheduler(scheduler)
- , m_invoked(false)
- , m_event(NULL)
- , m_tv(NULL)
-{
- m_event = evtimer_new(scheduler->base(), eventCallback, this);
- m_tv = new timeval;
-}
-
-Task::~Task()
-{
- if (m_event != NULL)
- {
- event_free(m_event);
- m_event = NULL;
- }
-
- if (m_tv != NULL)
- {
- delete m_tv;
- m_tv = NULL;
- }
-}
-
-void
-Task::setTv(double delay)
-{
- // Alex: when using abs function, i would recommend use it with std:: prefix, otherwise
- // the standard one may be used, which converts everything to INT, making a lot of problems
- double intPart, fraction;
- fraction = modf(std::abs(delay), &intPart);
-
- m_tv->tv_sec = static_cast<int>(intPart);
- m_tv->tv_usec = static_cast<int>((fraction * 1000000));
-}
-
-void
-Task::execute()
-{
- // m_scheduler->execute(boost::bind(&Task::run, this));
-
- // using a shared_ptr of this to ensure that when invoked from executor
- // the task object still exists
- // otherwise, it could be the case that the run() is to be executed, but before it
- // could finish, the TaskPtr gets deleted from scheduler and the task object
- // gets destroyed, causing crash
- m_scheduler->execute(boost::bind(&Task::run, shared_from_this()));
-}
diff --git a/scheduler/task.h b/scheduler/task.h
deleted file mode 100644
index 11a9fa6..0000000
--- a/scheduler/task.h
+++ /dev/null
@@ -1,103 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2013 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>
- * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
- */
-
-#ifndef TASK_H
-#define TASK_H
-
-#define _OVERRIDE
-#ifdef __GNUC__
-#if __GNUC_MAJOR >= 4 && __GNUC_MINOR__ >= 7
- #undef _OVERRIDE
- #define _OVERRIDE override
-#endif // __GNUC__ version
-#endif // __GNUC__
-
-#include <boost/function.hpp>
-#include <boost/shared_ptr.hpp>
-#include <boost/enable_shared_from_this.hpp>
-#include <sys/time.h>
-
-//////////////////////////////////////////////////
-// forward declarations
-class Task;
-typedef boost::shared_ptr<Task> TaskPtr;
-
-class Scheduler;
-typedef boost::shared_ptr<Scheduler> SchedulerPtr;
-
-struct event;
-//////////////////////////////////////////////////
-
-
-/**
- * @brief Base class for a task
- */
-class Task : public boost::enable_shared_from_this<Task>
-{
-public:
- // callback of this task
- typedef boost::function<void ()> Callback;
- // tag identifies this task, should be unique
- typedef std::string Tag;
- // used to match tasks
- typedef boost::function<bool (const TaskPtr &task)> TaskMatcher;
-
- // Task is associated with Schedulers due to the requirement that libevent event is associated with an libevent event_base
- Task(const Callback &callback, const Tag &tag, const SchedulerPtr &scheduler);
- virtual ~Task();
-
- virtual void
- run() = 0;
-
- Tag
- tag() { return m_tag; }
-
- event *
- ev() { return m_event; }
-
- timeval *
- tv() { return m_tv; }
-
- // Task needs to be resetted after the callback is invoked if it is to be schedule again; just for safety
- // it's called by scheduler automatically when addTask or rescheduleTask is called;
- // Tasks should do preparation work here (e.g. set up new delay, etc. )
- virtual void
- reset() = 0;
-
- // set delay
- // This overrides whatever delay kept in m_tv
- void
- setTv(double delay);
-
- void
- execute();
-
-protected:
- Callback m_callback;
- Tag m_tag;
- SchedulerPtr m_scheduler;
- bool m_invoked;
- event *m_event;
- timeval *m_tv;
-};
-
-
-#endif // TASK_H
diff --git a/src/action-log.cc b/src/action-log.cpp
similarity index 100%
rename from src/action-log.cc
rename to src/action-log.cpp
diff --git a/src/action-log.h b/src/action-log.hpp
similarity index 100%
rename from src/action-log.h
rename to src/action-log.hpp
diff --git a/src/content-server.cc b/src/content-server.cpp
similarity index 100%
rename from src/content-server.cc
rename to src/content-server.cpp
diff --git a/src/content-server.h b/src/content-server.hpp
similarity index 100%
rename from src/content-server.h
rename to src/content-server.hpp
diff --git a/src/db-helper.cc b/src/db-helper.cpp
similarity index 100%
rename from src/db-helper.cc
rename to src/db-helper.cpp
diff --git a/src/db-helper.h b/src/db-helper.hpp
similarity index 100%
rename from src/db-helper.h
rename to src/db-helper.hpp
diff --git a/src/dispatcher.cc b/src/dispatcher.cpp
similarity index 100%
rename from src/dispatcher.cc
rename to src/dispatcher.cpp
diff --git a/src/dispatcher.h b/src/dispatcher.hpp
similarity index 100%
rename from src/dispatcher.h
rename to src/dispatcher.hpp
diff --git a/src/fetch-manager.cc b/src/fetch-manager.cpp
similarity index 100%
rename from src/fetch-manager.cc
rename to src/fetch-manager.cpp
diff --git a/src/fetch-manager.h b/src/fetch-manager.hpp
similarity index 100%
rename from src/fetch-manager.h
rename to src/fetch-manager.hpp
diff --git a/src/fetch-task-db.cc b/src/fetch-task-db.cpp
similarity index 100%
rename from src/fetch-task-db.cc
rename to src/fetch-task-db.cpp
diff --git a/src/fetch-task-db.h b/src/fetch-task-db.hpp
similarity index 100%
rename from src/fetch-task-db.h
rename to src/fetch-task-db.hpp
diff --git a/src/fetcher.cc b/src/fetcher.cpp
similarity index 100%
rename from src/fetcher.cc
rename to src/fetcher.cpp
diff --git a/src/fetcher.h b/src/fetcher.hpp
similarity index 100%
rename from src/fetcher.h
rename to src/fetcher.hpp
diff --git a/src/file-state.cc b/src/file-state.cpp
similarity index 100%
rename from src/file-state.cc
rename to src/file-state.cpp
diff --git a/src/file-state.h b/src/file-state.hpp
similarity index 100%
rename from src/file-state.h
rename to src/file-state.hpp
diff --git a/src/hash-helper.cc b/src/hash-helper.cpp
similarity index 100%
rename from src/hash-helper.cc
rename to src/hash-helper.cpp
diff --git a/src/hash-helper.h b/src/hash-helper.hpp
similarity index 100%
rename from src/hash-helper.h
rename to src/hash-helper.hpp
diff --git a/src/logging.cc b/src/logging.cpp
similarity index 100%
rename from src/logging.cc
rename to src/logging.cpp
diff --git a/src/logging.h b/src/logging.hpp
similarity index 100%
rename from src/logging.h
rename to src/logging.hpp
diff --git a/src/object-db.cc b/src/object-db.cpp
similarity index 100%
rename from src/object-db.cc
rename to src/object-db.cpp
diff --git a/src/object-db.h b/src/object-db.hpp
similarity index 100%
rename from src/object-db.h
rename to src/object-db.hpp
diff --git a/src/object-manager.cc b/src/object-manager.cpp
similarity index 100%
rename from src/object-manager.cc
rename to src/object-manager.cpp
diff --git a/src/object-manager.h b/src/object-manager.hpp
similarity index 100%
rename from src/object-manager.h
rename to src/object-manager.hpp
diff --git a/src/state-server.cc b/src/state-server.cpp
similarity index 100%
rename from src/state-server.cc
rename to src/state-server.cpp
diff --git a/src/state-server.h b/src/state-server.hpp
similarity index 100%
rename from src/state-server.h
rename to src/state-server.hpp
diff --git a/src/sync-core.cc b/src/sync-core.cpp
similarity index 100%
rename from src/sync-core.cc
rename to src/sync-core.cpp
diff --git a/src/sync-core.h b/src/sync-core.hpp
similarity index 100%
rename from src/sync-core.h
rename to src/sync-core.hpp
diff --git a/src/sync-log.cc b/src/sync-log.cpp
similarity index 100%
rename from src/sync-log.cc
rename to src/sync-log.cpp
diff --git a/src/sync-log.h b/src/sync-log.hpp
similarity index 100%
rename from src/sync-log.h
rename to src/sync-log.hpp
diff --git a/src/sync-state-helper.h b/src/sync-state-helper.hpp
similarity index 100%
rename from src/sync-state-helper.h
rename to src/sync-state-helper.hpp
diff --git a/test/client/client.cc b/test/client/client.cc
deleted file mode 100644
index 4f61d52..0000000
--- a/test/client/client.cc
+++ /dev/null
@@ -1,155 +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: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
- * Zhenkai Zhu <zhenkai@cs.ucla.edu>
- */
-
-#include <iostream>
-#include <boost/algorithm/string.hpp>
-#include <config.h>
-#include <Ice/Ice.h>
-#include <chronoshare-client.ice.h>
-#include <sys/stat.h>
-#include <hash-helper.h>
-
-
-using namespace std;
-using namespace boost;
-using namespace ChronoshareClient;
-namespace fs = boost::filesystem;
-
-void
-usage ()
-{
- cerr << "Usage: chronoshare <cmd> [<options>]\n"
- << "\n"
- << " <cmd> is one of:\n"
- << " version\n"
- << " update <filename>\n"
- << " delete <filename>\n"
- << " move <filename> <filename>\n";
- exit (1);
-}
-
-
-int
-main (int argc, char **argv)
-{
- if (argc < 2)
- {
- usage ();
- }
-
- string cmd = argv[1];
- algorithm::to_lower (cmd);
-
- if (cmd == "version")
- {
- cout << "chronoshare version " << CHRONOSHARE_VERSION << endl;
- exit (0);
- }
-
- int status = 0;
- Ice::CommunicatorPtr ic;
- try
- {
- // Create a communicator
- //
- ic = Ice::initialize (argc, argv);
-
- Ice::ObjectPrx base = ic->stringToProxy("NotifyDaemon:default -p 55436");
- if (!base)
- {
- throw "Could not create proxy";
- }
-
- NotifyPrx notify = NotifyPrx::checkedCast (base);
- if (notify)
- {
-
- if (cmd == "update")
- {
- if (argc != 3)
- {
- usage ();
- }
-
- fs::path file (argv[2]);
- fs::file_status fileStatus = fs::status (file);
- if (is_regular_file (fileStatus))
- {
- // Alex: the following code is platform specific :(
- HashPtr fileHash = Hash::FromFileContent (file);
-
- notify->updateFile (file.generic_string (),
- make_pair(reinterpret_cast<const ::Ice::Byte*> (fileHash->GetHash ()),
- reinterpret_cast<const ::Ice::Byte*> (fileHash->GetHash ()) +
- fileHash->GetHashBytes ()),
- fs::last_write_time (file),
- // fileStats.st_atime, fileStats.st_mtime, fileStats.st_ctime,
- fileStatus.permissions ());
- }
- else
- {
- cerr << "File [" << argv[2] << "] doesn't exist or is not accessible" << endl;
- return 1;
- }
- }
- else if (cmd == "delete")
- {
- if (argc != 3)
- {
- usage ();
- }
-
- notify->deleteFile (argv[2]);
- }
- else if (cmd == "move")
- {
- if (argc != 4)
- {
- usage ();
- }
-
- fs::path srcFile (argv[2]);
- fs::path dstFile (argv[3]);
-
- notify->moveFile (srcFile.generic_string (), dstFile.generic_string ());
- }
- else
- {
- cerr << "ERROR: Unknown command " << cmd << endl;
- usage ();
- }
- }
- else
- {
- cerr << "ERROR: Cannot connect to the daemon\n";
- status = 1;
- }
- }
- catch (const Ice::Exception& ex)
- {
- cerr << ex << endl;
- status = 1;
- }
-
- if (ic)
- ic->destroy();
- return status;
-}
diff --git a/test/daemon/daemon.cc b/test/daemon/daemon.cc
deleted file mode 100644
index 6983965..0000000
--- a/test/daemon/daemon.cc
+++ /dev/null
@@ -1,129 +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: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
- * Zhenkai Zhu <zhenkai@cs.ucla.edu>
- */
-
-#include "action-log.h"
-#include <iostream>
-#include <Ice/Service.h>
-#include <Ice/Identity.h>
-#include <ndnx-wrapper.h>
-
-#include "notify-i.h"
-#include <boost/make_shared.hpp>
-
-using namespace std;
-using namespace boost;
-using namespace ChronoshareClient;
-using namespace Ndnx;
-
-typedef boost::error_info<struct tag_errmsg, std::string> errmsg_info_str;
-
-class MyService : public Ice::Service
-{
-public:
- MyService (ActionLogPtr actionLog)
- : m_actionLog (actionLog)
- {
- }
-
-protected:
- virtual bool start (int, char*[], int&)
- {
- _adapter = communicator ()->createObjectAdapterWithEndpoints ("ChronoShare", "default -p 55436");
-
- Ice::Identity identity;
- identity.name="NotifyDaemon";
- NotifyPtr servant=new NotifyI (m_actionLog);
-
- _adapter->add (servant, identity);
-
- _adapter->activate();
- // status = EXIT_SUCCESS;
- return true;
- }
-
-private:
- Ice::ObjectAdapterPtr _adapter;
- ActionLogPtr m_actionLog;
-};
-
-int
-main (int argc, char **argv)
-{
- int status = 0;
-
- try
- {
- // DbHelper db ("./", "/ndn/ucla.edu/alex");
- NdnxWrapperPtr ndnx = make_shared<NdnxWrapper> ();
- ActionLogPtr actionLog = make_shared<ActionLog> (ndnx, "./", "/ndn/ucla.edu/alex", "shared");
-
- MyService svc (actionLog);
- status = svc.main (argc, argv);
-
- // HashPtr hash = db.RememberStateInStateLog ();
- // // should be empty
- // cout << "Hash: [" << *hash << "]" << endl;
-
- // //
- // db.UpdateDeviceSeqno ("Alex", 1);
- // hash = db.RememberStateInStateLog ();
- // cout << "Hash: [" << *hash << "]" << endl;
-
- // db.UpdateDeviceSeqno ("Alex", 2);
- // hash = db.RememberStateInStateLog ();
- // cout << "Hash: [" << *hash << "]" << endl;
-
- // db.UpdateDeviceSeqno ("Alex", 2);
- // hash = db.RememberStateInStateLog ();
- // cout << "Hash: [" << *hash << "]" << endl;
-
- // db.UpdateDeviceSeqno ("Alex", 1);
- // hash = db.RememberStateInStateLog ();
- // cout << "Hash: [" << *hash << "]" << endl;
-
- // db.FindStateDifferences ("00", "ec0a9941fa726e1fb8f34ecdbd8e3faa75dc9dba22e6a2ea1d8482aae5fdfb52");
- // db.FindStateDifferences ("ec0a9941fa726e1fb8f34ecdbd8e3faa75dc9dba22e6a2ea1d8482aae5fdfb52", "00");
- // db.FindStateDifferences ("869c38c6dffe8911ced320aecc6d9244904d13d3e8cd21081311f2129b4557ce",
- // "ec0a9941fa726e1fb8f34ecdbd8e3faa75dc9dba22e6a2ea1d8482aae5fdfb52");
- // db.FindStateDifferences ("ec0a9941fa726e1fb8f34ecdbd8e3faa75dc9dba22e6a2ea1d8482aae5fdfb52",
- // "869c38c6dffe8911ced320aecc6d9244904d13d3e8cd21081311f2129b4557ce");
-
- // db.UpdateDeviceSeqno ("Bob", 1);
- // hash = db.RememberStateInStateLog ();
- // cout << "Hash: [" << *hash << "]" << endl;
-
- // db.FindStateDifferences ("00", "48f4d95b503b9a79c2d5939fa67722b13fc01db861fc501d09efd0a38dbafab8");
- // db.FindStateDifferences ("ec0a9941fa726e1fb8f34ecdbd8e3faa75dc9dba22e6a2ea1d8482aae5fdfb52",
- // "48f4d95b503b9a79c2d5939fa67722b13fc01db861fc501d09efd0a38dbafab8");
- }
- catch (const Ice::Exception& e)
- {
- cerr << e << endl;
- status = 1;
- }
- catch (const boost::exception &e)
- {
- cout << "ERRORR: " << *get_error_info<errmsg_info_str> (e) << endl;
- status = 1;
- }
-
- return status;
-}
diff --git a/test/daemon/notify-i.cc b/test/daemon/notify-i.cc
deleted file mode 100644
index 0a3880d..0000000
--- a/test/daemon/notify-i.cc
+++ /dev/null
@@ -1,72 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2013 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: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
- * Zhenkai Zhu <zhenkai@cs.ucla.edu>
- */
-
-#include "notify-i.h"
-#include <hash-helper.h>
-
-using namespace std;
-using namespace boost;
-
-NotifyI::NotifyI (ActionLogPtr &actionLog)
- : m_actionLog (actionLog)
-{
-}
-
-void
-NotifyI::updateFile (const ::std::string &filename,
- const ::std::pair<const Ice::Byte*, const Ice::Byte*> &hashRaw,
- ::Ice::Long wtime,
- ::Ice::Int mode,
- const ::Ice::Current&)
-{
- Hash hash (hashRaw.first, hashRaw.second-hashRaw.first);
-
- cout << "updateFile " << filename << " with hash " << hash << endl;
- try
- {
- m_actionLog->AddActionUpdate (filename, hash, wtime, mode);
-
- m_actionLog->RememberStateInStateLog ();
- }
- catch (const boost::exception &e)
- {
- cout << "ERRORR: " << *get_error_info<errmsg_info_str> (e) << endl;
- }
-}
-
-void
-NotifyI::moveFile (const ::std::string &oldFilename,
- const ::std::string &newFilename,
- const ::Ice::Current&)
-{
- cout << "moveFile from " << oldFilename << " to " << newFilename << endl;
- // m_actionLog->AddActionMove (oldFilename, newFilename);
-}
-
-void
-NotifyI::deleteFile (const ::std::string &filename,
- const ::Ice::Current&)
-{
- cout << "deleteFile " << filename << endl;
- m_actionLog->AddActionDelete (filename);
- m_actionLog->RememberStateInStateLog ();
-}
-
diff --git a/test/daemon/notify-i.h b/test/daemon/notify-i.h
deleted file mode 100644
index 426e2a9..0000000
--- a/test/daemon/notify-i.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2013 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: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
- * Zhenkai Zhu <zhenkai@cs.ucla.edu>
- */
-
-#ifndef NOTIFY_I_H
-#define NOTIFY_I_H
-
-#include <action-log.h>
-#include <chronoshare-client.ice.h>
-
-class NotifyI : public ChronoshareClient::Notify
-{
-public:
- NotifyI (ActionLogPtr &actionLog);
-
- virtual void
- updateFile (const ::std::string &filename,
- const ::std::pair<const Ice::Byte*, const Ice::Byte*> &hash,
- ::Ice::Long wtime,
- ::Ice::Int mode,
- const ::Ice::Current& = ::Ice::Current());
-
- virtual void
- moveFile (const ::std::string &oldFilename,
- const ::std::string &newFilename,
- const ::Ice::Current& = ::Ice::Current());
-
- virtual void
- deleteFile (const ::std::string &filename,
- const ::Ice::Current& = ::Ice::Current());
-
-private:
- ActionLogPtr m_actionLog;
-};
-
-#endif // NOTIFY_I_H
diff --git a/test/unit-tests/test-event-scheduler.cc b/test/unit-tests/test-event-scheduler.cc
deleted file mode 100644
index 0d70abf..0000000
--- a/test/unit-tests/test-event-scheduler.cc
+++ /dev/null
@@ -1,190 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2013 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>
- * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
- */
-
-#include "scheduler.h"
-#include "simple-interval-generator.h"
-#include "one-time-task.h"
-#include "periodic-task.h"
-#include "random-interval-generator.h"
-
-#include <boost/test/unit_test.hpp>
-#include <boost/make_shared.hpp>
-#include <map>
-#include <unistd.h>
-
-using namespace boost;
-using namespace std;
-
-BOOST_AUTO_TEST_SUITE(SchedulerTests)
-
-map<string, int> table;
-
-void func(string str)
-{
- map<string, int>::iterator it = table.find(str);
- if (it == table.end())
- {
- table.insert(make_pair(str, 1));
- }
- else
- {
- int count = it->second;
- count++;
- table.erase(it);
- table.insert(make_pair(str, count));
- }
-}
-
-bool
-matcher(const TaskPtr &task)
-{
- return task->tag() == "period" || task->tag() == "world";
-}
-
-BOOST_AUTO_TEST_CASE(SchedulerTest)
-{
- SchedulerPtr scheduler(new Scheduler());
- IntervalGeneratorPtr generator(new SimpleIntervalGenerator(0.2));
-
- string tag1 = "hello";
- string tag2 = "world";
- string tag3 = "period";
-
- TaskPtr task1(new OneTimeTask(boost::bind(func, tag1), tag1, scheduler, 0.5));
- TaskPtr task2(new OneTimeTask(boost::bind(func, tag2), tag2, scheduler, 0.5));
- TaskPtr task3(new PeriodicTask(boost::bind(func, tag3), tag3, scheduler, generator));
-
- scheduler->start();
- scheduler->addTask(task1);
- scheduler->addTask(task2);
- scheduler->addTask(task3);
- BOOST_CHECK_EQUAL(scheduler->size(), 3);
- usleep(600000);
- BOOST_CHECK_EQUAL(scheduler->size(), 1);
- scheduler->addTask(task1);
- BOOST_CHECK_EQUAL(scheduler->size(), 2);
- usleep(600000);
- scheduler->addTask(task1);
- BOOST_CHECK_EQUAL(scheduler->size(), 2);
- usleep(400000);
- scheduler->deleteTask(task1->tag());
- BOOST_CHECK_EQUAL(scheduler->size(), 1);
- usleep(200000);
-
- scheduler->addTask(task1);
- scheduler->addTask(task2);
- BOOST_CHECK_EQUAL(scheduler->size(), 3);
- usleep(100000);
- scheduler->deleteTask(bind(matcher, _1));
- BOOST_CHECK_EQUAL(scheduler->size(), 1);
- usleep(1000000);
-
- BOOST_CHECK_EQUAL(scheduler->size(), 0);
- scheduler->addTask(task1);
- usleep(400000);
- BOOST_CHECK_EQUAL(scheduler->size(), 1);
- scheduler->rescheduleTask(task1);
- usleep(400000);
- BOOST_CHECK_EQUAL(scheduler->size(), 1);
- usleep(110000);
- BOOST_CHECK_EQUAL(scheduler->size(), 0);
-
-
- int hello = 0, world = 0, period = 0;
-
- map<string, int>::iterator it;
- it = table.find(tag1);
- if (it != table.end())
- {
- hello = it->second;
- }
- it = table.find(tag2);
- if (it != table.end())
- {
- world = it->second;
- }
- it = table.find(tag3);
- if (it != table.end())
- {
- period = it->second;
- }
-
- // added five times, canceled once before invoking callback
- BOOST_CHECK_EQUAL(hello, 4);
- // added two times, canceled once by matcher before invoking callback
- BOOST_CHECK_EQUAL(world, 1);
- // invoked every 0.2 seconds before deleted by matcher
- BOOST_CHECK_EQUAL(period, static_cast<int>((0.6 + 0.6 + 0.4 + 0.2 + 0.1) / 0.2));
-
- scheduler->shutdown();
-}
-
-void reschedule();
-SchedulerPtr schd0(new Scheduler());
-int resCount;
-TaskPtr task0(new PeriodicTask(boost::bind(reschedule), "testtest", schd0, boost::make_shared<SimpleIntervalGenerator>(0.5)));
-void reschedule()
-{
- schd0->rescheduleTask(task0);
- resCount++;
-}
-
-BOOST_AUTO_TEST_CASE(RescheduleTest)
-{
- resCount = 0;
- schd0->start();
- schd0->addTask(task0);
- usleep(5100000);
- BOOST_CHECK_EQUAL(resCount, 10);
- schd0->shutdown();
-}
-
-BOOST_AUTO_TEST_CASE(GeneratorTest)
-{
- double interval = 10;
- double percent = 0.5;
- int times = 10000;
- IntervalGeneratorPtr generator(new RandomIntervalGenerator(interval, percent));
- double sum = 0.0;
- double min = 2 * interval;
- double max = -1;
- for (int i = 0; i < times; i++)
- {
- double next = generator->nextInterval();
- sum += next;
- if (next > max)
- {
- max = next;
- }
- if (next < min)
- {
- min = next;
- }
- }
-
- BOOST_CHECK( abs(1.0 - (sum / static_cast<double>(times)) / interval) < 0.05);
- BOOST_CHECK( min > interval * (1 - percent / 2.0));
- BOOST_CHECK( max < interval * (1 + percent / 2.0));
- BOOST_CHECK( abs(1.0 - ((max - min) / interval) / percent) < 0.05);
-
-}
-
-BOOST_AUTO_TEST_SUITE_END()
diff --git a/test/unit-tests/test-executor.cc b/test/unit-tests/test-executor.cc
deleted file mode 100644
index a13f373..0000000
--- a/test/unit-tests/test-executor.cc
+++ /dev/null
@@ -1,82 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2013 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>
- * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
- */
-
-
-#include <boost/test/unit_test.hpp>
-#include "executor.h"
-
-#include "logging.h"
-
-INIT_LOGGER ("Test.Executor");
-
-using namespace boost;
-using namespace std;
-
-void timeConsumingJob ()
-{
- _LOG_DEBUG ("Start sleep");
- sleep(1);
- _LOG_DEBUG ("Finish sleep");
-}
-
-BOOST_AUTO_TEST_CASE(TestExecutor)
-{
- INIT_LOGGERS ();
-
- {
- Executor executor (3);
- executor.start ();
- Executor::Job job = bind(timeConsumingJob);
-
- executor.execute(job);
- executor.execute(job);
-
- usleep(2000);
- // both jobs should have been taken care of
- BOOST_CHECK_EQUAL(executor.jobQueueSize(), 0);
-
- usleep(500000);
-
- // add four jobs while only one thread is idle
- executor.execute(job);
- executor.execute(job);
- executor.execute(job);
- executor.execute(job);
-
- usleep(1000);
- // three jobs should remain in queue
- BOOST_CHECK_EQUAL(executor.jobQueueSize(), 3);
-
- usleep(500000);
- // two threads should have finished and
- // take care of two queued jobs
- BOOST_CHECK_EQUAL(executor.jobQueueSize(), 1);
-
- // all jobs should have been fetched
- usleep(501000);
- BOOST_CHECK_EQUAL(executor.jobQueueSize(), 0);
-
- executor.shutdown ();
- } //separate scope to ensure that destructor is called
-
-
- sleep(1);
-}
diff --git a/test/unit-tests/test-ndnx-name.cc b/test/unit-tests/test-ndnx-name.cc
deleted file mode 100644
index a876ba4..0000000
--- a/test/unit-tests/test-ndnx-name.cc
+++ /dev/null
@@ -1,49 +0,0 @@
-
-#include "ccnx-name.h"
-
-#define BOOST_TEST_MAIN 1
-
-#include <boost/test/unit_test.hpp>
-
-using namespace Ccnx;
-using namespace std;
-using namespace boost;
-
-BOOST_AUTO_TEST_SUITE(CcnxNameTests)
-
-BOOST_AUTO_TEST_CASE (CcnxNameTest)
-{
- Name empty = Name();
- Name root = Name("/");
- BOOST_CHECK_EQUAL(empty, root);
- BOOST_CHECK_EQUAL(empty, "/");
- BOOST_CHECK_EQUAL(root.size(), 0);
- empty.appendComp("hello");
- empty.appendComp("world");
- BOOST_CHECK_EQUAL(empty.size(), 2);
- BOOST_CHECK_EQUAL(empty.toString(), "/hello/world");
- empty = empty + root;
- BOOST_CHECK_EQUAL(empty.toString(), "/hello/world");
- BOOST_CHECK_EQUAL(empty.getCompAsString(0), "hello");
- BOOST_CHECK_EQUAL(empty.getPartialName(1, 1), Name("/world"));
- Name name("/hello/world");
- BOOST_CHECK_EQUAL(empty, name);
- BOOST_CHECK_EQUAL(name, Name("/hello") + Name("/world"));
-
-
- name.appendComp (1);
- name.appendComp (255);
- name.appendComp (256);
- name.appendComp (1234567890);
-
- BOOST_CHECK_EQUAL (name.toString (), "/hello/world/%00%01/%00%ff/%00%00%01/%00%d2%02%96I");
-
- BOOST_CHECK_EQUAL (name.getCompAsInt (5), 1234567890);
- BOOST_CHECK_EQUAL (name.getCompAsInt (4), 256);
- BOOST_CHECK_EQUAL (name.getCompAsInt (3), 255);
- BOOST_CHECK_EQUAL (name.getCompAsInt (2), 1);
-
- // Charbuf related stuff will be checked in other place
-}
-
-BOOST_AUTO_TEST_SUITE_END()
diff --git a/test/unit-tests/test-ndnx-wrapper.cc b/test/unit-tests/test-ndnx-wrapper.cc
deleted file mode 100644
index 9989cdb..0000000
--- a/test/unit-tests/test-ndnx-wrapper.cc
+++ /dev/null
@@ -1,253 +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>
- * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
- */
-
-#include "ccnx-wrapper.h"
-#include "ccnx-closure.h"
-#include "ccnx-name.h"
-#include "ccnx-selectors.h"
-#include "ccnx-pco.h"
-#include <unistd.h>
-
-#include <boost/date_time/posix_time/posix_time.hpp>
-#include <boost/test/unit_test.hpp>
-#include <boost/make_shared.hpp>
-
-using namespace Ccnx;
-using namespace std;
-using namespace boost;
-
-BOOST_AUTO_TEST_SUITE(TestCcnxWrapper)
-
-CcnxWrapperPtr c1;
-CcnxWrapperPtr c2;
-int g_timeout_counter = 0;
-int g_dataCallback_counter = 0;
-
-void publish1(const Name &name)
-{
- string content = name.toString();
- c1->publishData(name, (const unsigned char*)content.c_str(), content.size(), 5);
-}
-
-void publish2(const Name &name)
-{
- string content = name.toString();
- c2->publishData(name, (const unsigned char*)content.c_str(), content.size(), 5);
-}
-
-void dataCallback(const Name &name, Ccnx::PcoPtr pco)
-{
- cout << " in data callback" << endl;
- BytesPtr content = pco->contentPtr ();
- string msg(reinterpret_cast<const char *> (head (*content)), content->size());
- g_dataCallback_counter ++;
- BOOST_CHECK_EQUAL(name, msg);
-}
-
-void encapCallback(const Name &name, Ccnx::PcoPtr pco)
-{
- cout << " in encap data callback" << endl;
- BOOST_CHECK(!c1->verify(pco));
- cout << "++++++++++++++++++ Outer content couldn't be verified, which is expected." << endl;
- PcoPtr npco = make_shared<ParsedContentObject> (*(pco->contentPtr()));
- g_dataCallback_counter ++;
- BOOST_CHECK(npco);
- BOOST_CHECK(c1->verify(npco));
-}
-
-void
-timeout(const Name &name, const Closure &closure, Selectors selectors)
-{
- g_timeout_counter ++;
-}
-
-void
-setup()
-{
- if (!c1)
- {
- c1 = make_shared<CcnxWrapper> ();
- }
- if (!c2)
- {
- c2 = make_shared<CcnxWrapper> ();
- }
-}
-
-void
-teardown()
-{
- if (c1)
- {
- c1.reset();
- }
- if (c2)
- {
- c2.reset();
- }
-}
-
-
-BOOST_AUTO_TEST_CASE (BlaCcnxWrapperTest)
-{
- INIT_LOGGERS ();
-
- setup();
- Name prefix1("/c1");
- Name prefix2("/c2");
-
- c1->setInterestFilter(prefix1, bind(publish1, _1));
- usleep(100000);
- c2->setInterestFilter(prefix2, bind(publish2, _1));
-
- Closure closure (bind(dataCallback, _1, _2), bind(timeout, _1, _2, _3));
-
- c1->sendInterest(Name("/c2/hi"), closure);
- usleep(100000);
- c2->sendInterest(Name("/c1/hi"), closure);
- sleep(1);
- BOOST_CHECK_EQUAL(g_dataCallback_counter, 2);
- // reset
- g_dataCallback_counter = 0;
- g_timeout_counter = 0;
-
- teardown();
-}
-
-BOOST_AUTO_TEST_CASE (CcnxWrapperSelector)
-{
-
- setup();
- Closure closure (bind(dataCallback, _1, _2), bind(timeout, _1, _2, _3));
-
- Selectors selectors;
- selectors
- .interestLifetime(1)
- .childSelector(Selectors::RIGHT);
-
- string n1 = "/random/01";
- c1->sendInterest(Name(n1), closure, selectors);
- sleep(2);
- c2->publishData(Name(n1), (const unsigned char *)n1.c_str(), n1.size(), 1);
- usleep(100000);
- BOOST_CHECK_EQUAL(g_timeout_counter, 1);
- BOOST_CHECK_EQUAL(g_dataCallback_counter, 0);
-
- string n2 = "/random/02";
- selectors.interestLifetime(2);
- c1->sendInterest(Name(n2), closure, selectors);
- sleep(1);
- c2->publishData(Name(n2), (const unsigned char *)n2.c_str(), n2.size(), 1);
- usleep(100000);
- BOOST_CHECK_EQUAL(g_timeout_counter, 1);
- BOOST_CHECK_EQUAL(g_dataCallback_counter, 1);
-
- // reset
- g_dataCallback_counter = 0;
- g_timeout_counter = 0;
-
- teardown();
-
-}
-
-void
-reexpress(const Name &name, const Closure &closure, Selectors selectors)
-{
- g_timeout_counter ++;
- c1->sendInterest(name, closure, selectors);
-}
-
-BOOST_AUTO_TEST_CASE (TestTimeout)
-{
- setup();
- g_dataCallback_counter = 0;
- g_timeout_counter = 0;
- Closure closure (bind(dataCallback, _1, _2), bind(reexpress, _1, _2, _3));
-
- Selectors selectors;
- selectors.interestLifetime(1);
-
- string n1 = "/random/04";
- c1->sendInterest(Name(n1), closure, selectors);
- usleep(3500000);
- c2->publishData(Name(n1), (const unsigned char *)n1.c_str(), n1.size(), 1);
- usleep(100000);
- BOOST_CHECK_EQUAL(g_dataCallback_counter, 1);
- BOOST_CHECK_EQUAL(g_timeout_counter, 3);
- teardown();
-}
-
-BOOST_AUTO_TEST_CASE (TestUnsigned)
-{
- setup();
- string n1 = "/xxxxxx/unsigned/01";
- Closure closure (bind(dataCallback, _1, _2), bind(timeout, _1, _2, _3));
-
- g_dataCallback_counter = 0;
- c1->sendInterest(Name(n1), closure);
- usleep(100000);
- c2->publishUnsignedData(Name(n1), (const unsigned char *)n1.c_str(), n1.size(), 1);
- usleep(100000);
- BOOST_CHECK_EQUAL(g_dataCallback_counter, 1);
-
- string n2 = "/xxxxxx/signed/01";
- Bytes content = c1->createContentObject(Name(n1), (const unsigned char *)n2.c_str(), n2.size(), 1);
- c1->publishUnsignedData(Name(n2), head(content), content.size(), 1);
- Closure encapClosure(bind(encapCallback, _1, _2), bind(timeout, _1, _2, _3));
- c2->sendInterest(Name(n2), encapClosure);
- usleep(4000000);
- BOOST_CHECK_EQUAL(g_dataCallback_counter, 2);
- teardown();
-}
-
-
- /*
- BOOST_AUTO_TEST_CASE (CcnxWrapperUnsigningTest)
- {
- setup();
- Bytes data;
- data.resize(1024);
- for (int i = 0; i < 1024; i++)
- {
- data[i] = 'm';
- }
-
- Name name("/unsigningtest");
-
- posix_time::ptime start = posix_time::second_clock::local_time();
- for (uint64_t i = 0; i < 100000; i++)
- {
- Name n = name;
- n.appendComp(i);
- c1->publishUnsignedData(n, data, 10);
- }
- posix_time::ptime end = posix_time::second_clock::local_time();
-
- posix_time::time_duration duration = end - start;
-
- cout << "Publishing 100000 1K size content objects costs " <<duration.total_milliseconds() << " milliseconds" << endl;
- cout << "Average time to publish one content object is " << (double) duration.total_milliseconds() / 100000.0 << " milliseconds" << endl;
- teardown();
- }
- */
-
-
-BOOST_AUTO_TEST_SUITE_END()
diff --git a/test/main.cpp b/tests/main.cpp
similarity index 97%
rename from test/main.cpp
rename to tests/main.cpp
index 9aeb059..4abe5de 100644
--- a/test/main.cpp
+++ b/tests/main.cpp
@@ -17,8 +17,9 @@
*
* See AUTHORS.md for complete list of ChronoShare authors and contributors.
*/
-
#define BOOST_TEST_MAIN 1
#define BOOST_TEST_DYN_LINK 1
+#include "test-common.hpp"
+
#include <boost/test/unit_test.hpp>
diff --git a/test/unit-tests/test-action-log.cc b/tests/unit-tests/action-log.t.cpp
similarity index 100%
rename from test/unit-tests/test-action-log.cc
rename to tests/unit-tests/action-log.t.cpp
diff --git a/test/unit-tests/test-dispatcher.cc b/tests/unit-tests/dispatcher.t.cpp
similarity index 100%
rename from test/unit-tests/test-dispatcher.cc
rename to tests/unit-tests/dispatcher.t.cpp
diff --git a/test/unit-tests/test-fetch-manager.cc b/tests/unit-tests/fetch-manager.t.cpp
similarity index 100%
rename from test/unit-tests/test-fetch-manager.cc
rename to tests/unit-tests/fetch-manager.t.cpp
diff --git a/test/unit-tests/test-fetch-task-db.cc b/tests/unit-tests/fetch-task-db.t.cpp
similarity index 100%
rename from test/unit-tests/test-fetch-task-db.cc
rename to tests/unit-tests/fetch-task-db.t.cpp
diff --git a/test/unit-tests/test-fs-watcher-delay.cc b/tests/unit-tests/fs-watcher-delay.t.cpp
similarity index 100%
rename from test/unit-tests/test-fs-watcher-delay.cc
rename to tests/unit-tests/fs-watcher-delay.t.cpp
diff --git a/test/unit-tests/test-fs-watcher.cc b/tests/unit-tests/fs-watcher.t.cpp
similarity index 100%
rename from test/unit-tests/test-fs-watcher.cc
rename to tests/unit-tests/fs-watcher.t.cpp
diff --git a/test/unit-tests/test-object-manager.cc b/tests/unit-tests/object-manager.t.cpp
similarity index 100%
rename from test/unit-tests/test-object-manager.cc
rename to tests/unit-tests/object-manager.t.cpp
diff --git a/test/unit-tests/test-protobuf.cc b/tests/unit-tests/protobuf.t.cpp
similarity index 100%
rename from test/unit-tests/test-protobuf.cc
rename to tests/unit-tests/protobuf.t.cpp
diff --git a/test/unit-tests/test-serve-and-fetch.cc b/tests/unit-tests/serve-and-fetch.t.cpp
similarity index 100%
rename from test/unit-tests/test-serve-and-fetch.cc
rename to tests/unit-tests/serve-and-fetch.t.cpp
diff --git a/test/unit-tests/test-sync-core.cc b/tests/unit-tests/sync-core.t.cpp
similarity index 100%
rename from test/unit-tests/test-sync-core.cc
rename to tests/unit-tests/sync-core.t.cpp
diff --git a/test/unit-tests/test-sync-log.cc b/tests/unit-tests/sync-log.t.cpp
similarity index 100%
rename from test/unit-tests/test-sync-log.cc
rename to tests/unit-tests/sync-log.t.cpp
diff --git a/test/wscript b/tests/wscript
similarity index 100%
rename from test/wscript
rename to tests/wscript
diff --git a/wscript b/wscript
index 8db6afa..a0115e7 100644
--- a/wscript
+++ b/wscript
@@ -207,7 +207,7 @@
# )
Logs.error("dump-db app compilation is temporary disabled")
- bld.recurse('test');
+ bld.recurse('tests');
from waflib import TaskGen
@TaskGen.extension('.mm')