ndn-handle: Implement TCP backdoor to inject data packets into repo
Change-Id: I74d0698f914a2e68d47ede427c7f36b3ba3b4f47
Refs: #1485
diff --git a/storage/sqlite/sqlite-handle.cpp b/storage/sqlite/sqlite-handle.cpp
index 732e9ab..2c872e4 100644
--- a/storage/sqlite/sqlite-handle.cpp
+++ b/storage/sqlite/sqlite-handle.cpp
@@ -33,7 +33,9 @@
"data BLOB, "
"parentName BLOB, "
"nChildren INTEGER);\n"
- "CREATE INDEX NdnRepoparentName ON NDN_REPO (parentName)", 0, 0, &errMsg);
+ "CREATE INDEX NdnRepoParentName ON NDN_REPO (parentName);\n"
+ "CREATE INDEX NdnRepoData ON NDN_REPO (data);\n"
+ , 0, 0, &errMsg);
// Ignore errors (when database already exists, errors are expected)
}
else {
@@ -504,7 +506,7 @@
if (nChildren > 0) {
internalNames.push(elementName);
}
- if (sqlite3_column_type(queryParentStmt, 3) != SQLITE_NULL) {
+ if (sqlite3_column_type(queryParentStmt, 1) != SQLITE_NULL) {
names.push_back(elementName);
}
}
@@ -779,4 +781,29 @@
return true;
}
+size_t
+SqliteHandle::size()
+{
+ sqlite3_stmt* queryStmt = 0;
+ string sql("SELECT count(*) FROM NDN_REPO WHERE data IS NOT NULL");
+ int rc = sqlite3_prepare_v2(m_db, sql.c_str(), -1, &queryStmt, 0);
+ if (rc != SQLITE_OK)
+ {
+ std::cerr << "Database query failure rc:" << rc << std::endl;
+ sqlite3_finalize(queryStmt);
+ throw Error("Database query failure");
+ }
+
+ rc = sqlite3_step(queryStmt);
+ if (rc != SQLITE_ROW)
+ {
+ std::cerr << "Database query failure rc:" << rc << std::endl;
+ sqlite3_finalize(queryStmt);
+ throw Error("Database query failure");
+ }
+
+ size_t nDatas = static_cast<size_t>(sqlite3_column_int64(queryStmt, 0));
+ return nDatas;
+}
+
} //namespace repo
diff --git a/storage/sqlite/sqlite-handle.hpp b/storage/sqlite/sqlite-handle.hpp
index a2091c8..a595242 100644
--- a/storage/sqlite/sqlite-handle.hpp
+++ b/storage/sqlite/sqlite-handle.hpp
@@ -60,6 +60,9 @@
virtual bool
readNameAny(const Name& name, const Selectors& selectors, vector<Name>& names);
+ virtual size_t
+ size();
+
private:
void
initializeRepo();
diff --git a/storage/storage-handle.hpp b/storage/storage-handle.hpp
index 48359d4..767db6f 100644
--- a/storage/storage-handle.hpp
+++ b/storage/storage-handle.hpp
@@ -32,8 +32,8 @@
using std::string;
using boost::noncopyable;
-/**
- * @brief this class defines handles to read, insert and delete data packets in storage media
+/**
+ * @brief this class defines handles to read, insert and delete data packets in storage media
*/
class StorageHandle : noncopyable
@@ -101,6 +101,12 @@
virtual bool
readNameAny(const Name& name, const Selectors& selectors, vector<Name>& names) = 0;
+ /**
+ * @brief Get the number of Data packets stored
+ */
+ virtual size_t
+ size() = 0;
+
private:
StorageMethod m_storageMethod;
};