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

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

Issue 2685783014: Replace NULL with nullptr in all C++ files. (Closed)
Patch Set: Fixing android. Created 3 years, 10 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 2012 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2012 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 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 : Port(thread, 192 : Port(thread,
193 RELAY_PORT_TYPE, 193 RELAY_PORT_TYPE,
194 factory, 194 factory,
195 network, 195 network,
196 socket->GetLocalAddress().ipaddr(), 196 socket->GetLocalAddress().ipaddr(),
197 username, 197 username,
198 password), 198 password),
199 server_address_(server_address), 199 server_address_(server_address),
200 credentials_(credentials), 200 credentials_(credentials),
201 socket_(socket), 201 socket_(socket),
202 resolver_(NULL), 202 resolver_(nullptr),
203 error_(0), 203 error_(0),
204 request_manager_(thread), 204 request_manager_(thread),
205 next_channel_number_(TURN_CHANNEL_NUMBER_START), 205 next_channel_number_(TURN_CHANNEL_NUMBER_START),
206 state_(STATE_CONNECTING), 206 state_(STATE_CONNECTING),
207 server_priority_(server_priority), 207 server_priority_(server_priority),
208 allocate_mismatch_retries_(0) { 208 allocate_mismatch_retries_(0) {
209 request_manager_.SignalSendPacket.connect(this, &TurnPort::OnSendStunPacket); 209 request_manager_.SignalSendPacket.connect(this, &TurnPort::OnSendStunPacket);
210 request_manager_.set_origin(origin); 210 request_manager_.set_origin(origin);
211 } 211 }
212 212
(...skipping 13 matching lines...) Expand all
226 RELAY_PORT_TYPE, 226 RELAY_PORT_TYPE,
227 factory, 227 factory,
228 network, 228 network,
229 ip, 229 ip,
230 min_port, 230 min_port,
231 max_port, 231 max_port,
232 username, 232 username,
233 password), 233 password),
234 server_address_(server_address), 234 server_address_(server_address),
235 credentials_(credentials), 235 credentials_(credentials),
236 socket_(NULL), 236 socket_(nullptr),
237 resolver_(NULL), 237 resolver_(nullptr),
238 error_(0), 238 error_(0),
239 request_manager_(thread), 239 request_manager_(thread),
240 next_channel_number_(TURN_CHANNEL_NUMBER_START), 240 next_channel_number_(TURN_CHANNEL_NUMBER_START),
241 state_(STATE_CONNECTING), 241 state_(STATE_CONNECTING),
242 server_priority_(server_priority), 242 server_priority_(server_priority),
243 allocate_mismatch_retries_(0) { 243 allocate_mismatch_retries_(0) {
244 request_manager_.SignalSendPacket.connect(this, &TurnPort::OnSendStunPacket); 244 request_manager_.SignalSendPacket.connect(this, &TurnPort::OnSendStunPacket);
245 request_manager_.set_origin(origin); 245 request_manager_.set_origin(origin);
246 } 246 }
247 247
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 } 434 }
435 435
436 LOG_J(LS_INFO, this) << "Allocating a new socket after " 436 LOG_J(LS_INFO, this) << "Allocating a new socket after "
437 << "STUN_ERROR_ALLOCATION_MISMATCH, retry = " 437 << "STUN_ERROR_ALLOCATION_MISMATCH, retry = "
438 << allocate_mismatch_retries_ + 1; 438 << allocate_mismatch_retries_ + 1;
439 if (SharedSocket()) { 439 if (SharedSocket()) {
440 ResetSharedSocket(); 440 ResetSharedSocket();
441 } else { 441 } else {
442 delete socket_; 442 delete socket_;
443 } 443 }
444 socket_ = NULL; 444 socket_ = nullptr;
445 445
446 ResetNonce(); 446 ResetNonce();
447 PrepareAddress(); 447 PrepareAddress();
448 ++allocate_mismatch_retries_; 448 ++allocate_mismatch_retries_;
449 } 449 }
450 450
451 Connection* TurnPort::CreateConnection(const Candidate& remote_candidate, 451 Connection* TurnPort::CreateConnection(const Candidate& remote_candidate,
452 CandidateOrigin origin) { 452 CandidateOrigin origin) {
453 // TURN-UDP can only connect to UDP candidates. 453 // TURN-UDP can only connect to UDP candidates.
454 if (!SupportsProtocol(remote_candidate.protocol())) { 454 if (!SupportsProtocol(remote_candidate.protocol())) {
455 return NULL; 455 return nullptr;
456 } 456 }
457 457
458 if (state_ == STATE_DISCONNECTED || state_ == STATE_RECEIVEONLY) { 458 if (state_ == STATE_DISCONNECTED || state_ == STATE_RECEIVEONLY) {
459 return NULL; 459 return nullptr;
460 } 460 }
461 461
462 // A TURN port will have two candiates, STUN and TURN. STUN may not 462 // A TURN port will have two candiates, STUN and TURN. STUN may not
463 // present in all cases. If present stun candidate will be added first 463 // present in all cases. If present stun candidate will be added first
464 // and TURN candidate later. 464 // and TURN candidate later.
465 for (size_t index = 0; index < Candidates().size(); ++index) { 465 for (size_t index = 0; index < Candidates().size(); ++index) {
466 const Candidate& local_candidate = Candidates()[index]; 466 const Candidate& local_candidate = Candidates()[index];
467 if (local_candidate.type() == RELAY_PORT_TYPE && 467 if (local_candidate.type() == RELAY_PORT_TYPE &&
468 local_candidate.address().family() == 468 local_candidate.address().family() ==
469 remote_candidate.address().family()) { 469 remote_candidate.address().family()) {
470 // Create an entry, if needed, so we can get our permissions set up 470 // Create an entry, if needed, so we can get our permissions set up
471 // correctly. 471 // correctly.
472 CreateOrRefreshEntry(remote_candidate.address()); 472 CreateOrRefreshEntry(remote_candidate.address());
473 ProxyConnection* conn = 473 ProxyConnection* conn =
474 new ProxyConnection(this, index, remote_candidate); 474 new ProxyConnection(this, index, remote_candidate);
475 AddOrReplaceConnection(conn); 475 AddOrReplaceConnection(conn);
476 return conn; 476 return conn;
477 } 477 }
478 } 478 }
479 return NULL; 479 return nullptr;
480 } 480 }
481 481
482 bool TurnPort::FailAndPruneConnection(const rtc::SocketAddress& address) { 482 bool TurnPort::FailAndPruneConnection(const rtc::SocketAddress& address) {
483 Connection* conn = GetConnection(address); 483 Connection* conn = GetConnection(address);
484 if (conn != nullptr) { 484 if (conn != nullptr) {
485 conn->FailAndPrune(); 485 conn->FailAndPrune();
486 return true; 486 return true;
487 } 487 }
488 return false; 488 return false;
489 } 489 }
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
800 // Send another allocate request to alternate server, with the received 800 // Send another allocate request to alternate server, with the received
801 // realm and nonce values. 801 // realm and nonce values.
802 SendRequest(new TurnAllocateRequest(this), 0); 802 SendRequest(new TurnAllocateRequest(this), 0);
803 } else { 803 } else {
804 // Since it's TCP, we have to delete the connected socket and reconnect 804 // Since it's TCP, we have to delete the connected socket and reconnect
805 // with the alternate server. PrepareAddress will send stun binding once 805 // with the alternate server. PrepareAddress will send stun binding once
806 // the new socket is connected. 806 // the new socket is connected.
807 RTC_DCHECK(server_address().proto == PROTO_TCP); 807 RTC_DCHECK(server_address().proto == PROTO_TCP);
808 RTC_DCHECK(!SharedSocket()); 808 RTC_DCHECK(!SharedSocket());
809 delete socket_; 809 delete socket_;
810 socket_ = NULL; 810 socket_ = nullptr;
811 PrepareAddress(); 811 PrepareAddress();
812 } 812 }
813 break; 813 break;
814 default: 814 default:
815 Port::OnMessage(message); 815 Port::OnMessage(message);
816 } 816 }
817 } 817 }
818 818
819 void TurnPort::OnAllocateRequestTimeout() { 819 void TurnPort::OnAllocateRequestTimeout() {
820 OnAllocateError(); 820 OnAllocateError();
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
986 return (std::find_if(entries_.begin(), entries_.end(), 986 return (std::find_if(entries_.begin(), entries_.end(),
987 std::bind2nd(std::ptr_fun(MatchesIP), ipaddr)) != entries_.end()); 987 std::bind2nd(std::ptr_fun(MatchesIP), ipaddr)) != entries_.end());
988 } 988 }
989 989
990 static bool MatchesAddress(TurnEntry* e, rtc::SocketAddress addr) { 990 static bool MatchesAddress(TurnEntry* e, rtc::SocketAddress addr) {
991 return e->address() == addr; 991 return e->address() == addr;
992 } 992 }
993 TurnEntry* TurnPort::FindEntry(const rtc::SocketAddress& addr) const { 993 TurnEntry* TurnPort::FindEntry(const rtc::SocketAddress& addr) const {
994 EntryList::const_iterator it = std::find_if(entries_.begin(), entries_.end(), 994 EntryList::const_iterator it = std::find_if(entries_.begin(), entries_.end(),
995 std::bind2nd(std::ptr_fun(MatchesAddress), addr)); 995 std::bind2nd(std::ptr_fun(MatchesAddress), addr));
996 return (it != entries_.end()) ? *it : NULL; 996 return (it != entries_.end()) ? *it : nullptr;
997 } 997 }
998 998
999 static bool MatchesChannelId(TurnEntry* e, int id) { 999 static bool MatchesChannelId(TurnEntry* e, int id) {
1000 return e->channel_id() == id; 1000 return e->channel_id() == id;
1001 } 1001 }
1002 TurnEntry* TurnPort::FindEntry(int channel_id) const { 1002 TurnEntry* TurnPort::FindEntry(int channel_id) const {
1003 EntryList::const_iterator it = std::find_if(entries_.begin(), entries_.end(), 1003 EntryList::const_iterator it = std::find_if(entries_.begin(), entries_.end(),
1004 std::bind2nd(std::ptr_fun(MatchesChannelId), channel_id)); 1004 std::bind2nd(std::ptr_fun(MatchesChannelId), channel_id));
1005 return (it != entries_.end()) ? *it : NULL; 1005 return (it != entries_.end()) ? *it : nullptr;
1006 } 1006 }
1007 1007
1008 bool TurnPort::EntryExists(TurnEntry* e) { 1008 bool TurnPort::EntryExists(TurnEntry* e) {
1009 auto it = std::find(entries_.begin(), entries_.end(), e); 1009 auto it = std::find(entries_.begin(), entries_.end(), e);
1010 return it != entries_.end(); 1010 return it != entries_.end();
1011 } 1011 }
1012 1012
1013 void TurnPort::CreateOrRefreshEntry(const rtc::SocketAddress& addr) { 1013 void TurnPort::CreateOrRefreshEntry(const rtc::SocketAddress& addr) {
1014 TurnEntry* entry = FindEntry(addr); 1014 TurnEntry* entry = FindEntry(addr);
1015 if (entry == nullptr) { 1015 if (entry == nullptr) {
1016 entry = new TurnEntry(this, next_channel_number_++, addr); 1016 entry = new TurnEntry(this, next_channel_number_++, addr);
1017 entries_.push_back(entry); 1017 entries_.push_back(entry);
1018 } else { 1018 } else {
1019 // The channel binding request for the entry will be refreshed automatically 1019 // The channel binding request for the entry will be refreshed automatically
1020 // until the entry is destroyed. 1020 // until the entry is destroyed.
1021 CancelEntryDestruction(entry); 1021 CancelEntryDestruction(entry);
1022 } 1022 }
1023 } 1023 }
1024 1024
1025 void TurnPort::DestroyEntry(TurnEntry* entry) { 1025 void TurnPort::DestroyEntry(TurnEntry* entry) {
1026 RTC_DCHECK(entry != NULL); 1026 RTC_DCHECK(entry != nullptr);
1027 entry->SignalDestroyed(entry); 1027 entry->SignalDestroyed(entry);
1028 entries_.remove(entry); 1028 entries_.remove(entry);
1029 delete entry; 1029 delete entry;
1030 } 1030 }
1031 1031
1032 void TurnPort::DestroyEntryIfNotCancelled(TurnEntry* entry, int64_t timestamp) { 1032 void TurnPort::DestroyEntryIfNotCancelled(TurnEntry* entry, int64_t timestamp) {
1033 if (!EntryExists(entry)) { 1033 if (!EntryExists(entry)) {
1034 return; 1034 return;
1035 } 1035 }
1036 bool cancelled = timestamp != entry->destruction_timestamp(); 1036 bool cancelled = timestamp != entry->destruction_timestamp();
1037 if (!cancelled) { 1037 if (!cancelled) {
1038 DestroyEntry(entry); 1038 DestroyEntry(entry);
1039 } 1039 }
1040 } 1040 }
1041 1041
1042 void TurnPort::HandleConnectionDestroyed(Connection* conn) { 1042 void TurnPort::HandleConnectionDestroyed(Connection* conn) {
1043 // Schedule an event to destroy TurnEntry for the connection, which is 1043 // Schedule an event to destroy TurnEntry for the connection, which is
1044 // already destroyed. 1044 // already destroyed.
1045 const rtc::SocketAddress& remote_address = conn->remote_candidate().address(); 1045 const rtc::SocketAddress& remote_address = conn->remote_candidate().address();
1046 TurnEntry* entry = FindEntry(remote_address); 1046 TurnEntry* entry = FindEntry(remote_address);
1047 RTC_DCHECK(entry != NULL); 1047 RTC_DCHECK(entry != nullptr);
1048 ScheduleEntryDestruction(entry); 1048 ScheduleEntryDestruction(entry);
1049 } 1049 }
1050 1050
1051 void TurnPort::ScheduleEntryDestruction(TurnEntry* entry) { 1051 void TurnPort::ScheduleEntryDestruction(TurnEntry* entry) {
1052 RTC_DCHECK(entry->destruction_timestamp() == 0); 1052 RTC_DCHECK(entry->destruction_timestamp() == 0);
1053 int64_t timestamp = rtc::TimeMillis(); 1053 int64_t timestamp = rtc::TimeMillis();
1054 entry->set_destruction_timestamp(timestamp); 1054 entry->set_destruction_timestamp(timestamp);
1055 invoker_.AsyncInvokeDelayed<void>( 1055 invoker_.AsyncInvokeDelayed<void>(
1056 RTC_FROM_HERE, thread(), 1056 RTC_FROM_HERE, thread(),
1057 rtc::Bind(&TurnPort::DestroyEntryIfNotCancelled, this, entry, timestamp), 1057 rtc::Bind(&TurnPort::DestroyEntryIfNotCancelled, this, entry, timestamp),
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
1364 void TurnCreatePermissionRequest::OnTimeout() { 1364 void TurnCreatePermissionRequest::OnTimeout() {
1365 LOG_J(LS_WARNING, port_) << "TURN create permission timeout " 1365 LOG_J(LS_WARNING, port_) << "TURN create permission timeout "
1366 << rtc::hex_encode(id()); 1366 << rtc::hex_encode(id());
1367 if (entry_) { 1367 if (entry_) {
1368 entry_->OnCreatePermissionTimeout(); 1368 entry_->OnCreatePermissionTimeout();
1369 } 1369 }
1370 } 1370 }
1371 1371
1372 void TurnCreatePermissionRequest::OnEntryDestroyed(TurnEntry* entry) { 1372 void TurnCreatePermissionRequest::OnEntryDestroyed(TurnEntry* entry) {
1373 RTC_DCHECK(entry_ == entry); 1373 RTC_DCHECK(entry_ == entry);
1374 entry_ = NULL; 1374 entry_ = nullptr;
1375 } 1375 }
1376 1376
1377 TurnChannelBindRequest::TurnChannelBindRequest( 1377 TurnChannelBindRequest::TurnChannelBindRequest(
1378 TurnPort* port, TurnEntry* entry, 1378 TurnPort* port, TurnEntry* entry,
1379 int channel_id, const rtc::SocketAddress& ext_addr) 1379 int channel_id, const rtc::SocketAddress& ext_addr)
1380 : StunRequest(new TurnMessage()), 1380 : StunRequest(new TurnMessage()),
1381 port_(port), 1381 port_(port),
1382 entry_(entry), 1382 entry_(entry),
1383 channel_id_(channel_id), 1383 channel_id_(channel_id),
1384 ext_addr_(ext_addr) { 1384 ext_addr_(ext_addr) {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1434 void TurnChannelBindRequest::OnTimeout() { 1434 void TurnChannelBindRequest::OnTimeout() {
1435 LOG_J(LS_WARNING, port_) << "TURN channel bind timeout " 1435 LOG_J(LS_WARNING, port_) << "TURN channel bind timeout "
1436 << rtc::hex_encode(id()); 1436 << rtc::hex_encode(id());
1437 if (entry_) { 1437 if (entry_) {
1438 entry_->OnChannelBindTimeout(); 1438 entry_->OnChannelBindTimeout();
1439 } 1439 }
1440 } 1440 }
1441 1441
1442 void TurnChannelBindRequest::OnEntryDestroyed(TurnEntry* entry) { 1442 void TurnChannelBindRequest::OnEntryDestroyed(TurnEntry* entry) {
1443 RTC_DCHECK(entry_ == entry); 1443 RTC_DCHECK(entry_ == entry);
1444 entry_ = NULL; 1444 entry_ = nullptr;
1445 } 1445 }
1446 1446
1447 TurnEntry::TurnEntry(TurnPort* port, int channel_id, 1447 TurnEntry::TurnEntry(TurnPort* port, int channel_id,
1448 const rtc::SocketAddress& ext_addr) 1448 const rtc::SocketAddress& ext_addr)
1449 : port_(port), 1449 : port_(port),
1450 channel_id_(channel_id), 1450 channel_id_(channel_id),
1451 ext_addr_(ext_addr), 1451 ext_addr_(ext_addr),
1452 state_(STATE_UNBOUND) { 1452 state_(STATE_UNBOUND) {
1453 // Creating permission for |ext_addr_|. 1453 // Creating permission for |ext_addr_|.
1454 SendCreatePermissionRequest(0); 1454 SendCreatePermissionRequest(0);
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
1552 } else { 1552 } else {
1553 state_ = STATE_UNBOUND; 1553 state_ = STATE_UNBOUND;
1554 port_->FailAndPruneConnection(ext_addr_); 1554 port_->FailAndPruneConnection(ext_addr_);
1555 } 1555 }
1556 } 1556 }
1557 void TurnEntry::OnChannelBindTimeout() { 1557 void TurnEntry::OnChannelBindTimeout() {
1558 state_ = STATE_UNBOUND; 1558 state_ = STATE_UNBOUND;
1559 port_->FailAndPruneConnection(ext_addr_); 1559 port_->FailAndPruneConnection(ext_addr_);
1560 } 1560 }
1561 } // namespace cricket 1561 } // namespace cricket
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698