Browse Source

synchronous resolver

cl-refactor
subtly 10 years ago
parent
commit
55986db377
  1. 10
      libp2p/Network.cpp
  2. 2
      libp2p/Network.h
  3. 9
      libwebthree/WebThree.h

10
libp2p/Network.cpp

@ -208,8 +208,10 @@ bi::tcp::endpoint Network::traverseNAT(std::set<bi::address> const& _ifAddresses
return upnpep;
}
bi::tcp::endpoint Network::resolveHost(ba::io_service& _ioService, string const& _addr)
bi::tcp::endpoint Network::resolveHost(string const& _addr)
{
static boost::asio::io_service s_resolverIoService;
vector<string> split;
boost::split(split, _addr, boost::is_any_of(":"));
unsigned port = split.size() > 1 ? stoi(split[1]) : c_defaultIPPort;
@ -223,9 +225,11 @@ bi::tcp::endpoint Network::resolveHost(ba::io_service& _ioService, string const&
{
boost::system::error_code ec;
// resolve returns an iterator (host can resolve to multiple addresses)
bi::tcp::resolver r(_ioService);
bi::tcp::resolver r(s_resolverIoService);
auto it = r.resolve({split[0], toString(port)}, ec);
if (!ec)
if (ec)
clog(NetWarn) << "Error resolving host address " << _addr << ":" << ec.message();
else
ep = *it;
}
return ep;

2
libp2p/Network.h

@ -71,7 +71,7 @@ public:
static bi::tcp::endpoint traverseNAT(std::set<bi::address> const& _ifAddresses, unsigned short _listenPort, bi::address& o_upnpifaddr);
/// Resolve "host:port" string as TCP endpoint. Returns unspecified endpoint on failure.
static bi::tcp::endpoint resolveHost(ba::io_service& _ioService, std::string const& _host);
static bi::tcp::endpoint resolveHost(std::string const& _host);
};
}

9
libwebthree/WebThree.h

@ -145,7 +145,7 @@ public:
virtual void addNode(p2p::NodeId const& _node, bi::tcp::endpoint const& _hostEndpoint) override;
/// Add node to connect to.
void addNode(p2p::NodeId const& _node, std::string const& _hostString) { addNode(_node, resolveHost(_hostString)); }
void addNode(p2p::NodeId const& _node, std::string const& _hostString) { addNode(_node, p2p::Network::resolveHost(_hostString)); }
/// Add node to connect to.
void addNode(bi::tcp::endpoint const& _endpoint) { addNode(p2p::NodeId(), _endpoint); }
@ -157,11 +157,8 @@ public:
void requirePeer(p2p::NodeId const& _node, bi::tcp::endpoint const& _endpoint) override;
/// Require connection to peer.
void requirePeer(p2p::NodeId const& _node, std::string const& _hostString) { requirePeer(_node, resolveHost(_hostString)); }
/// Resolve "host[:port]" string as TCP endpoint. Returns unspecified endpoint on failure.
bi::tcp::endpoint resolveHost(std::string const& _host) { return haveNetwork() ? p2p::Host::resolveHost(m_net, _host) : bi::tcp::endpoint(); }
void requirePeer(p2p::NodeId const& _node, std::string const& _hostString) { requirePeer(_node, p2p::Network::resolveHost(_hostString)); }
/// Save peers
dev::bytes saveNetwork() override;

Loading…
Cancel
Save