OLD | NEW |
---|---|
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 Loading... | |
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 | |
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) { | |
161 const addrinfo* address = addresses.head(); | |
162 if (address) { | |
willchan no longer on Chromium
2011/07/17 01:23:45
Should DCHECK() on this, because it must be availa
ramant (doing other things)
2011/07/17 08:12:30
Done.
| |
163 IPEndPoint endpoint; | |
164 endpoint.FromSockAddr(address->ai_addr, address->ai_addrlen); | |
165 aliases_[endpoint] = host_port_proxy_pair; | |
willchan no longer on Chromium
2011/07/17 01:23:45
If you take my suggestion on AddAlias() instead of
ramant (doing other things)
2011/07/17 08:12:30
Done.
| |
166 } | |
167 } | |
168 } | |
169 | |
153 // Now we can initialize the session with the SSL socket. | 170 // Now we can initialize the session with the SSL socket. |
154 return (*spdy_session)->InitializeWithSocket(connection, is_secure, | 171 return (*spdy_session)->InitializeWithSocket(connection, is_secure, |
155 certificate_error_code); | 172 certificate_error_code); |
156 } | 173 } |
157 | 174 |
158 bool SpdySessionPool::HasSession( | 175 bool SpdySessionPool::HasSession( |
159 const HostPortProxyPair& host_port_proxy_pair) const { | 176 const HostPortProxyPair& host_port_proxy_pair) const { |
160 if (GetSessionList(host_port_proxy_pair)) | 177 if (GetSessionList(host_port_proxy_pair)) |
161 return true; | 178 return true; |
162 | 179 |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
295 return *single_domain_pair; | 312 return *single_domain_pair; |
296 } | 313 } |
297 | 314 |
298 SpdySessionPool::SpdySessionList* | 315 SpdySessionPool::SpdySessionList* |
299 SpdySessionPool::AddSessionList( | 316 SpdySessionPool::AddSessionList( |
300 const HostPortProxyPair& host_port_proxy_pair) { | 317 const HostPortProxyPair& host_port_proxy_pair) { |
301 const HostPortProxyPair& pair = NormalizeListPair(host_port_proxy_pair); | 318 const HostPortProxyPair& pair = NormalizeListPair(host_port_proxy_pair); |
302 DCHECK(sessions_.find(pair) == sessions_.end()); | 319 DCHECK(sessions_.find(pair) == sessions_.end()); |
303 SpdySessionPool::SpdySessionList* list = new SpdySessionList(); | 320 SpdySessionPool::SpdySessionList* list = new SpdySessionList(); |
304 sessions_[pair] = list; | 321 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; | 322 return list; |
316 } | 323 } |
317 | 324 |
318 SpdySessionPool::SpdySessionList* | 325 SpdySessionPool::SpdySessionList* |
319 SpdySessionPool::GetSessionList( | 326 SpdySessionPool::GetSessionList( |
320 const HostPortProxyPair& host_port_proxy_pair) const { | 327 const HostPortProxyPair& host_port_proxy_pair) const { |
321 const HostPortProxyPair& pair = NormalizeListPair(host_port_proxy_pair); | 328 const HostPortProxyPair& pair = NormalizeListPair(host_port_proxy_pair); |
322 SpdySessionsMap::const_iterator it = sessions_.find(pair); | 329 SpdySessionsMap::const_iterator it = sessions_.find(pair); |
323 if (it != sessions_.end()) | 330 if (it != sessions_.end()) |
324 return it->second; | 331 return it->second; |
(...skipping 19 matching lines...) Expand all Loading... | |
344 resolve_info.set_only_use_cached_response(true); | 351 resolve_info.set_only_use_cached_response(true); |
345 int rv = resolver_->Resolve(resolve_info, | 352 int rv = resolver_->Resolve(resolve_info, |
346 addresses, | 353 addresses, |
347 NULL, | 354 NULL, |
348 NULL, | 355 NULL, |
349 net::BoundNetLog()); | 356 net::BoundNetLog()); |
350 DCHECK_NE(ERR_IO_PENDING, rv); | 357 DCHECK_NE(ERR_IO_PENDING, rv); |
351 return rv == OK; | 358 return rv == OK; |
352 } | 359 } |
353 | 360 |
354 void SpdySessionPool::AddAliases(const AddressList& addresses, | 361 void SpdySessionPool::AddAliases(const HostPortProxyPair& pair) { |
355 const HostPortProxyPair& pair) { | 362 if (!g_enable_ip_pooling) |
356 // Note: it is possible to think of strange overlapping sets of ip addresses | 363 return; |
357 // for hosts such that a new session can override the alias for an IP | 364 AddressList addresses; |
358 // address that was previously aliased to a different host. This is probably | 365 if (!LookupAddresses(pair, &addresses)) |
359 // undesirable, but seemingly unlikely and complicated to fix. | 366 return; |
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(); | 367 const addrinfo* address = addresses.head(); |
368 while (address) { | 368 while (address) { |
369 IPEndPoint endpoint; | 369 IPEndPoint endpoint; |
370 endpoint.FromSockAddr(address->ai_addr, address->ai_addrlen); | 370 endpoint.FromSockAddr(address->ai_addr, address->ai_addrlen); |
371 aliases_[endpoint] = pair; | 371 aliases_[endpoint] = pair; |
372 address = address->ai_next; | 372 address = address->ai_next; |
373 } | 373 } |
374 } | 374 } |
375 | 375 |
376 void SpdySessionPool::RemoveAliases(const HostPortProxyPair& pair) { | 376 void SpdySessionPool::RemoveAliases(const HostPortProxyPair& pair) { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
422 delete list; | 422 delete list; |
423 RemoveAliases(old_map.begin()->first); | 423 RemoveAliases(old_map.begin()->first); |
424 old_map.erase(old_map.begin()->first); | 424 old_map.erase(old_map.begin()->first); |
425 } | 425 } |
426 } | 426 } |
427 DCHECK(sessions_.empty()); | 427 DCHECK(sessions_.empty()); |
428 DCHECK(aliases_.empty()); | 428 DCHECK(aliases_.empty()); |
429 } | 429 } |
430 | 430 |
431 } // namespace net | 431 } // namespace net |
OLD | NEW |