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

Unified Diff: webrtc/p2p/base/turnport.cc

Issue 2568833002: Refactor "secure bool" into explicit PROTO_TLS. (Closed)
Patch Set: GetRelayPreference(): Add RTC_DCHECK(proto == PROTO_UDP). 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/p2p/base/turnport.cc
diff --git a/webrtc/p2p/base/turnport.cc b/webrtc/p2p/base/turnport.cc
index a34d25b612357d1e422468bcba1a3db029dc75bf..d2d9126c7a302ba35bc04999ef83ddf09e9175a8 100644
--- a/webrtc/p2p/base/turnport.cc
+++ b/webrtc/p2p/base/turnport.cc
@@ -44,16 +44,16 @@ inline bool IsTurnChannelData(uint16_t msg_type) {
return ((msg_type & 0xC000) == 0x4000); // MSB are 0b01
}
-static int GetRelayPreference(cricket::ProtocolType proto, bool secure) {
- int relay_preference = ICE_TYPE_PREFERENCE_RELAY;
- if (proto == cricket::PROTO_TCP) {
- relay_preference -= 1;
- if (secure)
- relay_preference -= 1;
+static int GetRelayPreference(cricket::ProtocolType proto) {
+ switch (proto) {
+ case cricket::PROTO_TCP:
+ return ICE_TYPE_PREFERENCE_RELAY_TCP;
+ case cricket::PROTO_TLS:
+ return ICE_TYPE_PREFERENCE_RELAY_TLS;
+ default:
+ RTC_DCHECK(proto == PROTO_UDP);
+ return ICE_TYPE_PREFERENCE_RELAY_UDP;
}
-
- ASSERT(relay_preference >= 0);
- return relay_preference;
}
class TurnAllocateRequest : public StunRequest {
@@ -322,11 +322,13 @@ bool TurnPort::CreateTurnClientSocket() {
if (server_address_.proto == PROTO_UDP && !SharedSocket()) {
socket_ = socket_factory()->CreateUdpSocket(
rtc::SocketAddress(ip(), 0), min_port(), max_port());
- } else if (server_address_.proto == PROTO_TCP) {
+ } else if (server_address_.proto == PROTO_TCP ||
+ server_address_.proto == PROTO_TLS) {
ASSERT(!SharedSocket());
int opts = rtc::PacketSocketFactory::OPT_STUN;
- // If secure bit is enabled in server address, use TLS over TCP.
- if (server_address_.secure) {
+
+ // Apply server address TLS and insecure bits to options.
+ if (server_address_.proto == PROTO_TLS) {
opts |= rtc::PacketSocketFactory::OPT_TLS;
}
socket_ = socket_factory()->CreateClientTcpSocket(
@@ -356,7 +358,8 @@ bool TurnPort::CreateTurnClientSocket() {
// TCP port is ready to send stun requests after the socket is connected,
// while UDP port is ready to do so once the socket is created.
- if (server_address_.proto == PROTO_TCP) {
+ if (server_address_.proto == PROTO_TCP ||
+ server_address_.proto == PROTO_TLS) {
socket_->SignalConnect.connect(this, &TurnPort::OnSocketConnect);
socket_->SignalClose.connect(this, &TurnPort::OnSocketClose);
} else {
@@ -652,8 +655,7 @@ bool TurnPort::SetAlternateServer(const rtc::SocketAddress& address) {
<< "] to TURN server ["
<< address.ToSensitiveString()
<< "]";
- server_address_ = ProtocolAddress(address, server_address_.proto,
- server_address_.secure);
+ server_address_ = ProtocolAddress(address, server_address_.proto);
// Insert the current address to prevent redirection pingpong.
attempted_server_addresses_.insert(server_address_.address);
@@ -736,8 +738,7 @@ void TurnPort::OnAllocateSuccess(const rtc::SocketAddress& address,
UDP_PROTOCOL_NAME,
ProtoToString(server_address_.proto), // The first hop protocol.
"", // TCP canddiate type, empty for turn candidates.
- RELAY_PORT_TYPE,
- GetRelayPreference(server_address_.proto, server_address_.secure),
+ RELAY_PORT_TYPE, GetRelayPreference(server_address_.proto),
server_priority_, true);
}
« 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