| OLD | NEW | 
|---|
| 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 20 matching lines...) Expand all  Loading... | 
| 31 static const int TURN_DEFAULT_PORT = 3478; | 31 static const int TURN_DEFAULT_PORT = 3478; | 
| 32 static const int TURN_CHANNEL_NUMBER_START = 0x4000; | 32 static const int TURN_CHANNEL_NUMBER_START = 0x4000; | 
| 33 static const int TURN_PERMISSION_TIMEOUT = 5 * 60 * 1000;  // 5 minutes | 33 static const int TURN_PERMISSION_TIMEOUT = 5 * 60 * 1000;  // 5 minutes | 
| 34 | 34 | 
| 35 static const size_t TURN_CHANNEL_HEADER_SIZE = 4U; | 35 static const size_t TURN_CHANNEL_HEADER_SIZE = 4U; | 
| 36 | 36 | 
| 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 inline bool IsTurnChannelData(uint16 msg_type) { | 41 inline bool IsTurnChannelData(uint16_t msg_type) { | 
| 42   return ((msg_type & 0xC000) == 0x4000);  // MSB are 0b01 | 42   return ((msg_type & 0xC000) == 0x4000);  // MSB are 0b01 | 
| 43 } | 43 } | 
| 44 | 44 | 
| 45 static int GetRelayPreference(cricket::ProtocolType proto, bool secure) { | 45 static int GetRelayPreference(cricket::ProtocolType proto, bool secure) { | 
| 46   int relay_preference = ICE_TYPE_PREFERENCE_RELAY; | 46   int relay_preference = ICE_TYPE_PREFERENCE_RELAY; | 
| 47   if (proto == cricket::PROTO_TCP) { | 47   if (proto == cricket::PROTO_TCP) { | 
| 48     relay_preference -= 1; | 48     relay_preference -= 1; | 
| 49     if (secure) | 49     if (secure) | 
| 50       relay_preference -= 1; | 50       relay_preference -= 1; | 
| 51   } | 51   } | 
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 189       server_priority_(server_priority), | 189       server_priority_(server_priority), | 
| 190       allocate_mismatch_retries_(0) { | 190       allocate_mismatch_retries_(0) { | 
| 191   request_manager_.SignalSendPacket.connect(this, &TurnPort::OnSendStunPacket); | 191   request_manager_.SignalSendPacket.connect(this, &TurnPort::OnSendStunPacket); | 
| 192   request_manager_.set_origin(origin); | 192   request_manager_.set_origin(origin); | 
| 193 } | 193 } | 
| 194 | 194 | 
| 195 TurnPort::TurnPort(rtc::Thread* thread, | 195 TurnPort::TurnPort(rtc::Thread* thread, | 
| 196                    rtc::PacketSocketFactory* factory, | 196                    rtc::PacketSocketFactory* factory, | 
| 197                    rtc::Network* network, | 197                    rtc::Network* network, | 
| 198                    const rtc::IPAddress& ip, | 198                    const rtc::IPAddress& ip, | 
| 199                    uint16 min_port, | 199                    uint16_t min_port, | 
| 200                    uint16 max_port, | 200                    uint16_t max_port, | 
| 201                    const std::string& username, | 201                    const std::string& username, | 
| 202                    const std::string& password, | 202                    const std::string& password, | 
| 203                    const ProtocolAddress& server_address, | 203                    const ProtocolAddress& server_address, | 
| 204                    const RelayCredentials& credentials, | 204                    const RelayCredentials& credentials, | 
| 205                    int server_priority, | 205                    int server_priority, | 
| 206                    const std::string& origin) | 206                    const std::string& origin) | 
| 207     : Port(thread, | 207     : Port(thread, | 
| 208            RELAY_PORT_TYPE, | 208            RELAY_PORT_TYPE, | 
| 209            factory, | 209            factory, | 
| 210            network, | 210            network, | 
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 527 | 527 | 
| 528   // The message must be at least the size of a channel header. | 528   // The message must be at least the size of a channel header. | 
| 529   if (size < TURN_CHANNEL_HEADER_SIZE) { | 529   if (size < TURN_CHANNEL_HEADER_SIZE) { | 
| 530     LOG_J(LS_WARNING, this) << "Received TURN message that was too short"; | 530     LOG_J(LS_WARNING, this) << "Received TURN message that was too short"; | 
| 531     return; | 531     return; | 
| 532   } | 532   } | 
| 533 | 533 | 
| 534   // Check the message type, to see if is a Channel Data message. | 534   // Check the message type, to see if is a Channel Data message. | 
| 535   // The message will either be channel data, a TURN data indication, or | 535   // The message will either be channel data, a TURN data indication, or | 
| 536   // a response to a previous request. | 536   // a response to a previous request. | 
| 537   uint16 msg_type = rtc::GetBE16(data); | 537   uint16_t msg_type = rtc::GetBE16(data); | 
| 538   if (IsTurnChannelData(msg_type)) { | 538   if (IsTurnChannelData(msg_type)) { | 
| 539     HandleChannelData(msg_type, data, size, packet_time); | 539     HandleChannelData(msg_type, data, size, packet_time); | 
| 540   } else if (msg_type == TURN_DATA_INDICATION) { | 540   } else if (msg_type == TURN_DATA_INDICATION) { | 
| 541     HandleDataIndication(data, size, packet_time); | 541     HandleDataIndication(data, size, packet_time); | 
| 542   } else { | 542   } else { | 
| 543     if (SharedSocket() && | 543     if (SharedSocket() && | 
| 544         (msg_type == STUN_BINDING_RESPONSE || | 544         (msg_type == STUN_BINDING_RESPONSE || | 
| 545          msg_type == STUN_BINDING_ERROR_RESPONSE)) { | 545          msg_type == STUN_BINDING_ERROR_RESPONSE)) { | 
| 546       LOG_J(LS_VERBOSE, this) << | 546       LOG_J(LS_VERBOSE, this) << | 
| 547           "Ignoring STUN binding response message on shared socket."; | 547           "Ignoring STUN binding response message on shared socket."; | 
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 772   //   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | 772   //   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | 
| 773   //   |                                                               | | 773   //   |                                                               | | 
| 774   //   /                       Application Data                        / | 774   //   /                       Application Data                        / | 
| 775   //   /                                                               / | 775   //   /                                                               / | 
| 776   //   |                                                               | | 776   //   |                                                               | | 
| 777   //   |                               +-------------------------------+ | 777   //   |                               +-------------------------------+ | 
| 778   //   |                               | | 778   //   |                               | | 
| 779   //   +-------------------------------+ | 779   //   +-------------------------------+ | 
| 780 | 780 | 
| 781   // Extract header fields from the message. | 781   // Extract header fields from the message. | 
| 782   uint16 len = rtc::GetBE16(data + 2); | 782   uint16_t len = rtc::GetBE16(data + 2); | 
| 783   if (len > size - TURN_CHANNEL_HEADER_SIZE) { | 783   if (len > size - TURN_CHANNEL_HEADER_SIZE) { | 
| 784     LOG_J(LS_WARNING, this) << "Received TURN channel data message with " | 784     LOG_J(LS_WARNING, this) << "Received TURN channel data message with " | 
| 785                             << "incorrect length, len=" << len; | 785                             << "incorrect length, len=" << len; | 
| 786     return; | 786     return; | 
| 787   } | 787   } | 
| 788   // Allowing messages larger than |len|, as ChannelData can be padded. | 788   // Allowing messages larger than |len|, as ChannelData can be padded. | 
| 789 | 789 | 
| 790   TurnEntry* entry = FindEntry(channel_id); | 790   TurnEntry* entry = FindEntry(channel_id); | 
| 791   if (!entry) { | 791   if (!entry) { | 
| 792     LOG_J(LS_WARNING, this) << "Received TURN channel data message for invalid " | 792     LOG_J(LS_WARNING, this) << "Received TURN channel data message for invalid " | 
| (...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1318     VERIFY(msg.Write(&buf)); | 1318     VERIFY(msg.Write(&buf)); | 
| 1319 | 1319 | 
| 1320     // If we're sending real data, request a channel bind that we can use later. | 1320     // If we're sending real data, request a channel bind that we can use later. | 
| 1321     if (state_ == STATE_UNBOUND && payload) { | 1321     if (state_ == STATE_UNBOUND && payload) { | 
| 1322       SendChannelBindRequest(0); | 1322       SendChannelBindRequest(0); | 
| 1323       state_ = STATE_BINDING; | 1323       state_ = STATE_BINDING; | 
| 1324     } | 1324     } | 
| 1325   } else { | 1325   } else { | 
| 1326     // If the channel is bound, we can send the data as a Channel Message. | 1326     // If the channel is bound, we can send the data as a Channel Message. | 
| 1327     buf.WriteUInt16(channel_id_); | 1327     buf.WriteUInt16(channel_id_); | 
| 1328     buf.WriteUInt16(static_cast<uint16>(size)); | 1328     buf.WriteUInt16(static_cast<uint16_t>(size)); | 
| 1329     buf.WriteBytes(reinterpret_cast<const char*>(data), size); | 1329     buf.WriteBytes(reinterpret_cast<const char*>(data), size); | 
| 1330   } | 1330   } | 
| 1331   return port_->Send(buf.Data(), buf.Length(), options); | 1331   return port_->Send(buf.Data(), buf.Length(), options); | 
| 1332 } | 1332 } | 
| 1333 | 1333 | 
| 1334 void TurnEntry::OnCreatePermissionSuccess() { | 1334 void TurnEntry::OnCreatePermissionSuccess() { | 
| 1335   LOG_J(LS_INFO, port_) << "Create permission for " | 1335   LOG_J(LS_INFO, port_) << "Create permission for " | 
| 1336                         << ext_addr_.ToSensitiveString() | 1336                         << ext_addr_.ToSensitiveString() | 
| 1337                         << " succeeded"; | 1337                         << " succeeded"; | 
| 1338   // For success result code will be 0. | 1338   // For success result code will be 0. | 
| (...skipping 23 matching lines...) Expand all  Loading... | 
| 1362   // bind request as per http://tools.ietf.org/html/rfc5766#section-11.3 | 1362   // bind request as per http://tools.ietf.org/html/rfc5766#section-11.3 | 
| 1363   if (code == STUN_ERROR_STALE_NONCE) { | 1363   if (code == STUN_ERROR_STALE_NONCE) { | 
| 1364     if (port_->UpdateNonce(response)) { | 1364     if (port_->UpdateNonce(response)) { | 
| 1365       // Send channel bind request with fresh nonce. | 1365       // Send channel bind request with fresh nonce. | 
| 1366       SendChannelBindRequest(0); | 1366       SendChannelBindRequest(0); | 
| 1367     } | 1367     } | 
| 1368   } | 1368   } | 
| 1369 } | 1369 } | 
| 1370 | 1370 | 
| 1371 }  // namespace cricket | 1371 }  // namespace cricket | 
| OLD | NEW | 
|---|