diff --git a/library/include/larra/client/client.hpp b/library/include/larra/client/client.hpp index 15f9884..e712e0c 100644 --- a/library/include/larra/client/client.hpp +++ b/library/include/larra/client/client.hpp @@ -157,6 +157,15 @@ struct StartTlsRequest { } }; +template +auto ConnectViaProxy(Socket& socket, const NoProxy&, std::string_view host, std::uint16_t port) -> boost::asio::awaitable { + auto executor = co_await boost::asio::this_coro::executor; + boost::asio::ip::tcp::resolver resolver(executor); + auto endpoints = co_await resolver.async_resolve(host, std::to_string(port), boost::asio::use_awaitable); + co_await boost::asio::async_connect(socket, endpoints, boost::asio::use_awaitable); + co_return; +} + template auto ConnectViaProxy(Socket& socket, const HttpProxy& param_proxy, std::string_view host, std::uint16_t port) -> boost::asio::awaitable { @@ -196,7 +205,7 @@ auto ConnectViaProxy(Socket& socket, const HttpProxy& param_proxy, std::string_v } template -auto ConnectViaProxy(Socket& socket, Socks5Proxy& socksProxy, std::string_view address, std::uint16_t port) +auto ConnectViaProxy(Socket& socket, const Socks5Proxy& socksProxy, std::string_view address, std::uint16_t port) -> boost::asio::awaitable { constexpr std::array kSocks5RequestStart = {std::byte{0x05}, std::byte{0x01}, std::byte{0x00}, std::byte{0x03}}; @@ -287,10 +296,12 @@ template auto ConnectToServer(Socket& socket, const ProxyType& proxy, std::string_view host, std::uint16_t port) -> boost::asio::awaitable { auto executor = co_await boost::asio::this_coro::executor; boost::asio::ip::tcp::resolver resolver(executor); - auto endpoints = co_await resolver.async_resolve(proxy.hostname, std::to_string(proxy.port), boost::asio::use_awaitable); - co_await boost::asio::async_connect(socket, endpoints, boost::asio::use_awaitable); + // auto endpoints = co_await resolver.async_resolve(proxy.hostname, std::to_string(proxy.port), boost::asio::use_awaitable); + // co_await boost::asio::async_connect(socket, endpoints, boost::asio::use_awaitable); if constexpr(!std::same_as) { + auto endpoints = co_await resolver.async_resolve(proxy.hostname, std::to_string(proxy.port), boost::asio::use_awaitable); + co_await boost::asio::async_connect(socket, endpoints, boost::asio::use_awaitable); co_await ConnectViaProxy(socket, proxy, host, port); } } @@ -308,12 +319,12 @@ auto ConnectToServer(Socket& socket, const SystemConfiguredProxy& proxy, std::st template auto ConnectWithProxy(Socket& socket, const Proxy& proxy, std::string_view host, std::uint16_t port) -> boost::asio::awaitable { - auto awaitable = std::visit( + co_await std::visit( [&socket, host, port](const auto& proxy_variant) { return ConnectToServer(socket, proxy_variant, host, port); }, proxy); - co_await awaitable; + // co_await awaitable; } inline auto GetAuthData(const PlainUserAccount& account) -> std::string { @@ -459,7 +470,7 @@ struct ClientCreateVisitor { template inline auto operator()(XmlStream stream) -> boost::asio::awaitable, Client>>> { - co_await this->Connect(stream.next_layer(), co_await this->Resolve()); + co_await this->Connect(stream.next_layer()); co_await stream.Send(UserStream{.from = account.Jid(), .to = account.Jid().server, .version = "1.0", .xmlLang = "en"}); SPDLOG_DEBUG("UserStream sended"); @@ -482,7 +493,7 @@ struct ClientCreateVisitor { inline auto operator()(XmlStream> stream) -> boost::asio::awaitable, Client>>> { auto& socket = stream.next_layer(); - co_await this->Connect(socket.next_layer(), co_await this->Resolve()); + co_await this->Connect(socket.next_layer()); co_await stream.Send( UserStream{.from = account.Jid().Username("anonymous"), .to = account.Jid().server, .version = "1.0", .xmlLang = "en"}, socket.next_layer());