| OLD | NEW |
| 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 #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" |
| 11 #include "net/base/sys_addrinfo.h" | |
| 12 #include "net/http/http_network_session.h" | 11 #include "net/http/http_network_session.h" |
| 13 #include "net/http/http_server_properties.h" | 12 #include "net/http/http_server_properties.h" |
| 14 #include "net/spdy/spdy_session.h" | 13 #include "net/spdy/spdy_session.h" |
| 15 | 14 |
| 16 | 15 |
| 17 namespace net { | 16 namespace net { |
| 18 | 17 |
| 19 namespace { | 18 namespace { |
| 20 | 19 |
| 21 enum SpdySessionGetTypes { | 20 enum SpdySessionGetTypes { |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 "source_dependency", (*spdy_session)->net_log().source()))); | 165 "source_dependency", (*spdy_session)->net_log().source()))); |
| 167 | 166 |
| 168 // We have a new session. Lookup the IP address for this session so that we | 167 // We have a new session. Lookup the IP address for this session so that we |
| 169 // can match future Sessions (potentially to different domains) which can | 168 // can match future Sessions (potentially to different domains) which can |
| 170 // potentially be pooled with this one. Because GetPeerAddress() reports the | 169 // potentially be pooled with this one. Because GetPeerAddress() reports the |
| 171 // proxy's address instead of the origin server, check to see if this is a | 170 // proxy's address instead of the origin server, check to see if this is a |
| 172 // direct connection. | 171 // direct connection. |
| 173 if (g_enable_ip_pooling && host_port_proxy_pair.second.is_direct()) { | 172 if (g_enable_ip_pooling && host_port_proxy_pair.second.is_direct()) { |
| 174 AddressList addresses; | 173 AddressList addresses; |
| 175 if (connection->socket()->GetPeerAddress(&addresses) == OK) | 174 if (connection->socket()->GetPeerAddress(&addresses) == OK) |
| 176 AddAlias(addresses.head(), host_port_proxy_pair); | 175 AddAlias(addresses.front(), host_port_proxy_pair); |
| 177 } | 176 } |
| 178 | 177 |
| 179 // Now we can initialize the session with the SSL socket. | 178 // Now we can initialize the session with the SSL socket. |
| 180 return (*spdy_session)->InitializeWithSocket(connection, is_secure, | 179 return (*spdy_session)->InitializeWithSocket(connection, is_secure, |
| 181 certificate_error_code); | 180 certificate_error_code); |
| 182 } | 181 } |
| 183 | 182 |
| 184 bool SpdySessionPool::HasSession( | 183 bool SpdySessionPool::HasSession( |
| 185 const HostPortProxyPair& host_port_proxy_pair) const { | 184 const HostPortProxyPair& host_port_proxy_pair) const { |
| 186 if (GetSessionList(host_port_proxy_pair)) | 185 if (GetSessionList(host_port_proxy_pair)) |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 bool record_histograms) const { | 267 bool record_histograms) const { |
| 269 // We should only be checking aliases when there is no direct session. | 268 // We should only be checking aliases when there is no direct session. |
| 270 DCHECK(!GetSessionList(host_port_proxy_pair)); | 269 DCHECK(!GetSessionList(host_port_proxy_pair)); |
| 271 | 270 |
| 272 if (!g_enable_ip_pooling) | 271 if (!g_enable_ip_pooling) |
| 273 return NULL; | 272 return NULL; |
| 274 | 273 |
| 275 AddressList addresses; | 274 AddressList addresses; |
| 276 if (!LookupAddresses(host_port_proxy_pair, net_log, &addresses)) | 275 if (!LookupAddresses(host_port_proxy_pair, net_log, &addresses)) |
| 277 return NULL; | 276 return NULL; |
| 278 const addrinfo* address = addresses.head(); | 277 for (AddressList::const_iterator iter = addresses.begin(); |
| 279 while (address) { | 278 iter != addresses.end(); |
| 280 IPEndPoint endpoint; | 279 ++iter) { |
| 281 endpoint.FromSockAddr(address->ai_addr, address->ai_addrlen); | 280 SpdyAliasMap::const_iterator alias_iter = aliases_.find(*iter); |
| 282 address = address->ai_next; | 281 if (alias_iter == aliases_.end()) |
| 283 | |
| 284 SpdyAliasMap::const_iterator it = aliases_.find(endpoint); | |
| 285 if (it == aliases_.end()) | |
| 286 continue; | 282 continue; |
| 287 | 283 |
| 288 // We found an alias. | 284 // We found an alias. |
| 289 const HostPortProxyPair& alias_pair = it->second; | 285 const HostPortProxyPair& alias_pair = alias_iter->second; |
| 290 | 286 |
| 291 // If the proxy settings match, we can reuse this session. | 287 // If the proxy settings match, we can reuse this session. |
| 292 if (!(alias_pair.second == host_port_proxy_pair.second)) | 288 if (!(alias_pair.second == host_port_proxy_pair.second)) |
| 293 continue; | 289 continue; |
| 294 | 290 |
| 295 SpdySessionList* list = GetSessionList(alias_pair); | 291 SpdySessionList* list = GetSessionList(alias_pair); |
| 296 if (!list) { | 292 if (!list) { |
| 297 NOTREACHED(); // It shouldn't be in the aliases table if we can't get it! | 293 NOTREACHED(); // It shouldn't be in the aliases table if we can't get it! |
| 298 continue; | 294 continue; |
| 299 } | 295 } |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 | 371 |
| 376 bool SpdySessionPool::LookupAddresses(const HostPortProxyPair& pair, | 372 bool SpdySessionPool::LookupAddresses(const HostPortProxyPair& pair, |
| 377 const BoundNetLog& net_log, | 373 const BoundNetLog& net_log, |
| 378 AddressList* addresses) const { | 374 AddressList* addresses) const { |
| 379 net::HostResolver::RequestInfo resolve_info(pair.first); | 375 net::HostResolver::RequestInfo resolve_info(pair.first); |
| 380 int rv = resolver_->ResolveFromCache(resolve_info, addresses, net_log); | 376 int rv = resolver_->ResolveFromCache(resolve_info, addresses, net_log); |
| 381 DCHECK_NE(ERR_IO_PENDING, rv); | 377 DCHECK_NE(ERR_IO_PENDING, rv); |
| 382 return rv == OK; | 378 return rv == OK; |
| 383 } | 379 } |
| 384 | 380 |
| 385 void SpdySessionPool::AddAlias(const addrinfo* address, | 381 void SpdySessionPool::AddAlias(const IPEndPoint& endpoint, |
| 386 const HostPortProxyPair& pair) { | 382 const HostPortProxyPair& pair) { |
| 387 DCHECK(g_enable_ip_pooling); | 383 DCHECK(g_enable_ip_pooling); |
| 388 DCHECK(address); | |
| 389 IPEndPoint endpoint; | |
| 390 endpoint.FromSockAddr(address->ai_addr, address->ai_addrlen); | |
| 391 aliases_[endpoint] = pair; | 384 aliases_[endpoint] = pair; |
| 392 } | 385 } |
| 393 | 386 |
| 394 void SpdySessionPool::RemoveAliases(const HostPortProxyPair& pair) { | 387 void SpdySessionPool::RemoveAliases(const HostPortProxyPair& pair) { |
| 395 // Walk the aliases map, find references to this pair. | 388 // Walk the aliases map, find references to this pair. |
| 396 // TODO(mbelshe): Figure out if this is too expensive. | 389 // TODO(mbelshe): Figure out if this is too expensive. |
| 397 SpdyAliasMap::iterator alias_it = aliases_.begin(); | 390 SpdyAliasMap::iterator alias_it = aliases_.begin(); |
| 398 while (alias_it != aliases_.end()) { | 391 while (alias_it != aliases_.end()) { |
| 399 if (HostPortProxyPairsAreEqual(alias_it->second, pair)) { | 392 if (HostPortProxyPairsAreEqual(alias_it->second, pair)) { |
| 400 aliases_.erase(alias_it); | 393 aliases_.erase(alias_it); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 const scoped_refptr<SpdySession>& session = *session_it; | 453 const scoped_refptr<SpdySession>& session = *session_it; |
| 461 CHECK(session); | 454 CHECK(session); |
| 462 if (!session->is_active()) { | 455 if (!session->is_active()) { |
| 463 session->CloseSessionOnError( | 456 session->CloseSessionOnError( |
| 464 net::ERR_ABORTED, true, "Closing idle sessions."); | 457 net::ERR_ABORTED, true, "Closing idle sessions."); |
| 465 } | 458 } |
| 466 } | 459 } |
| 467 } | 460 } |
| 468 | 461 |
| 469 } // namespace net | 462 } // namespace net |
| OLD | NEW |