Browse Source

Peer & key management.

cl-refactor
Gav Wood 10 years ago
parent
commit
a1216c3b74
  1. 11
      alethzero/MainWin.cpp
  2. 2
      libethereum/BlockChain.cpp
  3. 17
      libp2p/Host.cpp

11
alethzero/MainWin.cpp

@ -872,7 +872,7 @@ void Main::refreshBlockChain()
string filter = ui->blockChainFilter->text().toLower().toStdString();
auto const& bc = ethereum()->blockChain();
unsigned i = (ui->showAll->isChecked() || !filter.empty()) ? (unsigned)-1 : 10;
for (auto h = bc.currentHash(); h != bc.genesisHash() && bc.details(h) && i; h = bc.details(h).parent, --i)
for (auto h = bc.currentHash(); bc.details(h) && i; h = bc.details(h).parent, --i)
{
auto d = bc.details(h);
auto bm = blockMatch(filter, d, h, bc);
@ -912,6 +912,8 @@ void Main::refreshBlockChain()
}
n++;
}
if (h == bc.genesisHash())
break;
}
if (!ui->blocks->currentItem())
@ -1138,7 +1140,10 @@ void Main::on_blocks_currentItemChanged()
s << "<br/>Bloom: <b>" << details.bloom << "</b>";
s << "<br/>Transactions: <b>" << block[1].itemCount() << "</b> @<b>" << info.transactionsRoot << "</b>";
s << "<br/>Uncles: <b>" << block[2].itemCount() << "</b> @<b>" << info.sha3Uncles << "</b>";
if (info.parentHash)
s << "<br/>Pre: <b>" << BlockInfo(ethereum()->blockChain().block(info.parentHash)).stateRoot << "</b>";
else
s << "<br/>Pre: <i>Nothing is before the Gensesis</i>";
for (auto const& i: block[1])
s << "<br/>" << sha3(i[0].data()).abridged() << ": <b>" << i[1].toHash<h256>() << "</b> [<b>" << i[2].toInt<u256>() << "</b> used]";
s << "<br/>Post: <b>" << info.stateRoot << "</b>";
@ -1545,10 +1550,10 @@ void Main::on_net_triggered()
web3()->setIdealPeerCount(ui->idealPeers->value());
web3()->setNetworkPreferences(netPrefs());
ethereum()->setNetworkId(m_privateChain.size() ? sha3(m_privateChain.toStdString()) : 0);
if (m_peers.size()/* && ui->usePast->isChecked()*/)
web3()->restoreNodes(bytesConstRef((byte*)m_peers.data(), m_peers.size()));
web3()->startNetwork();
ui->downloadView->setDownloadMan(ethereum()->downloadMan());
if (m_peers.size() && ui->usePast->isChecked())
web3()->restoreNodes(bytesConstRef((byte*)m_peers.data(), m_peers.size()));
}
else
{

2
libethereum/BlockChain.cpp

@ -439,7 +439,7 @@ void BlockChain::checkConsistency()
if (p != h256())
{
auto dp = details(p);
assert(contains(dp.children, h)); // WTF?
// assert(contains(dp.children, h)); // WTF?
assert(dp.number == dh.number - 1);
}
}

17
libp2p/Host.cpp

@ -109,8 +109,6 @@ void Host::start()
determinePublic(m_netPrefs.publicIP, m_netPrefs.upnp);
ensureAccepting();
m_nodes.clear();
m_freePeers.clear();
m_nodesList.clear();
m_ready.reset();
@ -537,6 +535,7 @@ void Host::growPeers()
RecursiveGuard l(x_peers);
while (m_peers.size() < m_idealPeerCount)
{
// TODO: Make work with m_ready/m_private using all the Node information.
if (m_freePeers.empty())
{
if (chrono::steady_clock::now() > m_lastPeersRequest + chrono::seconds(10))
@ -637,7 +636,7 @@ bytes Host::saveNodes() const
for (auto const& i: m_nodes)
{
Node const& n = *(i.second);
nodes.appendList(4);
nodes.appendList(10);
if (n.address.address().is_v4())
nodes << n.address.address().to_v4().to_bytes();
else
@ -659,22 +658,22 @@ void Host::restoreNodes(bytesConstRef _b)
{
RecursiveGuard l(x_peers);
RLP r(_b);
if (r.itemCount() == 2 && r[0].isInt())
if (r.itemCount() > 0 && r[0].isInt())
switch (r[0].toInt<int>())
{
case 0:
m_key = KeyPair(r[1].toHash<Secret>());
for (auto i: r[2])
{
auto id = (NodeId)i[2];
auto o = (Origin)i[3].toInt<int>();
if (!m_nodes.count(id))
{
bi::tcp::endpoint ep;
if (i[0].size() == 4)
if (i[0].itemCount() == 4)
ep = bi::tcp::endpoint(bi::address_v4(i[0].toArray<byte, 4>()), i[1].toInt<short>());
else
ep = bi::tcp::endpoint(bi::address_v6(i[0].toArray<byte, 16>()), i[1].toInt<short>());
auto id = (NodeId)i[2];
if (!m_nodes.count(id))
{
auto o = (Origin)i[3].toInt<int>();
auto n = noteNode(id, ep, o, true);
n->lastConnected = chrono::system_clock::time_point(chrono::seconds(i[4].toInt<unsigned>()));
n->lastAttempted = chrono::system_clock::time_point(chrono::seconds(i[5].toInt<unsigned>()));

Loading…
Cancel
Save