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

Side by Side Diff: webrtc/p2p/base/relayport.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/pseudotcp.cc ('k') | webrtc/p2p/base/relayserver.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 #include <algorithm> 10 #include <algorithm>
11 11
12 #include "webrtc/p2p/base/relayport.h" 12 #include "webrtc/p2p/base/relayport.h"
13 #include "webrtc/base/asyncpacketsocket.h" 13 #include "webrtc/base/asyncpacketsocket.h"
14 #include "webrtc/base/checks.h"
14 #include "webrtc/base/helpers.h" 15 #include "webrtc/base/helpers.h"
15 #include "webrtc/base/logging.h" 16 #include "webrtc/base/logging.h"
16 17
17 namespace cricket { 18 namespace cricket {
18 19
19 static const int kMessageConnectTimeout = 1; 20 static const int kMessageConnectTimeout = 1;
20 static const int kKeepAliveDelay = 10 * 60 * 1000; 21 static const int kKeepAliveDelay = 10 * 60 * 1000;
21 static const int kRetryTimeout = 50 * 1000; // ICE says 50 secs 22 static const int kRetryTimeout = 50 * 1000; // ICE says 50 secs
22 // How long to wait for a socket to connect to remote host in milliseconds 23 // How long to wait for a socket to connect to remote host in milliseconds
23 // before trying another connection. 24 // before trying another connection.
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 } else { 264 } else {
264 return memcmp(data + 24, 265 return memcmp(data + 24,
265 TURN_MAGIC_COOKIE_VALUE, 266 TURN_MAGIC_COOKIE_VALUE,
266 sizeof(TURN_MAGIC_COOKIE_VALUE)) == 0; 267 sizeof(TURN_MAGIC_COOKIE_VALUE)) == 0;
267 } 268 }
268 } 269 }
269 270
270 void RelayPort::PrepareAddress() { 271 void RelayPort::PrepareAddress() {
271 // We initiate a connect on the first entry. If this completes, it will fill 272 // We initiate a connect on the first entry. If this completes, it will fill
272 // in the server address as the address of this port. 273 // in the server address as the address of this port.
273 ASSERT(entries_.size() == 1); 274 RTC_DCHECK(entries_.size() == 1);
274 entries_[0]->Connect(); 275 entries_[0]->Connect();
275 ready_ = false; 276 ready_ = false;
276 } 277 }
277 278
278 Connection* RelayPort::CreateConnection(const Candidate& address, 279 Connection* RelayPort::CreateConnection(const Candidate& address,
279 CandidateOrigin origin) { 280 CandidateOrigin origin) {
280 // We only create conns to non-udp sockets if they are incoming on this port 281 // We only create conns to non-udp sockets if they are incoming on this port
281 if ((address.protocol() != UDP_PROTOCOL_NAME) && 282 if ((address.protocol() != UDP_PROTOCOL_NAME) &&
282 (origin != ORIGIN_THIS_PORT)) { 283 (origin != ORIGIN_THIS_PORT)) {
283 return 0; 284 return 0;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 entry->SetServerIndex(entries_[0]->ServerIndex()); 335 entry->SetServerIndex(entries_[0]->ServerIndex());
335 } 336 }
336 entry->Connect(); 337 entry->Connect();
337 entries_.push_back(entry); 338 entries_.push_back(entry);
338 } 339 }
339 340
340 // If the entry is connected, then we can send on it (though wrapping may 341 // If the entry is connected, then we can send on it (though wrapping may
341 // still be necessary). Otherwise, we can't yet use this connection, so we 342 // still be necessary). Otherwise, we can't yet use this connection, so we
342 // default to the first one. 343 // default to the first one.
343 if (!entry || !entry->connected()) { 344 if (!entry || !entry->connected()) {
344 ASSERT(!entries_.empty()); 345 RTC_DCHECK(!entries_.empty());
345 entry = entries_[0]; 346 entry = entries_[0];
346 if (!entry->connected()) { 347 if (!entry->connected()) {
347 error_ = ENOTCONN; 348 error_ = ENOTCONN;
348 return SOCKET_ERROR; 349 return SOCKET_ERROR;
349 } 350 }
350 } 351 }
351 352
352 // Send the actual contents to the server using the usual mechanism. 353 // Send the actual contents to the server using the usual mechanism.
353 int sent = entry->SendTo(data, size, addr, options); 354 int sent = entry->SendTo(data, size, addr, options);
354 if (sent <= 0) { 355 if (sent <= 0) {
355 ASSERT(sent < 0); 356 RTC_DCHECK(sent < 0);
356 error_ = entry->GetError(); 357 error_ = entry->GetError();
357 return SOCKET_ERROR; 358 return SOCKET_ERROR;
358 } 359 }
359 // The caller of the function is expecting the number of user data bytes, 360 // The caller of the function is expecting the number of user data bytes,
360 // rather than the size of the packet. 361 // rather than the size of the packet.
361 return static_cast<int>(size); 362 return static_cast<int>(size);
362 } 363 }
363 364
364 int RelayPort::SetOption(rtc::Socket::Option opt, int value) { 365 int RelayPort::SetOption(rtc::Socket::Option opt, int value) {
365 int result = 0; 366 int result = 0;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 } 429 }
429 430
430 void RelayConnection::OnSendPacket(const void* data, size_t size, 431 void RelayConnection::OnSendPacket(const void* data, size_t size,
431 StunRequest* req) { 432 StunRequest* req) {
432 // TODO(mallinath) Find a way to get DSCP value from Port. 433 // TODO(mallinath) Find a way to get DSCP value from Port.
433 rtc::PacketOptions options; // Default dscp set to NO_CHANGE. 434 rtc::PacketOptions options; // Default dscp set to NO_CHANGE.
434 int sent = socket_->SendTo(data, size, GetAddress(), options); 435 int sent = socket_->SendTo(data, size, GetAddress(), options);
435 if (sent <= 0) { 436 if (sent <= 0) {
436 LOG(LS_VERBOSE) << "OnSendPacket: failed sending to " << GetAddress() << 437 LOG(LS_VERBOSE) << "OnSendPacket: failed sending to " << GetAddress() <<
437 strerror(socket_->GetError()); 438 strerror(socket_->GetError());
438 ASSERT(sent < 0); 439 RTC_DCHECK(sent < 0);
439 } 440 }
440 } 441 }
441 442
442 int RelayConnection::Send(const void* pv, size_t cb, 443 int RelayConnection::Send(const void* pv, size_t cb,
443 const rtc::PacketOptions& options) { 444 const rtc::PacketOptions& options) {
444 return socket_->SendTo(pv, cb, GetAddress(), options); 445 return socket_->SendTo(pv, cb, GetAddress(), options);
445 } 446 }
446 447
447 void RelayConnection::SendAllocateRequest(RelayEntry* entry, int delay) { 448 void RelayConnection::SendAllocateRequest(RelayEntry* entry, int delay) {
448 request_manager_->SendDelayed(new AllocateRequest(entry, this), delay); 449 request_manager_->SendDelayed(new AllocateRequest(entry, this), delay);
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 if (current_connection_) 639 if (current_connection_)
639 port()->SignalConnectFailure(current_connection_->protocol_address()); 640 port()->SignalConnectFailure(current_connection_->protocol_address());
640 641
641 // Try to connect to the next server address. 642 // Try to connect to the next server address.
642 server_index_ += 1; 643 server_index_ += 1;
643 Connect(); 644 Connect();
644 } 645 }
645 } 646 }
646 647
647 void RelayEntry::OnMessage(rtc::Message *pmsg) { 648 void RelayEntry::OnMessage(rtc::Message *pmsg) {
648 ASSERT(pmsg->message_id == kMessageConnectTimeout); 649 RTC_DCHECK(pmsg->message_id == kMessageConnectTimeout);
649 if (current_connection_) { 650 if (current_connection_) {
650 const ProtocolAddress* ra = current_connection_->protocol_address(); 651 const ProtocolAddress* ra = current_connection_->protocol_address();
651 LOG(LS_WARNING) << "Relay " << ra->proto << " connection to " << 652 LOG(LS_WARNING) << "Relay " << ra->proto << " connection to " <<
652 ra->address << " timed out"; 653 ra->address << " timed out";
653 654
654 // Currently we connect to each server address in sequence. If we 655 // Currently we connect to each server address in sequence. If we
655 // have more addresses to try, treat this is an error and move on to 656 // have more addresses to try, treat this is an error and move on to
656 // the next address, otherwise give this connection more time and 657 // the next address, otherwise give this connection more time and
657 // await the real timeout. 658 // await the real timeout.
658 // 659 //
(...skipping 18 matching lines...) Expand all
677 int error) { 678 int error) {
678 PLOG(LERROR, error) << "Relay connection failed: socket closed"; 679 PLOG(LERROR, error) << "Relay connection failed: socket closed";
679 HandleConnectFailure(socket); 680 HandleConnectFailure(socket);
680 } 681 }
681 682
682 void RelayEntry::OnReadPacket( 683 void RelayEntry::OnReadPacket(
683 rtc::AsyncPacketSocket* socket, 684 rtc::AsyncPacketSocket* socket,
684 const char* data, size_t size, 685 const char* data, size_t size,
685 const rtc::SocketAddress& remote_addr, 686 const rtc::SocketAddress& remote_addr,
686 const rtc::PacketTime& packet_time) { 687 const rtc::PacketTime& packet_time) {
687 // ASSERT(remote_addr == port_->server_addr()); 688 // RTC_DCHECK(remote_addr == port_->server_addr());
688 // TODO: are we worried about this? 689 // TODO: are we worried about this?
689 690
690 if (current_connection_ == NULL || socket != current_connection_->socket()) { 691 if (current_connection_ == NULL || socket != current_connection_->socket()) {
691 // This packet comes from an unknown address. 692 // This packet comes from an unknown address.
692 LOG(WARNING) << "Dropping packet: unknown address"; 693 LOG(WARNING) << "Dropping packet: unknown address";
693 return; 694 return;
694 } 695 }
695 696
696 // If the magic cookie is not present, then this is an unwrapped packet sent 697 // If the magic cookie is not present, then this is an unwrapped packet sent
697 // by the server, The actual remote address is the one we recorded. 698 // by the server, The actual remote address is the one we recorded.
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
838 if (rtc::TimeMillis() - start_time_ <= kRetryTimeout) 839 if (rtc::TimeMillis() - start_time_ <= kRetryTimeout)
839 entry_->ScheduleKeepAlive(); 840 entry_->ScheduleKeepAlive();
840 } 841 }
841 842
842 void AllocateRequest::OnTimeout() { 843 void AllocateRequest::OnTimeout() {
843 LOG(INFO) << "Allocate request timed out"; 844 LOG(INFO) << "Allocate request timed out";
844 entry_->HandleConnectFailure(connection_->socket()); 845 entry_->HandleConnectFailure(connection_->socket());
845 } 846 }
846 847
847 } // namespace cricket 848 } // namespace cricket
OLDNEW
« no previous file with comments | « webrtc/p2p/base/pseudotcp.cc ('k') | webrtc/p2p/base/relayserver.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698