Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(210)

Side by Side Diff: jingle/notifier/communicator/xmpp_connection_generator.cc

Issue 10309002: Reimplements net::AddressList without struct addrinfo. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added missing NET_EXPORT to *PortOnAddressList. Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "jingle/notifier/communicator/xmpp_connection_generator.h" 13 #include "jingle/notifier/communicator/xmpp_connection_generator.h"
14 14
15 #include <vector> 15 #include <vector>
16 16
17 #include "base/bind.h" 17 #include "base/bind.h"
18 #include "base/callback.h" 18 #include "base/callback.h"
19 #include "base/compiler_specific.h" 19 #include "base/compiler_specific.h"
20 #include "base/logging.h" 20 #include "base/logging.h"
21 #include "base/sys_byteorder.h" 21 #include "base/sys_byteorder.h"
22 #include "jingle/notifier/base/server_information.h" 22 #include "jingle/notifier/base/server_information.h"
23 #include "jingle/notifier/communicator/connection_options.h" 23 #include "jingle/notifier/communicator/connection_options.h"
24 #include "jingle/notifier/communicator/connection_settings.h" 24 #include "jingle/notifier/communicator/connection_settings.h"
25 #include "net/base/net_errors.h" 25 #include "net/base/net_errors.h"
26 #include "net/base/sys_addrinfo.h"
27 #include "talk/base/httpcommon-inl.h" 26 #include "talk/base/httpcommon-inl.h"
28 #include "talk/base/task.h" 27 #include "talk/base/task.h"
29 #include "talk/base/thread.h" 28 #include "talk/base/thread.h"
30 #include "talk/xmpp/prexmppauth.h" 29 #include "talk/xmpp/prexmppauth.h"
31 #include "talk/xmpp/xmppclientsettings.h" 30 #include "talk/xmpp/xmppclientsettings.h"
32 #include "talk/xmpp/xmppengine.h" 31 #include "talk/xmpp/xmppengine.h"
33 32
34 namespace notifier { 33 namespace notifier {
35 34
36 XmppConnectionGenerator::XmppConnectionGenerator( 35 XmppConnectionGenerator::XmppConnectionGenerator(
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 // Print logging info. 148 // Print logging info.
150 VLOG(1) << " server: " << current_server_->server.ToString() 149 VLOG(1) << " server: " << current_server_->server.ToString()
151 << ", error: " << status; 150 << ", error: " << status;
152 if (status != net::OK) { 151 if (status != net::OK) {
153 if (first_dns_error_ == 0) 152 if (first_dns_error_ == 0)
154 first_dns_error_ = status; 153 first_dns_error_ = status;
155 return; 154 return;
156 } 155 }
157 156
158 // Slurp the addresses into a vector. 157 // Slurp the addresses into a vector.
159 std::vector<uint32> ip_list; 158 std::vector<uint32> ip_list; // TODO(szym): not IPv6-safe.
160 for (const addrinfo* addr = address_list_.head(); 159 for (net::AddressList::const_iterator addr = address_list_.begin();
eroman 2012/05/04 01:08:41 Same comment as before. I recommend using an integ
161 addr != NULL; addr = addr->ai_next) { 160 addr != address_list_.end(); ++addr) {
162 const sockaddr_in& sockaddr = 161 DCHECK_EQ(addr->GetFamily(), AF_INET);
163 *reinterpret_cast<const sockaddr_in*>(addr->ai_addr); 162 uint32 ip = talk_base::NetworkToHost32(
164 uint32 ip = talk_base::NetworkToHost32(sockaddr.sin_addr.s_addr); 163 *reinterpret_cast<const uint32*>(&addr->address()[0]));
165 ip_list.push_back(ip); 164 ip_list.push_back(ip);
166 } 165 }
167 successfully_resolved_dns_ = !ip_list.empty(); 166 successfully_resolved_dns_ = !ip_list.empty();
168 167
169 for (int i = 0; i < static_cast<int>(ip_list.size()); ++i) { 168 for (int i = 0; i < static_cast<int>(ip_list.size()); ++i) {
170 VLOG(1) << " ip " << i 169 VLOG(1) << " ip " << i
171 << " : " << talk_base::SocketAddress::IPToString(ip_list[i]); 170 << " : " << talk_base::SocketAddress::IPToString(ip_list[i]);
172 } 171 }
173 172
174 GenerateSettingsForIPList(ip_list); 173 GenerateSettingsForIPList(ip_list);
175 } 174 }
176 175
177 void XmppConnectionGenerator::GenerateSettingsForIPList( 176 void XmppConnectionGenerator::GenerateSettingsForIPList(
178 const std::vector<uint32>& ip_list) { 177 const std::vector<uint32>& ip_list) {
179 // Build the ip list. 178 // Build the ip list.
180 DCHECK(settings_list_.get()); 179 DCHECK(settings_list_.get());
181 settings_index_ = -1; 180 settings_index_ = -1;
182 settings_list_->ClearPermutations(); 181 settings_list_->ClearPermutations();
183 settings_list_->AddPermutations( 182 settings_list_->AddPermutations(
184 current_server_->server.host(), 183 current_server_->server.host(),
185 ip_list, 184 ip_list,
186 current_server_->server.port(), 185 current_server_->server.port(),
187 current_server_->special_port_magic, 186 current_server_->special_port_magic,
188 try_ssltcp_first_); 187 try_ssltcp_first_);
189 } 188 }
190 189
191 } // namespace notifier 190 } // namespace notifier
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698