Simplify Leaf and its sub-classes.
Change-Id: I711db26bedee2bebdd39ffd8b637fa8918c16ff9
diff --git a/src/leaf.cpp b/src/leaf.cpp
new file mode 100644
index 0000000..129b1ea
--- /dev/null
+++ b/src/leaf.cpp
@@ -0,0 +1,78 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2012-2014 University of California, Los Angeles
+ *
+ * This file is part of ChronoSync, synchronization library for distributed realtime
+ * applications for NDN.
+ *
+ * ChronoSync is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation, either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * ChronoSync 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
+ * ChronoSync, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @author Zhenkai Zhu <http://irl.cs.ucla.edu/~zhenkai/>
+ * @author Chaoyi Bian <bcy@pku.edu.cn>
+ * @author Alexander Afanasyev <http://lasr.cs.ucla.edu/afanasyev/index.html>
+ */
+
+#include "leaf.hpp"
+
+namespace chronosync {
+
+Leaf::Leaf(const Name& sessionName, const SeqNo& seq)
+ : m_sessionName(sessionName)
+ , m_seq(seq)
+{
+ updateDigest();
+}
+
+Leaf::Leaf(const Name& userPrefix, uint64_t session, const SeqNo& seq)
+ : m_sessionName(userPrefix)
+ , m_seq(seq)
+{
+ m_sessionName.appendNumber(session);
+ updateDigest();
+}
+
+Leaf::~Leaf()
+{
+}
+
+ndn::ConstBufferPtr
+Leaf::getDigest() const
+{
+ return m_digest.computeDigest();
+}
+
+void
+Leaf::setSeq(const SeqNo& seq)
+{
+ if (seq > m_seq) {
+ m_seq = seq;
+ updateDigest();
+ }
+}
+
+void
+Leaf::updateDigest()
+{
+ m_digest.reset();
+ m_digest << getSessionName().wireEncode() << getSeq();
+ m_digest.computeDigest();
+}
+
+std::ostream&
+operator<<(std::ostream& os, const Leaf& leaf)
+{
+ os << leaf.getSessionName() << "(" << leaf.getSeq() << ")";
+ return os;
+}
+
+
+} // namespace chronosync
diff --git a/src/leaf.hpp b/src/leaf.hpp
new file mode 100644
index 0000000..635c087
--- /dev/null
+++ b/src/leaf.hpp
@@ -0,0 +1,93 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2012-2014 University of California, Los Angeles
+ *
+ * This file is part of ChronoSync, synchronization library for distributed realtime
+ * applications for NDN.
+ *
+ * ChronoSync is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation, either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * ChronoSync 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
+ * ChronoSync, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @author Zhenkai Zhu <http://irl.cs.ucla.edu/~zhenkai/>
+ * @author Chaoyi Bian <bcy@pku.edu.cn>
+ * @author Alexander Afanasyev <http://lasr.cs.ucla.edu/afanasyev/index.html>
+ * @author Yingdi Yu <yingdi@cs.ucla.edu>
+ */
+
+#ifndef CHRONOSYNC_LEAF_HPP
+#define CHRONOSYNC_LEAF_HPP
+
+#include "common.hpp"
+#include <ndn-cxx/util/digest.hpp>
+
+namespace chronosync {
+
+typedef uint64_t SeqNo;
+
+/**
+ * @brief Sync tree leaf
+ *
+ * The leaf node should be copyable when used to construct diff between two states.
+ */
+class Leaf
+{
+public:
+ Leaf(const Name& sessionName, const SeqNo& seq);
+
+ Leaf(const Name& userPrefix, uint64_t session, const SeqNo& seq);
+
+ virtual
+ ~Leaf();
+
+ const Name&
+ getSessionName() const
+ {
+ return m_sessionName;
+ }
+
+ const SeqNo&
+ getSeq() const
+ {
+ return m_seq;
+ }
+
+ ndn::ConstBufferPtr
+ getDigest() const;
+
+ /**
+ * @brief Update sequence number of the leaf
+ * @param seq Sequence number
+ *
+ * If seq is no greater than getSeq(), this operation has no effect.
+ */
+ virtual void
+ setSeq(const SeqNo& seq);
+
+private:
+ void
+ updateDigest();
+
+private:
+ Name m_sessionName;
+ SeqNo m_seq;
+
+ mutable ndn::util::Sha256 m_digest;
+};
+
+typedef boost::shared_ptr<Leaf> LeafPtr;
+typedef boost::shared_ptr<const Leaf> ConstLeafPtr;
+
+std::ostream&
+operator<<(std::ostream& os, const Leaf& leaf);
+
+} // namespace chronosync
+
+#endif // CHRONOSYNC_LEAF_HPP
diff --git a/src/sync-diff-leaf.cc b/src/sync-diff-leaf.cc
deleted file mode 100644
index 80527d6..0000000
--- a/src/sync-diff-leaf.cc
+++ /dev/null
@@ -1,75 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2012-2014 University of California, Los Angeles
- *
- * This file is part of ChronoSync, synchronization library for distributed realtime
- * applications for NDN.
- *
- * ChronoSync is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation, either
- * version 3 of the License, or (at your option) any later version.
- *
- * ChronoSync 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
- * ChronoSync, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
- *
- * @author Zhenkai Zhu <http://irl.cs.ucla.edu/~zhenkai/>
- * @author Chaoyi Bian <bcy@pku.edu.cn>
- * @author Alexander Afanasyev <http://lasr.cs.ucla.edu/afanasyev/index.html>
- */
-
-#include "sync-diff-leaf.h"
-#include <boost/throw_exception.hpp>
-typedef boost::error_info<struct tag_errmsg, std::string> errmsg_info;
-
-using namespace Sync::Error;
-
-namespace Sync {
-
-DiffLeaf::DiffLeaf (NameInfoConstPtr info, const SeqNo &seq)
- : Leaf (info, seq)
- , m_op (UPDATE)
-{
-}
-
-DiffLeaf::DiffLeaf (NameInfoConstPtr info)
- : Leaf (info, SeqNo (0,0))
- , m_op (REMOVE)
-{
-}
-
-std::ostream &
-operator << (std::ostream &os, Operation op)
-{
- switch (op)
- {
- case UPDATE:
- os << "update";
- break;
- case REMOVE:
- os << "remove";
- break;
- }
- return os;
-}
-
-std::istream &
-operator >> (std::istream &is, Operation &op)
-{
- std::string operation;
- is >> operation;
- if (operation == "update")
- op = UPDATE;
- else if (operation == "remove")
- op = REMOVE;
- else
- BOOST_THROW_EXCEPTION (SyncDiffLeafOperationParseError () << errmsg_info (operation));
-
- return is;
-}
-
-
-}
diff --git a/src/sync-diff-leaf.h b/src/sync-diff-leaf.h
deleted file mode 100644
index 2f692ee..0000000
--- a/src/sync-diff-leaf.h
+++ /dev/null
@@ -1,92 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2012-2014 University of California, Los Angeles
- *
- * This file is part of ChronoSync, synchronization library for distributed realtime
- * applications for NDN.
- *
- * ChronoSync is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation, either
- * version 3 of the License, or (at your option) any later version.
- *
- * ChronoSync 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
- * ChronoSync, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
- *
- * @author Zhenkai Zhu <http://irl.cs.ucla.edu/~zhenkai/>
- * @author Chaoyi Bian <bcy@pku.edu.cn>
- * @author Alexander Afanasyev <http://lasr.cs.ucla.edu/afanasyev/index.html>
- */
-
-#ifndef SYNC_DIFF_LEAF_H
-#define SYNC_DIFF_LEAF_H
-
-#include "sync-leaf.h"
-#include <boost/exception/all.hpp>
-
-namespace Sync {
-
-/**
- * @ingroup sync
- * @brief Annotation for SYNC leaf
- */
-enum Operation
- {
- UPDATE, ///< @brief Leaf was added or updated
- REMOVE ///< @brief Leaf was removed
- };
-
-/**
- * @ingroup sync
- * @brief Annotated SYNC leaf
- */
-class DiffLeaf : public Leaf
-{
-public:
- /**
- * @brief Constructor to create an UPDATE diff leaf
- * @param info Smart pointer to leaf's name
- * @param seq Initial sequence number of the pointer
- */
- DiffLeaf (NameInfoConstPtr info, const SeqNo &seq);
-
- /**
- * @brief Constructor to create an REMOVE diff leaf
- * @param info Smart pointer to leaf's name
- *
- * This constructor creates a leaf with phony sequence number
- * with 0 session ID and 0 sequence number
- */
- DiffLeaf (NameInfoConstPtr info);
-
- virtual ~DiffLeaf () { }
-
- /**
- * @brief Get diff leaf type
- */
- Operation
- getOperation () const { return m_op; }
-
-private:
- Operation m_op;
-};
-
-typedef boost::shared_ptr<DiffLeaf> DiffLeafPtr;
-typedef boost::shared_ptr<const DiffLeaf> DiffLeafConstPtr;
-
-std::ostream &
-operator << (std::ostream &os, Operation op);
-
-std::istream &
-operator >> (std::istream &is, Operation &op);
-
-namespace Error {
-struct SyncDiffLeafOperationParseError : virtual boost::exception, virtual std::exception { };
-} // Error
-
-} // Sync
-
-#endif // SYNC_DIFF_LEAF_H
diff --git a/src/sync-digest.cc b/src/sync-digest.cc
deleted file mode 100644
index ce1d506..0000000
--- a/src/sync-digest.cc
+++ /dev/null
@@ -1,262 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2012-2014 University of California, Los Angeles
- *
- * This file is part of ChronoSync, synchronization library for distributed realtime
- * applications for NDN.
- *
- * ChronoSync is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation, either
- * version 3 of the License, or (at your option) any later version.
- *
- * ChronoSync 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
- * ChronoSync, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
- *
- * @author Zhenkai Zhu <http://irl.cs.ucla.edu/~zhenkai/>
- * @author Chaoyi Bian <bcy@pku.edu.cn>
- * @author Alexander Afanasyev <http://lasr.cs.ucla.edu/afanasyev/index.html>
- */
-
-#include "sync-digest.h"
-#include <string.h>
-
-#include "boost-header.h"
-
-typedef boost::error_info<struct tag_errmsg, std::string> errmsg_info_str;
-typedef boost::error_info<struct tag_errmsg, int> errmsg_info_int;
-
-// for printing, may be disabled in optimized build
-
-// #ifdef DIGEST_BASE64
-// #include <boost/archive/iterators/base64_from_binary.hpp>
-// #include <boost/archive/iterators/binary_from_base64.hpp>
-// #endif
-
-
-
-using namespace boost;
-using namespace boost::archive::iterators;
-
-// Other options: VP_md2, EVP_md5, EVP_sha, EVP_sha1, EVP_sha256, EVP_dss, EVP_dss1, EVP_mdc2, EVP_ripemd160
-#define HASH_FUNCTION EVP_sha256
-#define HASH_FUNCTION_LEN 32
-
-
-// #ifndef DIGEST_BASE64
-
-template<class CharType>
-struct hex_from_4_bit
-{
- typedef CharType result_type;
- CharType operator () (CharType ch) const
- {
- const char *lookup_table = "0123456789abcdef";
- // cout << "New character: " << (int) ch << " (" << (char) ch << ")" << "\n";
- BOOST_ASSERT (ch < 16);
- return lookup_table[static_cast<size_t>(ch)];
- }
-};
-
-typedef transform_iterator<hex_from_4_bit<std::vector<uint8_t>::const_iterator::value_type>,
- transform_width<std::vector<uint8_t>::const_iterator, 4, 8, std::vector<uint8_t>::const_iterator::value_type> > string_from_binary;
-
-
-template<class CharType>
-struct hex_to_4_bit
-{
- typedef CharType result_type;
- CharType operator () (CharType ch) const
- {
- const signed char lookup_table [] = {
- -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
- -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
- -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,-1,-1,-1,-1,-1,-1,
- -1,10,11,12,13,14,15,-1,-1,-1,-1,-1,-1,-1,-1,-1,
- -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
- -1,10,11,12,13,14,15,-1,-1,-1,-1,-1,-1,-1,-1,-1,
- -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1
- };
-
- // cout << "New character: " << hex << (int) ch << " (" << (char) ch << ")" << "\n";
- signed char value = -1;
- if ((unsigned)ch < 128)
- value = lookup_table [(unsigned)ch];
- if (value == -1)
- BOOST_THROW_EXCEPTION (Sync::Error::DigestCalculationError () << errmsg_info_int ((int)ch));
-
- return value;
- }
-};
-
-typedef transform_width<transform_iterator<hex_to_4_bit<std::string::const_iterator::value_type>, std::string::const_iterator>, 8, 4> string_to_binary;
-
-namespace Sync {
-
-Digest::Digest ()
-{
- m_context = EVP_MD_CTX_create ();
-
- reset ();
-}
-
-Digest::~Digest ()
-{
- EVP_MD_CTX_destroy (m_context);
-}
-
-bool
-Digest::empty () const
-{
- return m_buffer.empty ();
-}
-
-bool
-Digest::isZero () const
-{
- if (m_buffer.empty ())
- BOOST_THROW_EXCEPTION (Error::DigestCalculationError ()
- << errmsg_info_str ("Digest has not been yet finalized"));
-
- return (m_buffer.size () == 1 && m_buffer[0] == 0);
-}
-
-
-void
-Digest::reset ()
-{
- m_buffer.clear ();
-
- int ok = EVP_DigestInit_ex (m_context, HASH_FUNCTION (), 0);
- if (!ok)
- BOOST_THROW_EXCEPTION (Error::DigestCalculationError ()
- << errmsg_info_str ("EVP_DigestInit_ex returned error")
- << errmsg_info_int (ok));
-}
-
-
-void
-Digest::finalize ()
-{
- if (!m_buffer.empty ()) return;
-
- m_buffer.resize (HASH_FUNCTION_LEN);
-
- unsigned int tmp;
- int ok = EVP_DigestFinal_ex (m_context,
- &m_buffer[0], &tmp);
- if (!ok)
- BOOST_THROW_EXCEPTION (Error::DigestCalculationError ()
- << errmsg_info_str ("EVP_DigestFinal_ex returned error")
- << errmsg_info_int (ok));
-}
-
-std::size_t
-Digest::getHash () const
-{
- if (isZero ()) return 0;
-
- if (sizeof (std::size_t) > m_buffer.size ())
- {
- BOOST_THROW_EXCEPTION (Error::DigestCalculationError ()
- << errmsg_info_str ("Hash is not zero and length is less than size_t")
- << errmsg_info_int (m_buffer.size ()));
- }
-
- // just getting first sizeof(std::size_t) bytes
- // not ideal, but should work pretty well
- return *(reinterpret_cast<const std::size_t*> (&m_buffer[0]));
-}
-
-bool
-Digest::operator == (const Digest &digest) const
-{
- if (m_buffer.empty ())
- BOOST_THROW_EXCEPTION (Error::DigestCalculationError ()
- << errmsg_info_str ("Digest1 is empty"));
-
- if (digest.m_buffer.empty ())
- BOOST_THROW_EXCEPTION (Error::DigestCalculationError ()
- << errmsg_info_str ("Digest2 is empty"));
-
- return m_buffer == digest.m_buffer;
-}
-
-
-void
-Digest::update (const uint8_t *buffer, size_t size)
-{
- // cout << "Update: " << (void*)buffer << " / size: " << size << "\n";
-
- // cannot update Digest when it has been finalized
- if (!m_buffer.empty ())
- BOOST_THROW_EXCEPTION (Error::DigestCalculationError ()
- << errmsg_info_str ("Digest has been already finalized"));
-
- bool ok = EVP_DigestUpdate (m_context, buffer, size);
- if (!ok)
- BOOST_THROW_EXCEPTION (Error::DigestCalculationError ()
- << errmsg_info_str ("EVP_DigestUpdate returned error")
- << errmsg_info_int (ok));
-}
-
-
-Digest &
-Digest::operator << (const Digest &src)
-{
- if (src.m_buffer.empty ())
- BOOST_THROW_EXCEPTION (Error::DigestCalculationError ()
- << errmsg_info_str ("Digest has not been yet finalized"));
-
- update (&src.m_buffer[0], src.m_buffer.size ());
-
- return *this;
-}
-
-std::ostream &
-operator << (std::ostream &os, const Digest &digest)
-{
- BOOST_ASSERT (!digest.m_buffer.empty ());
-
- std::ostreambuf_iterator<char> out_it (os); // ostream iterator
- // need to encode to base64
- copy (string_from_binary (digest.m_buffer.begin ()),
- string_from_binary (digest.m_buffer.end ()),
- out_it);
-
- return os;
-}
-
-std::istream &
-operator >> (std::istream &is, Digest &digest)
-{
- std::string str;
- is >> str; // read string first
-
- if (str.size () == 0)
- BOOST_THROW_EXCEPTION (Error::DigestCalculationError ()
- << errmsg_info_str ("Input is empty"));
-
- // uint8_t padding = (3 - str.size () % 3) % 3;
- // for (uint8_t i = 0; i < padding; i++) str.push_back ('=');
-
- // only empty digest object can be used for reading
- if (!digest.m_buffer.empty ())
- BOOST_THROW_EXCEPTION (Error::DigestCalculationError ()
- << errmsg_info_str ("Digest has been already finalized"));
-
- digest.m_buffer.clear ();
-
- copy (string_to_binary (str.begin ()),
- string_to_binary (str.end ()),
- std::back_inserter (digest.m_buffer));
-
- return is;
-}
-
-
-} // Sync
diff --git a/src/sync-digest.h b/src/sync-digest.h
deleted file mode 100644
index d66af3e..0000000
--- a/src/sync-digest.h
+++ /dev/null
@@ -1,200 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2012-2014 University of California, Los Angeles
- *
- * This file is part of ChronoSync, synchronization library for distributed realtime
- * applications for NDN.
- *
- * ChronoSync is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation, either
- * version 3 of the License, or (at your option) any later version.
- *
- * ChronoSync 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
- * ChronoSync, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
- *
- * @author Zhenkai Zhu <http://irl.cs.ucla.edu/~zhenkai/>
- * @author Chaoyi Bian <bcy@pku.edu.cn>
- * @author Alexander Afanasyev <http://lasr.cs.ucla.edu/afanasyev/index.html>
- */
-
-#ifndef SYNC_DIGEST_H
-#define SYNC_DIGEST_H
-
-#include <boost/exception/all.hpp>
-#include <openssl/evp.h>
-#include <boost/cstdint.hpp>
-#include <vector>
-
-namespace Sync {
-
-/**
- * @ingroup sync
- * @brief A simple wrapper for libcrypto hash functions
- */
-class Digest
-{
-public:
- /**
- * @brief Default constructor. Will initialize internal libssl structures
- */
- Digest ();
-
- /**
- * @brief Check if digest is empty
- */
- bool
- empty () const;
-
- /**
- * @brief Reset digest to the initial state
- */
- void
- reset ();
-
- /**
- * @brief Destructor
- */
- ~Digest ();
-
- /**
- * @brief Obtain a short version of the hash (just first sizeof(size_t) bytes
- *
- * Side effect: finalize() will be called on `this'
- */
- std::size_t
- getHash () const;
-
- /**
- * @brief Finalize digest. All subsequent calls to "operator <<" will fire an exception
- */
- void
- finalize ();
-
- /**
- * @brief Compare two full digests
- *
- * Side effect: Finalize will be called on `this' and `digest'
- */
- bool
- operator == (const Digest &digest) const;
-
- bool
- operator != (const Digest &digest) const
- { return ! (*this == digest); }
-
-
- /**
- * @brief Add existing digest to digest calculation
- * @param src digest to combine with
- *
- * The result of this combination is hash (hash (...))
- */
- Digest &
- operator << (const Digest &src);
-
- /**
- * @brief Add string to digest calculation
- * @param str string to put into digest
- */
- inline Digest &
- operator << (const std::string &str);
-
- /**
- * @brief Add uint64_t value to digest calculation
- * @param value uint64_t value to put into digest
- */
- inline Digest &
- operator << (uint64_t value);
-
- /**
- * @brief Checks if the stored hash is zero-root hash
- *
- * Zero-root hash is a valid hash that optimally represents an empty state
- */
- bool
- isZero () const;
-
-private:
- Digest &
- operator = (Digest &digest) { (void)digest; return *this; }
-
- /**
- * @brief Add size bytes of buffer to the hash
- */
- void
- update (const uint8_t *buffer, size_t size);
-
- friend std::ostream &
- operator << (std::ostream &os, const Digest &digest);
-
- friend std::istream &
- operator >> (std::istream &is, Digest &digest);
-
-private:
- EVP_MD_CTX *m_context;
- std::vector<uint8_t> m_buffer;
-};
-
-namespace Error {
-struct DigestCalculationError : virtual boost::exception, virtual std::exception { };
-}
-
-typedef boost::shared_ptr<Digest> DigestPtr;
-typedef boost::shared_ptr<const Digest> DigestConstPtr;
-
-Digest &
-Digest::operator << (const std::string &str)
-{
- update (reinterpret_cast<const uint8_t*> (str.c_str ()), str.size ());
- return *this;
-}
-
-inline Digest &
-Digest::operator << (uint64_t value)
-{
- update (reinterpret_cast<const uint8_t*> (&value), sizeof (uint64_t));
- return *this;
-}
-
-std::ostream &
-operator << (std::ostream &os, const Digest &digest);
-
-std::istream &
-operator >> (std::istream &is, Digest &digest);
-
-// template<class INT>
-// Digest &
-// Digest::operator << (INT value)
-// {
-// update (&value, sizeof (INT));
-// return *this;
-// }
-
-struct DigestPtrHash : public std::unary_function<Digest, std::size_t>
-{
- std::size_t
- operator() (DigestConstPtr digest) const
- {
- // std::cout << "digest->getHash: " << digest->getHash () << " (" << *digest << ")" << std::endl;
- return digest->getHash ();
- }
-};
-
-struct DigestPtrEqual : public std::unary_function<Digest, std::size_t>
-{
- bool
- operator() (DigestConstPtr digest1, DigestConstPtr digest2) const
- {
- // std::cout << boost::cref(*digest1) << " == " << boost::cref(*digest2) << " : " << (*digest1 == *digest2) << std::endl;
- return *digest1 == *digest2;
- }
-};
-
-
-} // Sync
-
-#endif // SYNC_DIGEST_H
diff --git a/src/sync-full-leaf.cc b/src/sync-full-leaf.cc
deleted file mode 100644
index 7a25c8b..0000000
--- a/src/sync-full-leaf.cc
+++ /dev/null
@@ -1,53 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2012-2014 University of California, Los Angeles
- *
- * This file is part of ChronoSync, synchronization library for distributed realtime
- * applications for NDN.
- *
- * ChronoSync is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation, either
- * version 3 of the License, or (at your option) any later version.
- *
- * ChronoSync 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
- * ChronoSync, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
- *
- * @author Zhenkai Zhu <http://irl.cs.ucla.edu/~zhenkai/>
- * @author Chaoyi Bian <bcy@pku.edu.cn>
- * @author Alexander Afanasyev <http://lasr.cs.ucla.edu/afanasyev/index.html>
- */
-
-#include "sync-full-leaf.h"
-#include <boost/ref.hpp>
-
-using namespace boost;
-
-namespace Sync {
-
-FullLeaf::FullLeaf (NameInfoConstPtr info, const SeqNo &seq)
- : Leaf (info, seq)
-{
- updateDigest ();
-}
-
-void
-FullLeaf::updateDigest ()
-{
- m_digest.reset ();
- m_digest << getInfo ()->getDigest () << *getSeq ().getDigest ();
- m_digest.finalize ();
-}
-
-// from Leaf
-void
-FullLeaf::setSeq (const SeqNo &seq)
-{
- Leaf::setSeq (seq);
- updateDigest ();
-}
-
-} // Sync
diff --git a/src/sync-full-leaf.h b/src/sync-full-leaf.h
deleted file mode 100644
index 5e7f8e1..0000000
--- a/src/sync-full-leaf.h
+++ /dev/null
@@ -1,72 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2012-2014 University of California, Los Angeles
- *
- * This file is part of ChronoSync, synchronization library for distributed realtime
- * applications for NDN.
- *
- * ChronoSync is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation, either
- * version 3 of the License, or (at your option) any later version.
- *
- * ChronoSync 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
- * ChronoSync, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
- *
- * @author Zhenkai Zhu <http://irl.cs.ucla.edu/~zhenkai/>
- * @author Chaoyi Bian <bcy@pku.edu.cn>
- * @author Alexander Afanasyev <http://lasr.cs.ucla.edu/afanasyev/index.html>
- */
-
-#ifndef SYNC_FULL_LEAF_H
-#define SYNC_FULL_LEAF_H
-
-#include "sync-leaf.h"
-
-namespace Sync {
-
-/**
- * @ingroup sync
- * @brief SYNC leaf for the full state (with support of Digest calculation)
- */
-class FullLeaf : public Leaf
-{
-public:
- /**
- * @brief Constructor to create an UPDATE diff leaf
- * @param info Smart pointer to leaf's name
- * @param seq Initial sequence number of the pointer
- */
- FullLeaf (NameInfoConstPtr info, const SeqNo &seq);
- virtual ~FullLeaf () { }
-
- /**
- * @brief Get hash digest of the leaf
- *
- * The underlying Digest object is recalculated on every update or removal
- * (including updates of child classes)
- */
- const Digest &
- getDigest () const { return m_digest; }
-
- // from Leaf
- virtual void
- setSeq (const SeqNo &seq);
-
-private:
- void
- updateDigest ();
-
-private:
- Digest m_digest;
-};
-
-typedef boost::shared_ptr<FullLeaf> FullLeafPtr;
-typedef boost::shared_ptr<const FullLeaf> FullLeafConstPtr;
-
-} // Sync
-
-#endif // SYNC_FULL_LEAF_H
diff --git a/src/sync-leaf.cc b/src/sync-leaf.cc
deleted file mode 100644
index e117ca3..0000000
--- a/src/sync-leaf.cc
+++ /dev/null
@@ -1,44 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2012-2014 University of California, Los Angeles
- *
- * This file is part of ChronoSync, synchronization library for distributed realtime
- * applications for NDN.
- *
- * ChronoSync is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation, either
- * version 3 of the License, or (at your option) any later version.
- *
- * ChronoSync 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
- * ChronoSync, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
- *
- * @author Zhenkai Zhu <http://irl.cs.ucla.edu/~zhenkai/>
- * @author Chaoyi Bian <bcy@pku.edu.cn>
- * @author Alexander Afanasyev <http://lasr.cs.ucla.edu/afanasyev/index.html>
- */
-
-#include "sync-leaf.h"
-
-namespace Sync {
-
-Leaf::Leaf (NameInfoConstPtr info, const SeqNo &seq)
- : m_info (info)
- , m_seq (seq)
-{
-}
-
-Leaf::~Leaf ()
-{
-}
-
-void
-Leaf::setSeq (const SeqNo &seq)
-{
- m_seq = std::max (m_seq, seq);
-}
-
-} // Sync
diff --git a/src/sync-leaf.h b/src/sync-leaf.h
deleted file mode 100644
index 567ab7e..0000000
--- a/src/sync-leaf.h
+++ /dev/null
@@ -1,85 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2012-2014 University of California, Los Angeles
- *
- * This file is part of ChronoSync, synchronization library for distributed realtime
- * applications for NDN.
- *
- * ChronoSync is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation, either
- * version 3 of the License, or (at your option) any later version.
- *
- * ChronoSync 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
- * ChronoSync, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
- *
- * @author Zhenkai Zhu <http://irl.cs.ucla.edu/~zhenkai/>
- * @author Chaoyi Bian <bcy@pku.edu.cn>
- * @author Alexander Afanasyev <http://lasr.cs.ucla.edu/afanasyev/index.html>
- */
-
-#ifndef SYNC_LEAF_H
-#define SYNC_LEAF_H
-
-#include "sync-seq-no.h"
-#include "sync-name-info.h"
-
-namespace Sync {
-
-/**
- * \ingroup sync
- * @brief Sync tree leaf
- */
-class Leaf
-{
-public:
- /**
- * @brief Constructor
- * @param info Smart pointer to leaf's name
- * @param seq Initial sequence number of the pointer
- */
- Leaf (NameInfoConstPtr info, const SeqNo &seq);
- virtual ~Leaf ();
-
- /**
- * @brief Get name of the leaf
- */
- NameInfoConstPtr
- getInfo () const { return m_info; }
-
- /**
- * @brief Get sequence number of the leaf
- */
- const SeqNo&
- getSeq () const { return m_seq; }
-
- /**
- * @brief Update sequence number of the leaf
- * @param seq Sequence number
- *
- * Sequence number is updated to the largest value among this->m_seq and seq
- */
- virtual void
- setSeq (const SeqNo &seq);
-
-private:
- NameInfoConstPtr m_info;
- SeqNo m_seq;
-};
-
-typedef boost::shared_ptr<Leaf> LeafPtr;
-typedef boost::shared_ptr<const Leaf> LeafConstPtr;
-
-inline std::ostream &
-operator << (std::ostream &os, const Leaf &leaf)
-{
- os << *leaf.getInfo () << "(" << leaf.getSeq () << ")";
- return os;
-}
-
-} // Sync
-
-#endif // SYNC_LEAF_H
diff --git a/src/sync-name-info.cc b/src/sync-name-info.cc
deleted file mode 100644
index eb7411a..0000000
--- a/src/sync-name-info.cc
+++ /dev/null
@@ -1,33 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2012-2014 University of California, Los Angeles
- *
- * This file is part of ChronoSync, synchronization library for distributed realtime
- * applications for NDN.
- *
- * ChronoSync is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation, either
- * version 3 of the License, or (at your option) any later version.
- *
- * ChronoSync 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
- * ChronoSync, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
- *
- * @author Zhenkai Zhu <http://irl.cs.ucla.edu/~zhenkai/>
- * @author Chaoyi Bian <bcy@pku.edu.cn>
- * @author Alexander Afanasyev <http://lasr.cs.ucla.edu/afanasyev/index.html>
- */
-
-#include "sync-name-info.h"
-
-// #include <boost/lexical_cast.hpp>
-
-namespace Sync {
-
-NameInfo::NameMap NameInfo::m_names;
-size_t NameInfo::m_ids = 0;
-
-} // Sync
diff --git a/src/sync-name-info.h b/src/sync-name-info.h
deleted file mode 100644
index 2932b6e..0000000
--- a/src/sync-name-info.h
+++ /dev/null
@@ -1,103 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2012-2014 University of California, Los Angeles
- *
- * This file is part of ChronoSync, synchronization library for distributed realtime
- * applications for NDN.
- *
- * ChronoSync is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation, either
- * version 3 of the License, or (at your option) any later version.
- *
- * ChronoSync 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
- * ChronoSync, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
- *
- * @author Zhenkai Zhu <http://irl.cs.ucla.edu/~zhenkai/>
- * @author Chaoyi Bian <bcy@pku.edu.cn>
- * @author Alexander Afanasyev <http://lasr.cs.ucla.edu/afanasyev/index.html>
- */
-
-#ifndef SYNC_NAME_INFO_H
-#define SYNC_NAME_INFO_H
-
-#include <boost/shared_ptr.hpp>
-#include <boost/weak_ptr.hpp>
-#include <map>
-#include <string>
-#include "sync-digest.h"
-
-namespace Sync {
-
-/**
- * @ingroup sync
- * @brief Templated class for the leaf name
- */
-class NameInfo
-{
-private:
- typedef boost::weak_ptr<const NameInfo> const_weak_ptr;
-
-public:
- virtual ~NameInfo () { };
-
- /**
- * @brief Get ID of the record (should be locally-unique, but not really necessary---this is be used for hashing purposes)
- */
- size_t
- getHashId () const { return m_id; }
-
- /**
- * @brief Check if two names are equal
- * @param info name to check with
- */
- virtual bool
- operator == (const NameInfo &info) const = 0;
-
- /**
- * @brief Check if two names are in order
- * @param info name to check with
- */
- virtual bool
- operator < (const NameInfo &info) const = 0;
-
- /**
- * @brief Calculates digest of the name
- */
- const Digest &
- getDigest () const { return m_digest; }
-
- /**
- * @brief Convert prefix to string
- * @returns string representation of prefix
- */
- virtual std::string
- toString () const = 0;
-
-protected:
- // actual stuff
- size_t m_id; ///< @brief Identifies NameInfo throughout the library (for hash container, doesn't need to be strictly unique)
- Digest m_digest;
-
- // static stuff
- typedef std::map<std::string, const_weak_ptr> NameMap;
- static size_t m_ids;
- static NameMap m_names;
-};
-
-typedef boost::shared_ptr<NameInfo> NameInfoPtr;
-typedef boost::shared_ptr<const NameInfo> NameInfoConstPtr;
-
-inline std::ostream &
-operator << (std::ostream &os, const NameInfo &info)
-{
- os << info.toString ();
- return os;
-}
-
-} // Sync
-
-#endif // SYNC_NAME_INFO_H
diff --git a/src/sync-seq-no.cc b/src/sync-seq-no.cc
deleted file mode 100644
index aba1672..0000000
--- a/src/sync-seq-no.cc
+++ /dev/null
@@ -1,41 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2012-2014 University of California, Los Angeles
- *
- * This file is part of ChronoSync, synchronization library for distributed realtime
- * applications for NDN.
- *
- * ChronoSync is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation, either
- * version 3 of the License, or (at your option) any later version.
- *
- * ChronoSync 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
- * ChronoSync, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
- *
- * @author Zhenkai Zhu <http://irl.cs.ucla.edu/~zhenkai/>
- * @author Chaoyi Bian <bcy@pku.edu.cn>
- * @author Alexander Afanasyev <http://lasr.cs.ucla.edu/afanasyev/index.html>
- * @author Yingdi Yu <http://irl.cs.ucla.edu/~yingdi/web/index.html>
- */
-
-#include "sync-seq-no.h"
-#include <boost/make_shared.hpp>
-
-using namespace boost;
-
-namespace Sync {
-
-DigestConstPtr
-SeqNo::getDigest () const
-{
- DigestPtr digest = make_shared<Digest> ();
- *digest << m_session << m_seq;
- digest->finalize ();
- return digest;
-}
-
-} // Sync
diff --git a/src/sync-seq-no.h b/src/sync-seq-no.h
deleted file mode 100644
index 7b8399f..0000000
--- a/src/sync-seq-no.h
+++ /dev/null
@@ -1,199 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2012-2014 University of California, Los Angeles
- *
- * This file is part of ChronoSync, synchronization library for distributed realtime
- * applications for NDN.
- *
- * ChronoSync is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation, either
- * version 3 of the License, or (at your option) any later version.
- *
- * ChronoSync 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
- * ChronoSync, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
- *
- * @author Zhenkai Zhu <http://irl.cs.ucla.edu/~zhenkai/>
- * @author Chaoyi Bian <bcy@pku.edu.cn>
- * @author Alexander Afanasyev <http://lasr.cs.ucla.edu/afanasyev/index.html>
- * @author Yingdi Yu <http://irl.cs.ucla.edu/~yingdi/web/index.html>
- */
-
-#ifndef SYNC_SEQ_NO_H
-#define SYNC_SEQ_NO_H
-
-#include <boost/cstdint.hpp>
-#include "sync-digest.h"
-
-namespace Sync {
-
-/**
- * @ingroup sync
- * @brief Sequence number abstraction
- */
-class SeqNo
-{
-public:
- /**
- * @brief Default constructor. Creates an zero sequence number with zero session ID (basically is an invalid object)
- */
- SeqNo ()
- : m_valid (false)
- , m_session (0)
- , m_seq (0)
- {
- }
-
- /**
- * @brief Copy constructor
- * @param seq sequence number object to copy from
- */
- SeqNo (const SeqNo &seq)
- {
- *this = seq;
- }
-
- /**
- * @brief Assignment operator
- * @param seq sequence number object to copy from
- */
- SeqNo &
- operator = (const SeqNo &seq)
- {
- m_valid = seq.m_valid;
- m_session = seq.m_session;
- m_seq = seq.m_seq;
-
- return *this;
- }
-
- /**
- * @brief Constructor with just sequence number. Session assumed to be zero
- * @param seq Sequence number
- */
- SeqNo (uint64_t seq)
- : m_valid (true)
- , m_session (0)
- , m_seq (seq)
- { }
-
- /**
- * @brief Constructor with session and sequence id
- * @param session Session ID
- * @param seq Sequence number
- */
- SeqNo (uint64_t session, uint64_t seq)
- : m_valid (true)
- , m_session (session)
- , m_seq (seq)
- { }
-
- /**
- * @brief Get sequence number digest
- *
- * Digest will be calculated every time it is requested
- */
- DigestConstPtr
- getDigest () const;
-
- /**
- * @brief Compare if one sequence number is lower
- * @param seq Another sequence number to compare with
- *
- * tuple (session1, seq1) is less than (session2, seq2) in two cases:
- * 1. session1 < session2
- * 2. session1 == session2 and seq1 < seq2
- */
- bool
- operator < (const SeqNo &seq) const
- {
- return m_session < seq.m_session || (m_session == seq.m_session && m_seq < seq.m_seq);
- }
-
- /**
- * @brief Compare if two sequence numbers are equal
- * @param seq Another sequence number to compare with
- */
- bool
- operator == (const SeqNo &seq) const
- {
- return m_session == seq.m_session && m_seq == seq.m_seq;
- }
-
- bool
- operator <= (const SeqNo &seq) const
- {
- return m_session == seq.m_session && m_seq <= seq.m_seq;
- }
-
- SeqNo &
- operator ++ ()
- {
- if (m_valid) {
- m_seq ++;
- }
- else {
- m_valid = true;
- }
- return *this;
- }
-
- bool
- isValid () const
- {
- return m_valid;
- }
-
- /**
- * @brief Get session id
- */
- uint64_t getSession () const
- { return m_session; }
-
- /**
- * @brief Get sequence number
- */
- uint64_t getSeq () const
- { return m_seq; }
-
- /**
- * @brief Set sequence number
- */
- void
- setSeq(uint64_t seq)
- { m_seq = seq; }
-
-private:
- bool m_valid;
-
- /**
- * @brief Session ID (e.g., after crash, application will choose new session ID.
- *
- * Note that session IDs for the same name should always increase. So, the good choice
- * for the session ID is client's timestamp
- */
- uint64_t m_session;
-
- /**
- * @brief Sequence number
- *
- * Sequence number for a session always starts with 0 and goes to max value.
- *
- * For now, wrapping sequence number after max to zero is not supported
- */
- uint64_t m_seq;
-};
-
-inline std::ostream &
-operator << (std::ostream &os, const SeqNo &seqno)
-{
- os << "<session>" << seqno.getSession () << "</session><seqno>" << seqno.getSeq () << "</seqno>";
- return os;
-}
-
-} // Sync
-
-#endif // SYNC_SEQ_NO_H
diff --git a/src/sync-std-name-info.cc b/src/sync-std-name-info.cc
deleted file mode 100644
index bc4e80f..0000000
--- a/src/sync-std-name-info.cc
+++ /dev/null
@@ -1,93 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2012-2014 University of California, Los Angeles
- *
- * This file is part of ChronoSync, synchronization library for distributed realtime
- * applications for NDN.
- *
- * ChronoSync is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation, either
- * version 3 of the License, or (at your option) any later version.
- *
- * ChronoSync 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
- * ChronoSync, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
- *
- * @author Zhenkai Zhu <http://irl.cs.ucla.edu/~zhenkai/>
- * @author Chaoyi Bian <bcy@pku.edu.cn>
- * @author Alexander Afanasyev <http://lasr.cs.ucla.edu/afanasyev/index.html>
- */
-
-#include "sync-std-name-info.h"
-
-// using namespace std;
-using namespace boost;
-
-namespace Sync {
-
-
-NameInfoConstPtr
-StdNameInfo::FindOrCreate (const std::string &key)
-{
- // std::cout << "FindOrCreate: " << m_names.size () << "\n";
-
- NameInfoConstPtr ret;
-
- NameMap::iterator item = m_names.find (key);
- if (item != m_names.end ())
- {
- ret = item->second.lock ();
- BOOST_ASSERT (ret != 0);
- }
- else
- {
- ret = NameInfoPtr (new StdNameInfo (key));
- weak_ptr<const NameInfo> value (ret);
- std::pair<NameMap::iterator,bool> inserted =
- m_names.insert (make_pair (key, value));
-
- BOOST_ASSERT (inserted.second); // previous call has to insert value
- item = inserted.first;
- }
-
- return ret;
-}
-
-StdNameInfo::StdNameInfo (const std::string &name)
- : m_name (name)
-{
- m_id = m_ids ++; // set ID for a newly inserted element
- m_digest << name;
- m_digest.finalize ();
-
- // std::cout << "StdNameInfo: " << name << " = " << m_id << "\n";
-}
-
-StdNameInfo::~StdNameInfo ()
-{
- // cout << "Destructor for " << m_name << "\n";
- m_names.erase (toString ());
-}
-
-std::string
-StdNameInfo::toString () const
-{
- return m_name;
-}
-
-bool
-StdNameInfo::operator == (const NameInfo &info) const
-{
- return m_name == dynamic_cast<const StdNameInfo&> (info).m_name;
-}
-
-bool
-StdNameInfo::operator < (const NameInfo &info) const
-{
- return m_name < dynamic_cast<const StdNameInfo&> (info).m_name;
-}
-
-} // Sync
diff --git a/src/sync-std-name-info.h b/src/sync-std-name-info.h
deleted file mode 100644
index 957829f..0000000
--- a/src/sync-std-name-info.h
+++ /dev/null
@@ -1,75 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2012-2014 University of California, Los Angeles
- *
- * This file is part of ChronoSync, synchronization library for distributed realtime
- * applications for NDN.
- *
- * ChronoSync is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation, either
- * version 3 of the License, or (at your option) any later version.
- *
- * ChronoSync 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
- * ChronoSync, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
- *
- * @author Zhenkai Zhu <http://irl.cs.ucla.edu/~zhenkai/>
- * @author Chaoyi Bian <bcy@pku.edu.cn>
- * @author Alexander Afanasyev <http://lasr.cs.ucla.edu/afanasyev/index.html>
- */
-
-#ifndef SYNC_STD_NAME_INFO_H
-#define SYNC_STD_NAME_INFO_H
-
-#include "sync-name-info.h"
-#include <string>
-
-namespace Sync {
-
-class StdNameInfo : public NameInfo
-{
-public:
- /**
- * @brief Lookup existing or create new NameInfo object
- * @param name routable prefix
- */
- static NameInfoConstPtr
- FindOrCreate (const std::string &name);
-
- /**
- * @brief Destructor which will clean up m_names structure
- */
- virtual ~StdNameInfo ();
-
- // from NameInfo
- virtual bool
- operator == (const NameInfo &info) const;
-
- virtual bool
- operator < (const NameInfo &info) const;
-
- virtual std::string
- toString () const;
-
-private:
- // implementing a singleton pattern.
- /**
- * @brief Disabled default constructor. NameInfo object should be created through FindOrCreate static call.
- */
-
- /**
- * @brief Disabled default
- */
- StdNameInfo () {}
- StdNameInfo& operator = (const StdNameInfo &info) { (void)info; return *this; }
- StdNameInfo (const std::string &name);
-
- std::string m_name;
-};
-
-} // Sync
-
-#endif // SYNC_CCNX_NAME_INFO_H