OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/tools/flip_server/sm_connection.h" | 5 #include "net/tools/flip_server/sm_connection.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <netinet/tcp.h> | 8 #include <netinet/tcp.h> |
9 #include <sys/socket.h> | 9 #include <sys/socket.h> |
10 #include <unistd.h> | 10 #include <unistd.h> |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 VLOG(1) << log_prefix_ << ACCEPTOR_CLIENT_IDENT << "!!! Got HUP or ERR"; | 297 VLOG(1) << log_prefix_ << ACCEPTOR_CLIENT_IDENT << "!!! Got HUP or ERR"; |
298 goto handle_close_or_error; | 298 goto handle_close_or_error; |
299 } | 299 } |
300 return; | 300 return; |
301 | 301 |
302 handle_close_or_error: | 302 handle_close_or_error: |
303 Cleanup("HandleEvents"); | 303 Cleanup("HandleEvents"); |
304 } | 304 } |
305 | 305 |
306 // Decide if SPDY was negotiated. | 306 // Decide if SPDY was negotiated. |
307 bool SMConnection::WasSpdyNegotiated(SpdyMajorVersion* version_negotiated) { | 307 bool SMConnection::WasSpdyNegotiated() { |
308 *version_negotiated = SPDY3; | |
309 if (force_spdy()) | 308 if (force_spdy()) |
310 return true; | 309 return true; |
311 | 310 |
312 // If this is an SSL connection, check if NPN specifies SPDY. | 311 // If this is an SSL connection, check if NPN specifies SPDY. |
313 if (ssl_) { | 312 if (ssl_) { |
314 const unsigned char* npn_proto; | 313 const unsigned char* npn_proto; |
315 unsigned int npn_proto_len; | 314 unsigned int npn_proto_len; |
316 SSL_get0_next_proto_negotiated(ssl_, &npn_proto, &npn_proto_len); | 315 SSL_get0_next_proto_negotiated(ssl_, &npn_proto, &npn_proto_len); |
317 if (npn_proto_len > 0) { | 316 if (npn_proto_len > 0) { |
318 std::string npn_proto_str((const char*)npn_proto, npn_proto_len); | 317 std::string npn_proto_str((const char*)npn_proto, npn_proto_len); |
319 VLOG(1) << log_prefix_ << ACCEPTOR_CLIENT_IDENT | 318 VLOG(1) << log_prefix_ << ACCEPTOR_CLIENT_IDENT |
320 << "NPN protocol detected: " << npn_proto_str; | 319 << "NPN protocol detected: " << npn_proto_str; |
321 if (!strncmp(reinterpret_cast<const char*>(npn_proto), | 320 if (!strncmp(reinterpret_cast<const char*>(npn_proto), |
322 "spdy/3", | 321 "spdy/3", |
323 npn_proto_len)) { | 322 npn_proto_len)) { |
324 *version_negotiated = SPDY3; | |
325 return true; | 323 return true; |
326 } | 324 } |
327 if (!strncmp(reinterpret_cast<const char*>(npn_proto), | 325 if (!strncmp(reinterpret_cast<const char*>(npn_proto), |
328 "spdy/4a2", | 326 "spdy/4a2", |
329 npn_proto_len)) { | 327 npn_proto_len)) { |
330 *version_negotiated = HTTP2; | |
331 return true; | 328 return true; |
332 } | 329 } |
333 } | 330 } |
334 } | 331 } |
335 | 332 |
336 return false; | 333 return false; |
337 } | 334 } |
338 | 335 |
339 bool SMConnection::SetupProtocolInterfaces() { | 336 bool SMConnection::SetupProtocolInterfaces() { |
340 DCHECK(!protocol_detected_); | 337 DCHECK(!protocol_detected_); |
341 protocol_detected_ = true; | 338 protocol_detected_ = true; |
342 | 339 |
343 SpdyMajorVersion version; | 340 bool spdy_negotiated = WasSpdyNegotiated(); |
344 bool spdy_negotiated = WasSpdyNegotiated(&version); | |
345 bool using_ssl = ssl_ != NULL; | 341 bool using_ssl = ssl_ != NULL; |
346 | 342 |
347 if (using_ssl) | 343 if (using_ssl) |
348 VLOG(1) << (SSL_session_reused(ssl_) ? "Resumed" : "Renegotiated") | 344 VLOG(1) << (SSL_session_reused(ssl_) ? "Resumed" : "Renegotiated") |
349 << " SSL Session."; | 345 << " SSL Session."; |
350 | 346 |
351 if (acceptor_->spdy_only_ && !spdy_negotiated) { | 347 if (acceptor_->spdy_only_ && !spdy_negotiated) { |
352 VLOG(1) << log_prefix_ << ACCEPTOR_CLIENT_IDENT | 348 VLOG(1) << log_prefix_ << ACCEPTOR_CLIENT_IDENT |
353 << "SPDY proxy only, closing HTTPS connection."; | 349 << "SPDY proxy only, closing HTTPS connection."; |
354 return false; | 350 return false; |
(...skipping 25 matching lines...) Expand all Loading... |
380 if (!spdy_negotiated) | 376 if (!spdy_negotiated) |
381 break; | 377 break; |
382 } | 378 } |
383 // Otherwise fall through into the case below. | 379 // Otherwise fall through into the case below. |
384 case FLIP_HANDLER_SPDY_SERVER: { | 380 case FLIP_HANDLER_SPDY_SERVER: { |
385 DCHECK(spdy_negotiated); | 381 DCHECK(spdy_negotiated); |
386 VLOG(2) << log_prefix_ << ACCEPTOR_CLIENT_IDENT | 382 VLOG(2) << log_prefix_ << ACCEPTOR_CLIENT_IDENT |
387 << (sm_spdy_interface_ ? "Creating" : "Reusing") | 383 << (sm_spdy_interface_ ? "Creating" : "Reusing") |
388 << " SPDY interface."; | 384 << " SPDY interface."; |
389 if (sm_spdy_interface_) | 385 if (sm_spdy_interface_) |
390 sm_spdy_interface_->CreateFramer(version); | 386 sm_spdy_interface_->CreateFramer(); |
391 else | 387 else |
392 sm_spdy_interface_ = new SpdySM( | 388 sm_spdy_interface_ = |
393 this, NULL, epoll_server_, memory_cache_, acceptor_, version); | 389 new SpdySM(this, NULL, epoll_server_, memory_cache_, acceptor_); |
394 sm_interface_ = sm_spdy_interface_; | 390 sm_interface_ = sm_spdy_interface_; |
395 break; | 391 break; |
396 } | 392 } |
397 } | 393 } |
398 | 394 |
399 CorkSocket(); | 395 CorkSocket(); |
400 if (!sm_interface_->PostAcceptHook()) | 396 if (!sm_interface_->PostAcceptHook()) |
401 return false; | 397 return false; |
402 | 398 |
403 return true; | 399 return true; |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
652 SMConnection* SMConnection::NewSMConnection(EpollServer* epoll_server, | 648 SMConnection* SMConnection::NewSMConnection(EpollServer* epoll_server, |
653 SSLState* ssl_state, | 649 SSLState* ssl_state, |
654 MemoryCache* memory_cache, | 650 MemoryCache* memory_cache, |
655 FlipAcceptor* acceptor, | 651 FlipAcceptor* acceptor, |
656 std::string log_prefix) { | 652 std::string log_prefix) { |
657 return new SMConnection( | 653 return new SMConnection( |
658 epoll_server, ssl_state, memory_cache, acceptor, log_prefix); | 654 epoll_server, ssl_state, memory_cache, acceptor, log_prefix); |
659 } | 655 } |
660 | 656 |
661 } // namespace net | 657 } // namespace net |
OLD | NEW |