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

Side by Side Diff: net/spdy/spdy_session_pool.cc

Issue 7349023: Changed SPDY's ip connection pooling logic to only add the used IP, (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 5 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
« no previous file with comments | « net/socket/ssl_client_socket_pool_unittest.cc ('k') | net/spdy/spdy_session_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "net/spdy/spdy_session_pool.h" 5 #include "net/spdy/spdy_session_pool.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "net/base/address_list.h" 10 #include "net/base/address_list.h"
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 if (!list) 143 if (!list)
144 list = AddSessionList(host_port_proxy_pair); 144 list = AddSessionList(host_port_proxy_pair);
145 DCHECK(list->empty()); 145 DCHECK(list->empty());
146 list->push_back(*spdy_session); 146 list->push_back(*spdy_session);
147 147
148 net_log.AddEvent( 148 net_log.AddEvent(
149 NetLog::TYPE_SPDY_SESSION_POOL_IMPORTED_SESSION_FROM_SOCKET, 149 NetLog::TYPE_SPDY_SESSION_POOL_IMPORTED_SESSION_FROM_SOCKET,
150 make_scoped_refptr(new NetLogSourceParameter( 150 make_scoped_refptr(new NetLogSourceParameter(
151 "session", (*spdy_session)->net_log().source()))); 151 "session", (*spdy_session)->net_log().source())));
152 152
153 // We have a new session. Lookup the IP addresses for this session so that
willchan no longer on Chromium 2011/07/14 12:35:39 There should only be a single IP address. You shou
wtc 2011/07/14 17:03:14 I came to the same conclusion after I went home la
willchan no longer on Chromium 2011/07/14 17:10:51 We don't resolve the hostnames here. LookupAddress
154 // we can match future Sessions (potentially to different domains) which can
155 // potentially be pooled with this one.
156 if (g_enable_ip_pooling) {
157 // Get connected address from spdy_session.
158 AddressList addresses;
159 if (connection->socket()->GetPeerAddress(&addresses) == net::OK)
160 AddAliases(addresses, host_port_proxy_pair);
161 }
162
153 // Now we can initialize the session with the SSL socket. 163 // Now we can initialize the session with the SSL socket.
154 return (*spdy_session)->InitializeWithSocket(connection, is_secure, 164 return (*spdy_session)->InitializeWithSocket(connection, is_secure,
155 certificate_error_code); 165 certificate_error_code);
156 } 166 }
157 167
158 bool SpdySessionPool::HasSession( 168 bool SpdySessionPool::HasSession(
159 const HostPortProxyPair& host_port_proxy_pair) const { 169 const HostPortProxyPair& host_port_proxy_pair) const {
160 if (GetSessionList(host_port_proxy_pair)) 170 if (GetSessionList(host_port_proxy_pair))
161 return true; 171 return true;
162 172
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 return *single_domain_pair; 305 return *single_domain_pair;
296 } 306 }
297 307
298 SpdySessionPool::SpdySessionList* 308 SpdySessionPool::SpdySessionList*
299 SpdySessionPool::AddSessionList( 309 SpdySessionPool::AddSessionList(
300 const HostPortProxyPair& host_port_proxy_pair) { 310 const HostPortProxyPair& host_port_proxy_pair) {
301 const HostPortProxyPair& pair = NormalizeListPair(host_port_proxy_pair); 311 const HostPortProxyPair& pair = NormalizeListPair(host_port_proxy_pair);
302 DCHECK(sessions_.find(pair) == sessions_.end()); 312 DCHECK(sessions_.find(pair) == sessions_.end());
303 SpdySessionPool::SpdySessionList* list = new SpdySessionList(); 313 SpdySessionPool::SpdySessionList* list = new SpdySessionList();
304 sessions_[pair] = list; 314 sessions_[pair] = list;
305
306 // We have a new session. Lookup the IP addresses for this session so that
307 // we can match future Sessions (potentially to different domains) which can
308 // potentially be pooled with this one.
309 if (g_enable_ip_pooling) {
310 AddressList addresses;
311 if (LookupAddresses(host_port_proxy_pair, &addresses))
312 AddAliases(addresses, host_port_proxy_pair);
313 }
314
315 return list; 315 return list;
316 } 316 }
317 317
318 SpdySessionPool::SpdySessionList* 318 SpdySessionPool::SpdySessionList*
319 SpdySessionPool::GetSessionList( 319 SpdySessionPool::GetSessionList(
320 const HostPortProxyPair& host_port_proxy_pair) const { 320 const HostPortProxyPair& host_port_proxy_pair) const {
321 const HostPortProxyPair& pair = NormalizeListPair(host_port_proxy_pair); 321 const HostPortProxyPair& pair = NormalizeListPair(host_port_proxy_pair);
322 SpdySessionsMap::const_iterator it = sessions_.find(pair); 322 SpdySessionsMap::const_iterator it = sessions_.find(pair);
323 if (it != sessions_.end()) 323 if (it != sessions_.end())
324 return it->second; 324 return it->second;
(...skipping 21 matching lines...) Expand all
346 addresses, 346 addresses,
347 NULL, 347 NULL,
348 NULL, 348 NULL,
349 net::BoundNetLog()); 349 net::BoundNetLog());
350 DCHECK_NE(ERR_IO_PENDING, rv); 350 DCHECK_NE(ERR_IO_PENDING, rv);
351 return rv == OK; 351 return rv == OK;
352 } 352 }
353 353
354 void SpdySessionPool::AddAliases(const AddressList& addresses, 354 void SpdySessionPool::AddAliases(const AddressList& addresses,
355 const HostPortProxyPair& pair) { 355 const HostPortProxyPair& pair) {
356 // Note: it is possible to think of strange overlapping sets of ip addresses
357 // for hosts such that a new session can override the alias for an IP
358 // address that was previously aliased to a different host. This is probably
359 // undesirable, but seemingly unlikely and complicated to fix.
360 // Example:
361 // host1 = 1.1.1.1, 1.1.1.4
362 // host2 = 1.1.1.4, 1.1.1.5
363 // host3 = 1.1.1.3, 1.1.1.5
364 // Creating session1 (to host1), creates an alias for host2 to host1.
365 // Creating session2 (to host3), overrides the alias for host2 to host3.
366
367 const addrinfo* address = addresses.head(); 356 const addrinfo* address = addresses.head();
368 while (address) { 357 while (address) {
369 IPEndPoint endpoint; 358 IPEndPoint endpoint;
370 endpoint.FromSockAddr(address->ai_addr, address->ai_addrlen); 359 endpoint.FromSockAddr(address->ai_addr, address->ai_addrlen);
371 aliases_[endpoint] = pair; 360 aliases_[endpoint] = pair;
372 address = address->ai_next; 361 address = address->ai_next;
373 } 362 }
374 } 363 }
375 364
376 void SpdySessionPool::RemoveAliases(const HostPortProxyPair& pair) { 365 void SpdySessionPool::RemoveAliases(const HostPortProxyPair& pair) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 delete list; 411 delete list;
423 RemoveAliases(old_map.begin()->first); 412 RemoveAliases(old_map.begin()->first);
424 old_map.erase(old_map.begin()->first); 413 old_map.erase(old_map.begin()->first);
425 } 414 }
426 } 415 }
427 DCHECK(sessions_.empty()); 416 DCHECK(sessions_.empty());
428 DCHECK(aliases_.empty()); 417 DCHECK(aliases_.empty());
429 } 418 }
430 419
431 } // namespace net 420 } // namespace net
OLDNEW
« no previous file with comments | « net/socket/ssl_client_socket_pool_unittest.cc ('k') | net/spdy/spdy_session_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698