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

Side by Side Diff: webrtc/p2p/base/p2ptransportchannel.cc

Issue 1172483002: Connection resurrected with incorrect candidate type. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Created 5 years, 6 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
OLDNEW
1 /* 1 /*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 } 471 }
472 } 472 }
473 473
474 // The STUN binding request may arrive after setRemoteDescription and before 474 // The STUN binding request may arrive after setRemoteDescription and before
475 // adding remote candidate, so we need to set the password to the shared 475 // adding remote candidate, so we need to set the password to the shared
476 // password if the user name matches. 476 // password if the user name matches.
477 if (remote_password.empty() && remote_username == remote_ice_ufrag_) { 477 if (remote_password.empty() && remote_username == remote_ice_ufrag_) {
478 remote_password = remote_ice_pwd_; 478 remote_password = remote_ice_pwd_;
479 } 479 }
480 480
481 Candidate new_remote_candidate; 481 Candidate remote_candidate;
482 bool remote_candidate_is_new = false;
pthatcher1 2015/06/09 23:58:03 Perhaps more clear as: bool remote_candidate_is_n
guoweis_webrtc 2015/06/10 18:12:41 Done.
482 if (candidate != NULL) { 483 if (candidate != NULL) {
483 new_remote_candidate = *candidate; 484 remote_candidate = *candidate;
484 if (ufrag_per_port) { 485 if (ufrag_per_port) {
485 new_remote_candidate.set_address(address); 486 remote_candidate.set_address(address);
486 } 487 }
487 } else { 488 } else {
489 remote_candidate_is_new = true;
488 // Create a new candidate with this address. 490 // Create a new candidate with this address.
489 std::string type; 491 std::string type;
490 if (port->IceProtocol() == ICEPROTO_RFC5245) { 492 if (port->IceProtocol() == ICEPROTO_RFC5245) {
491 type = PRFLX_PORT_TYPE; 493 type = PRFLX_PORT_TYPE;
492 } else { 494 } else {
493 // G-ICE doesn't support prflx candidate. 495 // G-ICE doesn't support prflx candidate.
494 // We set candidate type to STUN_PORT_TYPE if the binding request comes 496 // We set candidate type to STUN_PORT_TYPE if the binding request comes
495 // from a relay port or the shared socket is used. Otherwise we use the 497 // from a relay port or the shared socket is used. Otherwise we use the
496 // port's type as the candidate type. 498 // port's type as the candidate type.
497 if (port->Type() == RELAY_PORT_TYPE || port->SharedSocket()) { 499 if (port->Type() == RELAY_PORT_TYPE || port->SharedSocket()) {
498 type = STUN_PORT_TYPE; 500 type = STUN_PORT_TYPE;
499 } else { 501 } else {
500 type = port->Type(); 502 type = port->Type();
501 } 503 }
502 } 504 }
503 505
504 new_remote_candidate = 506 remote_candidate =
505 Candidate(component(), ProtoToString(proto), address, 0, 507 Candidate(component(), ProtoToString(proto), address, 0,
506 remote_username, remote_password, type, 0U, ""); 508 remote_username, remote_password, type, 0U, "");
507 509
508 // From RFC 5245, section-7.2.1.3: 510 // From RFC 5245, section-7.2.1.3:
509 // The foundation of the candidate is set to an arbitrary value, different 511 // The foundation of the candidate is set to an arbitrary value, different
510 // from the foundation for all other remote candidates. 512 // from the foundation for all other remote candidates.
511 new_remote_candidate.set_foundation( 513 remote_candidate.set_foundation(
512 rtc::ToString<uint32>(rtc::ComputeCrc32(new_remote_candidate.id()))); 514 rtc::ToString<uint32>(rtc::ComputeCrc32(remote_candidate.id())));
513 515
514 new_remote_candidate.set_priority(new_remote_candidate.GetPriority( 516 remote_candidate.set_priority(remote_candidate.GetPriority(
515 ICE_TYPE_PREFERENCE_PRFLX, port->Network()->preference(), 0)); 517 ICE_TYPE_PREFERENCE_PRFLX, port->Network()->preference(), 0));
516 } 518 }
517 519
518 if (port->IceProtocol() == ICEPROTO_RFC5245) { 520 if (port->IceProtocol() == ICEPROTO_RFC5245) {
519 // RFC 5245 521 // RFC 5245
520 // If the source transport address of the request does not match any 522 // If the source transport address of the request does not match any
521 // existing remote candidates, it represents a new peer reflexive remote 523 // existing remote candidates, it represents a new peer reflexive remote
522 // candidate. 524 // candidate.
523 525
524 // The priority of the candidate is set to the PRIORITY attribute 526 // The priority of the candidate is set to the PRIORITY attribute
525 // from the request. 527 // from the request.
526 const StunUInt32Attribute* priority_attr = 528 const StunUInt32Attribute* priority_attr =
527 stun_msg->GetUInt32(STUN_ATTR_PRIORITY); 529 stun_msg->GetUInt32(STUN_ATTR_PRIORITY);
528 if (!priority_attr) { 530 if (!priority_attr) {
529 LOG(LS_WARNING) << "P2PTransportChannel::OnUnknownAddress - " 531 LOG(LS_WARNING) << "P2PTransportChannel::OnUnknownAddress - "
530 << "No STUN_ATTR_PRIORITY found in the " 532 << "No STUN_ATTR_PRIORITY found in the "
531 << "stun request message"; 533 << "stun request message";
532 port->SendBindingErrorResponse(stun_msg, address, 534 port->SendBindingErrorResponse(stun_msg, address,
533 STUN_ERROR_BAD_REQUEST, 535 STUN_ERROR_BAD_REQUEST,
534 STUN_ERROR_REASON_BAD_REQUEST); 536 STUN_ERROR_REASON_BAD_REQUEST);
535 return; 537 return;
536 } 538 }
537 new_remote_candidate.set_priority(priority_attr->value()); 539 if (remote_candidate_is_new) {
540 remote_candidate.set_priority(priority_attr->value());
541 }
pthatcher1 2015/06/09 23:58:03 Can you move this up into the rest of the "remote_
guoweis_webrtc 2015/06/10 18:12:41 Done.
538 542
539 // RFC5245, the agent constructs a pair whose local candidate is equal to 543 // RFC5245, the agent constructs a pair whose local candidate is equal to
540 // the transport address on which the STUN request was received, and a 544 // the transport address on which the STUN request was received, and a
541 // remote candidate equal to the source transport address where the 545 // remote candidate equal to the source transport address where the
542 // request came from. 546 // request came from.
543 547
544 // There shouldn't be an existing connection with this remote address. 548 // There shouldn't be an existing connection with this remote address.
545 // When ports are muxed, this channel might get multiple unknown address 549 // When ports are muxed, this channel might get multiple unknown address
546 // signals. In that case if the connection is already exists, we should 550 // signals. In that case if the connection is already exists, we should
547 // simply ignore the signal othewise send server error. 551 // simply ignore the signal othewise send server error.
548 if (port->GetConnection(new_remote_candidate.address())) { 552 if (port->GetConnection(remote_candidate.address())) {
549 if (port_muxed) { 553 if (port_muxed) {
550 LOG(LS_INFO) << "Connection already exists for peer reflexive " 554 LOG(LS_INFO) << "Connection already exists for peer reflexive "
551 << "candidate: " << new_remote_candidate.ToString(); 555 << "candidate: " << remote_candidate.ToString();
552 return; 556 return;
553 } else { 557 } else {
554 ASSERT(false); 558 ASSERT(false);
555 port->SendBindingErrorResponse(stun_msg, address, 559 port->SendBindingErrorResponse(stun_msg, address,
556 STUN_ERROR_SERVER_ERROR, 560 STUN_ERROR_SERVER_ERROR,
557 STUN_ERROR_REASON_SERVER_ERROR); 561 STUN_ERROR_REASON_SERVER_ERROR);
558 return; 562 return;
559 } 563 }
560 } 564 }
561 565
562 Connection* connection = port->CreateConnection( 566 Connection* connection = port->CreateConnection(
563 new_remote_candidate, cricket::PortInterface::ORIGIN_THIS_PORT); 567 remote_candidate, cricket::PortInterface::ORIGIN_THIS_PORT);
564 if (!connection) { 568 if (!connection) {
565 ASSERT(false); 569 ASSERT(false);
566 port->SendBindingErrorResponse(stun_msg, address, 570 port->SendBindingErrorResponse(stun_msg, address,
567 STUN_ERROR_SERVER_ERROR, 571 STUN_ERROR_SERVER_ERROR,
568 STUN_ERROR_REASON_SERVER_ERROR); 572 STUN_ERROR_REASON_SERVER_ERROR);
569 return; 573 return;
570 } 574 }
571 575
572 LOG(LS_INFO) << "Adding connection from peer reflexive candidate: " 576 LOG(LS_INFO) << "Adding connection from "
573 << new_remote_candidate.ToString(); 577 << (remote_candidate_is_new ? "peer reflexive" : "resurrected")
578 << " candidate: " << remote_candidate.ToString();
574 AddConnection(connection); 579 AddConnection(connection);
575 connection->ReceivedPing(); 580 connection->ReceivedPing();
576 581
577 // Send the pinger a successful stun response. 582 // Send the pinger a successful stun response.
578 port->SendBindingResponse(stun_msg, address); 583 port->SendBindingResponse(stun_msg, address);
579 584
580 // Update the list of connections since we just added another. We do this 585 // Update the list of connections since we just added another. We do this
581 // after sending the response since it could (in principle) delete the 586 // after sending the response since it could (in principle) delete the
582 // connection in question. 587 // connection in question.
583 SortConnections(); 588 SortConnections();
584 } else { 589 } else {
585 // Check for connectivity to this address. Create connections 590 // Check for connectivity to this address. Create connections
586 // to this address across all local ports. First, add this as a new remote 591 // to this address across all local ports. First, add this as a new remote
587 // address 592 // address
588 if (!CreateConnections(new_remote_candidate, port, true)) { 593 if (!CreateConnections(remote_candidate, port, true)) {
589 // Hopefully this won't occur, because changing a destination address 594 // Hopefully this won't occur, because changing a destination address
590 // shouldn't cause a new connection to fail 595 // shouldn't cause a new connection to fail
591 ASSERT(false); 596 ASSERT(false);
592 port->SendBindingErrorResponse(stun_msg, address, STUN_ERROR_SERVER_ERROR, 597 port->SendBindingErrorResponse(stun_msg, address, STUN_ERROR_SERVER_ERROR,
593 STUN_ERROR_REASON_SERVER_ERROR); 598 STUN_ERROR_REASON_SERVER_ERROR);
594 return; 599 return;
595 } 600 }
596 601
597 // Send the pinger a successful stun response. 602 // Send the pinger a successful stun response.
598 port->SendBindingResponse(stun_msg, address); 603 port->SendBindingResponse(stun_msg, address);
(...skipping 769 matching lines...) Expand 10 before | Expand all | Expand 10 after
1368 SignalReadPacket(this, data, len, packet_time, 0); 1373 SignalReadPacket(this, data, len, packet_time, 0);
1369 } 1374 }
1370 1375
1371 void P2PTransportChannel::OnReadyToSend(Connection* connection) { 1376 void P2PTransportChannel::OnReadyToSend(Connection* connection) {
1372 if (connection == best_connection_ && writable()) { 1377 if (connection == best_connection_ && writable()) {
1373 SignalReadyToSend(this); 1378 SignalReadyToSend(this);
1374 } 1379 }
1375 } 1380 }
1376 1381
1377 } // namespace cricket 1382 } // namespace cricket
OLDNEW
« no previous file with comments | « no previous file | webrtc/p2p/base/p2ptransportchannel_unittest.cc » ('j') | webrtc/p2p/base/p2ptransportchannel_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698