add ccnx discovery, but no good way to test
diff --git a/ccnx/ccnx-discovery.cpp b/ccnx/ccnx-discovery.cpp
new file mode 100644
index 0000000..e5d9998
--- /dev/null
+++ b/ccnx/ccnx-discovery.cpp
@@ -0,0 +1,136 @@
+#include "ccnx-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 Ccnx;
+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
+CcnxDiscovery::INTERVAL = 15.0;
+
+CcnxDiscovery *
+CcnxDiscovery::instance = NULL;
+
+boost::mutex
+CcnxDiscovery::mutex;
+
+CcnxDiscovery::CcnxDiscovery()
+              : m_scheduler(new Scheduler())
+              , m_localPrefix("/")
+{
+  m_scheduler->start();
+  IntervalGeneratorPtr generator = boost::make_shared<SimpleIntervalGenerator>(INTERVAL);
+  TaskPtr task = boost::make_shared<PeriodicTask>(boost::bind(&CcnxDiscovery::poll, this), "Local-Prefix-Check", m_scheduler, generator);
+  m_scheduler->addTask(task);
+}
+
+CcnxDiscovery::~CcnxDiscovery()
+{
+  m_scheduler->shutdown();
+}
+
+void
+CcnxDiscovery::addCallback(const TaggedFunction &callback)
+{
+  m_callbacks.push_back(callback);
+}
+
+int
+CcnxDiscovery::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
+CcnxDiscovery::poll()
+{
+  Name localPrefix = CcnxWrapper::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
+CcnxDiscovery::registerCallback(const TaggedFunction &callback)
+{
+  Lock lock(mutex);
+  if (instance == NULL)
+  {
+    instance = new CcnxDiscovery();
+  }
+
+  instance->addCallback(callback);
+}
+
+void
+CcnxDiscovery::deregisterCallback(const TaggedFunction &callback)
+{
+  Lock lock(mutex);
+  if (instance == NULL)
+  {
+    cerr << "CcnxDiscovery::deregisterCallback called without instance" << endl;
+  }
+  else
+  {
+    int size = instance->deleteCallback(callback);
+    if (size == 0)
+    {
+      delete instance;
+      instance = NULL;
+    }
+  }
+}
+
diff --git a/ccnx/ccnx-discovery.h b/ccnx/ccnx-discovery.h
new file mode 100644
index 0000000..959167a
--- /dev/null
+++ b/ccnx/ccnx-discovery.h
@@ -0,0 +1,109 @@
+/* -*- 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 CCNX_DISCOVERY_H
+#define CCNX_DISCOVERY_H
+
+#include "ccnx-wrapper.h"
+#include "ccnx-common.h"
+#include "ccnx-name.h"
+#include "scheduler.h"
+#include <boost/shared_ptr.hpp>
+#include <boost/function.hpp>
+#include <boost/random/random_device.hpp>
+#include <boost/random/uniform_int_distribution.hpp>
+#include <boost/thread/mutex.hpp>
+#include <boost/thread/locks.hpp>
+#include <list>
+
+namespace Ccnx
+{
+
+class CcnxDiscovery;
+typedef boost::shared_ptr<CcnxDiscovery> CcnxDiscoveryPtr;
+
+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 CcnxDiscovery
+{
+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:
+  CcnxDiscovery();
+  ~CcnxDiscovery();
+
+  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 CcnxDiscovery *instance;
+  static Mutex mutex;
+  List m_callbacks;
+  SchedulerPtr m_scheduler;
+  Name m_localPrefix;
+};
+
+} // Ccnx
+#endif // CCNX_DISCOVERY_H