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

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
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 address for this session so that we
154 // can match future Sessions (potentially to different domains) which can
155 // potentially be pooled with this one. Because GetPeerAddress() reports the
156 // proxy's address instead of the origin server, added the check to see if
wtc 2011/07/19 00:11:19 Nit: added the check to see => check
ramant (doing other things) 2011/07/19 03:48:47 Done.
157 // this is a direct connection.
158 if (g_enable_ip_pooling && host_port_proxy_pair.second.is_direct()) {
159 AddressList addresses;
160 if (connection->socket()->GetPeerAddress(&addresses) == net::OK) {
wtc 2011/07/19 00:11:19 Remove "net::" because this is in the net namespac
ramant (doing other things) 2011/07/19 03:48:47 Done.
161 const addrinfo* address = addresses.head();
162 DCHECK(address);
163 IPEndPoint endpoint;
164 endpoint.FromSockAddr(address->ai_addr, address->ai_addrlen);
165 AddAlias(endpoint, host_port_proxy_pair);
166 }
167 }
168
153 // Now we can initialize the session with the SSL socket. 169 // Now we can initialize the session with the SSL socket.
154 return (*spdy_session)->InitializeWithSocket(connection, is_secure, 170 return (*spdy_session)->InitializeWithSocket(connection, is_secure,
155 certificate_error_code); 171 certificate_error_code);
156 } 172 }
157 173
158 bool SpdySessionPool::HasSession( 174 bool SpdySessionPool::HasSession(
159 const HostPortProxyPair& host_port_proxy_pair) const { 175 const HostPortProxyPair& host_port_proxy_pair) const {
160 if (GetSessionList(host_port_proxy_pair)) 176 if (GetSessionList(host_port_proxy_pair))
161 return true; 177 return true;
162 178
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 return *single_domain_pair; 311 return *single_domain_pair;
296 } 312 }
297 313
298 SpdySessionPool::SpdySessionList* 314 SpdySessionPool::SpdySessionList*
299 SpdySessionPool::AddSessionList( 315 SpdySessionPool::AddSessionList(
300 const HostPortProxyPair& host_port_proxy_pair) { 316 const HostPortProxyPair& host_port_proxy_pair) {
301 const HostPortProxyPair& pair = NormalizeListPair(host_port_proxy_pair); 317 const HostPortProxyPair& pair = NormalizeListPair(host_port_proxy_pair);
302 DCHECK(sessions_.find(pair) == sessions_.end()); 318 DCHECK(sessions_.find(pair) == sessions_.end());
303 SpdySessionPool::SpdySessionList* list = new SpdySessionList(); 319 SpdySessionPool::SpdySessionList* list = new SpdySessionList();
304 sessions_[pair] = list; 320 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; 321 return list;
316 } 322 }
317 323
318 SpdySessionPool::SpdySessionList* 324 SpdySessionPool::SpdySessionList*
319 SpdySessionPool::GetSessionList( 325 SpdySessionPool::GetSessionList(
320 const HostPortProxyPair& host_port_proxy_pair) const { 326 const HostPortProxyPair& host_port_proxy_pair) const {
321 const HostPortProxyPair& pair = NormalizeListPair(host_port_proxy_pair); 327 const HostPortProxyPair& pair = NormalizeListPair(host_port_proxy_pair);
322 SpdySessionsMap::const_iterator it = sessions_.find(pair); 328 SpdySessionsMap::const_iterator it = sessions_.find(pair);
323 if (it != sessions_.end()) 329 if (it != sessions_.end())
324 return it->second; 330 return it->second;
(...skipping 19 matching lines...) Expand all
344 resolve_info.set_only_use_cached_response(true); 350 resolve_info.set_only_use_cached_response(true);
345 int rv = resolver_->Resolve(resolve_info, 351 int rv = resolver_->Resolve(resolve_info,
346 addresses, 352 addresses,
347 NULL, 353 NULL,
348 NULL, 354 NULL,
349 net::BoundNetLog()); 355 net::BoundNetLog());
350 DCHECK_NE(ERR_IO_PENDING, rv); 356 DCHECK_NE(ERR_IO_PENDING, rv);
351 return rv == OK; 357 return rv == OK;
352 } 358 }
353 359
354 void SpdySessionPool::AddAliases(const AddressList& addresses, 360 void SpdySessionPool::AddAlias(const IPEndPoint& endpoint,
355 const HostPortProxyPair& pair) { 361 const HostPortProxyPair& pair) {
356 // Note: it is possible to think of strange overlapping sets of ip addresses 362 DCHECK(g_enable_ip_pooling);
357 // for hosts such that a new session can override the alias for an IP 363 aliases_[endpoint] = pair;
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();
368 while (address) {
369 IPEndPoint endpoint;
370 endpoint.FromSockAddr(address->ai_addr, address->ai_addrlen);
371 aliases_[endpoint] = pair;
372 address = address->ai_next;
373 }
374 } 364 }
375 365
376 void SpdySessionPool::RemoveAliases(const HostPortProxyPair& pair) { 366 void SpdySessionPool::RemoveAliases(const HostPortProxyPair& pair) {
377 // Walk the aliases map, find references to this pair. 367 // Walk the aliases map, find references to this pair.
378 // TODO(mbelshe): Figure out if this is too expensive. 368 // TODO(mbelshe): Figure out if this is too expensive.
379 SpdyAliasMap::iterator alias_it = aliases_.begin(); 369 SpdyAliasMap::iterator alias_it = aliases_.begin();
380 while (alias_it != aliases_.end()) { 370 while (alias_it != aliases_.end()) {
381 if (HostPortProxyPairsAreEqual(alias_it->second, pair)) { 371 if (HostPortProxyPairsAreEqual(alias_it->second, pair)) {
382 aliases_.erase(alias_it); 372 aliases_.erase(alias_it);
383 alias_it = aliases_.begin(); // Iterator was invalidated. 373 alias_it = aliases_.begin(); // Iterator was invalidated.
(...skipping 38 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

Powered by Google App Engine
This is Rietveld 408576698