Skip to content
This repository was archived by the owner on Oct 28, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 21 additions & 16 deletions aleth-bootnode/main.cpp
Original file line number Diff line number Diff line change
@@ -1,23 +1,11 @@
/*
This file is part of aleth.

aleth is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

aleth is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with aleth. If not, see <http://www.gnu.org/licenses/>.
*/
// Aleth: Ethereum C++ client, tools and libraries.
// Copyright 2019 Aleth Authors.
// Licensed under the GNU General Public License, Version 3.

#include <libdevcore/FileSystem.h>
#include <libdevcore/LoggingProgramOptions.h>
#include <libethcore/Common.h>
#include <libp2p/Common.h>
#include <libp2p/Host.h>
#include <boost/program_options.hpp>
#include <boost/program_options/options_description.hpp>
Expand All @@ -26,6 +14,7 @@

namespace po = boost::program_options;
namespace fs = boost::filesystem;
namespace bi = boost::asio::ip;

using namespace dev;
using namespace dev::p2p;
Expand All @@ -43,6 +32,7 @@ int main(int argc, char** argv)
setDefaultOrCLocale();

bool allowLocalDiscovery = false;
bool noBootstrap = false;

po::options_description generalOptions("GENERAL OPTIONS", c_lineWidth);
auto addGeneralOption = generalOptions.add_options();
Expand All @@ -66,6 +56,8 @@ int main(int argc, char** argv)
"Listen on the given port for incoming connections (default: 30303)");
addNetworkingOption("allow-local-discovery", po::bool_switch(&allowLocalDiscovery),
"Include local addresses in the discovery process. Used for testing purposes.");
addNetworkingOption("no-bootstrap", po::bool_switch(&noBootstrap),
"Do not connect to the default Ethereum bootnode servers");
po::options_description allowedOptions("Allowed options");
allowedOptions.add(generalOptions).add(loggingProgramOptions).add(clientNetworking);

Expand Down Expand Up @@ -122,6 +114,7 @@ int main(int argc, char** argv)
listenIP = vm["listen-ip"].as<string>();
if (vm.count("listen"))
listenPort = vm["listen"].as<unsigned short>();

setupLogging(loggingOptions);
if (loggingOptions.verbosity > 0)
cout << EthGrayBold << c_programName << ", a C++ Ethereum bootnode implementation" EthReset
Expand All @@ -134,9 +127,21 @@ int main(int argc, char** argv)

Host h(c_programName, netPrefs, &netData);
h.start();
if (!h.haveNetwork())
return AlethErrors::NetworkStartFailure;

cout << "Node ID: " << h.enode() << endl;

if (!noBootstrap)
{
for (auto const& bn : defaultBootNodes())
{
bi::tcp::endpoint ep = Network::resolveHost(bn.second);
h.addNode(
bn.first, NodeIPEndpoint{ep.address(), ep.port() /* udp */, ep.port() /* tcp */});
}
}

ExitHandler exitHandler;
signal(SIGTERM, &ExitHandler::exitHandler);
signal(SIGABRT, &ExitHandler::exitHandler);
Expand Down
2 changes: 1 addition & 1 deletion aleth/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,7 @@ int main(int argc, char** argv)
web3.addNode(p.first, p.second.first);

if (bootstrap && privateChain.empty())
for (auto const& i : Host::pocHosts())
for (auto const& i : defaultBootNodes())
web3.requirePeer(i.first, i.second);
if (!remoteHost.empty())
web3.addNode(p2p::NodeID(), remoteHost + ":" + toString(remotePort));
Expand Down
31 changes: 25 additions & 6 deletions libp2p/Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ using namespace std;
const NodeIPEndpoint UnspecifiedNodeIPEndpoint = NodeIPEndpoint{{}, 0, 0};
const Node UnspecifiedNode = Node{{}, UnspecifiedNodeIPEndpoint};

bool isPublicAddress(std::string const& _addressToCheck)
bool isPublicAddress(string const& _addressToCheck)
{
return _addressToCheck.empty() ? false :
isPublicAddress(bi::address::from_string(_addressToCheck));
Expand Down Expand Up @@ -69,7 +69,7 @@ bool isPrivateAddress(bi::address const& _addressToCheck)
return false;
}

bool isPrivateAddress(std::string const& _addressToCheck)
bool isPrivateAddress(string const& _addressToCheck)
{
return _addressToCheck.empty() ? false :
isPrivateAddress(bi::address::from_string(_addressToCheck));
Expand All @@ -89,13 +89,13 @@ bool isLocalHostAddress(bi::address const& _addressToCheck)
return c_rejectAddresses.find(_addressToCheck) != c_rejectAddresses.end();
}

bool isLocalHostAddress(std::string const& _addressToCheck)
bool isLocalHostAddress(string const& _addressToCheck)
{
return _addressToCheck.empty() ? false :
isLocalHostAddress(bi::address::from_string(_addressToCheck));
}

std::string reasonOf(DisconnectReason _r)
string reasonOf(DisconnectReason _r)
{
switch (_r)
{
Expand Down Expand Up @@ -216,7 +216,7 @@ NodeIPEndpoint NodeSpec::nodeIPEndpoint() const
return {Network::resolveHost(m_address).address(), m_udpPort, m_tcpPort};
}

std::string NodeSpec::enode() const
string NodeSpec::enode() const
{
string ret = m_address;

Expand All @@ -238,7 +238,7 @@ bool NodeSpec::isValid() const
return m_id && !m_address.empty();
}

std::ostream& operator<<(std::ostream& _out, NodeIPEndpoint const& _ep)
ostream& operator<<(ostream& _out, NodeIPEndpoint const& _ep)
{
_out << _ep.address() << ':' << _ep.tcpPort();
// It rarely happens that TCP and UDP are different, so save space
Expand All @@ -253,5 +253,24 @@ boost::log::formatting_ostream& operator<<(boost::log::formatting_ostream& _log,
return _log << _node.id << '@' << _node.endpoint;
}

unordered_map<Public, string>& defaultBootNodes()
{
static unordered_map<Public, string> ret = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, does it have to be a map at all? I think an std::array would work.

// Mainnet:
{ Public("a979fb575495b8d6db44f750317d0f4622bf4c2aa3365d6af7c284339968eef29b69ad0dce72a4d8db5ebb4968de0e3bec910127f134779fbcb0cb6d3331163c"), "52.16.188.185:30303" },
{ Public("3f1d12044546b76342d59d4a05532c14b85aa669704bfe1f864fe079415aa2c02d743e03218e57a33fb94523adb54032871a6c51b2cc5514cb7c7e35b3ed0a99"), "13.93.211.84:30303" },
{ Public("78de8a0916848093c73790ead81d1928bec737d565119932b98c6b100d944b7a95e94f847f689fc723399d2e31129d182f7ef3863f2b4c820abbf3ab2722344d"), "191.235.84.50:30303" },
{ Public("158f8aab45f6d19c6cbf4a089c2670541a8da11978a2f90dbf6a502a4a3bab80d288afdbeb7ec0ef6d92de563767f3b1ea9e8e334ca711e9f8e2df5a0385e8e6"), "13.75.154.138:30303" },
{ Public("1118980bf48b0a3640bdba04e0fe78b1add18e1cd99bf22d53daac1fd9972ad650df52176e7c7d89d1114cfef2bc23a2959aa54998a46afcf7d91809f0855082"), "52.74.57.123:30303" },
// Ropsten:
{ Public("30b7ab30a01c124a6cceca36863ece12c4f5fa68e3ba9b0b51407ccc002eeed3b3102d20a88f1c1d3c3154e2449317b8ef95090e77b312d5cc39354f86d5d606"), "52.176.7.10:30303" },
{ Public("865a63255b3bb68023b6bffd5095118fcc13e79dcf014fe4e47e065c350c7cc72af2e53eff895f11ba1bbb6a2b33271c1116ee870f266618eadfc2e78aa7349c"), "52.176.100.77:30303" },
{ Public("6332792c4a00e3e4ee0926ed89e0d27ef985424d97b6a45bf0f23e51f0dcb5e66b875777506458aea7af6f9e4ffb69f43f3778ee73c81ed9d34c51c4b16b0b0f"), "52.232.243.152:30303" },
{ Public("94c15d1b9e2fe7ce56e458b9a3b672ef11894ddedd0c6f247e0f1d3487f52b66208fb4aeb8179fce6e3a749ea93ed147c37976d67af557508d199d9594c35f09"), "192.81.208.223:30303" },
};

return ret;
}

} // namespace p2p
} // namespace dev
37 changes: 11 additions & 26 deletions libp2p/Common.h
Original file line number Diff line number Diff line change
@@ -1,26 +1,10 @@
/*
This file is part of cpp-ethereum.

cpp-ethereum is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

cpp-ethereum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file Common.h
* @author Gav Wood <i@gavwood.com>
* @author Alex Leverington <nessence@gmail.com>
* @date 2014
*
* Miscellanea required for the Host/Session/NodeTable classes.
*/
// Aleth: Ethereum C++ client, tools and libraries.
// Copyright 2019 Aleth Authors.
// Licensed under the GNU General Public License, Version 3.

//
// Miscellanea required for the Host/Session/NodeTable classes.
//

#pragma once

Expand Down Expand Up @@ -313,8 +297,10 @@ class DeadlineOps

/// Simple stream output for a NodeIPEndpoint.
std::ostream& operator<<(std::ostream& _out, NodeIPEndpoint const& _ep);

/// Official Ethereum boot nodes
std::unordered_map<Public, std::string>& defaultBootNodes();
}

}

/// std::hash for asio::adress
Expand All @@ -337,5 +323,4 @@ template <> struct hash<bi::address>
return std::hash<std::string>()(_a.to_string());
}
};

}
} // namespace std
17 changes: 0 additions & 17 deletions libp2p/Host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,23 +472,6 @@ void Host::runAcceptor()
}
}

unordered_map<Public, string> Host::pocHosts()
{
return {
// Mainnet:
{ Public("a979fb575495b8d6db44f750317d0f4622bf4c2aa3365d6af7c284339968eef29b69ad0dce72a4d8db5ebb4968de0e3bec910127f134779fbcb0cb6d3331163c"), "52.16.188.185:30303" },
{ Public("3f1d12044546b76342d59d4a05532c14b85aa669704bfe1f864fe079415aa2c02d743e03218e57a33fb94523adb54032871a6c51b2cc5514cb7c7e35b3ed0a99"), "13.93.211.84:30303" },
{ Public("78de8a0916848093c73790ead81d1928bec737d565119932b98c6b100d944b7a95e94f847f689fc723399d2e31129d182f7ef3863f2b4c820abbf3ab2722344d"), "191.235.84.50:30303" },
{ Public("158f8aab45f6d19c6cbf4a089c2670541a8da11978a2f90dbf6a502a4a3bab80d288afdbeb7ec0ef6d92de563767f3b1ea9e8e334ca711e9f8e2df5a0385e8e6"), "13.75.154.138:30303" },
{ Public("1118980bf48b0a3640bdba04e0fe78b1add18e1cd99bf22d53daac1fd9972ad650df52176e7c7d89d1114cfef2bc23a2959aa54998a46afcf7d91809f0855082"), "52.74.57.123:30303" },
// Ropsten:
{ Public("30b7ab30a01c124a6cceca36863ece12c4f5fa68e3ba9b0b51407ccc002eeed3b3102d20a88f1c1d3c3154e2449317b8ef95090e77b312d5cc39354f86d5d606"), "52.176.7.10:30303" },
{ Public("865a63255b3bb68023b6bffd5095118fcc13e79dcf014fe4e47e065c350c7cc72af2e53eff895f11ba1bbb6a2b33271c1116ee870f266618eadfc2e78aa7349c"), "52.176.100.77:30303" },
{ Public("6332792c4a00e3e4ee0926ed89e0d27ef985424d97b6a45bf0f23e51f0dcb5e66b875777506458aea7af6f9e4ffb69f43f3778ee73c81ed9d34c51c4b16b0b0f"), "52.232.243.152:30303" },
{ Public("94c15d1b9e2fe7ce56e458b9a3b672ef11894ddedd0c6f247e0f1d3487f52b66208fb4aeb8179fce6e3a749ea93ed147c37976d67af557508d199d9594c35f09"), "192.81.208.223:30303" },
};
}

void Host::registerCapability(shared_ptr<CapabilityFace> const& _cap)
{
registerCapability(_cap, _cap->name(), _cap->version());
Expand Down
3 changes: 0 additions & 3 deletions libp2p/Host.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,6 @@ class Host: public Worker
/// Will block on network process events.
virtual ~Host();

/// Default hosts for current version of client.
static std::unordered_map<Public, std::string> pocHosts();

/// Register a host capability; all new peer connections will see this capability.
void registerCapability(std::shared_ptr<CapabilityFace> const& _cap);

Expand Down