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

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

Issue 2568833002: Refactor "secure bool" into explicit PROTO_TLS. (Closed)
Patch Set: Created 4 years 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/relayport.cc ('k') | webrtc/p2p/base/turnport_unittest.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 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 26 matching lines...) Expand all
37 // Retry at most twice (i.e. three different ALLOCATE requests) on 37 // Retry at most twice (i.e. three different ALLOCATE requests) on
38 // STUN_ERROR_ALLOCATION_MISMATCH error per rfc5766. 38 // STUN_ERROR_ALLOCATION_MISMATCH error per rfc5766.
39 static const size_t MAX_ALLOCATE_MISMATCH_RETRIES = 2; 39 static const size_t MAX_ALLOCATE_MISMATCH_RETRIES = 2;
40 40
41 static const int TURN_SUCCESS_RESULT_CODE = 0; 41 static const int TURN_SUCCESS_RESULT_CODE = 0;
42 42
43 inline bool IsTurnChannelData(uint16_t msg_type) { 43 inline bool IsTurnChannelData(uint16_t msg_type) {
44 return ((msg_type & 0xC000) == 0x4000); // MSB are 0b01 44 return ((msg_type & 0xC000) == 0x4000); // MSB are 0b01
45 } 45 }
46 46
47 static int GetRelayPreference(cricket::ProtocolType proto, bool secure) { 47 static int GetRelayPreference(cricket::ProtocolType proto) {
48 int relay_preference = ICE_TYPE_PREFERENCE_RELAY; 48 switch (proto) {
49 if (proto == cricket::PROTO_TCP) { 49 case cricket::PROTO_TCP:
50 relay_preference -= 1; 50 return ICE_TYPE_PREFERENCE_RELAY_TCP;
51 if (secure) 51 case cricket::PROTO_TLS:
52 relay_preference -= 1; 52 return ICE_TYPE_PREFERENCE_RELAY_TLS;
53 default:
Taylor Brandstetter 2016/12/13 00:31:40 nit: I'd RTC_DCHECK that proto is PROTO_UDP, in ca
hnsl1 2016/12/13 12:53:02 Done.
54 return ICE_TYPE_PREFERENCE_RELAY_UDP;
53 } 55 }
54
55 ASSERT(relay_preference >= 0);
56 return relay_preference;
57 } 56 }
58 57
59 class TurnAllocateRequest : public StunRequest { 58 class TurnAllocateRequest : public StunRequest {
60 public: 59 public:
61 explicit TurnAllocateRequest(TurnPort* port); 60 explicit TurnAllocateRequest(TurnPort* port);
62 void Prepare(StunMessage* request) override; 61 void Prepare(StunMessage* request) override;
63 void OnSent() override; 62 void OnSent() override;
64 void OnResponse(StunMessage* response) override; 63 void OnResponse(StunMessage* response) override;
65 void OnErrorResponse(StunMessage* response) override; 64 void OnErrorResponse(StunMessage* response) override;
66 void OnTimeout() override; 65 void OnTimeout() override;
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 } 314 }
316 } 315 }
317 } 316 }
318 317
319 bool TurnPort::CreateTurnClientSocket() { 318 bool TurnPort::CreateTurnClientSocket() {
320 ASSERT(!socket_ || SharedSocket()); 319 ASSERT(!socket_ || SharedSocket());
321 320
322 if (server_address_.proto == PROTO_UDP && !SharedSocket()) { 321 if (server_address_.proto == PROTO_UDP && !SharedSocket()) {
323 socket_ = socket_factory()->CreateUdpSocket( 322 socket_ = socket_factory()->CreateUdpSocket(
324 rtc::SocketAddress(ip(), 0), min_port(), max_port()); 323 rtc::SocketAddress(ip(), 0), min_port(), max_port());
325 } else if (server_address_.proto == PROTO_TCP) { 324 } else if (server_address_.proto == PROTO_TCP ||
325 server_address_.proto == PROTO_TLS) {
326 ASSERT(!SharedSocket()); 326 ASSERT(!SharedSocket());
327 int opts = rtc::PacketSocketFactory::OPT_STUN; 327 int opts = rtc::PacketSocketFactory::OPT_STUN;
328 // If secure bit is enabled in server address, use TLS over TCP. 328
329 if (server_address_.secure) { 329 // Apply server address TLS and insecure bits to options.
330 if (server_address_.proto == PROTO_TLS) {
330 opts |= rtc::PacketSocketFactory::OPT_TLS; 331 opts |= rtc::PacketSocketFactory::OPT_TLS;
331 } 332 }
332 socket_ = socket_factory()->CreateClientTcpSocket( 333 socket_ = socket_factory()->CreateClientTcpSocket(
333 rtc::SocketAddress(ip(), 0), server_address_.address, 334 rtc::SocketAddress(ip(), 0), server_address_.address,
334 proxy(), user_agent(), opts); 335 proxy(), user_agent(), opts);
335 } 336 }
336 337
337 if (!socket_) { 338 if (!socket_) {
338 error_ = SOCKET_ERROR; 339 error_ = SOCKET_ERROR;
339 return false; 340 return false;
340 } 341 }
341 342
342 // Apply options if any. 343 // Apply options if any.
343 for (SocketOptionsMap::iterator iter = socket_options_.begin(); 344 for (SocketOptionsMap::iterator iter = socket_options_.begin();
344 iter != socket_options_.end(); ++iter) { 345 iter != socket_options_.end(); ++iter) {
345 socket_->SetOption(iter->first, iter->second); 346 socket_->SetOption(iter->first, iter->second);
346 } 347 }
347 348
348 if (!SharedSocket()) { 349 if (!SharedSocket()) {
349 // If socket is shared, AllocationSequence will receive the packet. 350 // If socket is shared, AllocationSequence will receive the packet.
350 socket_->SignalReadPacket.connect(this, &TurnPort::OnReadPacket); 351 socket_->SignalReadPacket.connect(this, &TurnPort::OnReadPacket);
351 } 352 }
352 353
353 socket_->SignalReadyToSend.connect(this, &TurnPort::OnReadyToSend); 354 socket_->SignalReadyToSend.connect(this, &TurnPort::OnReadyToSend);
354 355
355 socket_->SignalSentPacket.connect(this, &TurnPort::OnSentPacket); 356 socket_->SignalSentPacket.connect(this, &TurnPort::OnSentPacket);
356 357
357 // TCP port is ready to send stun requests after the socket is connected, 358 // TCP port is ready to send stun requests after the socket is connected,
358 // while UDP port is ready to do so once the socket is created. 359 // while UDP port is ready to do so once the socket is created.
359 if (server_address_.proto == PROTO_TCP) { 360 if (server_address_.proto == PROTO_TCP ||
361 server_address_.proto == PROTO_TLS) {
360 socket_->SignalConnect.connect(this, &TurnPort::OnSocketConnect); 362 socket_->SignalConnect.connect(this, &TurnPort::OnSocketConnect);
361 socket_->SignalClose.connect(this, &TurnPort::OnSocketClose); 363 socket_->SignalClose.connect(this, &TurnPort::OnSocketClose);
362 } else { 364 } else {
363 state_ = STATE_CONNECTED; 365 state_ = STATE_CONNECTED;
364 } 366 }
365 return true; 367 return true;
366 } 368 }
367 369
368 void TurnPort::OnSocketConnect(rtc::AsyncPacketSocket* socket) { 370 void TurnPort::OnSocketConnect(rtc::AsyncPacketSocket* socket) {
369 ASSERT(server_address_.proto == PROTO_TCP); 371 ASSERT(server_address_.proto == PROTO_TCP);
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 LOG_J(LS_WARNING, this) 647 LOG_J(LS_WARNING, this)
646 << "Blocking attempted redirect to loopback address."; 648 << "Blocking attempted redirect to loopback address.";
647 return false; 649 return false;
648 } 650 }
649 651
650 LOG_J(LS_INFO, this) << "Redirecting from TURN server [" 652 LOG_J(LS_INFO, this) << "Redirecting from TURN server ["
651 << server_address_.address.ToSensitiveString() 653 << server_address_.address.ToSensitiveString()
652 << "] to TURN server [" 654 << "] to TURN server ["
653 << address.ToSensitiveString() 655 << address.ToSensitiveString()
654 << "]"; 656 << "]";
655 server_address_ = ProtocolAddress(address, server_address_.proto, 657 server_address_ = ProtocolAddress(address, server_address_.proto);
656 server_address_.secure);
657 658
658 // Insert the current address to prevent redirection pingpong. 659 // Insert the current address to prevent redirection pingpong.
659 attempted_server_addresses_.insert(server_address_.address); 660 attempted_server_addresses_.insert(server_address_.address);
660 return true; 661 return true;
661 } 662 }
662 663
663 void TurnPort::ResolveTurnAddress(const rtc::SocketAddress& address) { 664 void TurnPort::ResolveTurnAddress(const rtc::SocketAddress& address) {
664 if (resolver_) 665 if (resolver_)
665 return; 666 return;
666 667
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
729 730
730 rtc::SocketAddress related_address = stun_address; 731 rtc::SocketAddress related_address = stun_address;
731 732
732 // For relayed candidate, Base is the candidate itself. 733 // For relayed candidate, Base is the candidate itself.
733 AddAddress(address, // Candidate address. 734 AddAddress(address, // Candidate address.
734 address, // Base address. 735 address, // Base address.
735 related_address, // Related address. 736 related_address, // Related address.
736 UDP_PROTOCOL_NAME, 737 UDP_PROTOCOL_NAME,
737 ProtoToString(server_address_.proto), // The first hop protocol. 738 ProtoToString(server_address_.proto), // The first hop protocol.
738 "", // TCP canddiate type, empty for turn candidates. 739 "", // TCP canddiate type, empty for turn candidates.
739 RELAY_PORT_TYPE, 740 RELAY_PORT_TYPE, GetRelayPreference(server_address_.proto),
740 GetRelayPreference(server_address_.proto, server_address_.secure),
741 server_priority_, true); 741 server_priority_, true);
742 } 742 }
743 743
744 void TurnPort::OnAllocateError() { 744 void TurnPort::OnAllocateError() {
745 // We will send SignalPortError asynchronously as this can be sent during 745 // We will send SignalPortError asynchronously as this can be sent during
746 // port initialization. This way it will not be blocking other port 746 // port initialization. This way it will not be blocking other port
747 // creation. 747 // creation.
748 thread()->Post(RTC_FROM_HERE, this, MSG_ALLOCATE_ERROR); 748 thread()->Post(RTC_FROM_HERE, this, MSG_ALLOCATE_ERROR);
749 } 749 }
750 750
(...skipping 791 matching lines...) Expand 10 before | Expand all | Expand 10 after
1542 } else { 1542 } else {
1543 state_ = STATE_UNBOUND; 1543 state_ = STATE_UNBOUND;
1544 port_->FailAndPruneConnection(ext_addr_); 1544 port_->FailAndPruneConnection(ext_addr_);
1545 } 1545 }
1546 } 1546 }
1547 void TurnEntry::OnChannelBindTimeout() { 1547 void TurnEntry::OnChannelBindTimeout() {
1548 state_ = STATE_UNBOUND; 1548 state_ = STATE_UNBOUND;
1549 port_->FailAndPruneConnection(ext_addr_); 1549 port_->FailAndPruneConnection(ext_addr_);
1550 } 1550 }
1551 } // namespace cricket 1551 } // namespace cricket
OLDNEW
« no previous file with comments | « webrtc/p2p/base/relayport.cc ('k') | webrtc/p2p/base/turnport_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698