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

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

Issue 1800753003: Port::GetStunMessage: Write to scoped_ptr instead of raw pointer (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Let caller worry about clearing the output argument Created 4 years, 9 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
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 // If the user has enabled port packets, just hand this over. 281 // If the user has enabled port packets, just hand this over.
282 if (enable_port_packets_) { 282 if (enable_port_packets_) {
283 SignalReadPacket(this, data, size, addr); 283 SignalReadPacket(this, data, size, addr);
284 return; 284 return;
285 } 285 }
286 286
287 // If this is an authenticated STUN request, then signal unknown address and 287 // If this is an authenticated STUN request, then signal unknown address and
288 // send back a proper binding response. 288 // send back a proper binding response.
289 rtc::scoped_ptr<IceMessage> msg; 289 rtc::scoped_ptr<IceMessage> msg;
290 std::string remote_username; 290 std::string remote_username;
291 if (!GetStunMessage(data, size, addr, msg.accept(), &remote_username)) { 291 if (!GetStunMessage(data, size, addr, &msg, &remote_username)) {
292 LOG_J(LS_ERROR, this) << "Received non-STUN packet from unknown address (" 292 LOG_J(LS_ERROR, this) << "Received non-STUN packet from unknown address ("
293 << addr.ToSensitiveString() << ")"; 293 << addr.ToSensitiveString() << ")";
294 } else if (!msg) { 294 } else if (!msg) {
295 // STUN message handled already 295 // STUN message handled already
296 } else if (msg->type() == STUN_BINDING_REQUEST) { 296 } else if (msg->type() == STUN_BINDING_REQUEST) {
297 LOG(LS_INFO) << "Received STUN ping " 297 LOG(LS_INFO) << "Received STUN ping "
298 << " id=" << rtc::hex_encode(msg->transaction_id()) 298 << " id=" << rtc::hex_encode(msg->transaction_id())
299 << " from unknown address " << addr.ToSensitiveString(); 299 << " from unknown address " << addr.ToSensitiveString();
300 300
301 // Check for role conflicts. 301 // Check for role conflicts.
(...skipping 21 matching lines...) Expand all
323 for (; iter != connections_.end(); ++iter) { 323 for (; iter != connections_.end(); ++iter) {
324 iter->second->OnReadyToSend(); 324 iter->second->OnReadyToSend();
325 } 325 }
326 } 326 }
327 327
328 size_t Port::AddPrflxCandidate(const Candidate& local) { 328 size_t Port::AddPrflxCandidate(const Candidate& local) {
329 candidates_.push_back(local); 329 candidates_.push_back(local);
330 return (candidates_.size() - 1); 330 return (candidates_.size() - 1);
331 } 331 }
332 332
333 bool Port::GetStunMessage(const char* data, size_t size, 333 bool Port::GetStunMessage(const char* data,
334 size_t size,
334 const rtc::SocketAddress& addr, 335 const rtc::SocketAddress& addr,
335 IceMessage** out_msg, std::string* out_username) { 336 rtc::scoped_ptr<IceMessage>* out_msg,
337 std::string* out_username) {
336 // NOTE: This could clearly be optimized to avoid allocating any memory. 338 // NOTE: This could clearly be optimized to avoid allocating any memory.
337 // However, at the data rates we'll be looking at on the client side, 339 // However, at the data rates we'll be looking at on the client side,
338 // this probably isn't worth worrying about. 340 // this probably isn't worth worrying about.
339 ASSERT(out_msg != NULL); 341 ASSERT(out_msg != NULL);
340 ASSERT(out_username != NULL); 342 ASSERT(out_username != NULL);
341 *out_msg = NULL;
342 out_username->clear(); 343 out_username->clear();
343 344
344 // Don't bother parsing the packet if we can tell it's not STUN. 345 // Don't bother parsing the packet if we can tell it's not STUN.
345 // In ICE mode, all STUN packets will have a valid fingerprint. 346 // In ICE mode, all STUN packets will have a valid fingerprint.
346 if (!StunMessage::ValidateFingerprint(data, size)) { 347 if (!StunMessage::ValidateFingerprint(data, size)) {
347 return false; 348 return false;
348 } 349 }
349 350
350 // Parse the request message. If the packet is not a complete and correct 351 // Parse the request message. If the packet is not a complete and correct
351 // STUN message, then ignore it. 352 // STUN message, then ignore it.
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 // No stun attributes will be verified, if it's stun indication message. 416 // No stun attributes will be verified, if it's stun indication message.
416 // Returning from end of the this method. 417 // Returning from end of the this method.
417 } else { 418 } else {
418 LOG_J(LS_ERROR, this) << "Received STUN packet with invalid type (" 419 LOG_J(LS_ERROR, this) << "Received STUN packet with invalid type ("
419 << stun_msg->type() << ") from " 420 << stun_msg->type() << ") from "
420 << addr.ToSensitiveString(); 421 << addr.ToSensitiveString();
421 return true; 422 return true;
422 } 423 }
423 424
424 // Return the STUN message found. 425 // Return the STUN message found.
425 *out_msg = stun_msg.release(); 426 *out_msg = std::move(stun_msg);
426 return true; 427 return true;
427 } 428 }
428 429
429 bool Port::IsCompatibleAddress(const rtc::SocketAddress& addr) { 430 bool Port::IsCompatibleAddress(const rtc::SocketAddress& addr) {
430 int family = ip().family(); 431 int family = ip().family();
431 // We use single-stack sockets, so families must match. 432 // We use single-stack sockets, so families must match.
432 if (addr.family() != family) { 433 if (addr.family() != family) {
433 return false; 434 return false;
434 } 435 }
435 // Link-local IPv6 ports can only connect to other link-local IPv6 ports. 436 // Link-local IPv6 ports can only connect to other link-local IPv6 ports.
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after
895 << " err=" << err 896 << " err=" << err
896 << " id=" << rtc::hex_encode(req->id()); 897 << " id=" << rtc::hex_encode(req->id());
897 } 898 }
898 } 899 }
899 900
900 void Connection::OnReadPacket( 901 void Connection::OnReadPacket(
901 const char* data, size_t size, const rtc::PacketTime& packet_time) { 902 const char* data, size_t size, const rtc::PacketTime& packet_time) {
902 rtc::scoped_ptr<IceMessage> msg; 903 rtc::scoped_ptr<IceMessage> msg;
903 std::string remote_ufrag; 904 std::string remote_ufrag;
904 const rtc::SocketAddress& addr(remote_candidate_.address()); 905 const rtc::SocketAddress& addr(remote_candidate_.address());
905 if (!port_->GetStunMessage(data, size, addr, msg.accept(), &remote_ufrag)) { 906 if (!port_->GetStunMessage(data, size, addr, &msg, &remote_ufrag)) {
906 // The packet did not parse as a valid STUN message 907 // The packet did not parse as a valid STUN message
907 // This is a data packet, pass it along. 908 // This is a data packet, pass it along.
908 set_receiving(true); 909 set_receiving(true);
909 last_data_received_ = rtc::Time(); 910 last_data_received_ = rtc::Time();
910 recv_rate_tracker_.AddSamples(size); 911 recv_rate_tracker_.AddSamples(size);
911 SignalReadPacket(this, data, size, packet_time); 912 SignalReadPacket(this, data, size, packet_time);
912 913
913 // If timed out sending writability checks, start up again 914 // If timed out sending writability checks, start up again
914 if (!pruned_ && (write_state_ == STATE_WRITE_TIMEOUT)) { 915 if (!pruned_ && (write_state_ == STATE_WRITE_TIMEOUT)) {
915 LOG(LS_WARNING) << "Received a data packet on a timed-out Connection. " 916 LOG(LS_WARNING) << "Received a data packet on a timed-out Connection. "
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after
1443 ASSERT(sent < 0); 1444 ASSERT(sent < 0);
1444 error_ = port_->GetError(); 1445 error_ = port_->GetError();
1445 sent_packets_discarded_++; 1446 sent_packets_discarded_++;
1446 } else { 1447 } else {
1447 send_rate_tracker_.AddSamples(sent); 1448 send_rate_tracker_.AddSamples(sent);
1448 } 1449 }
1449 return sent; 1450 return sent;
1450 } 1451 }
1451 1452
1452 } // namespace cricket 1453 } // 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