Fabcoin Core  0.16.2
P2P Digital Currency
WhisperDB.h
Go to the documentation of this file.
1 /*
2  This file is part of cpp-ethereum.
3 
4  cpp-ethereum is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  cpp-ethereum is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
16 */
22 #pragma once
23 
24 #include <libdevcore/db.h>
25 #include <libdevcore/FixedHash.h>
26 #include "Common.h"
27 #include "Message.h"
28 
29 namespace dev
30 {
31 namespace shh
32 {
33 
34 struct WrongTypeLevelDB: virtual Exception {};
35 struct FailedToOpenLevelDB: virtual Exception { FailedToOpenLevelDB(std::string const& _message): Exception(_message) {} };
36 struct FailedInsertInLevelDB: virtual Exception { FailedInsertInLevelDB(std::string const& _message): Exception(_message) {} };
37 struct FailedLookupInLevelDB: virtual Exception { FailedLookupInLevelDB(std::string const& _message): Exception(_message) {} };
38 struct FailedDeleteInLevelDB: virtual Exception { FailedDeleteInLevelDB(std::string const& _message): Exception(_message) {} };
39 
40 class WhisperHost;
41 
42 class WhisperDB
43 {
44 public:
45  WhisperDB(std::string const& _type);
46  virtual ~WhisperDB() {}
47  std::string lookup(dev::h256 const& _key) const;
48  void insert(dev::h256 const& _key, std::string const& _value);
49  void insert(dev::h256 const& _key, bytes const& _value);
50  void kill(dev::h256 const& _key);
51 
52 protected:
53  leveldb::ReadOptions m_readOptions;
54  leveldb::WriteOptions m_writeOptions;
55  std::unique_ptr<leveldb::DB> m_db;
56 };
57 
59 {
60 public:
61  WhisperMessagesDB(): WhisperDB("messages") {}
62  virtual ~WhisperMessagesDB() {}
63  void loadAllMessages(std::map<h256, Envelope>& o_dst);
64  void saveSingleMessage(dev::h256 const& _key, Envelope const& _e);
65 };
66 
68 {
69 public:
70  WhisperFiltersDB(): WhisperDB("filters") {}
71  virtual ~WhisperFiltersDB() {}
72 };
73 
74 }
75 }
FailedToOpenLevelDB(std::string const &_message)
Definition: WhisperDB.h:35
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
Definition: Arith256.cpp:15
FailedLookupInLevelDB(std::string const &_message)
Definition: WhisperDB.h:37
std::unique_ptr< leveldb::DB > m_db
Definition: WhisperDB.h:55
FailedInsertInLevelDB(std::string const &_message)
Definition: WhisperDB.h:36
Base class for all exceptions.
Definition: Exceptions.h:39
leveldb::ReadOptions m_readOptions
Definition: WhisperDB.h:53
std::vector< byte > bytes
Definition: Common.h:75
leveldb::WriteOptions m_writeOptions
Definition: WhisperDB.h:54
virtual ~WhisperDB()
Definition: WhisperDB.h:46
Exception(std::string _message=std::string())
Definition: Exceptions.h:41
FailedDeleteInLevelDB(std::string const &_message)
Definition: WhisperDB.h:38