diff --git a/alethzero/MainWin.cpp b/alethzero/MainWin.cpp index 5842664b3..f940a2961 100644 --- a/alethzero/MainWin.cpp +++ b/alethzero/MainWin.cpp @@ -97,25 +97,9 @@ Main::Main(QWidget *parent) : // ui->log->addItem(QString::fromStdString(s)); }; -#if 0&Ð_DEBUG - m_servers.append("192.168.0.10:30301"); -#else - int pocnumber = QString(dev::Version).section('.', 1, 1).toInt(); - if (pocnumber == 5) - m_servers.push_back("54.72.69.180:30303"); - else if (pocnumber == 6) - m_servers.push_back("54.76.56.74:30303"); - else - { - connect(&m_webCtrl, &QNetworkAccessManager::finished, [&](QNetworkReply* _r) - { - m_servers = QString::fromUtf8(_r->readAll()).split("\n", QString::SkipEmptyParts); - }); - QNetworkRequest r(QUrl("http://www.ethereum.org/servers.poc" + QString::number(pocnumber) + ".txt")); - r.setHeader(QNetworkRequest::UserAgentHeader, "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1712.0 Safari/537.36"); - m_webCtrl.get(r); - srand(time(0)); - } + m_servers.append(QString::fromStdString(Host::pocHost() + ":30303")); +#if ETH_DEBUG + m_servers.append("localhost:30303"); #endif cerr << "State root: " << BlockChain::genesis().stateRoot << endl; diff --git a/exp/main.cpp b/exp/main.cpp index 40804958e..1f29ab207 100644 --- a/exp/main.cpp +++ b/exp/main.cpp @@ -37,9 +37,9 @@ using namespace dev::shh; int main() { DownloadMan man; - DownloadSub s0(&man); - DownloadSub s1(&man); - DownloadSub s2(&man); + DownloadSub s0(man); + DownloadSub s1(man); + DownloadSub s2(man); man.resetToChain(h256s({u256(0), u256(1), u256(2), u256(3), u256(4), u256(5), u256(6), u256(7), u256(8)})); cnote << s0.nextFetch(2); cnote << s1.nextFetch(2); diff --git a/libethereum/DownloadMan.cpp b/libethereum/DownloadMan.cpp index 65ad6adc4..115813a31 100644 --- a/libethereum/DownloadMan.cpp +++ b/libethereum/DownloadMan.cpp @@ -24,7 +24,7 @@ using namespace std; using namespace dev; using namespace dev::eth; -DownloadSub::DownloadSub(DownloadMan* _man): m_man(_man) +DownloadSub::DownloadSub(DownloadMan& _man): m_man(&_man) { WriteGuard l(m_man->x_subs); m_man->m_subs.insert(this); diff --git a/libethereum/DownloadMan.h b/libethereum/DownloadMan.h index 056f089b6..6375f69e4 100644 --- a/libethereum/DownloadMan.h +++ b/libethereum/DownloadMan.h @@ -42,7 +42,7 @@ class DownloadSub friend class DownloadMan; public: - DownloadSub(DownloadMan* _man); + DownloadSub(DownloadMan& _man); ~DownloadSub(); /// Finished last fetch - grab the next bunch of block hashes to download. diff --git a/libethereum/EthereumHost.h b/libethereum/EthereumHost.h index 3021f26ee..2ff8e35d4 100644 --- a/libethereum/EthereumHost.h +++ b/libethereum/EthereumHost.h @@ -35,6 +35,7 @@ #include #include "CommonNet.h" #include "EthereumPeer.h" +#include "DownloadMan.h" namespace dev { @@ -122,6 +123,8 @@ private: h256Set m_blocksOnWay; + DownloadMan m_man; + h256 m_latestBlockSent; h256Set m_transactionsSent; }; diff --git a/libethereum/EthereumPeer.cpp b/libethereum/EthereumPeer.cpp index 7ccf6939b..557c67242 100644 --- a/libethereum/EthereumPeer.cpp +++ b/libethereum/EthereumPeer.cpp @@ -35,7 +35,8 @@ using namespace p2p; #define clogS(X) dev::LogOutputStream(false) << "| " << std::setw(2) << session()->socketId() << "] " EthereumPeer::EthereumPeer(Session* _s, HostCapabilityFace* _h): - Capability(_s, _h) + Capability(_s, _h), + m_sub(host()->m_man) { sendStatus(); } @@ -90,7 +91,7 @@ void EthereumPeer::tryGrabbingHashChain() u256 td = max(host()->m_chain.details().totalDifficulty, host()->m_totalDifficultyOfNeeded); clogS(NetAllDetail) << "Attempt chain-grab? Latest:" << c.abridged() << ", number:" << n << ", TD: max(" << host()->m_chain.details().totalDifficulty << "," << host()->m_totalDifficultyOfNeeded << ") versus " << m_totalDifficulty; - if (td > m_totalDifficulty) + if (td >= m_totalDifficulty) { clogS(NetAllDetail) << "No. Our chain is better."; m_grabbing = Grabbing::Nothing; diff --git a/libethereum/EthereumPeer.h b/libethereum/EthereumPeer.h index adf82c215..960f1f482 100644 --- a/libethereum/EthereumPeer.h +++ b/libethereum/EthereumPeer.h @@ -32,6 +32,7 @@ #include #include #include "CommonNet.h" +#include "DownloadMan.h" namespace dev { @@ -94,6 +95,8 @@ private: std::set m_knownBlocks; std::set m_knownTransactions; std::mutex x_knownTransactions; + + DownloadSub m_sub; }; } diff --git a/libp2p/Host.cpp b/libp2p/Host.cpp index 15727f9c1..2a27a4b85 100644 --- a/libp2p/Host.cpp +++ b/libp2p/Host.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include "Session.h" @@ -349,12 +350,20 @@ void Host::ensureAccepting() } } +string Host::pocHost() +{ + vector strs; + boost::split(strs, dev::Version, boost::is_any_of(".")); + return "poc-" + strs[1] + ".ethdev.com"; +} + void Host::connect(std::string const& _addr, unsigned short _port) noexcept { try { - // TODO: actual DNS lookup. - connect(bi::tcp::endpoint(bi::address::from_string(_addr), _port)); + bi::tcp::resolver r(m_ioService); + connect(r.resolve({_addr, toString(_port)})->endpoint()); +// connect(bi::tcp::endpoint(bi::address::from_string(_addr), _port)); } catch (exception const& e) { diff --git a/libp2p/Host.h b/libp2p/Host.h index e8b95e2a8..f5f2f9e97 100644 --- a/libp2p/Host.h +++ b/libp2p/Host.h @@ -82,6 +82,7 @@ public: template std::shared_ptr cap() const { try { return std::static_pointer_cast(m_capabilities.at(T::staticName())); } catch (...) { return nullptr; } } /// Connect to a peer explicitly. + static std::string pocHost(); void connect(std::string const& _addr, unsigned short _port = 30303) noexcept; void connect(bi::tcp::endpoint const& _ep);