| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 |
| 11 // yield connection | 11 // yield connection |
| 12 | 12 |
| 13 #include "chrome/browser/sync/notifier/communicator/xmpp_connection_generator.h" | 13 #include "chrome/browser/sync/notifier/communicator/xmpp_connection_generator.h" |
| 14 | 14 |
| 15 #include <vector> | 15 #include <vector> |
| 16 | 16 |
| 17 #include "base/logging.h" |
| 17 #include "chrome/browser/sync/notifier/base/async_dns_lookup.h" | 18 #include "chrome/browser/sync/notifier/base/async_dns_lookup.h" |
| 18 #include "chrome/browser/sync/notifier/base/signal_thread_task.h" | 19 #include "chrome/browser/sync/notifier/base/signal_thread_task.h" |
| 19 #include "chrome/browser/sync/notifier/communicator/connection_options.h" | 20 #include "chrome/browser/sync/notifier/communicator/connection_options.h" |
| 20 #include "chrome/browser/sync/notifier/communicator/connection_settings.h" | 21 #include "chrome/browser/sync/notifier/communicator/connection_settings.h" |
| 21 #include "chrome/browser/sync/notifier/communicator/product_info.h" | 22 #include "chrome/browser/sync/notifier/communicator/product_info.h" |
| 22 #include "talk/base/autodetectproxy.h" | 23 #include "talk/base/autodetectproxy.h" |
| 23 #include "talk/base/httpcommon.h" | 24 #include "talk/base/httpcommon.h" |
| 24 #include "talk/base/logging.h" | |
| 25 #include "talk/base/task.h" | 25 #include "talk/base/task.h" |
| 26 #include "talk/base/thread.h" | 26 #include "talk/base/thread.h" |
| 27 #include "talk/xmpp/prexmppauth.h" | 27 #include "talk/xmpp/prexmppauth.h" |
| 28 #include "talk/xmpp/xmppclientsettings.h" | 28 #include "talk/xmpp/xmppclientsettings.h" |
| 29 #include "talk/xmpp/xmppengine.h" | 29 #include "talk/xmpp/xmppengine.h" |
| 30 | 30 |
| 31 namespace notifier { | 31 namespace notifier { |
| 32 | 32 |
| 33 XmppConnectionGenerator::XmppConnectionGenerator( | 33 XmppConnectionGenerator::XmppConnectionGenerator( |
| 34 talk_base::Task* parent, | 34 talk_base::Task* parent, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 48 parent_(parent) { | 48 parent_(parent) { |
| 49 assert(parent); | 49 assert(parent); |
| 50 assert(options); | 50 assert(options); |
| 51 assert(server_count_ > 0); | 51 assert(server_count_ > 0); |
| 52 for (int i = 0; i < server_count_; ++i) { | 52 for (int i = 0; i < server_count_; ++i) { |
| 53 server_list_[i] = server_list[i]; | 53 server_list_[i] = server_list[i]; |
| 54 } | 54 } |
| 55 } | 55 } |
| 56 | 56 |
| 57 XmppConnectionGenerator::~XmppConnectionGenerator() { | 57 XmppConnectionGenerator::~XmppConnectionGenerator() { |
| 58 LOG(LS_VERBOSE) << "XmppConnectionGenerator::~XmppConnectionGenerator"; | 58 LOG(INFO) << "XmppConnectionGenerator::~XmppConnectionGenerator"; |
| 59 } | 59 } |
| 60 | 60 |
| 61 const talk_base::ProxyInfo& XmppConnectionGenerator::proxy() const { | 61 const talk_base::ProxyInfo& XmppConnectionGenerator::proxy() const { |
| 62 assert(settings_list_.get()); | 62 assert(settings_list_.get()); |
| 63 if (settings_index_ >= settings_list_->GetCount()) { | 63 if (settings_index_ >= settings_list_->GetCount()) { |
| 64 return settings_list_->proxy(); | 64 return settings_list_->proxy(); |
| 65 } | 65 } |
| 66 | 66 |
| 67 ConnectionSettings* settings = settings_list_->GetSettings(settings_index_); | 67 ConnectionSettings* settings = settings_list_->GetSettings(settings_index_); |
| 68 return settings->proxy(); | 68 return settings->proxy(); |
| 69 } | 69 } |
| 70 | 70 |
| 71 // Starts resolving proxy information. | 71 // Starts resolving proxy information. |
| 72 void XmppConnectionGenerator::StartGenerating() { | 72 void XmppConnectionGenerator::StartGenerating() { |
| 73 LOG(LS_VERBOSE) << "XmppConnectionGenerator::StartGenerating"; | 73 LOG(INFO) << "XmppConnectionGenerator::StartGenerating"; |
| 74 | 74 |
| 75 talk_base::AutoDetectProxy* proxy_detect = | 75 talk_base::AutoDetectProxy* proxy_detect = |
| 76 new talk_base::AutoDetectProxy(GetUserAgentString()); | 76 new talk_base::AutoDetectProxy(GetUserAgentString()); |
| 77 | 77 |
| 78 if (options_->autodetect_proxy()) { | 78 if (options_->autodetect_proxy()) { |
| 79 // Pretend the xmpp server is https, when detecting whether a proxy is | 79 // Pretend the xmpp server is https, when detecting whether a proxy is |
| 80 // required to connect. | 80 // required to connect. |
| 81 talk_base::Url<char> host_url("/", | 81 talk_base::Url<char> host_url("/", |
| 82 server_list_[0].server.IPAsString().c_str(), | 82 server_list_[0].server.IPAsString().c_str(), |
| 83 server_list_[0].server.port()); | 83 server_list_[0].server.port()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 95 SignalThreadTask<talk_base::AutoDetectProxy>* wrapper_task = | 95 SignalThreadTask<talk_base::AutoDetectProxy>* wrapper_task = |
| 96 new SignalThreadTask<talk_base::AutoDetectProxy>(parent_, &proxy_detect); | 96 new SignalThreadTask<talk_base::AutoDetectProxy>(parent_, &proxy_detect); |
| 97 wrapper_task->SignalWorkDone.connect( | 97 wrapper_task->SignalWorkDone.connect( |
| 98 this, | 98 this, |
| 99 &XmppConnectionGenerator::OnProxyDetect); | 99 &XmppConnectionGenerator::OnProxyDetect); |
| 100 wrapper_task->Start(); | 100 wrapper_task->Start(); |
| 101 } | 101 } |
| 102 | 102 |
| 103 void XmppConnectionGenerator::OnProxyDetect( | 103 void XmppConnectionGenerator::OnProxyDetect( |
| 104 talk_base::AutoDetectProxy* proxy_detect) { | 104 talk_base::AutoDetectProxy* proxy_detect) { |
| 105 LOG(LS_VERBOSE) << "XmppConnectionGenerator::OnProxyDetect"; | 105 LOG(INFO) << "XmppConnectionGenerator::OnProxyDetect"; |
| 106 | 106 |
| 107 ASSERT(settings_list_.get()); | 107 ASSERT(settings_list_.get()); |
| 108 ASSERT(proxy_detect); | 108 ASSERT(proxy_detect); |
| 109 settings_list_->SetProxy(proxy_detect->proxy()); | 109 settings_list_->SetProxy(proxy_detect->proxy()); |
| 110 | 110 |
| 111 // Start iterating through the connections (which are generated on demand). | 111 // Start iterating through the connections (which are generated on demand). |
| 112 UseNextConnection(); | 112 UseNextConnection(); |
| 113 } | 113 } |
| 114 | 114 |
| 115 void XmppConnectionGenerator::UseNextConnection() { | 115 void XmppConnectionGenerator::UseNextConnection() { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 137 wrapper_task->Start(); | 137 wrapper_task->Start(); |
| 138 return; | 138 return; |
| 139 } | 139 } |
| 140 | 140 |
| 141 // All out of possibilities. | 141 // All out of possibilities. |
| 142 HandleExhaustedConnections(); | 142 HandleExhaustedConnections(); |
| 143 } | 143 } |
| 144 | 144 |
| 145 void XmppConnectionGenerator::OnServerDNSResolved( | 145 void XmppConnectionGenerator::OnServerDNSResolved( |
| 146 AsyncDNSLookup* dns_lookup) { | 146 AsyncDNSLookup* dns_lookup) { |
| 147 LOG(LS_VERBOSE) << "XmppConnectionGenerator::OnServerDNSResolved"; | 147 LOG(INFO) << "XmppConnectionGenerator::OnServerDNSResolved"; |
| 148 | 148 |
| 149 // Print logging info. | 149 // Print logging info. |
| 150 LOG(LS_VERBOSE) << " server: " << | 150 LOG(INFO) << " server: " << |
| 151 server_list_[server_index_].server.ToString() << | 151 server_list_[server_index_].server.ToString() << |
| 152 " error: " << dns_lookup->error(); | 152 " error: " << dns_lookup->error(); |
| 153 if (first_dns_error_ == 0 && dns_lookup->error() != 0) { | 153 if (first_dns_error_ == 0 && dns_lookup->error() != 0) { |
| 154 first_dns_error_ = dns_lookup->error(); | 154 first_dns_error_ = dns_lookup->error(); |
| 155 } | 155 } |
| 156 | 156 |
| 157 if (!successfully_resolved_dns_ && dns_lookup->ip_list().size() > 0) { | 157 if (!successfully_resolved_dns_ && dns_lookup->ip_list().size() > 0) { |
| 158 successfully_resolved_dns_ = true; | 158 successfully_resolved_dns_ = true; |
| 159 } | 159 } |
| 160 | 160 |
| 161 for (int i = 0; i < static_cast<int>(dns_lookup->ip_list().size()); ++i) { | 161 for (int i = 0; i < static_cast<int>(dns_lookup->ip_list().size()); ++i) { |
| 162 LOG(LS_VERBOSE) | 162 LOG(INFO) |
| 163 << " ip " << i << " : " | 163 << " ip " << i << " : " |
| 164 << talk_base::SocketAddress::IPToString(dns_lookup->ip_list()[i]); | 164 << talk_base::SocketAddress::IPToString(dns_lookup->ip_list()[i]); |
| 165 } | 165 } |
| 166 | 166 |
| 167 // Build the ip list. | 167 // Build the ip list. |
| 168 assert(settings_list_.get()); | 168 assert(settings_list_.get()); |
| 169 settings_index_ = -1; | 169 settings_index_ = -1; |
| 170 settings_list_->ClearPermutations(); | 170 settings_list_->ClearPermutations(); |
| 171 settings_list_->AddPermutations( | 171 settings_list_->AddPermutations( |
| 172 server_list_[server_index_].server.IPAsString(), | 172 server_list_[server_index_].server.IPAsString(), |
| 173 dns_lookup->ip_list(), | 173 dns_lookup->ip_list(), |
| 174 server_list_[server_index_].server.port(), | 174 server_list_[server_index_].server.port(), |
| 175 server_list_[server_index_].special_port_magic, | 175 server_list_[server_index_].special_port_magic, |
| 176 proxy_only_); | 176 proxy_only_); |
| 177 | 177 |
| 178 UseNextConnection(); | 178 UseNextConnection(); |
| 179 } | 179 } |
| 180 | 180 |
| 181 static const char* const PROTO_NAMES[cricket::PROTO_LAST + 1] = { | 181 static const char* const PROTO_NAMES[cricket::PROTO_LAST + 1] = { |
| 182 "udp", "tcp", "ssltcp" | 182 "udp", "tcp", "ssltcp" |
| 183 }; | 183 }; |
| 184 | 184 |
| 185 static const char* ProtocolToString(cricket::ProtocolType proto) { | 185 static const char* ProtocolToString(cricket::ProtocolType proto) { |
| 186 return PROTO_NAMES[proto]; | 186 return PROTO_NAMES[proto]; |
| 187 } | 187 } |
| 188 | 188 |
| 189 void XmppConnectionGenerator::UseCurrentConnection() { | 189 void XmppConnectionGenerator::UseCurrentConnection() { |
| 190 LOG(LS_VERBOSE) << "XmppConnectionGenerator::UseCurrentConnection"; | 190 LOG(INFO) << "XmppConnectionGenerator::UseCurrentConnection"; |
| 191 | 191 |
| 192 ConnectionSettings* settings = settings_list_->GetSettings(settings_index_); | 192 ConnectionSettings* settings = settings_list_->GetSettings(settings_index_); |
| 193 LOG(LS_INFO) << "*** Attempting " | 193 LOG(INFO) << "*** Attempting " |
| 194 << ProtocolToString(settings->protocol()) << " connection to " | 194 << ProtocolToString(settings->protocol()) << " connection to " |
| 195 << settings->server().IPAsString() << ":" | 195 << settings->server().IPAsString() << ":" |
| 196 << settings->server().port() | 196 << settings->server().port() |
| 197 << " (via " << ProxyToString(settings->proxy().type) | 197 << " (via " << ProxyToString(settings->proxy().type) |
| 198 << " proxy @ " << settings->proxy().address.IPAsString() << ":" | 198 << " proxy @ " << settings->proxy().address.IPAsString() << ":" |
| 199 << settings->proxy().address.port() << ")"; | 199 << settings->proxy().address.port() << ")"; |
| 200 | 200 |
| 201 SignalNewSettings(*settings); | 201 SignalNewSettings(*settings); |
| 202 } | 202 } |
| 203 | 203 |
| 204 void XmppConnectionGenerator::HandleExhaustedConnections() { | 204 void XmppConnectionGenerator::HandleExhaustedConnections() { |
| 205 LOG_F(LS_VERBOSE) << "(" << buzz::XmppEngine::ERROR_SOCKET | 205 LOG(INFO) << "(" << buzz::XmppEngine::ERROR_SOCKET |
| 206 << ", " << first_dns_error_ << ")"; | 206 << ", " << first_dns_error_ << ")"; |
| 207 SignalExhaustedSettings(successfully_resolved_dns_, first_dns_error_); | 207 SignalExhaustedSettings(successfully_resolved_dns_, first_dns_error_); |
| 208 } | 208 } |
| 209 | 209 |
| 210 } // namespace notifier | 210 } // namespace notifier |
| OLD | NEW |