State: reset wire after adding names; fix tests when zlib is disabled

refs: #5083, #5077

Change-Id: I48f24ad53d676036f6b03cc0472be9bb5026016e
diff --git a/PSync/detail/iblt.hpp b/PSync/detail/iblt.hpp
index d51612c..d3d023f 100644
--- a/PSync/detail/iblt.hpp
+++ b/PSync/detail/iblt.hpp
@@ -95,7 +95,7 @@
    * @param scheme compression scheme to be used for the IBLT
    */
   explicit
-  IBLT(size_t expectedNumEntries, CompressionScheme scheme = CompressionScheme::ZLIB);
+  IBLT(size_t expectedNumEntries, CompressionScheme scheme);
 
   /**
    * @brief Populate the hash table using the vector representation of IBLT
diff --git a/PSync/detail/state.cpp b/PSync/detail/state.cpp
index 850115f..0a5242c 100644
--- a/PSync/detail/state.cpp
+++ b/PSync/detail/state.cpp
@@ -31,6 +31,7 @@
 void
 State::addContent(const ndn::Name& prefix)
 {
+  m_wire.reset();
   m_content.emplace_back(prefix);
 }
 
@@ -79,6 +80,8 @@
                                           ndn::to_string(blockType)));
   }
 
+  m_content.clear();
+
   wire.parse();
   m_wire = wire;
 
diff --git a/PSync/detail/util.cpp b/PSync/detail/util.cpp
index 7e546fc..c622ecd 100644
--- a/PSync/detail/util.cpp
+++ b/PSync/detail/util.cpp
@@ -22,7 +22,6 @@
  **/
 
 #include "PSync/detail/util.hpp"
-#include "PSync/detail/config.hpp"
 
 #include <ndn-cxx/encoding/buffer-stream.hpp>
 #include <ndn-cxx/util/backports.hpp>
diff --git a/PSync/detail/util.hpp b/PSync/detail/util.hpp
index 4da380b..b160cd3 100644
--- a/PSync/detail/util.hpp
+++ b/PSync/detail/util.hpp
@@ -24,6 +24,8 @@
 #ifndef PSYNC_UTIL_HPP
 #define PSYNC_UTIL_HPP
 
+#include "PSync/detail/config.hpp"
+
 #include <ndn-cxx/name.hpp>
 
 #include <inttypes.h>
@@ -54,7 +56,12 @@
   GZIP,
   BZIP2,
   LZMA,
-  ZSTD
+  ZSTD,
+#ifdef PSYNC_HAVE_ZLIB
+  DEFAULT = ZLIB
+#else
+  DEFAULT = NONE
+#endif
 };
 
 std::shared_ptr<ndn::Buffer>
diff --git a/PSync/full-producer.cpp b/PSync/full-producer.cpp
index ef0770a..31ef4a2 100644
--- a/PSync/full-producer.cpp
+++ b/PSync/full-producer.cpp
@@ -158,7 +158,7 @@
   NDN_LOG_DEBUG("Full Sync Interest Received, nonce: " << interest.getNonce() <<
                 ", hash: " << std::hash<ndn::Name>{}(interestName));
 
-  IBLT iblt(m_expectedNumEntries);
+  IBLT iblt(m_expectedNumEntries, m_ibltCompression);
   try {
     iblt.initialize(ibltName);
   }
diff --git a/PSync/full-producer.hpp b/PSync/full-producer.hpp
index 720e256..ffbdc77 100644
--- a/PSync/full-producer.hpp
+++ b/PSync/full-producer.hpp
@@ -82,8 +82,8 @@
                const UpdateCallback& onUpdateCallBack,
                ndn::time::milliseconds syncInterestLifetime = SYNC_INTEREST_LIFTIME,
                ndn::time::milliseconds syncReplyFreshness = SYNC_REPLY_FRESHNESS,
-               CompressionScheme ibltCompression = CompressionScheme::ZLIB,
-               CompressionScheme contentCompression = CompressionScheme::ZLIB);
+               CompressionScheme ibltCompression = CompressionScheme::DEFAULT,
+               CompressionScheme contentCompression = CompressionScheme::DEFAULT);
 
   ~FullProducer();
 
diff --git a/PSync/producer-base.hpp b/PSync/producer-base.hpp
index 510546e..29a1c04 100644
--- a/PSync/producer-base.hpp
+++ b/PSync/producer-base.hpp
@@ -75,8 +75,8 @@
                const ndn::Name& syncPrefix,
                const ndn::Name& userPrefix,
                ndn::time::milliseconds syncReplyFreshness = SYNC_REPLY_FRESHNESS,
-               CompressionScheme ibltCompression = CompressionScheme::ZLIB,
-               CompressionScheme contentCompression = CompressionScheme::ZLIB);
+               CompressionScheme ibltCompression = CompressionScheme::NONE,
+               CompressionScheme contentCompression = CompressionScheme::NONE);
 public:
   /**
    * @brief Returns the current sequence number of the given prefix
diff --git a/tests/test-full-sync.cpp b/tests/test-full-sync.cpp
index 34bef0c..1f5c6bb 100644
--- a/tests/test-full-sync.cpp
+++ b/tests/test-full-sync.cpp
@@ -398,16 +398,26 @@
 {
   addNode(0);
 
-  for (int i = 0; i < 2000; i++) {
-    Name prefixToPublish("userNode0-" + to_string(i));
+  int i = 0;
+  State state;
+
+  std::shared_ptr<ndn::Buffer> compressed;
+  do {
+    Name prefixToPublish("userNode0-" + to_string(i++));
     nodes[0]->addUserNode(prefixToPublish);
     nodes[0]->publishName(prefixToPublish);
-  }
+
+    state.addContent(ndn::Name(prefixToPublish).appendNumber(nodes[0]->m_prefixes[prefixToPublish]));
+
+    auto block = state.wireEncode();
+    compressed = compress(nodes[0]->m_contentCompression, block.wire(), block.size());
+
+  } while (compressed->size() < (ndn::MAX_NDN_PACKET_SIZE >> 1));
 
   advanceClocks(ndn::time::milliseconds(10), 100);
 
   Name syncInterestName(syncPrefix);
-  IBLT iblt(40);
+  IBLT iblt(40, nodes[0]->m_ibltCompression);
   iblt.appendToName(syncInterestName);
 
   nodes[0]->onSyncInterest(syncPrefix, Interest(syncInterestName));
diff --git a/tests/test-iblt.cpp b/tests/test-iblt.cpp
index 5be1d80..e99bf6e 100644
--- a/tests/test-iblt.cpp
+++ b/tests/test-iblt.cpp
@@ -34,8 +34,8 @@
 {
   int size = 10;
 
-  IBLT iblt1(size);
-  IBLT iblt2(size);
+  IBLT iblt1(size, CompressionScheme::DEFAULT);
+  IBLT iblt2(size, CompressionScheme::DEFAULT);
   BOOST_CHECK_EQUAL(iblt1, iblt2);
 
   std::string prefix = Name("/test/memphis").appendNumber(1).toUri();
@@ -55,7 +55,7 @@
 {
   int size = 10;
 
-  IBLT iblt(size);
+  IBLT iblt(size, CompressionScheme::DEFAULT);
   std::string prefix = Name("/test/memphis").appendNumber(1).toUri();
   uint32_t newHash = murmurHash3(11, prefix);
   iblt.insert(newHash);
@@ -63,12 +63,12 @@
   Name ibltName("sync");
   iblt.appendToName(ibltName);
 
-  IBLT rcvd(size);
+  IBLT rcvd(size, CompressionScheme::DEFAULT);
   rcvd.initialize(ibltName.get(-1));
 
   BOOST_CHECK_EQUAL(iblt, rcvd);
 
-  IBLT rcvdDiffSize(20);
+  IBLT rcvdDiffSize(20, CompressionScheme::DEFAULT);
   BOOST_CHECK_THROW(rcvdDiffSize.initialize(ibltName.get(-1)), std::runtime_error);
 }
 
@@ -76,7 +76,7 @@
 {
   int size = 10;
 
-  IBLT iblt1(size);
+  IBLT iblt1(size, CompressionScheme::DEFAULT);
 
   std::string prefix = Name("/test/memphis").appendNumber(1).toUri();
   uint32_t hash1 = murmurHash3(11, prefix);
@@ -105,8 +105,8 @@
   // Relevant to full sync case
   int size = 10;
 
-  IBLT ownIBF(size);
-  IBLT rcvdIBF(size);
+  IBLT ownIBF(size, CompressionScheme::DEFAULT);
+  IBLT rcvdIBF(size, CompressionScheme::DEFAULT);
 
   std::string prefix = Name("/test/memphis").appendNumber(3).toUri();
   uint32_t hash1 = murmurHash3(11, prefix);
@@ -129,7 +129,7 @@
 {
   int size = 10;
 
-  IBLT ownIBF(size);
+  IBLT ownIBF(size, CompressionScheme::DEFAULT);
 
   IBLT rcvdIBF = ownIBF;
 
@@ -169,7 +169,7 @@
 
   int size = 10;
 
-  IBLT ownIBF(size);
+  IBLT ownIBF(size, CompressionScheme::DEFAULT);
 
   for (int i = 0; i < 50; i++) {
     std::string prefix = Name("/test/memphis" + std::to_string(i)).appendNumber(1).toUri();
diff --git a/tests/test-state.cpp b/tests/test-state.cpp
index 25626c4..6d7239c 100644
--- a/tests/test-state.cpp
+++ b/tests/test-state.cpp
@@ -74,6 +74,20 @@
   BOOST_CHECK_EQUAL(state2.getContent().size(), 0);
 }
 
+BOOST_AUTO_TEST_CASE(ReEncode)
+{
+  State state;
+  state.addContent(ndn::Name("test1"));
+  state.addContent(ndn::Name("test2"));
+
+  state.wireEncode();
+
+  state.addContent(ndn::Name("test3"));
+
+  State state2(state.wireEncode());
+  BOOST_CHECK_EQUAL(state2.getContent().size(), 3);
+}
+
 BOOST_AUTO_TEST_SUITE_END()
 
 } // namespace psync
\ No newline at end of file