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

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

Issue 1595613004: Reset TURN port NONCE when a new socket is created. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Created 4 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
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 415 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 LOG_J(LS_INFO, this) << "Allocating a new socket after " 426 LOG_J(LS_INFO, this) << "Allocating a new socket after "
427 << "STUN_ERROR_ALLOCATION_MISMATCH, retry = " 427 << "STUN_ERROR_ALLOCATION_MISMATCH, retry = "
428 << allocate_mismatch_retries_ + 1; 428 << allocate_mismatch_retries_ + 1;
429 if (SharedSocket()) { 429 if (SharedSocket()) {
430 ResetSharedSocket(); 430 ResetSharedSocket();
431 } else { 431 } else {
432 delete socket_; 432 delete socket_;
433 } 433 }
434 socket_ = NULL; 434 socket_ = NULL;
435 435
436 ResetNonce();
436 PrepareAddress(); 437 PrepareAddress();
437 ++allocate_mismatch_retries_; 438 ++allocate_mismatch_retries_;
438 } 439 }
439 440
440 Connection* TurnPort::CreateConnection(const Candidate& address, 441 Connection* TurnPort::CreateConnection(const Candidate& address,
441 CandidateOrigin origin) { 442 CandidateOrigin origin) {
442 // TURN-UDP can only connect to UDP candidates. 443 // TURN-UDP can only connect to UDP candidates.
443 if (!SupportsProtocol(address.protocol())) { 444 if (!SupportsProtocol(address.protocol())) {
444 return NULL; 445 return NULL;
445 } 446 }
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
757 // realm and nonce values. 758 // realm and nonce values.
758 SendRequest(new TurnAllocateRequest(this), 0); 759 SendRequest(new TurnAllocateRequest(this), 0);
759 } else { 760 } else {
760 // Since it's TCP, we have to delete the connected socket and reconnect 761 // Since it's TCP, we have to delete the connected socket and reconnect
761 // with the alternate server. PrepareAddress will send stun binding once 762 // with the alternate server. PrepareAddress will send stun binding once
762 // the new socket is connected. 763 // the new socket is connected.
763 ASSERT(server_address().proto == PROTO_TCP); 764 ASSERT(server_address().proto == PROTO_TCP);
764 ASSERT(!SharedSocket()); 765 ASSERT(!SharedSocket());
765 delete socket_; 766 delete socket_;
766 socket_ = NULL; 767 socket_ = NULL;
768 ResetNonce();
pthatcher1 2016/01/19 01:48:38 It looks like we don't have a unit test for this.
honghaiz3 2016/01/20 00:54:38 I removed this change because The alternate server
767 PrepareAddress(); 769 PrepareAddress();
768 } 770 }
769 break; 771 break;
770 default: 772 default:
771 Port::OnMessage(message); 773 Port::OnMessage(message);
772 } 774 }
773 } 775 }
774 776
775 void TurnPort::OnAllocateRequestTimeout() { 777 void TurnPort::OnAllocateRequestTimeout() {
776 OnAllocateError(); 778 OnAllocateError();
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
920 response->GetByteString(STUN_ATTR_NONCE); 922 response->GetByteString(STUN_ATTR_NONCE);
921 if (!nonce_attr) { 923 if (!nonce_attr) {
922 LOG(LS_ERROR) << "Missing STUN_ATTR_NONCE attribute in " 924 LOG(LS_ERROR) << "Missing STUN_ATTR_NONCE attribute in "
923 << "stale nonce error response."; 925 << "stale nonce error response.";
924 return false; 926 return false;
925 } 927 }
926 set_nonce(nonce_attr->GetString()); 928 set_nonce(nonce_attr->GetString());
927 return true; 929 return true;
928 } 930 }
929 931
932 void TurnPort::ResetNonce() {
933 hash_.clear();
934 nonce_.clear();
935 realm_.clear();
936 }
937
930 static bool MatchesIP(TurnEntry* e, rtc::IPAddress ipaddr) { 938 static bool MatchesIP(TurnEntry* e, rtc::IPAddress ipaddr) {
931 return e->address().ipaddr() == ipaddr; 939 return e->address().ipaddr() == ipaddr;
932 } 940 }
933 bool TurnPort::HasPermission(const rtc::IPAddress& ipaddr) const { 941 bool TurnPort::HasPermission(const rtc::IPAddress& ipaddr) const {
934 return (std::find_if(entries_.begin(), entries_.end(), 942 return (std::find_if(entries_.begin(), entries_.end(),
935 std::bind2nd(std::ptr_fun(MatchesIP), ipaddr)) != entries_.end()); 943 std::bind2nd(std::ptr_fun(MatchesIP), ipaddr)) != entries_.end());
936 } 944 }
937 945
938 static bool MatchesAddress(TurnEntry* e, rtc::SocketAddress addr) { 946 static bool MatchesAddress(TurnEntry* e, rtc::SocketAddress addr) {
939 return e->address() == addr; 947 return e->address() == addr;
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after
1500 } else { 1508 } else {
1501 state_ = STATE_UNBOUND; 1509 state_ = STATE_UNBOUND;
1502 port_->DestroyConnection(ext_addr_); 1510 port_->DestroyConnection(ext_addr_);
1503 } 1511 }
1504 } 1512 }
1505 void TurnEntry::OnChannelBindTimeout() { 1513 void TurnEntry::OnChannelBindTimeout() {
1506 state_ = STATE_UNBOUND; 1514 state_ = STATE_UNBOUND;
1507 port_->DestroyConnection(ext_addr_); 1515 port_->DestroyConnection(ext_addr_);
1508 } 1516 }
1509 } // namespace cricket 1517 } // namespace cricket
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698