socket: allow applications to set seq numbers

refs: #4032

Change-Id: I4ed379baaebc1643abf5864f7b674724f901e0e6
diff --git a/src/socket.cpp b/src/socket.cpp
index dad1125..4a947d7 100644
--- a/src/socket.cpp
+++ b/src/socket.cpp
@@ -107,6 +107,13 @@
 }
 
 void
+Socket::publishData(const uint8_t* buf, size_t len, const ndn::time::milliseconds& freshness,
+                    const uint64_t& seqNo, const Name& prefix)
+{
+  publishData(ndn::encoding::makeBinaryBlock(ndn::tlv::Content, buf, len), freshness, seqNo, prefix);
+}
+
+void
 Socket::publishData(const Block& content, const ndn::time::milliseconds& freshness,
                     const Name& prefix)
 {
@@ -130,6 +137,29 @@
 }
 
 void
+Socket::publishData(const Block& content, const ndn::time::milliseconds& freshness,
+                    const uint64_t& seqNo, const Name& prefix)
+{
+  shared_ptr<Data> data = make_shared<Data>();
+  data->setContent(content);
+  data->setFreshnessPeriod(freshness);
+
+  SeqNo newSeq = seqNo;
+  Name dataName;
+  dataName.append(m_logic.getSessionName(prefix)).appendNumber(newSeq);
+  data->setName(dataName);
+
+  if (m_signingId.empty())
+    m_keyChain.sign(*data);
+  else
+    m_keyChain.signByIdentity(*data, m_signingId);
+
+  m_ims.insert(*data);
+
+  m_logic.updateSeqNo(newSeq, prefix);
+}
+
+void
 Socket::fetchData(const Name& sessionName, const SeqNo& seqNo,
                   const ndn::OnDataValidated& dataCallback,
                   int nRetries)
diff --git a/src/socket.hpp b/src/socket.hpp
index 807e173..09fee72 100644
--- a/src/socket.hpp
+++ b/src/socket.hpp
@@ -115,6 +115,24 @@
    *
    * This method will create a data packet with the supplied content.
    * The packet name is the local session + seqNo.
+   * The seqNo is set by the application.
+   *
+   * @throws It will throw error, if the prefix does not exist in m_logic
+   *
+   * @param buf Pointer to the bytes in content
+   * @param len size of the bytes in content
+   * @param freshness FreshnessPeriod of the data packet.
+   * @param seqNo Sequence number of the data
+   */
+  void
+  publishData(const uint8_t* buf, size_t len, const ndn::time::milliseconds& freshness,
+              const uint64_t& seqNo, const Name& prefix = DEFAULT_PREFIX);
+
+  /**
+   * @brief Publish a data packet in the session and trigger synchronization updates
+   *
+   * This method will create a data packet with the supplied content.
+   * The packet name is the local session + seqNo.
    * The seqNo is automatically maintained by internal Logic.
    *
    * @throws It will throw error, if the prefix does not exist in m_logic
@@ -127,6 +145,23 @@
               const Name& prefix = DEFAULT_PREFIX);
 
   /**
+   * @brief Publish a data packet in the session and trigger synchronization updates
+   *
+   * This method will create a data packet with the supplied content.
+   * The packet name is the local session + seqNo.
+   * The seqNo is set by the application.
+   *
+   * @throws It will throw error, if the prefix does not exist in m_logic
+   *
+   * @param content Block that will be set as the content of the data packet.
+   * @param freshness FreshnessPeriod of the data packet.
+   * @param seqNo Sequence number of the data
+   */
+  void
+  publishData(const Block& content, const ndn::time::milliseconds& freshness,
+              const uint64_t& seqNo, const Name& prefix = DEFAULT_PREFIX);
+
+  /**
    * @brief Retrive a data packet with a particular seqNo from a session
    *
    * @param sessionName The name of the target session.