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

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

Issue 2620303003: Replace ASSERT by RTC_DCHECK in all non-test code. (Closed)
Patch Set: Address final nits. Created 3 years, 11 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
« no previous file with comments | « webrtc/p2p/base/p2ptransportchannel.cc ('k') | webrtc/p2p/base/pseudotcp.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 max_port_(max_port), 177 max_port_(max_port),
178 component_(ICE_CANDIDATE_COMPONENT_DEFAULT), 178 component_(ICE_CANDIDATE_COMPONENT_DEFAULT),
179 generation_(0), 179 generation_(0),
180 ice_username_fragment_(username_fragment), 180 ice_username_fragment_(username_fragment),
181 password_(password), 181 password_(password),
182 timeout_delay_(kPortTimeoutDelay), 182 timeout_delay_(kPortTimeoutDelay),
183 enable_port_packets_(false), 183 enable_port_packets_(false),
184 ice_role_(ICEROLE_UNKNOWN), 184 ice_role_(ICEROLE_UNKNOWN),
185 tiebreaker_(0), 185 tiebreaker_(0),
186 shared_socket_(false) { 186 shared_socket_(false) {
187 ASSERT(factory_ != NULL); 187 RTC_DCHECK(factory_ != NULL);
188 Construct(); 188 Construct();
189 } 189 }
190 190
191 void Port::Construct() { 191 void Port::Construct() {
192 // TODO(pthatcher): Remove this old behavior once we're sure no one 192 // TODO(pthatcher): Remove this old behavior once we're sure no one
193 // relies on it. If the username_fragment and password are empty, 193 // relies on it. If the username_fragment and password are empty,
194 // we should just create one. 194 // we should just create one.
195 if (ice_username_fragment_.empty()) { 195 if (ice_username_fragment_.empty()) {
196 ASSERT(password_.empty()); 196 RTC_DCHECK(password_.empty());
197 ice_username_fragment_ = rtc::CreateRandomString(ICE_UFRAG_LENGTH); 197 ice_username_fragment_ = rtc::CreateRandomString(ICE_UFRAG_LENGTH);
198 password_ = rtc::CreateRandomString(ICE_PWD_LENGTH); 198 password_ = rtc::CreateRandomString(ICE_PWD_LENGTH);
199 } 199 }
200 network_->SignalTypeChanged.connect(this, &Port::OnNetworkTypeChanged); 200 network_->SignalTypeChanged.connect(this, &Port::OnNetworkTypeChanged);
201 network_cost_ = network_->GetCost(); 201 network_cost_ = network_->GetCost();
202 202
203 thread_->PostDelayed(RTC_FROM_HERE, timeout_delay_, this, 203 thread_->PostDelayed(RTC_FROM_HERE, timeout_delay_, this,
204 MSG_DESTROY_IF_DEAD); 204 MSG_DESTROY_IF_DEAD);
205 LOG_J(LS_INFO, this) << "Port created with network cost " << network_cost_; 205 LOG_J(LS_INFO, this) << "Port created with network cost " << network_cost_;
206 } 206 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 const rtc::SocketAddress& base_address, 246 const rtc::SocketAddress& base_address,
247 const rtc::SocketAddress& related_address, 247 const rtc::SocketAddress& related_address,
248 const std::string& protocol, 248 const std::string& protocol,
249 const std::string& relay_protocol, 249 const std::string& relay_protocol,
250 const std::string& tcptype, 250 const std::string& tcptype,
251 const std::string& type, 251 const std::string& type,
252 uint32_t type_preference, 252 uint32_t type_preference,
253 uint32_t relay_preference, 253 uint32_t relay_preference,
254 bool final) { 254 bool final) {
255 if (protocol == TCP_PROTOCOL_NAME && type == LOCAL_PORT_TYPE) { 255 if (protocol == TCP_PROTOCOL_NAME && type == LOCAL_PORT_TYPE) {
256 ASSERT(!tcptype.empty()); 256 RTC_DCHECK(!tcptype.empty());
257 } 257 }
258 258
259 std::string foundation = 259 std::string foundation =
260 ComputeFoundation(type, protocol, relay_protocol, base_address); 260 ComputeFoundation(type, protocol, relay_protocol, base_address);
261 Candidate c(component_, protocol, address, 0U, username_fragment(), password_, 261 Candidate c(component_, protocol, address, 0U, username_fragment(), password_,
262 type, generation_, foundation, network_->id(), network_cost_); 262 type, generation_, foundation, network_->id(), network_cost_);
263 c.set_priority( 263 c.set_priority(
264 c.GetPriority(type_preference, network_->preference(), relay_preference)); 264 c.GetPriority(type_preference, network_->preference(), relay_preference));
265 c.set_relay_protocol(relay_protocol); 265 c.set_relay_protocol(relay_protocol);
266 c.set_tcptype(tcptype); 266 c.set_tcptype(tcptype);
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 } 348 }
349 349
350 bool Port::GetStunMessage(const char* data, 350 bool Port::GetStunMessage(const char* data,
351 size_t size, 351 size_t size,
352 const rtc::SocketAddress& addr, 352 const rtc::SocketAddress& addr,
353 std::unique_ptr<IceMessage>* out_msg, 353 std::unique_ptr<IceMessage>* out_msg,
354 std::string* out_username) { 354 std::string* out_username) {
355 // NOTE: This could clearly be optimized to avoid allocating any memory. 355 // NOTE: This could clearly be optimized to avoid allocating any memory.
356 // However, at the data rates we'll be looking at on the client side, 356 // However, at the data rates we'll be looking at on the client side,
357 // this probably isn't worth worrying about. 357 // this probably isn't worth worrying about.
358 ASSERT(out_msg != NULL); 358 RTC_DCHECK(out_msg != NULL);
359 ASSERT(out_username != NULL); 359 RTC_DCHECK(out_username != NULL);
360 out_username->clear(); 360 out_username->clear();
361 361
362 // Don't bother parsing the packet if we can tell it's not STUN. 362 // Don't bother parsing the packet if we can tell it's not STUN.
363 // In ICE mode, all STUN packets will have a valid fingerprint. 363 // In ICE mode, all STUN packets will have a valid fingerprint.
364 if (!StunMessage::ValidateFingerprint(data, size)) { 364 if (!StunMessage::ValidateFingerprint(data, size)) {
365 return false; 365 return false;
366 } 366 }
367 367
368 // Parse the request message. If the packet is not a complete and correct 368 // Parse the request message. If the packet is not a complete and correct
369 // STUN message, then ignore it. 369 // STUN message, then ignore it.
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 void Port::CreateStunUsername(const std::string& remote_username, 547 void Port::CreateStunUsername(const std::string& remote_username,
548 std::string* stun_username_attr_str) const { 548 std::string* stun_username_attr_str) const {
549 stun_username_attr_str->clear(); 549 stun_username_attr_str->clear();
550 *stun_username_attr_str = remote_username; 550 *stun_username_attr_str = remote_username;
551 stun_username_attr_str->append(":"); 551 stun_username_attr_str->append(":");
552 stun_username_attr_str->append(username_fragment()); 552 stun_username_attr_str->append(username_fragment());
553 } 553 }
554 554
555 void Port::SendBindingResponse(StunMessage* request, 555 void Port::SendBindingResponse(StunMessage* request,
556 const rtc::SocketAddress& addr) { 556 const rtc::SocketAddress& addr) {
557 ASSERT(request->type() == STUN_BINDING_REQUEST); 557 RTC_DCHECK(request->type() == STUN_BINDING_REQUEST);
558 558
559 // Retrieve the username from the request. 559 // Retrieve the username from the request.
560 const StunByteStringAttribute* username_attr = 560 const StunByteStringAttribute* username_attr =
561 request->GetByteString(STUN_ATTR_USERNAME); 561 request->GetByteString(STUN_ATTR_USERNAME);
562 ASSERT(username_attr != NULL); 562 RTC_DCHECK(username_attr != NULL);
563 if (username_attr == NULL) { 563 if (username_attr == NULL) {
564 // No valid username, skip the response. 564 // No valid username, skip the response.
565 return; 565 return;
566 } 566 }
567 567
568 // Fill in the response message. 568 // Fill in the response message.
569 StunMessage response; 569 StunMessage response;
570 response.SetType(STUN_BINDING_RESPONSE); 570 response.SetType(STUN_BINDING_RESPONSE);
571 response.SetTransactionID(request->transaction_id()); 571 response.SetTransactionID(request->transaction_id());
572 const StunUInt32Attribute* retransmit_attr = 572 const StunUInt32Attribute* retransmit_attr =
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 << ", to=" << addr.ToSensitiveString() 611 << ", to=" << addr.ToSensitiveString()
612 << ", id=" << rtc::hex_encode(response.transaction_id()); 612 << ", id=" << rtc::hex_encode(response.transaction_id());
613 613
614 conn->stats_.sent_ping_responses++; 614 conn->stats_.sent_ping_responses++;
615 } 615 }
616 } 616 }
617 617
618 void Port::SendBindingErrorResponse(StunMessage* request, 618 void Port::SendBindingErrorResponse(StunMessage* request,
619 const rtc::SocketAddress& addr, 619 const rtc::SocketAddress& addr,
620 int error_code, const std::string& reason) { 620 int error_code, const std::string& reason) {
621 ASSERT(request->type() == STUN_BINDING_REQUEST); 621 RTC_DCHECK(request->type() == STUN_BINDING_REQUEST);
622 622
623 // Fill in the response message. 623 // Fill in the response message.
624 StunMessage response; 624 StunMessage response;
625 response.SetType(STUN_BINDING_ERROR_RESPONSE); 625 response.SetType(STUN_BINDING_ERROR_RESPONSE);
626 response.SetTransactionID(request->transaction_id()); 626 response.SetTransactionID(request->transaction_id());
627 627
628 // When doing GICE, we need to write out the error code incorrectly to 628 // When doing GICE, we need to write out the error code incorrectly to
629 // maintain backwards compatiblility. 629 // maintain backwards compatiblility.
630 StunErrorCodeAttribute* error_attr = StunAttribute::CreateErrorCode(); 630 StunErrorCodeAttribute* error_attr = StunAttribute::CreateErrorCode();
631 error_attr->SetCode(error_code); 631 error_attr->SetCode(error_code);
(...skipping 22 matching lines...) Expand all
654 state_ = State::KEEP_ALIVE_UNTIL_PRUNED; 654 state_ = State::KEEP_ALIVE_UNTIL_PRUNED;
655 } 655 }
656 } 656 }
657 657
658 void Port::Prune() { 658 void Port::Prune() {
659 state_ = State::PRUNED; 659 state_ = State::PRUNED;
660 thread_->Post(RTC_FROM_HERE, this, MSG_DESTROY_IF_DEAD); 660 thread_->Post(RTC_FROM_HERE, this, MSG_DESTROY_IF_DEAD);
661 } 661 }
662 662
663 void Port::OnMessage(rtc::Message *pmsg) { 663 void Port::OnMessage(rtc::Message *pmsg) {
664 ASSERT(pmsg->message_id == MSG_DESTROY_IF_DEAD); 664 RTC_DCHECK(pmsg->message_id == MSG_DESTROY_IF_DEAD);
665 bool dead = 665 bool dead =
666 (state_ == State::INIT || state_ == State::PRUNED) && 666 (state_ == State::INIT || state_ == State::PRUNED) &&
667 connections_.empty() && 667 connections_.empty() &&
668 rtc::TimeMillis() - last_time_all_connections_removed_ >= timeout_delay_; 668 rtc::TimeMillis() - last_time_all_connections_removed_ >= timeout_delay_;
669 if (dead) { 669 if (dead) {
670 Destroy(); 670 Destroy();
671 } 671 }
672 } 672 }
673 673
674 void Port::OnNetworkTypeChanged(const rtc::Network* network) { 674 void Port::OnNetworkTypeChanged(const rtc::Network* network) {
675 ASSERT(network == network_); 675 RTC_DCHECK(network == network_);
676 676
677 UpdateNetworkCost(); 677 UpdateNetworkCost();
678 } 678 }
679 679
680 std::string Port::ToString() const { 680 std::string Port::ToString() const {
681 std::stringstream ss; 681 std::stringstream ss;
682 ss << "Port[" << std::hex << this << std::dec << ":" << content_name_ << ":" 682 ss << "Port[" << std::hex << this << std::dec << ":" << content_name_ << ":"
683 << component_ << ":" << generation_ << ":" << type_ << ":" 683 << component_ << ":" << generation_ << ":" << type_ << ":"
684 << network_->ToString() << "]"; 684 << network_->ToString() << "]";
685 return ss.str(); 685 return ss.str();
(...skipping 22 matching lines...) Expand all
708 } 708 }
709 } 709 }
710 710
711 void Port::EnablePortPackets() { 711 void Port::EnablePortPackets() {
712 enable_port_packets_ = true; 712 enable_port_packets_ = true;
713 } 713 }
714 714
715 void Port::OnConnectionDestroyed(Connection* conn) { 715 void Port::OnConnectionDestroyed(Connection* conn) {
716 AddressMap::iterator iter = 716 AddressMap::iterator iter =
717 connections_.find(conn->remote_candidate().address()); 717 connections_.find(conn->remote_candidate().address());
718 ASSERT(iter != connections_.end()); 718 RTC_DCHECK(iter != connections_.end());
719 connections_.erase(iter); 719 connections_.erase(iter);
720 HandleConnectionDestroyed(conn); 720 HandleConnectionDestroyed(conn);
721 721
722 // Ports time out after all connections fail if it is not marked as 722 // Ports time out after all connections fail if it is not marked as
723 // "keep alive until pruned." 723 // "keep alive until pruned."
724 // Note: If a new connection is added after this message is posted, but it 724 // Note: If a new connection is added after this message is posted, but it
725 // fails and is removed before kPortTimeoutDelay, then this message will 725 // fails and is removed before kPortTimeoutDelay, then this message will
726 // not cause the Port to be destroyed. 726 // not cause the Port to be destroyed.
727 if (connections_.empty()) { 727 if (connections_.empty()) {
728 last_time_all_connections_removed_ = rtc::TimeMillis(); 728 last_time_all_connections_removed_ = rtc::TimeMillis();
729 thread_->PostDelayed(RTC_FROM_HERE, timeout_delay_, this, 729 thread_->PostDelayed(RTC_FROM_HERE, timeout_delay_, this,
730 MSG_DESTROY_IF_DEAD); 730 MSG_DESTROY_IF_DEAD);
731 } 731 }
732 } 732 }
733 733
734 void Port::Destroy() { 734 void Port::Destroy() {
735 ASSERT(connections_.empty()); 735 RTC_DCHECK(connections_.empty());
736 LOG_J(LS_INFO, this) << "Port deleted"; 736 LOG_J(LS_INFO, this) << "Port deleted";
737 SignalDestroyed(this); 737 SignalDestroyed(this);
738 delete this; 738 delete this;
739 } 739 }
740 740
741 const std::string Port::username_fragment() const { 741 const std::string Port::username_fragment() const {
742 return ice_username_fragment_; 742 return ice_username_fragment_;
743 } 743 }
744 744
745 // A ConnectionRequest is a simple STUN ping used to determine writability. 745 // A ConnectionRequest is a simple STUN ping used to determine writability.
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
876 // TODO(mallinath) - Start connections from STATE_FROZEN. 876 // TODO(mallinath) - Start connections from STATE_FROZEN.
877 // Wire up to send stun packets 877 // Wire up to send stun packets
878 requests_.SignalSendPacket.connect(this, &Connection::OnSendStunPacket); 878 requests_.SignalSendPacket.connect(this, &Connection::OnSendStunPacket);
879 LOG_J(LS_INFO, this) << "Connection created"; 879 LOG_J(LS_INFO, this) << "Connection created";
880 } 880 }
881 881
882 Connection::~Connection() { 882 Connection::~Connection() {
883 } 883 }
884 884
885 const Candidate& Connection::local_candidate() const { 885 const Candidate& Connection::local_candidate() const {
886 ASSERT(local_candidate_index_ < port_->Candidates().size()); 886 RTC_DCHECK(local_candidate_index_ < port_->Candidates().size());
887 return port_->Candidates()[local_candidate_index_]; 887 return port_->Candidates()[local_candidate_index_];
888 } 888 }
889 889
890 const Candidate& Connection::remote_candidate() const { 890 const Candidate& Connection::remote_candidate() const {
891 return remote_candidate_; 891 return remote_candidate_;
892 } 892 }
893 893
894 uint64_t Connection::priority() const { 894 uint64_t Connection::priority() const {
895 uint64_t priority = 0; 895 uint64_t priority = 0;
896 // RFC 5245 - 5.7.2. Computing Pair Priority and Ordering Pairs 896 // RFC 5245 - 5.7.2. Computing Pair Priority and Ordering Pairs
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after
1448 remote_candidate_.protocol() == new_candidate.protocol() && 1448 remote_candidate_.protocol() == new_candidate.protocol() &&
1449 remote_candidate_.address() == new_candidate.address() && 1449 remote_candidate_.address() == new_candidate.address() &&
1450 remote_candidate_.username() == new_candidate.username() && 1450 remote_candidate_.username() == new_candidate.username() &&
1451 remote_candidate_.password() == new_candidate.password() && 1451 remote_candidate_.password() == new_candidate.password() &&
1452 remote_candidate_.generation() == new_candidate.generation()) { 1452 remote_candidate_.generation() == new_candidate.generation()) {
1453 remote_candidate_ = new_candidate; 1453 remote_candidate_ = new_candidate;
1454 } 1454 }
1455 } 1455 }
1456 1456
1457 void Connection::OnMessage(rtc::Message *pmsg) { 1457 void Connection::OnMessage(rtc::Message *pmsg) {
1458 ASSERT(pmsg->message_id == MSG_DELETE); 1458 RTC_DCHECK(pmsg->message_id == MSG_DELETE);
1459 LOG(LS_INFO) << "Connection deleted with number of pings sent: " 1459 LOG(LS_INFO) << "Connection deleted with number of pings sent: "
1460 << num_pings_sent_; 1460 << num_pings_sent_;
1461 SignalDestroyed(this); 1461 SignalDestroyed(this);
1462 delete this; 1462 delete this;
1463 } 1463 }
1464 1464
1465 int64_t Connection::last_received() const { 1465 int64_t Connection::last_received() const {
1466 return std::max(last_data_received_, 1466 return std::max(last_data_received_,
1467 std::max(last_ping_received_, last_ping_response_received_)); 1467 std::max(last_ping_received_, last_ping_response_received_));
1468 } 1468 }
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
1573 size_t index, 1573 size_t index,
1574 const Candidate& remote_candidate) 1574 const Candidate& remote_candidate)
1575 : Connection(port, index, remote_candidate) {} 1575 : Connection(port, index, remote_candidate) {}
1576 1576
1577 int ProxyConnection::Send(const void* data, size_t size, 1577 int ProxyConnection::Send(const void* data, size_t size,
1578 const rtc::PacketOptions& options) { 1578 const rtc::PacketOptions& options) {
1579 stats_.sent_total_packets++; 1579 stats_.sent_total_packets++;
1580 int sent = port_->SendTo(data, size, remote_candidate_.address(), 1580 int sent = port_->SendTo(data, size, remote_candidate_.address(),
1581 options, true); 1581 options, true);
1582 if (sent <= 0) { 1582 if (sent <= 0) {
1583 ASSERT(sent < 0); 1583 RTC_DCHECK(sent < 0);
1584 error_ = port_->GetError(); 1584 error_ = port_->GetError();
1585 stats_.sent_discarded_packets++; 1585 stats_.sent_discarded_packets++;
1586 } else { 1586 } else {
1587 send_rate_tracker_.AddSamples(sent); 1587 send_rate_tracker_.AddSamples(sent);
1588 } 1588 }
1589 return sent; 1589 return sent;
1590 } 1590 }
1591 1591
1592 } // namespace cricket 1592 } // namespace cricket
OLDNEW
« no previous file with comments | « webrtc/p2p/base/p2ptransportchannel.cc ('k') | webrtc/p2p/base/pseudotcp.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698