From 363dae6a64321f5083103968bb461c5731bdd0e0 Mon Sep 17 00:00:00 2001 From: Vlad Gluhovsky Date: Tue, 7 Jul 2015 17:00:56 +0200 Subject: [PATCH 1/9] levelDB for whisper --- libwhisper/WhisperDB.cpp | 90 +++++++++++++++++++++++++++++++++++ libwhisper/WhisperDB.h | 50 +++++++++++++++++++ test/libwhisper/whisperDB.cpp | 70 +++++++++++++++++++++++++++ 3 files changed, 210 insertions(+) create mode 100644 libwhisper/WhisperDB.cpp create mode 100644 libwhisper/WhisperDB.h create mode 100644 test/libwhisper/whisperDB.cpp diff --git a/libwhisper/WhisperDB.cpp b/libwhisper/WhisperDB.cpp new file mode 100644 index 000000000..e5d40e571 --- /dev/null +++ b/libwhisper/WhisperDB.cpp @@ -0,0 +1,90 @@ +/* + This file is part of cpp-ethereum. + + cpp-ethereum is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + cpp-ethereum 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 cpp-ethereum. If not, see . +*/ +/** @file WhisperDB.cpp +* @author Vladislav Gluhovsky +* @date July 2015 + */ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include "WhisperDB.h" + +using namespace std; +using namespace dev; +using namespace dev::shh; +using namespace dev::eth; + +WhisperDB::WhisperDB() +{ + string path = Defaults::dbPath(); + boost::filesystem::create_directories(path); + ldb::Options o; + o.create_if_missing = true; + ldb::DB::Open(o, path + "/whisper", &m_db); +} + +WhisperDB::~WhisperDB() +{ + delete m_db; +} + +bool WhisperDB::put(dev::h256 const& _key, string const& _value) +{ + string s = _key.hex(); + string cropped = s.substr(s.size() - 8); + leveldb::Status status = m_db->Put(m_writeOptions, s, _value); + if (status.ok()) + cdebug << "Whisper DB put:" << cropped << _value; + else + cdebug << "Whisper DB put failed:" << status.ToString() << "key:" << cropped; + + return status.ok(); +} + +string WhisperDB::get(dev::h256 const& _key) const +{ + string ret; + string s = _key.hex(); + string cropped = s.substr(s.size() - 8); + leveldb::Status status = m_db->Get(m_readOptions, s, &ret); + if (status.ok()) + cdebug << "Whisper DB get:" << cropped << ret; + else + cdebug << "Whisper DB get failed:" << status.ToString() << "key:" << cropped; + + return ret; +} + +bool WhisperDB::erase(dev::h256 const& _key) +{ + string s = _key.hex(); + string cropped = s.substr(s.size() - 8); + leveldb::Status status = m_db->Delete(m_writeOptions, s); + if (status.ok()) + cdebug << "Whisper DB erase:" << cropped; + else + cdebug << "Whisper DB erase failed:" << status.ToString() << "key:" << cropped; + + return status.ok(); +} diff --git a/libwhisper/WhisperDB.h b/libwhisper/WhisperDB.h new file mode 100644 index 000000000..70b65ef84 --- /dev/null +++ b/libwhisper/WhisperDB.h @@ -0,0 +1,50 @@ +/* + This file is part of cpp-ethereum. + + cpp-ethereum is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + cpp-ethereum 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 cpp-ethereum. If not, see . +*/ +/** @file WhisperDB.h +* @author Vladislav Gluhovsky +* @date July 2015 + */ + +#pragma once + +#include +#include +#include "Common.h" + +namespace dev +{ +namespace shh +{ + +class WhisperDB +{ + public: + WhisperDB(); + ~WhisperDB(); + + bool put(dev::h256 const& _key, std::string const& _value); + bool erase(dev::h256 const& _key); + std::string get(dev::h256 const& _key) const; + +private: + ldb::ReadOptions m_readOptions; + ldb::WriteOptions m_writeOptions; + ldb::DB* m_db = nullptr; +}; + +} +} \ No newline at end of file diff --git a/test/libwhisper/whisperDB.cpp b/test/libwhisper/whisperDB.cpp new file mode 100644 index 000000000..4b821e0c5 --- /dev/null +++ b/test/libwhisper/whisperDB.cpp @@ -0,0 +1,70 @@ +/* +This file is part of cpp-ethereum. + +cpp-ethereum is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +cpp-ethereum 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 cpp-ethereum. If not, see . +*/ +/** @file whisperMessage.cpp +* @author Vladislav Gluhovsky +* @date July 2015 +*/ + +#include +#include + +using namespace std; +using namespace dev; +using namespace dev::shh; + +BOOST_AUTO_TEST_SUITE(whisperDB) + +BOOST_AUTO_TEST_CASE(first) +{ + VerbosityHolder setTemporaryLevel(10); + cnote << "Testing Whisper DB..."; + + WhisperDB db; + + h256 h1(0x12345678); + h256 h2(0xBADD00DE); + + string s; + string const text1 = "lorem_ipsum"; + string const text2 = "dolor_sit_amet"; + + db.erase(h1); + db.erase(h2); + + db.put(h1, text2); + s = db.get(h2); + BOOST_REQUIRE(s.empty()); + s = db.get(h1); + BOOST_REQUIRE(!s.compare(text2)); + + db.put(h1, text1); + s = db.get(h2); + BOOST_REQUIRE(s.empty()); + s = db.get(h1); + BOOST_REQUIRE(!s.compare(text1)); + + db.put(h2, text2); + s = db.get(h2); + BOOST_REQUIRE(!s.compare(text2)); + s = db.get(h1); + BOOST_REQUIRE(!s.compare(text1)); + + db.erase(h1); + db.erase(h2); +} + +BOOST_AUTO_TEST_SUITE_END() From 24564e0dd32ac3715e18ea8cef1f66ac8f532d00 Mon Sep 17 00:00:00 2001 From: Vlad Gluhovsky Date: Wed, 8 Jul 2015 11:40:55 +0200 Subject: [PATCH 2/9] small fix --- libwhisper/CMakeLists.txt | 1 + libwhisper/WhisperDB.cpp | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/libwhisper/CMakeLists.txt b/libwhisper/CMakeLists.txt index 5af43d0b2..5cf6a865f 100644 --- a/libwhisper/CMakeLists.txt +++ b/libwhisper/CMakeLists.txt @@ -21,6 +21,7 @@ file(GLOB HEADERS "*.h") add_library(${EXECUTABLE} ${SRC_LIST} ${HEADERS}) +target_link_libraries(${EXECUTABLE} ethereum) target_link_libraries(${EXECUTABLE} ethcore) target_link_libraries(${EXECUTABLE} devcrypto) target_link_libraries(${EXECUTABLE} devcore) diff --git a/libwhisper/WhisperDB.cpp b/libwhisper/WhisperDB.cpp index e5d40e571..a880bc279 100644 --- a/libwhisper/WhisperDB.cpp +++ b/libwhisper/WhisperDB.cpp @@ -39,9 +39,10 @@ WhisperDB::WhisperDB() { string path = Defaults::dbPath(); boost::filesystem::create_directories(path); - ldb::Options o; - o.create_if_missing = true; - ldb::DB::Open(o, path + "/whisper", &m_db); + ldb::Options op; + op.create_if_missing = true; + op.max_open_files = 256; + ldb::DB::Open(op, path + "/whisper", &m_db); } WhisperDB::~WhisperDB() From bd525e0408f0488201f014b4d5ea0fdee38c9c0c Mon Sep 17 00:00:00 2001 From: Vlad Gluhovsky Date: Wed, 8 Jul 2015 13:30:42 +0200 Subject: [PATCH 3/9] removed excessive dependency --- libwhisper/CMakeLists.txt | 1 - libwhisper/WhisperDB.cpp | 5 ++--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/libwhisper/CMakeLists.txt b/libwhisper/CMakeLists.txt index 5cf6a865f..5af43d0b2 100644 --- a/libwhisper/CMakeLists.txt +++ b/libwhisper/CMakeLists.txt @@ -21,7 +21,6 @@ file(GLOB HEADERS "*.h") add_library(${EXECUTABLE} ${SRC_LIST} ${HEADERS}) -target_link_libraries(${EXECUTABLE} ethereum) target_link_libraries(${EXECUTABLE} ethcore) target_link_libraries(${EXECUTABLE} devcrypto) target_link_libraries(${EXECUTABLE} devcore) diff --git a/libwhisper/WhisperDB.cpp b/libwhisper/WhisperDB.cpp index a880bc279..b8977161c 100644 --- a/libwhisper/WhisperDB.cpp +++ b/libwhisper/WhisperDB.cpp @@ -27,17 +27,16 @@ #include #include #include -#include +#include #include "WhisperDB.h" using namespace std; using namespace dev; using namespace dev::shh; -using namespace dev::eth; WhisperDB::WhisperDB() { - string path = Defaults::dbPath(); + string path = dev::getDataDir(); boost::filesystem::create_directories(path); ldb::Options op; op.create_if_missing = true; From 52b36b6b6affd6957baf64def533f0714ff55f4f Mon Sep 17 00:00:00 2001 From: Vlad Gluhovsky Date: Thu, 9 Jul 2015 19:45:13 +0200 Subject: [PATCH 4/9] naming conventions changed --- libwhisper/WhisperDB.cpp | 6 +++--- libwhisper/WhisperDB.h | 6 +++--- test/libwhisper/whisperDB.cpp | 26 +++++++++++++------------- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/libwhisper/WhisperDB.cpp b/libwhisper/WhisperDB.cpp index b8977161c..dcb3cf1e0 100644 --- a/libwhisper/WhisperDB.cpp +++ b/libwhisper/WhisperDB.cpp @@ -49,7 +49,7 @@ WhisperDB::~WhisperDB() delete m_db; } -bool WhisperDB::put(dev::h256 const& _key, string const& _value) +bool WhisperDB::insert(dev::h256 const& _key, string const& _value) { string s = _key.hex(); string cropped = s.substr(s.size() - 8); @@ -62,7 +62,7 @@ bool WhisperDB::put(dev::h256 const& _key, string const& _value) return status.ok(); } -string WhisperDB::get(dev::h256 const& _key) const +string WhisperDB::lookup(dev::h256 const& _key) const { string ret; string s = _key.hex(); @@ -76,7 +76,7 @@ string WhisperDB::get(dev::h256 const& _key) const return ret; } -bool WhisperDB::erase(dev::h256 const& _key) +bool WhisperDB::kill(dev::h256 const& _key) { string s = _key.hex(); string cropped = s.substr(s.size() - 8); diff --git a/libwhisper/WhisperDB.h b/libwhisper/WhisperDB.h index 70b65ef84..b2aa12df3 100644 --- a/libwhisper/WhisperDB.h +++ b/libwhisper/WhisperDB.h @@ -36,9 +36,9 @@ class WhisperDB WhisperDB(); ~WhisperDB(); - bool put(dev::h256 const& _key, std::string const& _value); - bool erase(dev::h256 const& _key); - std::string get(dev::h256 const& _key) const; + bool insert(dev::h256 const& _key, std::string const& _value); + bool kill(dev::h256 const& _key); + std::string lookup(dev::h256 const& _key) const; private: ldb::ReadOptions m_readOptions; diff --git a/test/libwhisper/whisperDB.cpp b/test/libwhisper/whisperDB.cpp index 4b821e0c5..9c262fb8e 100644 --- a/test/libwhisper/whisperDB.cpp +++ b/test/libwhisper/whisperDB.cpp @@ -42,29 +42,29 @@ BOOST_AUTO_TEST_CASE(first) string const text1 = "lorem_ipsum"; string const text2 = "dolor_sit_amet"; - db.erase(h1); - db.erase(h2); + db.kill(h1); + db.kill(h2); - db.put(h1, text2); - s = db.get(h2); + db.insert(h1, text2); + s = db.lookup(h2); BOOST_REQUIRE(s.empty()); - s = db.get(h1); + s = db.lookup(h1); BOOST_REQUIRE(!s.compare(text2)); - db.put(h1, text1); - s = db.get(h2); + db.insert(h1, text1); + s = db.lookup(h2); BOOST_REQUIRE(s.empty()); - s = db.get(h1); + s = db.lookup(h1); BOOST_REQUIRE(!s.compare(text1)); - db.put(h2, text2); - s = db.get(h2); + db.insert(h2, text2); + s = db.lookup(h2); BOOST_REQUIRE(!s.compare(text2)); - s = db.get(h1); + s = db.lookup(h1); BOOST_REQUIRE(!s.compare(text1)); - db.erase(h1); - db.erase(h2); + db.kill(h1); + db.kill(h2); } BOOST_AUTO_TEST_SUITE_END() From 581e4b2bd5e5042a0951785b45a9831a6155cbc8 Mon Sep 17 00:00:00 2001 From: Vlad Gluhovsky Date: Fri, 10 Jul 2015 17:03:04 +0200 Subject: [PATCH 5/9] minor changes --- libwhisper/WhisperDB.cpp | 67 ++++++++++++++-------------------------- libwhisper/WhisperDB.h | 13 +++++--- 2 files changed, 32 insertions(+), 48 deletions(-) diff --git a/libwhisper/WhisperDB.cpp b/libwhisper/WhisperDB.cpp index dcb3cf1e0..91c5f74f4 100644 --- a/libwhisper/WhisperDB.cpp +++ b/libwhisper/WhisperDB.cpp @@ -19,16 +19,9 @@ * @date July 2015 */ -#include +#include "WhisperDB.h" #include - -#include -#include -#include -#include -#include #include -#include "WhisperDB.h" using namespace std; using namespace dev; @@ -41,50 +34,36 @@ WhisperDB::WhisperDB() ldb::Options op; op.create_if_missing = true; op.max_open_files = 256; - ldb::DB::Open(op, path + "/whisper", &m_db); -} - -WhisperDB::~WhisperDB() -{ - delete m_db; -} - -bool WhisperDB::insert(dev::h256 const& _key, string const& _value) -{ - string s = _key.hex(); - string cropped = s.substr(s.size() - 8); - leveldb::Status status = m_db->Put(m_writeOptions, s, _value); - if (status.ok()) - cdebug << "Whisper DB put:" << cropped << _value; - else - cdebug << "Whisper DB put failed:" << status.ToString() << "key:" << cropped; - - return status.ok(); + ldb::DB* p = nullptr; + leveldb::Status status = ldb::DB::Open(op, path + "/whisper", &p); + m_db.reset(p); + if (!status.ok()) + BOOST_THROW_EXCEPTION(FailedToOpenLevelDB(status.ToString())); } string WhisperDB::lookup(dev::h256 const& _key) const { string ret; - string s = _key.hex(); - string cropped = s.substr(s.size() - 8); - leveldb::Status status = m_db->Get(m_readOptions, s, &ret); - if (status.ok()) - cdebug << "Whisper DB get:" << cropped << ret; - else - cdebug << "Whisper DB get failed:" << status.ToString() << "key:" << cropped; + leveldb::Slice slice((char const*)_key.data(), _key.size); + leveldb::Status status = m_db->Get(m_readOptions, slice, &ret); + if (!status.ok() && !status.IsNotFound()) + BOOST_THROW_EXCEPTION(FailedLookupInLevelDB(status.ToString())); return ret; } -bool WhisperDB::kill(dev::h256 const& _key) +void WhisperDB::insert(dev::h256 const& _key, string const& _value) +{ + leveldb::Slice slice((char const*)_key.data(), _key.size); + leveldb::Status status = m_db->Put(m_writeOptions, slice, _value); + if (!status.ok()) + BOOST_THROW_EXCEPTION(FailedInsertInLevelDB(status.ToString())); +} + +void WhisperDB::kill(dev::h256 const& _key) { - string s = _key.hex(); - string cropped = s.substr(s.size() - 8); - leveldb::Status status = m_db->Delete(m_writeOptions, s); - if (status.ok()) - cdebug << "Whisper DB erase:" << cropped; - else - cdebug << "Whisper DB erase failed:" << status.ToString() << "key:" << cropped; - - return status.ok(); + leveldb::Slice slice((char const*)_key.data(), _key.size); + leveldb::Status status = m_db->Delete(m_writeOptions, slice); + if (!status.ok()) + BOOST_THROW_EXCEPTION(FailedDeleteInLevelDB(status.ToString())); } diff --git a/libwhisper/WhisperDB.h b/libwhisper/WhisperDB.h index b2aa12df3..c20f52a75 100644 --- a/libwhisper/WhisperDB.h +++ b/libwhisper/WhisperDB.h @@ -30,20 +30,25 @@ namespace dev namespace shh { +struct FailedToOpenLevelDB: virtual Exception { FailedToOpenLevelDB(std::string _message = std::string()): Exception(_message) {} }; +struct FailedInsertInLevelDB: virtual Exception { FailedInsertInLevelDB(std::string _message = std::string()): Exception(_message) {} }; +struct FailedLookupInLevelDB: virtual Exception { FailedLookupInLevelDB(std::string _message = std::string()): Exception(_message) {} }; +struct FailedDeleteInLevelDB: virtual Exception { FailedDeleteInLevelDB(std::string _message = std::string()): Exception(_message) {} }; + class WhisperDB { public: WhisperDB(); - ~WhisperDB(); + ~WhisperDB() {} - bool insert(dev::h256 const& _key, std::string const& _value); - bool kill(dev::h256 const& _key); std::string lookup(dev::h256 const& _key) const; + void insert(dev::h256 const& _key, std::string const& _value); + void kill(dev::h256 const& _key); private: ldb::ReadOptions m_readOptions; ldb::WriteOptions m_writeOptions; - ldb::DB* m_db = nullptr; + std::unique_ptr m_db; }; } From f4eb948c1558bee8c2f7dbe5235ed6d852a47a18 Mon Sep 17 00:00:00 2001 From: Vlad Gluhovsky Date: Fri, 10 Jul 2015 18:58:20 +0200 Subject: [PATCH 6/9] new tests added --- test/libwhisper/whisperDB.cpp | 68 ++++++++++++++++++++++++++++++----- 1 file changed, 60 insertions(+), 8 deletions(-) diff --git a/test/libwhisper/whisperDB.cpp b/test/libwhisper/whisperDB.cpp index 9c262fb8e..552820621 100644 --- a/test/libwhisper/whisperDB.cpp +++ b/test/libwhisper/whisperDB.cpp @@ -19,6 +19,7 @@ along with cpp-ethereum. If not, see . * @date July 2015 */ +#include #include #include @@ -28,23 +29,24 @@ using namespace dev::shh; BOOST_AUTO_TEST_SUITE(whisperDB) -BOOST_AUTO_TEST_CASE(first) +BOOST_AUTO_TEST_CASE(basic) { VerbosityHolder setTemporaryLevel(10); cnote << "Testing Whisper DB..."; - WhisperDB db; - - h256 h1(0x12345678); - h256 h2(0xBADD00DE); - string s; - string const text1 = "lorem_ipsum"; - string const text2 = "dolor_sit_amet"; + string const text1 = "lorem"; + string const text2 = "ipsum"; + h256 h1(0xBEEF); + h256 h2(0xC0FFEE); + WhisperDB db; db.kill(h1); db.kill(h2); + s = db.lookup(h1); + BOOST_REQUIRE(s.empty()); + db.insert(h1, text2); s = db.lookup(h2); BOOST_REQUIRE(s.empty()); @@ -65,6 +67,56 @@ BOOST_AUTO_TEST_CASE(first) db.kill(h1); db.kill(h2); + + s = db.lookup(h2); + BOOST_REQUIRE(s.empty()); + s = db.lookup(h1); + BOOST_REQUIRE(s.empty()); +} + +BOOST_AUTO_TEST_CASE(persistence) +{ + VerbosityHolder setTemporaryLevel(10); + cnote << "Testing persistence of Whisper DB..."; + + string s; + string const text1 = "sator"; + string const text2 = "arepo"; + h256 const h1(0x12345678); + h256 const h2(0xBADD00DE); + + { + WhisperDB db; + db.kill(h1); + db.kill(h2); + s = db.lookup(h1); + BOOST_REQUIRE(s.empty()); + db.insert(h1, text2); + s = db.lookup(h2); + BOOST_REQUIRE(s.empty()); + s = db.lookup(h1); + BOOST_REQUIRE(!s.compare(text2)); + } + + this_thread::sleep_for(chrono::milliseconds(20)); + + { + WhisperDB db; + db.insert(h1, text1); + db.insert(h2, text2); + } + + this_thread::sleep_for(chrono::milliseconds(20)); + + { + WhisperDB db; + s = db.lookup(h2); + BOOST_REQUIRE(!s.compare(text2)); + s = db.lookup(h1); + BOOST_REQUIRE(!s.compare(text1)); + db.kill(h1); + db.kill(h2); + } } BOOST_AUTO_TEST_SUITE_END() From e7c5191b7627b50f67ea2d32a4d4ef703e6171c4 Mon Sep 17 00:00:00 2001 From: Vlad Gluhovsky Date: Fri, 10 Jul 2015 19:09:04 +0200 Subject: [PATCH 7/9] namespaces updated --- libwhisper/WhisperDB.cpp | 6 +++--- libwhisper/WhisperDB.h | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/libwhisper/WhisperDB.cpp b/libwhisper/WhisperDB.cpp index 91c5f74f4..4bfa6caa7 100644 --- a/libwhisper/WhisperDB.cpp +++ b/libwhisper/WhisperDB.cpp @@ -31,11 +31,11 @@ WhisperDB::WhisperDB() { string path = dev::getDataDir(); boost::filesystem::create_directories(path); - ldb::Options op; + leveldb::Options op; op.create_if_missing = true; op.max_open_files = 256; - ldb::DB* p = nullptr; - leveldb::Status status = ldb::DB::Open(op, path + "/whisper", &p); + leveldb::DB* p = nullptr; + leveldb::Status status = leveldb::DB::Open(op, path + "/whisper", &p); m_db.reset(p); if (!status.ok()) BOOST_THROW_EXCEPTION(FailedToOpenLevelDB(status.ToString())); diff --git a/libwhisper/WhisperDB.h b/libwhisper/WhisperDB.h index c20f52a75..efea322a8 100644 --- a/libwhisper/WhisperDB.h +++ b/libwhisper/WhisperDB.h @@ -46,9 +46,9 @@ class WhisperDB void kill(dev::h256 const& _key); private: - ldb::ReadOptions m_readOptions; - ldb::WriteOptions m_writeOptions; - std::unique_ptr m_db; + leveldb::ReadOptions m_readOptions; + leveldb::WriteOptions m_writeOptions; + std::unique_ptr m_db; }; } From 9edfae2e6ae5e074ab102fe5e5e9510ab0482eec Mon Sep 17 00:00:00 2001 From: Vlad Gluhovsky Date: Sat, 11 Jul 2015 13:13:25 +0200 Subject: [PATCH 8/9] signatures and path --- libwhisper/WhisperDB.cpp | 4 ++-- libwhisper/WhisperDB.h | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/libwhisper/WhisperDB.cpp b/libwhisper/WhisperDB.cpp index 4bfa6caa7..fd2eef060 100644 --- a/libwhisper/WhisperDB.cpp +++ b/libwhisper/WhisperDB.cpp @@ -29,13 +29,13 @@ using namespace dev::shh; WhisperDB::WhisperDB() { - string path = dev::getDataDir(); + string path = dev::getDataDir("shh"); boost::filesystem::create_directories(path); leveldb::Options op; op.create_if_missing = true; op.max_open_files = 256; leveldb::DB* p = nullptr; - leveldb::Status status = leveldb::DB::Open(op, path + "/whisper", &p); + leveldb::Status status = leveldb::DB::Open(op, path + "/messages", &p); m_db.reset(p); if (!status.ok()) BOOST_THROW_EXCEPTION(FailedToOpenLevelDB(status.ToString())); diff --git a/libwhisper/WhisperDB.h b/libwhisper/WhisperDB.h index efea322a8..0cb97e244 100644 --- a/libwhisper/WhisperDB.h +++ b/libwhisper/WhisperDB.h @@ -30,10 +30,10 @@ namespace dev namespace shh { -struct FailedToOpenLevelDB: virtual Exception { FailedToOpenLevelDB(std::string _message = std::string()): Exception(_message) {} }; -struct FailedInsertInLevelDB: virtual Exception { FailedInsertInLevelDB(std::string _message = std::string()): Exception(_message) {} }; -struct FailedLookupInLevelDB: virtual Exception { FailedLookupInLevelDB(std::string _message = std::string()): Exception(_message) {} }; -struct FailedDeleteInLevelDB: virtual Exception { FailedDeleteInLevelDB(std::string _message = std::string()): Exception(_message) {} }; +struct FailedToOpenLevelDB: virtual Exception { FailedToOpenLevelDB(std::string const& _message): Exception(_message) {} }; +struct FailedInsertInLevelDB: virtual Exception { FailedInsertInLevelDB(std::string const& _message): Exception(_message) {} }; +struct FailedLookupInLevelDB: virtual Exception { FailedLookupInLevelDB(std::string const& _message): Exception(_message) {} }; +struct FailedDeleteInLevelDB: virtual Exception { FailedDeleteInLevelDB(std::string const& _message): Exception(_message) {} }; class WhisperDB { From 1887c600409e40d8a6100a2a74e64f55cbf4e0e3 Mon Sep 17 00:00:00 2001 From: Vlad Gluhovsky Date: Tue, 14 Jul 2015 15:22:15 +0200 Subject: [PATCH 9/9] test fixed --- test/libp2p/peer.cpp | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/test/libp2p/peer.cpp b/test/libp2p/peer.cpp index e84e86027..5417450b4 100644 --- a/test/libp2p/peer.cpp +++ b/test/libp2p/peer.cpp @@ -43,28 +43,32 @@ BOOST_AUTO_TEST_CASE(host) if (test::Options::get().nonetwork) return; - VerbosityHolder sentinel(10); - + VerbosityHolder setTemporaryLevel(10); NetworkPreferences host1prefs("127.0.0.1", 30301, false); - NetworkPreferences host2prefs("127.0.0.1", 30302, false); - + NetworkPreferences host2prefs("127.0.0.1", 30302, false); Host host1("Test", host1prefs); - host1.start(); - Host host2("Test", host2prefs); - auto node2 = host2.id(); + host1.start(); host2.start(); - - while (!host2.haveNetwork()) - this_thread::sleep_for(chrono::milliseconds(20)); + auto node2 = host2.id(); + int const step = 10; + + for (int i = 0; i < 3000 && (!host1.isStarted() || !host2.isStarted()); i += step) + this_thread::sleep_for(chrono::milliseconds(step)); + + BOOST_REQUIRE(host1.isStarted() && host2.isStarted()); host1.addNode(node2, NodeIPEndpoint(bi::address::from_string("127.0.0.1"), host2prefs.listenPort, host2prefs.listenPort)); - this_thread::sleep_for(chrono::seconds(3)); - - auto host1peerCount = host1.peerCount(); - auto host2peerCount = host2.peerCount(); - BOOST_REQUIRE_EQUAL(host1peerCount, 1); - BOOST_REQUIRE_EQUAL(host2peerCount, 1); + for (int i = 0; i < 3000 && (!host1.haveNetwork() || !host2.haveNetwork()); i += step) + this_thread::sleep_for(chrono::milliseconds(step)); + + BOOST_REQUIRE(host1.haveNetwork() && host2.haveNetwork()); + + for (int i = 0; i < 3000 && (!host1.peerCount() || !host2.peerCount()); i += step) + this_thread::sleep_for(chrono::milliseconds(step)); + + BOOST_REQUIRE_EQUAL(host1.peerCount(), 1); + BOOST_REQUIRE_EQUAL(host2.peerCount(), 1); } BOOST_AUTO_TEST_CASE(networkConfig)