Initial support for libcrypto

Added partially implemented libcrypto wrapper (Digest)
diff --git a/model/sync-diff-state-container.h b/model/sync-diff-state-container.h
new file mode 100644
index 0000000..2865c5d
--- /dev/null
+++ b/model/sync-diff-state-container.h
@@ -0,0 +1,80 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2012 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu>
+ *         卞超轶 Chaoyi Bian <bcy@pku.edu.cn>
+ *	   Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#ifndef SYNC_DIFF_STATE_CONTAINER_H
+#define SYNC_DIFF_STATE_CONTAINER_H
+
+namespace ns3 {
+namespace Sync {
+
+#include "diff-state.h"
+
+#include <boost/multi_index_container.hpp>
+// #include <boost/multi_index/tag.hpp>
+// #include <boost/multi_index/ordered_index.hpp>
+// #include <boost/multi_index/composite_key.hpp>
+#include <boost/multi_index/hashed_index.hpp>
+#include <boost/multi_index/sequenced_index.hpp>
+// #include <boost/multi_index/random_access_index.hpp>
+// #include <boost/multi_index/member.hpp>
+#include <boost/multi_index/mem_fun.hpp>
+
+namespace mi = boost::multi_index;
+
+// struct DigestHash : public std::unary_function<Digest, std::size_t>
+// {
+//   std::size_t
+//   operator() (const Digest &digest) const
+//   {
+//     return digest % std::limits<std::size_t>::max ();
+//   }
+// };
+
+struct sequenced { };
+ 
+/**
+ * \ingroup sync
+ * @brief Container for differential states
+ */
+struct LeafContainer : public mi::multi_index_container<
+    DiffStatePtr,
+    // mi::indexed_by<
+    //   // For fast access to elements using DiffState hashes
+    //   mi::hashed_unique<
+    //     mi::tag<hashed>,
+    //     mi::const_mem_fun<Leaf, const Digest&, &DiffState::getDigest>,
+    //     DigestHash
+    //   >,
+
+  // sequenced index to access older/newer element (like in list)
+      mi::indexed_by<
+        mi::sequenced<mi::tag<seqenced> >
+    >
+   >
+{
+};
+
+
+} // Sync
+} // ns3
+
+#endif // SYNC_DIFF_STATE_CONTAINER_H
diff --git a/model/sync-digest.cc b/model/sync-digest.cc
new file mode 100644
index 0000000..65e3b44
--- /dev/null
+++ b/model/sync-digest.cc
@@ -0,0 +1,93 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2012 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu>
+ *         卞超轶 Chaoyi Bian <bcy@pku.edu.cn>
+ *	   Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#include "sync-digest.h"
+#include <string.h>
+
+#include "ns3/assert.h"
+
+namespace ns3 {
+namespace Sync {
+
+Digest::Digest ()
+  : m_buffer (0)
+  , m_hashLength (0)
+{
+  m_context = EVP_MD_CTX_create ();
+
+  int ok = EVP_DigestInit_ex (m_context, EVP_sha1 (), 0);
+  if (!ok)
+    throw DigestCalculationError ();
+}
+
+Digest::~Digest ()
+{
+  if (m_buffer != 0)
+    delete [] m_buffer;
+
+  EVP_MD_CTX_destroy (m_context);
+}
+
+void
+Digest::Finalize ()
+{
+  if (m_buffer != 0) return;
+
+  m_buffer = new uint8_t [HASH_SIZE];
+
+  int ok = EVP_DigestFinal_ex (m_context,
+			       m_buffer, &m_hashLength);
+  if (!ok)
+    throw DigestCalculationError ();
+}
+  
+std::size_t
+Digest::getHash ()
+{
+  if (m_buffer == 0)
+    Finalize ();
+
+  NS_ASSERT (sizeof (std::size_t) <= m_hashLength);
+  
+  // just getting first sizeof(std::size_t) bytes
+  // not ideal, but should work pretty well
+  return reinterpret_cast<std::size_t> (m_buffer);
+}
+
+bool
+Digest::operator == (Digest &digest)
+{
+  if (m_buffer == 0)
+    Finalize ();
+
+  if (digest.m_buffer == 0)
+    digest.Finalize ();
+  
+  NS_ASSERT (m_hashLength == digest.m_hashLength);
+
+  return memcmp (m_buffer, digest.m_buffer, m_hashLength) == 0;
+}
+
+
+} // Sync
+} // ns3
+
diff --git a/model/sync-digest.h b/model/sync-digest.h
new file mode 100644
index 0000000..2816b3e
--- /dev/null
+++ b/model/sync-digest.h
@@ -0,0 +1,88 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2012 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu>
+ *         卞超轶 Chaoyi Bian <bcy@pku.edu.cn>
+ *	   Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#ifndef SYNC_DIGEST_H
+#define SYNC_DIGEST_H
+
+#include <boost/exception/all.hpp>
+#include <openssl/evp.h>
+#include <boost/cstdint.hpp>
+
+namespace ns3 {
+namespace Sync {
+
+const std::size_t HASH_SIZE = 160;
+
+/**
+ * @ingroup sync
+ * @brief A simple wrapper for libcrypto hash functions
+ */
+class Digest
+{
+public:
+  /**
+   * @brief Default constructor.  Will initialize internal libssl structures
+   */
+  Digest ();
+
+  /**
+   * @brief Destructor
+   */
+  ~Digest ();
+
+  // Digest &
+  // operator << (
+
+  /**
+   * @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 ();
+
+  /**
+   * @brief Compare two full digests
+   *
+   * Side effect: Finalize will be called on `this' and `digest'
+   */
+  bool
+  operator == (Digest &digest);
+
+private:
+  /**
+   * @brief Finalize digest. All subsequent calls to "operator <<" will fire an exception
+   */
+  void Finalize ();
+  
+private:
+  EVP_MD_CTX *m_context;
+  uint8_t *m_buffer;
+  uint32_t m_hashLength;
+};
+
+struct DigestCalculationError : virtual boost::exception { };
+
+} // Sync
+} // ns3
+
+#endif // SYNC_DIGEST_H
diff --git a/model/sync-state-manager.h b/model/sync-state-manager.h
index 2d05055..3aa12bd 100644
--- a/model/sync-state-manager.h
+++ b/model/sync-state-manager.h
@@ -23,20 +23,22 @@
 #ifndef SYNC_STATE_MANAGER_H
 #define SYNC_STATE_MANAGER_H
 
-namespace ns3
-{
+#include "sync-diff-state-container.h"
 
-namespace Sync
-{
+namespace ns3 {
+namespace Sync {
 
 class StateManager
 {
 public:
 private:
+  FullState m_state;
+  FullState m_localState;
+  DiffStateContainer m_log;  
 };
 
-} // Sync
 
+} // Sync
 } // ns3
 
 #endif // SYNC_STATE_MANAGER_H
diff --git a/wscript b/wscript
index 4120c88..d0fcea4 100644
--- a/wscript
+++ b/wscript
@@ -5,6 +5,9 @@
 
 # def configure(conf):
 #     conf.check_nonfatal(header_name='stdint.h', define_name='HAVE_STDINT_H')
+def configure(conf):
+    conf.check_cfg(atleast_pkgconfig_version='0.20')
+    conf.check_cfg(package='openssl', args=['--cflags', '--libs'], uselib_store='SSL')
 
 def build (bld):
     deps = ['core', 'network', 'NDNabstraction']
@@ -12,7 +15,7 @@
         deps.append ('visualizer')
 
     module = bld.create_ns3_module ('sync', deps)
-    module.uselib = 'BOOST BOOST_IOSTREAMS'
+    module.uselib = 'BOOST BOOST_IOSTREAMS SSL'
 
     # tests = bld.create_ns3_module_test_library('sync')
     # tests.source = [