OLD | NEW |
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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 SendResponse(response, remote_addr); | 55 SendResponse(response, remote_addr); |
56 } | 56 } |
57 | 57 |
58 void StunServer::SendErrorResponse( | 58 void StunServer::SendErrorResponse( |
59 const StunMessage& msg, const rtc::SocketAddress& addr, | 59 const StunMessage& msg, const rtc::SocketAddress& addr, |
60 int error_code, const char* error_desc) { | 60 int error_code, const char* error_desc) { |
61 StunMessage err_msg; | 61 StunMessage err_msg; |
62 err_msg.SetType(GetStunErrorResponseType(msg.type())); | 62 err_msg.SetType(GetStunErrorResponseType(msg.type())); |
63 err_msg.SetTransactionID(msg.transaction_id()); | 63 err_msg.SetTransactionID(msg.transaction_id()); |
64 | 64 |
65 StunErrorCodeAttribute* err_code = StunAttribute::CreateErrorCode(); | 65 auto err_code = StunAttribute::CreateErrorCode(); |
66 err_code->SetCode(error_code); | 66 err_code->SetCode(error_code); |
67 err_code->SetReason(error_desc); | 67 err_code->SetReason(error_desc); |
68 err_msg.AddAttribute(err_code); | 68 err_msg.AddAttribute(std::move(err_code)); |
69 | 69 |
70 SendResponse(err_msg, addr); | 70 SendResponse(err_msg, addr); |
71 } | 71 } |
72 | 72 |
73 void StunServer::SendResponse( | 73 void StunServer::SendResponse( |
74 const StunMessage& msg, const rtc::SocketAddress& addr) { | 74 const StunMessage& msg, const rtc::SocketAddress& addr) { |
75 rtc::ByteBufferWriter buf; | 75 rtc::ByteBufferWriter buf; |
76 msg.Write(&buf); | 76 msg.Write(&buf); |
77 rtc::PacketOptions options; | 77 rtc::PacketOptions options; |
78 if (socket_->SendTo(buf.Data(), buf.Length(), addr, options) < 0) | 78 if (socket_->SendTo(buf.Data(), buf.Length(), addr, options) < 0) |
79 LOG_ERR(LS_ERROR) << "sendto"; | 79 LOG_ERR(LS_ERROR) << "sendto"; |
80 } | 80 } |
81 | 81 |
82 void StunServer::GetStunBindReqponse(StunMessage* request, | 82 void StunServer::GetStunBindReqponse(StunMessage* request, |
83 const rtc::SocketAddress& remote_addr, | 83 const rtc::SocketAddress& remote_addr, |
84 StunMessage* response) const { | 84 StunMessage* response) const { |
85 response->SetType(STUN_BINDING_RESPONSE); | 85 response->SetType(STUN_BINDING_RESPONSE); |
86 response->SetTransactionID(request->transaction_id()); | 86 response->SetTransactionID(request->transaction_id()); |
87 | 87 |
88 // Tell the user the address that we received their request from. | 88 // Tell the user the address that we received their request from. |
89 StunAddressAttribute* mapped_addr; | 89 std::unique_ptr<StunAddressAttribute> mapped_addr; |
90 if (!request->IsLegacy()) { | 90 if (!request->IsLegacy()) { |
91 mapped_addr = StunAttribute::CreateAddress(STUN_ATTR_MAPPED_ADDRESS); | 91 mapped_addr = StunAttribute::CreateAddress(STUN_ATTR_MAPPED_ADDRESS); |
92 } else { | 92 } else { |
93 mapped_addr = StunAttribute::CreateXorAddress(STUN_ATTR_XOR_MAPPED_ADDRESS); | 93 mapped_addr = StunAttribute::CreateXorAddress(STUN_ATTR_XOR_MAPPED_ADDRESS); |
94 } | 94 } |
95 mapped_addr->SetAddress(remote_addr); | 95 mapped_addr->SetAddress(remote_addr); |
96 response->AddAttribute(mapped_addr); | 96 response->AddAttribute(std::move(mapped_addr)); |
97 } | 97 } |
98 | 98 |
99 } // namespace cricket | 99 } // namespace cricket |
OLD | NEW |