| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 // | 4 // |
| 5 // XmppConnectionGenerator does the following algorithm: | 5 // XmppConnectionGenerator does the following algorithm: |
| 6 // proxy = ResolveProxyInformation(connection_options) | 6 // proxy = ResolveProxyInformation(connection_options) |
| 7 // for server in server_list | 7 // for server in server_list |
| 8 // get dns_addresses for server | 8 // get dns_addresses for server |
| 9 // connection_list = (dns_addresses X connection methods X proxy).shuffle() | 9 // connection_list = (dns_addresses X connection methods X proxy).shuffle() |
| 10 // for connection in connection_list | 10 // for connection in connection_list |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 ALLOW_THIS_IN_INITIALIZER_LIST( | 49 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 50 NewCallback(this, | 50 NewCallback(this, |
| 51 &XmppConnectionGenerator::OnServerDNSResolved))), | 51 &XmppConnectionGenerator::OnServerDNSResolved))), |
| 52 settings_list_(new ConnectionSettingsList()), | 52 settings_list_(new ConnectionSettingsList()), |
| 53 settings_index_(0), | 53 settings_index_(0), |
| 54 servers_(servers), | 54 servers_(servers), |
| 55 current_server_(servers_.end()), | 55 current_server_(servers_.end()), |
| 56 try_ssltcp_first_(try_ssltcp_first), | 56 try_ssltcp_first_(try_ssltcp_first), |
| 57 successfully_resolved_dns_(false), | 57 successfully_resolved_dns_(false), |
| 58 first_dns_error_(0), | 58 first_dns_error_(0), |
| 59 should_resolve_dns_(true), |
| 59 options_(options) { | 60 options_(options) { |
| 60 DCHECK(delegate_); | 61 DCHECK(delegate_); |
| 61 DCHECK(host_resolver); | 62 DCHECK(host_resolver); |
| 62 DCHECK(options_); | 63 DCHECK(options_); |
| 63 DCHECK_GT(servers_.size(), 0u); | 64 DCHECK_GT(servers_.size(), 0u); |
| 64 } | 65 } |
| 65 | 66 |
| 66 XmppConnectionGenerator::~XmppConnectionGenerator() { | 67 XmppConnectionGenerator::~XmppConnectionGenerator() { |
| 67 VLOG(1) << "XmppConnectionGenerator::~XmppConnectionGenerator"; | 68 VLOG(1) << "XmppConnectionGenerator::~XmppConnectionGenerator"; |
| 68 } | 69 } |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 } | 113 } |
| 113 if (current_server_ == servers_.end()) { | 114 if (current_server_ == servers_.end()) { |
| 114 // All out of possibilities. | 115 // All out of possibilities. |
| 115 VLOG(1) << "(" << buzz::XmppEngine::ERROR_SOCKET | 116 VLOG(1) << "(" << buzz::XmppEngine::ERROR_SOCKET |
| 116 << ", " << first_dns_error_ << ")"; | 117 << ", " << first_dns_error_ << ")"; |
| 117 delegate_->OnExhaustedSettings( | 118 delegate_->OnExhaustedSettings( |
| 118 successfully_resolved_dns_, first_dns_error_); | 119 successfully_resolved_dns_, first_dns_error_); |
| 119 return; | 120 return; |
| 120 } | 121 } |
| 121 | 122 |
| 122 // Resolve the server. | 123 if (should_resolve_dns_) { |
| 123 const net::HostPortPair& server = current_server_->server; | 124 // Resolve the server. |
| 124 net::HostResolver::RequestInfo request_info(server); | 125 const net::HostPortPair& server = current_server_->server; |
| 125 int status = | 126 net::HostResolver::RequestInfo request_info(server); |
| 126 host_resolver_.Resolve( | 127 int status = |
| 127 request_info, &address_list_, resolve_callback_.get(), | 128 host_resolver_.Resolve( |
| 128 bound_net_log_); | 129 request_info, &address_list_, resolve_callback_.get(), |
| 129 if (status == net::ERR_IO_PENDING) { | 130 bound_net_log_); |
| 130 // resolve_callback_ will call us when it's called. | 131 if (status == net::ERR_IO_PENDING) { |
| 131 return; | 132 // resolve_callback_ will call us when it's called. |
| 133 return; |
| 134 } |
| 135 HandleServerDNSResolved(status); |
| 136 } else { |
| 137 // We are not resolving DNS here (DNS will be resolved by a lower layer). |
| 138 // Generate settings using an empty IP list (which will just use the |
| 139 // host name for the current server). |
| 140 std::vector<uint32> ip_list; |
| 141 GenerateSettingsForIPList(ip_list); |
| 132 } | 142 } |
| 133 HandleServerDNSResolved(status); | |
| 134 } | 143 } |
| 135 } | 144 } |
| 136 | 145 |
| 137 void XmppConnectionGenerator::OnServerDNSResolved(int status) { | 146 void XmppConnectionGenerator::OnServerDNSResolved(int status) { |
| 138 DCHECK_NE(status, net::ERR_IO_PENDING); | 147 DCHECK_NE(status, net::ERR_IO_PENDING); |
| 139 HandleServerDNSResolved(status); | 148 HandleServerDNSResolved(status); |
| 140 // Reenter loop. | 149 // Reenter loop. |
| 141 UseNextConnection(); | 150 UseNextConnection(); |
| 142 } | 151 } |
| 143 | 152 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 162 uint32 ip = ntohl(sockaddr.sin_addr.s_addr); | 171 uint32 ip = ntohl(sockaddr.sin_addr.s_addr); |
| 163 ip_list.push_back(ip); | 172 ip_list.push_back(ip); |
| 164 } | 173 } |
| 165 successfully_resolved_dns_ = !ip_list.empty(); | 174 successfully_resolved_dns_ = !ip_list.empty(); |
| 166 | 175 |
| 167 for (int i = 0; i < static_cast<int>(ip_list.size()); ++i) { | 176 for (int i = 0; i < static_cast<int>(ip_list.size()); ++i) { |
| 168 VLOG(1) << " ip " << i | 177 VLOG(1) << " ip " << i |
| 169 << " : " << talk_base::SocketAddress::IPToString(ip_list[i]); | 178 << " : " << talk_base::SocketAddress::IPToString(ip_list[i]); |
| 170 } | 179 } |
| 171 | 180 |
| 181 GenerateSettingsForIPList(ip_list); |
| 182 } |
| 183 |
| 184 void XmppConnectionGenerator::GenerateSettingsForIPList( |
| 185 const std::vector<uint32>& ip_list) { |
| 172 // Build the ip list. | 186 // Build the ip list. |
| 173 DCHECK(settings_list_.get()); | 187 DCHECK(settings_list_.get()); |
| 174 settings_index_ = -1; | 188 settings_index_ = -1; |
| 175 settings_list_->ClearPermutations(); | 189 settings_list_->ClearPermutations(); |
| 176 settings_list_->AddPermutations( | 190 settings_list_->AddPermutations( |
| 177 current_server_->server.host(), | 191 current_server_->server.host(), |
| 178 ip_list, | 192 ip_list, |
| 179 current_server_->server.port(), | 193 current_server_->server.port(), |
| 180 current_server_->special_port_magic, | 194 current_server_->special_port_magic, |
| 181 try_ssltcp_first_); | 195 try_ssltcp_first_); |
| 182 } | 196 } |
| 183 | 197 |
| 184 } // namespace notifier | 198 } // namespace notifier |
| OLD | NEW |