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

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

Issue 2757893003: Add MakeUnique from chromium and change StunMessage::AddAttribute to take a unique_ptr. (Closed)
Patch Set: add ptr_util.h to rtc_base_approved build target Created 3 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/relayport.cc ('k') | webrtc/p2p/base/relayserver_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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 } 53 }
54 54
55 // Constructs a STUN error response and sends it on the given socket. 55 // Constructs a STUN error response and sends it on the given socket.
56 void SendStunError(const StunMessage& msg, rtc::AsyncPacketSocket* socket, 56 void SendStunError(const StunMessage& msg, rtc::AsyncPacketSocket* socket,
57 const rtc::SocketAddress& remote_addr, int error_code, 57 const rtc::SocketAddress& remote_addr, int error_code,
58 const char* error_desc, const std::string& magic_cookie) { 58 const char* error_desc, const std::string& magic_cookie) {
59 RelayMessage err_msg; 59 RelayMessage err_msg;
60 err_msg.SetType(GetStunErrorResponseType(msg.type())); 60 err_msg.SetType(GetStunErrorResponseType(msg.type()));
61 err_msg.SetTransactionID(msg.transaction_id()); 61 err_msg.SetTransactionID(msg.transaction_id());
62 62
63 StunByteStringAttribute* magic_cookie_attr = 63 auto magic_cookie_attr =
64 StunAttribute::CreateByteString(cricket::STUN_ATTR_MAGIC_COOKIE); 64 StunAttribute::CreateByteString(cricket::STUN_ATTR_MAGIC_COOKIE);
65 if (magic_cookie.size() == 0) { 65 if (magic_cookie.size() == 0) {
66 magic_cookie_attr->CopyBytes(cricket::TURN_MAGIC_COOKIE_VALUE, 66 magic_cookie_attr->CopyBytes(cricket::TURN_MAGIC_COOKIE_VALUE,
67 sizeof(cricket::TURN_MAGIC_COOKIE_VALUE)); 67 sizeof(cricket::TURN_MAGIC_COOKIE_VALUE));
68 } else { 68 } else {
69 magic_cookie_attr->CopyBytes(magic_cookie.c_str(), magic_cookie.size()); 69 magic_cookie_attr->CopyBytes(magic_cookie.c_str(), magic_cookie.size());
70 } 70 }
71 err_msg.AddAttribute(magic_cookie_attr); 71 err_msg.AddAttribute(std::move(magic_cookie_attr));
72 72
73 StunErrorCodeAttribute* err_code = StunAttribute::CreateErrorCode(); 73 auto err_code = StunAttribute::CreateErrorCode();
74 err_code->SetClass(error_code / 100); 74 err_code->SetClass(error_code / 100);
75 err_code->SetNumber(error_code % 100); 75 err_code->SetNumber(error_code % 100);
76 err_code->SetReason(error_desc); 76 err_code->SetReason(error_desc);
77 err_msg.AddAttribute(err_code); 77 err_msg.AddAttribute(std::move(err_code));
78 78
79 SendStun(err_msg, socket, remote_addr); 79 SendStun(err_msg, socket, remote_addr);
80 } 80 }
81 81
82 RelayServer::RelayServer(rtc::Thread* thread) 82 RelayServer::RelayServer(rtc::Thread* thread)
83 : thread_(thread), log_bindings_(true) { 83 : thread_(thread), log_bindings_(true) {
84 } 84 }
85 85
86 RelayServer::~RelayServer() { 86 RelayServer::~RelayServer() {
87 // Deleting the binding will cause it to be removed from the map. 87 // Deleting the binding will cause it to be removed from the map.
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 void RelayServer::HandleStunAllocate( 414 void RelayServer::HandleStunAllocate(
415 RelayServerConnection* int_conn, const StunMessage& request) { 415 RelayServerConnection* int_conn, const StunMessage& request) {
416 416
417 // Create a response message that includes an address with which external 417 // Create a response message that includes an address with which external
418 // clients can communicate. 418 // clients can communicate.
419 419
420 RelayMessage response; 420 RelayMessage response;
421 response.SetType(STUN_ALLOCATE_RESPONSE); 421 response.SetType(STUN_ALLOCATE_RESPONSE);
422 response.SetTransactionID(request.transaction_id()); 422 response.SetTransactionID(request.transaction_id());
423 423
424 StunByteStringAttribute* magic_cookie_attr = 424 auto magic_cookie_attr =
425 StunAttribute::CreateByteString(cricket::STUN_ATTR_MAGIC_COOKIE); 425 StunAttribute::CreateByteString(cricket::STUN_ATTR_MAGIC_COOKIE);
426 magic_cookie_attr->CopyBytes(int_conn->binding()->magic_cookie().c_str(), 426 magic_cookie_attr->CopyBytes(int_conn->binding()->magic_cookie().c_str(),
427 int_conn->binding()->magic_cookie().size()); 427 int_conn->binding()->magic_cookie().size());
428 response.AddAttribute(magic_cookie_attr); 428 response.AddAttribute(std::move(magic_cookie_attr));
429 429
430 size_t index = rand() % external_sockets_.size(); 430 size_t index = rand() % external_sockets_.size();
431 rtc::SocketAddress ext_addr = 431 rtc::SocketAddress ext_addr =
432 external_sockets_[index]->GetLocalAddress(); 432 external_sockets_[index]->GetLocalAddress();
433 433
434 StunAddressAttribute* addr_attr = 434 auto addr_attr = StunAttribute::CreateAddress(STUN_ATTR_MAPPED_ADDRESS);
435 StunAttribute::CreateAddress(STUN_ATTR_MAPPED_ADDRESS);
436 addr_attr->SetIP(ext_addr.ipaddr()); 435 addr_attr->SetIP(ext_addr.ipaddr());
437 addr_attr->SetPort(ext_addr.port()); 436 addr_attr->SetPort(ext_addr.port());
438 response.AddAttribute(addr_attr); 437 response.AddAttribute(std::move(addr_attr));
439 438
440 StunUInt32Attribute* res_lifetime_attr = 439 auto res_lifetime_attr = StunAttribute::CreateUInt32(STUN_ATTR_LIFETIME);
441 StunAttribute::CreateUInt32(STUN_ATTR_LIFETIME);
442 res_lifetime_attr->SetValue(int_conn->binding()->lifetime() / 1000); 440 res_lifetime_attr->SetValue(int_conn->binding()->lifetime() / 1000);
443 response.AddAttribute(res_lifetime_attr); 441 response.AddAttribute(std::move(res_lifetime_attr));
444 442
445 // TODO: Support transport-prefs (preallocate RTCP port). 443 // TODO: Support transport-prefs (preallocate RTCP port).
446 // TODO: Support bandwidth restrictions. 444 // TODO: Support bandwidth restrictions.
447 // TODO: Add message integrity check. 445 // TODO: Add message integrity check.
448 446
449 // Send a response to the caller. 447 // Send a response to the caller.
450 int_conn->SendStun(response); 448 int_conn->SendStun(response);
451 } 449 }
452 450
453 void RelayServer::HandleStunSend( 451 void RelayServer::HandleStunSend(
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
487 const StunUInt32Attribute* options_attr = 485 const StunUInt32Attribute* options_attr =
488 request.GetUInt32(STUN_ATTR_OPTIONS); 486 request.GetUInt32(STUN_ATTR_OPTIONS);
489 if (options_attr && (options_attr->value() & 0x01)) { 487 if (options_attr && (options_attr->value() & 0x01)) {
490 int_conn->set_default_destination(ext_addr); 488 int_conn->set_default_destination(ext_addr);
491 int_conn->Lock(); 489 int_conn->Lock();
492 490
493 RelayMessage response; 491 RelayMessage response;
494 response.SetType(STUN_SEND_RESPONSE); 492 response.SetType(STUN_SEND_RESPONSE);
495 response.SetTransactionID(request.transaction_id()); 493 response.SetTransactionID(request.transaction_id());
496 494
497 StunByteStringAttribute* magic_cookie_attr = 495 auto magic_cookie_attr =
498 StunAttribute::CreateByteString(cricket::STUN_ATTR_MAGIC_COOKIE); 496 StunAttribute::CreateByteString(cricket::STUN_ATTR_MAGIC_COOKIE);
499 magic_cookie_attr->CopyBytes(int_conn->binding()->magic_cookie().c_str(), 497 magic_cookie_attr->CopyBytes(int_conn->binding()->magic_cookie().c_str(),
500 int_conn->binding()->magic_cookie().size()); 498 int_conn->binding()->magic_cookie().size());
501 response.AddAttribute(magic_cookie_attr); 499 response.AddAttribute(std::move(magic_cookie_attr));
502 500
503 StunUInt32Attribute* options2_attr = 501 auto options2_attr =
504 StunAttribute::CreateUInt32(cricket::STUN_ATTR_OPTIONS); 502 StunAttribute::CreateUInt32(cricket::STUN_ATTR_OPTIONS);
505 options2_attr->SetValue(0x01); 503 options2_attr->SetValue(0x01);
506 response.AddAttribute(options2_attr); 504 response.AddAttribute(std::move(options2_attr));
507 505
508 int_conn->SendStun(response); 506 int_conn->SendStun(response);
509 } 507 }
510 } 508 }
511 509
512 void RelayServer::AddConnection(RelayServerConnection* conn) { 510 void RelayServer::AddConnection(RelayServerConnection* conn) {
513 RTC_DCHECK(connections_.find(conn->addr_pair()) == connections_.end()); 511 RTC_DCHECK(connections_.find(conn->addr_pair()) == connections_.end());
514 connections_[conn->addr_pair()] = conn; 512 connections_[conn->addr_pair()] = conn;
515 } 513 }
516 514
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 if (locked() && (from_addr == default_dest_)) { 594 if (locked() && (from_addr == default_dest_)) {
597 Send(data, size); 595 Send(data, size);
598 return; 596 return;
599 } 597 }
600 598
601 // Wrap the given data in a data-indication packet. 599 // Wrap the given data in a data-indication packet.
602 600
603 RelayMessage msg; 601 RelayMessage msg;
604 msg.SetType(STUN_DATA_INDICATION); 602 msg.SetType(STUN_DATA_INDICATION);
605 603
606 StunByteStringAttribute* magic_cookie_attr = 604 auto magic_cookie_attr =
607 StunAttribute::CreateByteString(cricket::STUN_ATTR_MAGIC_COOKIE); 605 StunAttribute::CreateByteString(cricket::STUN_ATTR_MAGIC_COOKIE);
608 magic_cookie_attr->CopyBytes(binding_->magic_cookie().c_str(), 606 magic_cookie_attr->CopyBytes(binding_->magic_cookie().c_str(),
609 binding_->magic_cookie().size()); 607 binding_->magic_cookie().size());
610 msg.AddAttribute(magic_cookie_attr); 608 msg.AddAttribute(std::move(magic_cookie_attr));
611 609
612 StunAddressAttribute* addr_attr = 610 auto addr_attr = StunAttribute::CreateAddress(STUN_ATTR_SOURCE_ADDRESS2);
613 StunAttribute::CreateAddress(STUN_ATTR_SOURCE_ADDRESS2);
614 addr_attr->SetIP(from_addr.ipaddr()); 611 addr_attr->SetIP(from_addr.ipaddr());
615 addr_attr->SetPort(from_addr.port()); 612 addr_attr->SetPort(from_addr.port());
616 msg.AddAttribute(addr_attr); 613 msg.AddAttribute(std::move(addr_attr));
617 614
618 StunByteStringAttribute* data_attr = 615 auto data_attr = StunAttribute::CreateByteString(STUN_ATTR_DATA);
619 StunAttribute::CreateByteString(STUN_ATTR_DATA);
620 RTC_DCHECK(size <= 65536); 616 RTC_DCHECK(size <= 65536);
621 data_attr->CopyBytes(data, uint16_t(size)); 617 data_attr->CopyBytes(data, uint16_t(size));
622 msg.AddAttribute(data_attr); 618 msg.AddAttribute(std::move(data_attr));
623 619
624 SendStun(msg); 620 SendStun(msg);
625 } 621 }
626 622
627 void RelayServerConnection::SendStun(const StunMessage& msg) { 623 void RelayServerConnection::SendStun(const StunMessage& msg) {
628 // Note that the binding has been used again. 624 // Note that the binding has been used again.
629 binding_->NoteUsed(); 625 binding_->NoteUsed();
630 626
631 cricket::SendStun(msg, socket_, addr_pair_.source()); 627 cricket::SendStun(msg, socket_, addr_pair_.source());
632 } 628 }
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
744 server_->thread()->PostDelayed(RTC_FROM_HERE, lifetime_, this, 740 server_->thread()->PostDelayed(RTC_FROM_HERE, lifetime_, this,
745 MSG_LIFETIME_TIMER); 741 MSG_LIFETIME_TIMER);
746 } 742 }
747 743
748 } else { 744 } else {
749 RTC_NOTREACHED(); 745 RTC_NOTREACHED();
750 } 746 }
751 } 747 }
752 748
753 } // namespace cricket 749 } // namespace cricket
OLDNEW
« no previous file with comments | « webrtc/p2p/base/relayport.cc ('k') | webrtc/p2p/base/relayserver_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698