Browse Source

refactoring

cl-refactor
Vlad Gluhovsky 10 years ago
parent
commit
432e1988f9
  1. 2
      libethereum/BlockChain.cpp
  2. 20
      libp2p/Common.h
  3. 22
      libwhisper/WhisperDB.cpp
  4. 4
      libwhisper/WhisperDB.h
  5. 8
      test/libwhisper/whisperDB.cpp

2
libethereum/BlockChain.cpp

@ -386,6 +386,7 @@ tuple<ImportRoute, bool, unsigned> BlockChain::sync(BlockQueue& _bq, OverlayDB c
if (!badBlocks.empty())
badBlocks.push_back(block.verified.info.hash());
else
{
do {
try
{
@ -427,6 +428,7 @@ tuple<ImportRoute, bool, unsigned> BlockChain::sync(BlockQueue& _bq, OverlayDB c
badBlocks.push_back(block.verified.info.hash());
}
} while (false);
}
return make_tuple(ImportRoute{dead, fresh, goodTransactions}, _bq.doneDrain(badBlocks), count);
}

20
libp2p/Common.h

@ -243,25 +243,7 @@ public:
void stop() { m_stopped = true; DEV_GUARDED(x_timers) m_timers.clear(); }
protected:
void reap()
{
Guard l(x_timers);
std::vector<DeadlineOp>::iterator t = m_timers.begin();
while (t != m_timers.end())
if (t->expired())
{
t->wait();
t = m_timers.erase(t);
}
else
t++;
m_timers.emplace_back(m_io, m_reapIntervalMs, [this](boost::system::error_code const& ec)
{
if (!ec)
reap();
});
}
void reap();
private:
ba::io_service& m_io;

22
libwhisper/WhisperDB.cpp

@ -158,17 +158,13 @@ void WhisperMessagesDB::saveSingleMessage(h256 const& _key, Envelope const& _e)
}
}
vector<unsigned> WhisperFiltersDB::restoreTopicsFromDB(WhisperHost* _host, string const& _password)
vector<unsigned> WhisperFiltersDB::restoreTopicsFromDB(WhisperHost* _host, h256 const& _id)
{
vector<unsigned> ret;
h256 s = sha3(_password);
h256 h = sha3(s);
string raw = lookup(h);
string raw = lookup(_id);
if (!raw.empty())
{
bytes plain;
decryptSym(s, raw, plain);
RLP rlp(plain);
RLP rlp(raw);
auto sz = rlp.itemCountStrict();
for (unsigned i = 0; i < sz; ++i)
@ -191,15 +187,11 @@ vector<unsigned> WhisperFiltersDB::restoreTopicsFromDB(WhisperHost* _host, strin
return ret;
}
void WhisperFiltersDB::saveTopicsToDB(WhisperHost const& _host, std::string const& _password)
void WhisperFiltersDB::saveTopicsToDB(WhisperHost const& _host, h256 const& _id)
{
bytes plain;
bytes b;
RLPStream rlp;
_host.exportFilters(rlp);
rlp.swapOut(plain);
h256 s = sha3(_password);
h256 h = sha3(s);
bytes encrypted;
encryptSym(s, &plain, encrypted);
insert(h, encrypted);
rlp.swapOut(b);
insert(_id, b);
}

4
libwhisper/WhisperDB.h

@ -69,8 +69,8 @@ class WhisperFiltersDB: public WhisperDB
public:
WhisperFiltersDB(): WhisperDB("filters") {}
virtual ~WhisperFiltersDB() {}
std::vector<unsigned> restoreTopicsFromDB(WhisperHost* _host, std::string const& _password);
void saveTopicsToDB(WhisperHost const& _host, std::string const& _password);
std::vector<unsigned> restoreTopicsFromDB(WhisperHost* _host, h256 const& _id);
void saveTopicsToDB(WhisperHost const& _host, h256 const& _id);
};
}

8
test/libwhisper/whisperDB.cpp

@ -213,7 +213,7 @@ BOOST_AUTO_TEST_CASE(filters)
{
cnote << "Testing filters saving...";
VerbosityHolder setTemporaryLevel(2);
string const password("some pseudorandom string");
h256 persistID(0xC0FFEE);
{
WhisperFiltersDB db;
@ -221,7 +221,7 @@ BOOST_AUTO_TEST_CASE(filters)
auto wh = h.registerCapability(new WhisperHost());
wh->installWatch(BuildTopic("t1"));
wh->installWatch(BuildTopic("t2"));
db.saveTopicsToDB(*wh, password);
db.saveTopicsToDB(*wh, persistID);
}
short unsigned port1 = 30313;
@ -236,8 +236,8 @@ BOOST_AUTO_TEST_CASE(filters)
auto whost1 = host1.registerCapability(new WhisperHost());
host1.start();
WhisperFiltersDB db;
auto watches = db.restoreTopicsFromDB(whost1.get(), password);
auto zero = db.restoreTopicsFromDB(whost1.get(), password + "qwer");
auto watches = db.restoreTopicsFromDB(whost1.get(), persistID);
auto zero = db.restoreTopicsFromDB(whost1.get(), ++persistID);
BOOST_REQUIRE(!watches.empty());
BOOST_REQUIRE(zero.empty());

Loading…
Cancel
Save