Remove proxy IPAddress from ProxyInfo.

GitOrigin-RevId: 1c83e4dc45c3186e887a9922fa77e6b25612c3be
This commit is contained in:
levlam 2019-07-22 05:42:19 +03:00
parent feb2beeec0
commit 92201f904d
3 changed files with 23 additions and 27 deletions

View File

@ -579,9 +579,9 @@ class TestProxyRequest : public RequestOnceActor {
send_closure(actor_id, &TestProxyRequest::on_connection_data, std::move(r_data), std::move(promise)); send_closure(actor_id, &TestProxyRequest::on_connection_data, std::move(r_data), std::move(promise));
}); });
child_ = child_ = ConnectionCreator::prepare_connection(r_socket_fd.move_as_ok(), ConnectionCreator::ProxyInfo{&proxy_},
ConnectionCreator::prepare_connection(r_socket_fd.move_as_ok(), {&proxy_, ip}, get_transport(), "TestPingDC2", get_transport(), "TestPingDC2", std::move(mtproto_ip), nullptr, {},
std::move(mtproto_ip), nullptr, {}, false, std::move(connection_promise)); false, std::move(connection_promise));
} }
void on_connection_data(Result<ConnectionCreator::ConnectionData> r_data, Promise<Unit> &&promise) { void on_connection_data(Result<ConnectionCreator::ConnectionData> r_data, Promise<Unit> &&promise) {

View File

@ -295,7 +295,7 @@ ActorId<GetHostByNameActor> ConnectionCreator::get_dns_resolver() {
void ConnectionCreator::ping_proxy(int32 proxy_id, Promise<double> promise) { void ConnectionCreator::ping_proxy(int32 proxy_id, Promise<double> promise) {
if (proxy_id == 0) { if (proxy_id == 0) {
ProxyInfo proxy{nullptr, IPAddress()}; ProxyInfo proxy{nullptr};
auto main_dc_id = G()->net_query_dispatcher().main_dc_id(); auto main_dc_id = G()->net_query_dispatcher().main_dc_id();
bool prefer_ipv6 = G()->shared_config().get_option_boolean("prefer_ipv6"); bool prefer_ipv6 = G()->shared_config().get_option_boolean("prefer_ipv6");
auto infos = dc_options_set_.find_all_connections(main_dc_id, false, false, prefer_ipv6, false); auto infos = dc_options_set_.find_all_connections(main_dc_id, false, false, prefer_ipv6, false);
@ -314,7 +314,7 @@ void ConnectionCreator::ping_proxy(int32 proxy_id, Promise<double> promise) {
request.result = Status::Error(400, "Failed to ping"); request.result = Status::Error(400, "Failed to ping");
for (auto &info : infos) { for (auto &info : infos) {
auto r_transport_type = get_transport_type(ProxyInfo{nullptr, IPAddress()}, info); auto r_transport_type = get_transport_type(ProxyInfo{nullptr}, info);
if (r_transport_type.is_error()) { if (r_transport_type.is_error()) {
LOG(ERROR) << r_transport_type.error(); LOG(ERROR) << r_transport_type.error();
on_ping_main_dc_result(token, r_transport_type.move_as_error()); on_ping_main_dc_result(token, r_transport_type.move_as_error());
@ -359,10 +359,10 @@ void ConnectionCreator::ping_proxy_resolved(int32 proxy_id, IPAddress ip_address
if (it == proxies_.end()) { if (it == proxies_.end()) {
return promise.set_error(Status::Error(400, "Unknown proxy identifier")); return promise.set_error(Status::Error(400, "Unknown proxy identifier"));
} }
ProxyInfo proxy(&it->second, ip_address); ProxyInfo proxy(&it->second);
auto main_dc_id = G()->net_query_dispatcher().main_dc_id(); auto main_dc_id = G()->net_query_dispatcher().main_dc_id();
FindConnectionExtra extra; FindConnectionExtra extra;
auto r_socket_fd = find_connection(proxy, main_dc_id, false, extra); auto r_socket_fd = find_connection(proxy, ip_address, main_dc_id, false, extra);
if (r_socket_fd.is_error()) { if (r_socket_fd.is_error()) {
return promise.set_error(Status::Error(400, r_socket_fd.error().public_message())); return promise.set_error(Status::Error(400, r_socket_fd.error().public_message()));
} }
@ -638,7 +638,7 @@ void ConnectionCreator::request_raw_connection_by_ip(IPAddress ip_address, mtpro
}); });
auto token = next_token(); auto token = next_token();
auto ref = prepare_connection(std::move(socket_fd), {nullptr, IPAddress()}, transport_type, auto ref = prepare_connection(std::move(socket_fd), ProxyInfo{nullptr}, transport_type,
PSTRING() << "to IP address " << ip_address, IPAddress(), nullptr, PSTRING() << "to IP address " << ip_address, IPAddress(), nullptr,
create_reference(token), false, std::move(connection_promise)); create_reference(token), false, std::move(connection_promise));
if (!ref.empty()) { if (!ref.empty()) {
@ -676,11 +676,11 @@ Result<mtproto::TransportType> ConnectionCreator::get_transport_type(const Proxy
} }
} }
Result<SocketFd> ConnectionCreator::find_connection(const ProxyInfo &proxy, DcId dc_id, bool allow_media_only, Result<SocketFd> ConnectionCreator::find_connection(const ProxyInfo &proxy, const IPAddress &proxy_ip_address,
FindConnectionExtra &extra) { DcId dc_id, bool allow_media_only, FindConnectionExtra &extra) {
extra.debug_str = PSTRING() << "Failed to find valid IP for " << dc_id; extra.debug_str = PSTRING() << "Failed to find valid IP for " << dc_id;
bool prefer_ipv6 = bool prefer_ipv6 =
G()->shared_config().get_option_boolean("prefer_ipv6") || (proxy.use_proxy() && proxy.ip_address().is_ipv6()); G()->shared_config().get_option_boolean("prefer_ipv6") || (proxy.use_proxy() && proxy_ip_address.is_ipv6());
bool only_http = proxy.use_http_caching_proxy(); bool only_http = proxy.use_http_caching_proxy();
TRY_RESULT(info, dc_options_set_.find_connection( TRY_RESULT(info, dc_options_set_.find_connection(
dc_id, allow_media_only, proxy.use_proxy() && proxy.use_socks5_proxy(), prefer_ipv6, only_http)); dc_id, allow_media_only, proxy.use_proxy() && proxy.use_socks5_proxy(), prefer_ipv6, only_http));
@ -692,10 +692,10 @@ Result<SocketFd> ConnectionCreator::find_connection(const ProxyInfo &proxy, DcId
<< (info.use_http ? " over HTTP" : ""); << (info.use_http ? " over HTTP" : "");
if (proxy.use_mtproto_proxy()) { if (proxy.use_mtproto_proxy()) {
extra.debug_str = PSTRING() << "Mtproto " << proxy.ip_address() << extra.debug_str; extra.debug_str = PSTRING() << "Mtproto " << proxy_ip_address << extra.debug_str;
LOG(INFO) << "Create: " << extra.debug_str; LOG(INFO) << "Create: " << extra.debug_str;
return SocketFd::open(proxy.ip_address()); return SocketFd::open(proxy_ip_address);
} }
extra.check_mode |= info.should_check; extra.check_mode |= info.should_check;
@ -703,9 +703,9 @@ Result<SocketFd> ConnectionCreator::find_connection(const ProxyInfo &proxy, DcId
if (proxy.use_proxy()) { if (proxy.use_proxy()) {
extra.mtproto_ip = info.option->get_ip_address(); extra.mtproto_ip = info.option->get_ip_address();
extra.debug_str = PSTRING() << (proxy.use_socks5_proxy() ? "Socks5" : (only_http ? "HTTP_ONLY" : "HTTP_TCP")) << ' ' extra.debug_str = PSTRING() << (proxy.use_socks5_proxy() ? "Socks5" : (only_http ? "HTTP_ONLY" : "HTTP_TCP")) << ' '
<< proxy.ip_address() << " --> " << extra.mtproto_ip << extra.debug_str; << proxy_ip_address << " --> " << extra.mtproto_ip << extra.debug_str;
LOG(INFO) << "Create: " << extra.debug_str; LOG(INFO) << "Create: " << extra.debug_str;
return SocketFd::open(proxy.ip_address()); return SocketFd::open(proxy_ip_address);
} else { } else {
extra.debug_str = PSTRING() << info.option->get_ip_address() << extra.debug_str; extra.debug_str = PSTRING() << info.option->get_ip_address() << extra.debug_str;
LOG(INFO) << "Create: " << extra.debug_str; LOG(INFO) << "Create: " << extra.debug_str;
@ -800,9 +800,9 @@ void ConnectionCreator::client_loop(ClientInfo &client) {
return; return;
} }
ProxyInfo proxy{active_proxy_id_ == 0 ? nullptr : &proxies_[active_proxy_id_], proxy_ip_address_}; ProxyInfo proxy{active_proxy_id_ == 0 ? nullptr : &proxies_[active_proxy_id_]};
if (proxy.use_proxy() && !proxy.ip_address().is_valid()) { if (proxy.use_proxy() && !proxy_ip_address_.is_valid()) {
VLOG(connections) << "Exit client_loop, because there is no valid IP address for proxy: " << proxy.ip_address(); VLOG(connections) << "Exit client_loop, because there is no valid IP address for proxy: " << proxy_ip_address_;
return; return;
} }
@ -870,7 +870,7 @@ void ConnectionCreator::client_loop(ClientInfo &client) {
// Create new RawConnection // Create new RawConnection
// sync part // sync part
FindConnectionExtra extra; FindConnectionExtra extra;
auto r_socket_fd = find_connection(proxy, client.dc_id, client.allow_media_only, extra); auto r_socket_fd = find_connection(proxy, proxy_ip_address_, client.dc_id, client.allow_media_only, extra);
check_mode |= extra.check_mode; check_mode |= extra.check_mode;
if (r_socket_fd.is_error()) { if (r_socket_fd.is_error()) {
LOG(WARNING) << extra.debug_str << ": " << r_socket_fd.error(); LOG(WARNING) << extra.debug_str << ": " << r_socket_fd.error();

View File

@ -91,7 +91,7 @@ class ConnectionCreator : public NetQueryCallback {
}; };
class ProxyInfo { class ProxyInfo {
public: public:
ProxyInfo(Proxy *proxy, IPAddress ip_address) : proxy_(proxy), ip_address_(std::move(ip_address)) { explicit ProxyInfo(const Proxy *proxy) : proxy_(proxy) {
} }
bool use_proxy() const { bool use_proxy() const {
return proxy_ != nullptr; return proxy_ != nullptr;
@ -115,13 +115,9 @@ class ConnectionCreator : public NetQueryCallback {
CHECK(use_proxy()); CHECK(use_proxy());
return *proxy_; return *proxy_;
} }
const IPAddress &ip_address() const {
return ip_address_;
}
private: private:
Proxy *proxy_; const Proxy *proxy_;
IPAddress ip_address_;
}; };
static DcOptions get_default_dc_options(bool is_test); static DcOptions get_default_dc_options(bool is_test);
@ -280,8 +276,8 @@ class ConnectionCreator : public NetQueryCallback {
static Result<mtproto::TransportType> get_transport_type(const ProxyInfo &proxy, static Result<mtproto::TransportType> get_transport_type(const ProxyInfo &proxy,
const DcOptionsSet::ConnectionInfo &info); const DcOptionsSet::ConnectionInfo &info);
Result<SocketFd> find_connection(const ProxyInfo &proxy, DcId dc_id, bool allow_media_only, Result<SocketFd> find_connection(const ProxyInfo &proxy, const IPAddress &proxy_ip_address, DcId dc_id,
FindConnectionExtra &extra); bool allow_media_only, FindConnectionExtra &extra);
ActorId<GetHostByNameActor> get_dns_resolver(); ActorId<GetHostByNameActor> get_dns_resolver();