WhisperDB.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. This file is part of cpp-ethereum.
  3. cpp-ethereum is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 3 of the License, or
  6. (at your option) any later version.
  7. cpp-ethereum is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. /** @file WhisperDB.h
  15. * @author Vladislav Gluhovsky <vlad@ethdev.com>
  16. * @date July 2015
  17. */
  18. #pragma once
  19. #include <libdevcore/db.h>
  20. #include <libdevcore/FixedHash.h>
  21. #include "Common.h"
  22. #include "Message.h"
  23. namespace dev
  24. {
  25. namespace shh
  26. {
  27. struct WrongTypeLevelDB: virtual Exception {};
  28. struct FailedToOpenLevelDB: virtual Exception { FailedToOpenLevelDB(std::string const& _message): Exception(_message) {} };
  29. struct FailedInsertInLevelDB: virtual Exception { FailedInsertInLevelDB(std::string const& _message): Exception(_message) {} };
  30. struct FailedLookupInLevelDB: virtual Exception { FailedLookupInLevelDB(std::string const& _message): Exception(_message) {} };
  31. struct FailedDeleteInLevelDB: virtual Exception { FailedDeleteInLevelDB(std::string const& _message): Exception(_message) {} };
  32. class WhisperHost;
  33. class WhisperDB
  34. {
  35. public:
  36. WhisperDB(std::string const& _type);
  37. virtual ~WhisperDB() {}
  38. std::string lookup(dev::h256 const& _key) const;
  39. void insert(dev::h256 const& _key, std::string const& _value);
  40. void insert(dev::h256 const& _key, bytes const& _value);
  41. void kill(dev::h256 const& _key);
  42. protected:
  43. leveldb::ReadOptions m_readOptions;
  44. leveldb::WriteOptions m_writeOptions;
  45. std::unique_ptr<leveldb::DB> m_db;
  46. };
  47. class WhisperMessagesDB: public WhisperDB
  48. {
  49. public:
  50. WhisperMessagesDB(): WhisperDB("messages") {}
  51. virtual ~WhisperMessagesDB() {}
  52. void loadAllMessages(std::map<h256, Envelope>& o_dst);
  53. void saveSingleMessage(dev::h256 const& _key, Envelope const& _e);
  54. };
  55. class WhisperFiltersDB: public WhisperDB
  56. {
  57. public:
  58. WhisperFiltersDB(): WhisperDB("filters") {}
  59. virtual ~WhisperFiltersDB() {}
  60. };
  61. }
  62. }