socket: allow manipulating multiple nodes in single logic
Change-Id: I61241f4c3d92703e975d988d593957d445942ad0
diff --git a/src/logic.cpp b/src/logic.cpp
index 08ed60e..0c5b87a 100644
--- a/src/logic.cpp
+++ b/src/logic.cpp
@@ -110,7 +110,7 @@
bind(&Logic::onSyncInterest, this, _1, _2),
bind(&Logic::onSyncRegisterFailed, this, _1, _2));
-
+ sendSyncInterest();
_LOG_DEBUG_ID("<< Logic::Logic");
}
diff --git a/src/socket.cpp b/src/socket.cpp
index 45c6890..695f758 100644
--- a/src/socket.cpp
+++ b/src/socket.cpp
@@ -30,6 +30,7 @@
namespace chronosync {
+const ndn::Name Socket::DEFAULT_PREFIX;
const ndn::Name Socket::DEFAULT_NAME;
const ndn::shared_ptr<ndn::Validator> Socket::DEFAULT_VALIDATOR;
@@ -47,23 +48,30 @@
{
}
-
void
-Socket::publishData(const uint8_t* buf, size_t len, const ndn::time::milliseconds& freshness)
+Socket::addSyncNode(const Name& prefix, const Name& signingId)
{
- publishData(ndn::dataBlock(ndn::tlv::Content, buf, len), freshness);
+ m_logic.addUserNode(prefix, signingId);
}
void
-Socket::publishData(const Block& content, const ndn::time::milliseconds& freshness)
+Socket::publishData(const uint8_t* buf, size_t len, const ndn::time::milliseconds& freshness,
+ const Name& prefix)
+{
+ publishData(ndn::dataBlock(ndn::tlv::Content, buf, len), freshness, prefix);
+}
+
+void
+Socket::publishData(const Block& content, const ndn::time::milliseconds& freshness,
+ const Name& prefix)
{
shared_ptr<Data> data = make_shared<Data>();
data->setContent(content);
data->setFreshnessPeriod(freshness);
- SeqNo newSeq = m_logic.getSeqNo() + 1;
+ SeqNo newSeq = m_logic.getSeqNo(prefix) + 1;
Name dataName;
- dataName.append(m_logic.getSessionName()).appendNumber(newSeq);
+ dataName.append(m_logic.getSessionName(prefix)).appendNumber(newSeq);
data->setName(dataName);
if (m_signingId.empty())
@@ -73,7 +81,7 @@
m_face.put(*data);
- m_logic.updateSeqNo(newSeq);
+ m_logic.updateSeqNo(newSeq, prefix);
}
void
diff --git a/src/socket.hpp b/src/socket.hpp
index c01fb05..3e09c79 100644
--- a/src/socket.hpp
+++ b/src/socket.hpp
@@ -64,19 +64,8 @@
const Name& signingId = DEFAULT_NAME,
ndn::shared_ptr<ndn::Validator> validator = DEFAULT_VALIDATOR);
- /**
- * @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.
- *
- * @param buf Pointer to the bytes in content
- * @param len size of the bytes in content
- * @param freshness FreshnessPeriod of the data packet.
- */
void
- publishData(const uint8_t* buf, size_t len, const ndn::time::milliseconds& freshness);
+ addSyncNode(const Name& prefix, const Name& signingId = DEFAULT_NAME);
/**
* @brief Publish a data packet in the session and trigger synchronization updates
@@ -85,11 +74,31 @@
* 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
+ *
+ * @param buf Pointer to the bytes in content
+ * @param len size of the bytes in content
+ * @param freshness FreshnessPeriod of the data packet.
+ */
+ void
+ publishData(const uint8_t* buf, size_t len, const ndn::time::milliseconds& freshness,
+ 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
+ *
* @param content Block that will be set as the content of the data packet.
* @param freshness FreshnessPeriod of the data packet.
*/
void
- publishData(const Block& content, const ndn::time::milliseconds& freshness);
+ publishData(const Block& content, const ndn::time::milliseconds& freshness,
+ const Name& prefix = DEFAULT_PREFIX);
/**
* @brief Retrive a data packet with a particular seqNo from a session
@@ -146,6 +155,7 @@
public:
static const ndn::Name DEFAULT_NAME;
+ static const ndn::Name DEFAULT_PREFIX;
static const ndn::shared_ptr<ndn::Validator> DEFAULT_VALIDATOR;
private: