|
|
@ -17,32 +17,39 @@ namespace libp2p::transport { |
|
|
|
} |
|
|
|
|
|
|
|
auto conn = std::make_shared<TcpConnection>(*context_); |
|
|
|
auto rendpoint = detail::makeEndpoint(address); |
|
|
|
if (!rendpoint) { |
|
|
|
return handler(rendpoint.error()); |
|
|
|
} |
|
|
|
|
|
|
|
conn->resolve(rendpoint.value(), |
|
|
|
[self{shared_from_this()}, conn, handler{std::move(handler)}, |
|
|
|
remoteId](auto ec, auto r) mutable { |
|
|
|
if (ec) { |
|
|
|
return handler(ec); |
|
|
|
} |
|
|
|
|
|
|
|
conn->connect( |
|
|
|
r, |
|
|
|
[self, conn, handler{std::move(handler)}, remoteId]( |
|
|
|
auto ec, auto &e) mutable { |
|
|
|
if (ec) { |
|
|
|
return handler(ec); |
|
|
|
} |
|
|
|
|
|
|
|
auto session = std::make_shared<UpgraderSession>( |
|
|
|
self->upgrader_, std::move(conn), handler); |
|
|
|
|
|
|
|
session->secureOutbound(remoteId); |
|
|
|
}); |
|
|
|
}); |
|
|
|
auto [host, port] = detail::getHostAndTcpPort(address); |
|
|
|
|
|
|
|
auto connect = [self{shared_from_this()}, conn, handler{std::move(handler)}, |
|
|
|
remoteId](auto ec, auto r) mutable { |
|
|
|
if (ec) { |
|
|
|
return handler(ec); |
|
|
|
} |
|
|
|
|
|
|
|
conn->connect(r, |
|
|
|
[self, conn, handler{std::move(handler)}, remoteId]( |
|
|
|
auto ec, auto &e) mutable { |
|
|
|
if (ec) { |
|
|
|
return handler(ec); |
|
|
|
} |
|
|
|
|
|
|
|
auto session = std::make_shared<UpgraderSession>( |
|
|
|
self->upgrader_, std::move(conn), handler); |
|
|
|
|
|
|
|
session->secureOutbound(remoteId); |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
using P = multi::Protocol::Code; |
|
|
|
switch (detail::getFirstProtocol(address)) { |
|
|
|
case P::DNS4: |
|
|
|
return conn->resolve(boost::asio::ip::tcp::v4(), host, port, connect); |
|
|
|
case P::DNS6: |
|
|
|
return conn->resolve(boost::asio::ip::tcp::v6(), host, port, connect); |
|
|
|
default: // Could be only DNS, IP6 or IP4 as canDial already checked for
|
|
|
|
// that in the beginning of the method
|
|
|
|
return conn->resolve(host, port, connect); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
std::shared_ptr<TransportListener> TcpTransport::createListener( |
|
|
|