4 #include "validation.h" 7 #include <boost/thread.hpp> 9 static const char MESSAGE_FLAG =
'Z';
10 static const char MY_MESSAGE_CHANNEL =
'C';
11 static const char MY_SEEN_ADDRESSES =
'S';
12 static const char DB_FLAG =
'D';
19 return Write(std::make_pair(MESSAGE_FLAG, message.
out), message);
24 return Read(std::make_pair(MESSAGE_FLAG, out), message);
29 return Erase(std::make_pair(MESSAGE_FLAG, out));
34 std::unique_ptr<CDBIterator> pcursor(
NewIterator());
36 pcursor->Seek(std::make_pair(MESSAGE_FLAG,
COutPoint()));
39 while (pcursor->Valid()) {
40 boost::this_thread::interruption_point();
41 std::pair<char, COutPoint> key;
42 if (pcursor->GetKey(key) && key.first == MESSAGE_FLAG) {
44 if (pcursor->GetValue(message)) {
45 setMessages.insert(message);
48 LogPrintf(
"%s: failed to read message\n", __func__);
60 std::set<CMessage> setMessages;
61 std::unique_ptr<CDBIterator> pcursor(
NewIterator());
63 pcursor->Seek(std::make_pair(MESSAGE_FLAG,
COutPoint()));
66 while (pcursor->Valid()) {
67 boost::this_thread::interruption_point();
68 std::pair<char, COutPoint> key;
69 if (pcursor->GetKey(key) && key.first == MESSAGE_FLAG) {
71 if (pcursor->GetValue(message)) {
72 setMessages.insert(message);
75 LogPrintf(
"%s: failed to read message\n", __func__);
83 count += setMessages.size();
84 for (
auto message : setMessages)
95 return error(
"%s: failed to erase message %s", __func__, messageRemove.ToString());
100 return error(
"%s: failed to write message %s", __func__, messageAdd.second.ToString());
109 return error(
"%s: failed to write message orphan %s", __func__, msg.
ToString());
112 setDirtyMessagesRemove.clear();
113 mapDirtyMessagesAdd.clear();
114 mapDirtyMessagesOrphaned.clear();
115 }
catch (
const std::runtime_error& e) {
116 return error(
"%s : %s ", __func__, std::string(
"System error while flushing messages: ") + e.what());
127 return Write(std::make_pair(MY_MESSAGE_CHANNEL, channelname), 1);
133 return Read(std::make_pair(MY_MESSAGE_CHANNEL, channelname), i);
138 return Erase(std::make_pair(MY_MESSAGE_CHANNEL, channelname));
144 std::unique_ptr<CDBIterator> pcursor(
NewIterator());
146 pcursor->Seek(std::make_pair(MY_MESSAGE_CHANNEL, std::string()));
149 while (pcursor->Valid()) {
150 boost::this_thread::interruption_point();
151 std::pair<char, std::string> key;
152 if (pcursor->GetKey(key) && key.first == MY_MESSAGE_CHANNEL) {
153 setChannels.insert(key.second);
165 return Write(std::make_pair(DB_FLAG, name), fValue ?
'1' :
'0');
171 if (!
Read(std::make_pair(DB_FLAG, name), ch))
180 return Write(std::make_pair(MY_SEEN_ADDRESSES, address), 1);
185 return Read(std::make_pair(MY_SEEN_ADDRESSES, address), i);
189 return Erase(std::make_pair(MY_SEEN_ADDRESSES, address));
194 return Write(std::make_pair(DB_FLAG, name), fValue ?
'1' :
'0');
200 if (!
Read(std::make_pair(DB_FLAG, name), ch))
212 return error(
"%s: failed to erase messagechannel %s", __func__, channelRemove);
217 return error(
"%s: failed to write messagechannel %s", __func__, channelAdd);
222 return error(
"%s: failed to write seenaddress %s", __func__, seenAddress);
225 setDirtyChannelsRemove.clear();
226 setDirtyChannelsAdd.clear();
227 setDirtySeenAddressAdd.clear();
230 }
catch (
const std::runtime_error& e) {
231 return error(
"%s : %s ", __func__, std::string(
"System error while flushing messagechannels: ") + e.what());
std::set< COutPoint > setDirtyMessagesRemove
std::string ToString() const
CMessageChannelDB(size_t nCacheSize, bool fMemory=false, bool fWipe=false)
bool LoadMessages(std::set< CMessage > &setMessages)
bool ReadFlag(const std::string &name, bool &fValue)
bool EraseMyMessageChannel(const std::string &channelname)
bool ReadMyMessageChannel(const std::string &channelname)
CMessageDB(size_t nCacheSize, bool fMemory=false, bool fWipe=false)
bool EraseAllMessages(int &count)
CDBIterator * NewIterator()
bool EraseUsedAddress(const std::string &address)
bool ReadMessage(const COutPoint &out, CMessage &message)
std::set< std::string > setDirtyChannelsRemove
std::set< std::string > setSubscribedChannelsAskedForFalse
bool ReadFlag(const std::string &name, bool &fValue)
bool Erase(const K &key, bool fSync=false)
bool EraseMessage(const COutPoint &out)
bool WriteFlag(const std::string &name, bool fValue)
std::set< std::string > setAddressAskedForFalse
std::map< COutPoint, CMessage > mapDirtyMessagesOrphaned
bool LoadMyMessageChannels(std::set< std::string > &setChannels)
An outpoint - a combination of a transaction hash and an index n into its vout.
bool Read(const K &key, V &value) const
std::map< COutPoint, CMessage > mapDirtyMessagesAdd
bool Write(const K &key, const V &value, bool fSync=false)
bool WriteMyMessageChannel(const std::string &channelname)
bool error(const char *fmt, const Args &... args)
std::set< std::string > setDirtyChannelsAdd
const fs::path & GetDataDir(bool fNetSpecific)
bool WriteUsedAddress(const std::string &address)
bool WriteMessage(const CMessage &message)
bool ReadUsedAddress(const std::string &address)
bool WriteFlag(const std::string &name, bool fValue)
std::set< std::string > setDirtySeenAddressAdd