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

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

Issue 1923163003: Replace scoped_ptr with unique_ptr in webrtc/p2p/ (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 7 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
« no previous file with comments | « webrtc/p2p/base/port.h ('k') | webrtc/p2p/base/port_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 2004 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2004 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
11 #include "webrtc/p2p/base/port.h" 11 #include "webrtc/p2p/base/port.h"
12 12
13 #include <algorithm> 13 #include <algorithm>
14 #include <vector> 14 #include <vector>
15 15
16 #include "webrtc/p2p/base/common.h" 16 #include "webrtc/p2p/base/common.h"
17 #include "webrtc/p2p/base/portallocator.h" 17 #include "webrtc/p2p/base/portallocator.h"
18 #include "webrtc/base/base64.h" 18 #include "webrtc/base/base64.h"
19 #include "webrtc/base/crc32.h" 19 #include "webrtc/base/crc32.h"
20 #include "webrtc/base/helpers.h" 20 #include "webrtc/base/helpers.h"
21 #include "webrtc/base/logging.h" 21 #include "webrtc/base/logging.h"
22 #include "webrtc/base/messagedigest.h" 22 #include "webrtc/base/messagedigest.h"
23 #include "webrtc/base/network.h" 23 #include "webrtc/base/network.h"
24 #include "webrtc/base/scoped_ptr.h"
25 #include "webrtc/base/stringencode.h" 24 #include "webrtc/base/stringencode.h"
26 #include "webrtc/base/stringutils.h" 25 #include "webrtc/base/stringutils.h"
27 26
28 namespace { 27 namespace {
29 28
30 // Determines whether we have seen at least the given maximum number of 29 // Determines whether we have seen at least the given maximum number of
31 // pings fail to have a response. 30 // pings fail to have a response.
32 inline bool TooManyFailures( 31 inline bool TooManyFailures(
33 const std::vector<cricket::Connection::SentPing>& pings_since_last_response, 32 const std::vector<cricket::Connection::SentPing>& pings_since_last_response,
34 uint32_t maximum_failures, 33 uint32_t maximum_failures,
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 const char* data, size_t size, const rtc::SocketAddress& addr, 270 const char* data, size_t size, const rtc::SocketAddress& addr,
272 ProtocolType proto) { 271 ProtocolType proto) {
273 // If the user has enabled port packets, just hand this over. 272 // If the user has enabled port packets, just hand this over.
274 if (enable_port_packets_) { 273 if (enable_port_packets_) {
275 SignalReadPacket(this, data, size, addr); 274 SignalReadPacket(this, data, size, addr);
276 return; 275 return;
277 } 276 }
278 277
279 // If this is an authenticated STUN request, then signal unknown address and 278 // If this is an authenticated STUN request, then signal unknown address and
280 // send back a proper binding response. 279 // send back a proper binding response.
281 rtc::scoped_ptr<IceMessage> msg; 280 std::unique_ptr<IceMessage> msg;
282 std::string remote_username; 281 std::string remote_username;
283 if (!GetStunMessage(data, size, addr, &msg, &remote_username)) { 282 if (!GetStunMessage(data, size, addr, &msg, &remote_username)) {
284 LOG_J(LS_ERROR, this) << "Received non-STUN packet from unknown address (" 283 LOG_J(LS_ERROR, this) << "Received non-STUN packet from unknown address ("
285 << addr.ToSensitiveString() << ")"; 284 << addr.ToSensitiveString() << ")";
286 } else if (!msg) { 285 } else if (!msg) {
287 // STUN message handled already 286 // STUN message handled already
288 } else if (msg->type() == STUN_BINDING_REQUEST) { 287 } else if (msg->type() == STUN_BINDING_REQUEST) {
289 LOG(LS_INFO) << "Received STUN ping " 288 LOG(LS_INFO) << "Received STUN ping "
290 << " id=" << rtc::hex_encode(msg->transaction_id()) 289 << " id=" << rtc::hex_encode(msg->transaction_id())
291 << " from unknown address " << addr.ToSensitiveString(); 290 << " from unknown address " << addr.ToSensitiveString();
(...skipping 26 matching lines...) Expand all
318 } 317 }
319 318
320 size_t Port::AddPrflxCandidate(const Candidate& local) { 319 size_t Port::AddPrflxCandidate(const Candidate& local) {
321 candidates_.push_back(local); 320 candidates_.push_back(local);
322 return (candidates_.size() - 1); 321 return (candidates_.size() - 1);
323 } 322 }
324 323
325 bool Port::GetStunMessage(const char* data, 324 bool Port::GetStunMessage(const char* data,
326 size_t size, 325 size_t size,
327 const rtc::SocketAddress& addr, 326 const rtc::SocketAddress& addr,
328 rtc::scoped_ptr<IceMessage>* out_msg, 327 std::unique_ptr<IceMessage>* out_msg,
329 std::string* out_username) { 328 std::string* out_username) {
330 // NOTE: This could clearly be optimized to avoid allocating any memory. 329 // NOTE: This could clearly be optimized to avoid allocating any memory.
331 // However, at the data rates we'll be looking at on the client side, 330 // However, at the data rates we'll be looking at on the client side,
332 // this probably isn't worth worrying about. 331 // this probably isn't worth worrying about.
333 ASSERT(out_msg != NULL); 332 ASSERT(out_msg != NULL);
334 ASSERT(out_username != NULL); 333 ASSERT(out_username != NULL);
335 out_username->clear(); 334 out_username->clear();
336 335
337 // Don't bother parsing the packet if we can tell it's not STUN. 336 // Don't bother parsing the packet if we can tell it's not STUN.
338 // In ICE mode, all STUN packets will have a valid fingerprint. 337 // In ICE mode, all STUN packets will have a valid fingerprint.
339 if (!StunMessage::ValidateFingerprint(data, size)) { 338 if (!StunMessage::ValidateFingerprint(data, size)) {
340 return false; 339 return false;
341 } 340 }
342 341
343 // Parse the request message. If the packet is not a complete and correct 342 // Parse the request message. If the packet is not a complete and correct
344 // STUN message, then ignore it. 343 // STUN message, then ignore it.
345 rtc::scoped_ptr<IceMessage> stun_msg(new IceMessage()); 344 std::unique_ptr<IceMessage> stun_msg(new IceMessage());
346 rtc::ByteBufferReader buf(data, size); 345 rtc::ByteBufferReader buf(data, size);
347 if (!stun_msg->Read(&buf) || (buf.Length() > 0)) { 346 if (!stun_msg->Read(&buf) || (buf.Length() > 0)) {
348 return false; 347 return false;
349 } 348 }
350 349
351 if (stun_msg->type() == STUN_BINDING_REQUEST) { 350 if (stun_msg->type() == STUN_BINDING_REQUEST) {
352 // Check for the presence of USERNAME and MESSAGE-INTEGRITY (if ICE) first. 351 // Check for the presence of USERNAME and MESSAGE-INTEGRITY (if ICE) first.
353 // If not present, fail with a 400 Bad Request. 352 // If not present, fail with a 400 Bad Request.
354 if (!stun_msg->GetByteString(STUN_ATTR_USERNAME) || 353 if (!stun_msg->GetByteString(STUN_ATTR_USERNAME) ||
355 !stun_msg->GetByteString(STUN_ATTR_MESSAGE_INTEGRITY)) { 354 !stun_msg->GetByteString(STUN_ATTR_MESSAGE_INTEGRITY)) {
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after
888 data, size, remote_candidate_.address(), options, false); 887 data, size, remote_candidate_.address(), options, false);
889 if (err < 0) { 888 if (err < 0) {
890 LOG_J(LS_WARNING, this) << "Failed to send STUN ping " 889 LOG_J(LS_WARNING, this) << "Failed to send STUN ping "
891 << " err=" << err 890 << " err=" << err
892 << " id=" << rtc::hex_encode(req->id()); 891 << " id=" << rtc::hex_encode(req->id());
893 } 892 }
894 } 893 }
895 894
896 void Connection::OnReadPacket( 895 void Connection::OnReadPacket(
897 const char* data, size_t size, const rtc::PacketTime& packet_time) { 896 const char* data, size_t size, const rtc::PacketTime& packet_time) {
898 rtc::scoped_ptr<IceMessage> msg; 897 std::unique_ptr<IceMessage> msg;
899 std::string remote_ufrag; 898 std::string remote_ufrag;
900 const rtc::SocketAddress& addr(remote_candidate_.address()); 899 const rtc::SocketAddress& addr(remote_candidate_.address());
901 if (!port_->GetStunMessage(data, size, addr, &msg, &remote_ufrag)) { 900 if (!port_->GetStunMessage(data, size, addr, &msg, &remote_ufrag)) {
902 // The packet did not parse as a valid STUN message 901 // The packet did not parse as a valid STUN message
903 // This is a data packet, pass it along. 902 // This is a data packet, pass it along.
904 set_receiving(true); 903 set_receiving(true);
905 last_data_received_ = rtc::Time64(); 904 last_data_received_ = rtc::Time64();
906 recv_rate_tracker_.AddSamples(size); 905 recv_rate_tracker_.AddSamples(size);
907 SignalReadPacket(this, data, size, packet_time); 906 SignalReadPacket(this, data, size, packet_time);
908 907
(...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after
1450 ASSERT(sent < 0); 1449 ASSERT(sent < 0);
1451 error_ = port_->GetError(); 1450 error_ = port_->GetError();
1452 sent_packets_discarded_++; 1451 sent_packets_discarded_++;
1453 } else { 1452 } else {
1454 send_rate_tracker_.AddSamples(sent); 1453 send_rate_tracker_.AddSamples(sent);
1455 } 1454 }
1456 return sent; 1455 return sent;
1457 } 1456 }
1458 1457
1459 } // namespace cricket 1458 } // namespace cricket
OLDNEW
« no previous file with comments | « webrtc/p2p/base/port.h ('k') | webrtc/p2p/base/port_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698