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

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 | « no previous file | no next file » | 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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 // Now we can initialize the session with the SSL socket. 153 // Now we can initialize the session with the SSL socket.
154 return (*spdy_session)->InitializeWithSocket(connection, is_secure, 154 net::Error error =
155 certificate_error_code); 155 (*spdy_session)->InitializeWithSocket(connection, is_secure,
156 certificate_error_code);
157 // We have a new session. Lookup the IP addresses for this session so that
158 // we can match future Sessions (potentially to different domains) which can
159 // potentially be pooled with this one.
160 if (error == net::OK && g_enable_ip_pooling) {
161 // Get connected address from spdy_session.
162 AddressList addresses;
163 if ((*spdy_session)->GetPeerAddress(&addresses) == net::OK)
164 AddAliases(addresses, host_port_proxy_pair);
165 }
166 return error;
wtc 2011/07/14 02:30:40 Testing error == net::OK is too strict. (*spdy_ses
156 } 167 }
157 168
158 bool SpdySessionPool::HasSession( 169 bool SpdySessionPool::HasSession(
159 const HostPortProxyPair& host_port_proxy_pair) const { 170 const HostPortProxyPair& host_port_proxy_pair) const {
160 if (GetSessionList(host_port_proxy_pair)) 171 if (GetSessionList(host_port_proxy_pair))
161 return true; 172 return true;
162 173
163 // Check if we have a session via an alias. 174 // Check if we have a session via an alias.
164 scoped_refptr<SpdySession> spdy_session = 175 scoped_refptr<SpdySession> spdy_session =
165 GetFromAlias(host_port_proxy_pair, BoundNetLog(), false); 176 GetFromAlias(host_port_proxy_pair, BoundNetLog(), false);
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 return *single_domain_pair; 306 return *single_domain_pair;
296 } 307 }
297 308
298 SpdySessionPool::SpdySessionList* 309 SpdySessionPool::SpdySessionList*
299 SpdySessionPool::AddSessionList( 310 SpdySessionPool::AddSessionList(
300 const HostPortProxyPair& host_port_proxy_pair) { 311 const HostPortProxyPair& host_port_proxy_pair) {
301 const HostPortProxyPair& pair = NormalizeListPair(host_port_proxy_pair); 312 const HostPortProxyPair& pair = NormalizeListPair(host_port_proxy_pair);
302 DCHECK(sessions_.find(pair) == sessions_.end()); 313 DCHECK(sessions_.find(pair) == sessions_.end());
303 SpdySessionPool::SpdySessionList* list = new SpdySessionList(); 314 SpdySessionPool::SpdySessionList* list = new SpdySessionList();
304 sessions_[pair] = list; 315 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; 316 return list;
316 } 317 }
317 318
318 SpdySessionPool::SpdySessionList* 319 SpdySessionPool::SpdySessionList*
319 SpdySessionPool::GetSessionList( 320 SpdySessionPool::GetSessionList(
320 const HostPortProxyPair& host_port_proxy_pair) const { 321 const HostPortProxyPair& host_port_proxy_pair) const {
321 const HostPortProxyPair& pair = NormalizeListPair(host_port_proxy_pair); 322 const HostPortProxyPair& pair = NormalizeListPair(host_port_proxy_pair);
322 SpdySessionsMap::const_iterator it = sessions_.find(pair); 323 SpdySessionsMap::const_iterator it = sessions_.find(pair);
323 if (it != sessions_.end()) 324 if (it != sessions_.end())
324 return it->second; 325 return it->second;
(...skipping 21 matching lines...) Expand all
346 addresses, 347 addresses,
347 NULL, 348 NULL,
348 NULL, 349 NULL,
349 net::BoundNetLog()); 350 net::BoundNetLog());
350 DCHECK_NE(ERR_IO_PENDING, rv); 351 DCHECK_NE(ERR_IO_PENDING, rv);
351 return rv == OK; 352 return rv == OK;
352 } 353 }
353 354
354 void SpdySessionPool::AddAliases(const AddressList& addresses, 355 void SpdySessionPool::AddAliases(const AddressList& addresses,
355 const HostPortProxyPair& pair) { 356 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(); 357 const addrinfo* address = addresses.head();
368 while (address) { 358 while (address) {
369 IPEndPoint endpoint; 359 IPEndPoint endpoint;
370 endpoint.FromSockAddr(address->ai_addr, address->ai_addrlen); 360 endpoint.FromSockAddr(address->ai_addr, address->ai_addrlen);
371 aliases_[endpoint] = pair; 361 aliases_[endpoint] = pair;
372 address = address->ai_next; 362 address = address->ai_next;
373 } 363 }
374 } 364 }
375 365
376 void SpdySessionPool::RemoveAliases(const HostPortProxyPair& pair) { 366 void SpdySessionPool::RemoveAliases(const HostPortProxyPair& pair) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 delete list; 412 delete list;
423 RemoveAliases(old_map.begin()->first); 413 RemoveAliases(old_map.begin()->first);
424 old_map.erase(old_map.begin()->first); 414 old_map.erase(old_map.begin()->first);
425 } 415 }
426 } 416 }
427 DCHECK(sessions_.empty()); 417 DCHECK(sessions_.empty());
428 DCHECK(aliases_.empty()); 418 DCHECK(aliases_.empty());
429 } 419 }
430 420
431 } // namespace net 421 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698