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 10 matching lines...) Expand all Loading... |
21 | 21 |
22 StunServer::~StunServer() { | 22 StunServer::~StunServer() { |
23 socket_->SignalReadPacket.disconnect(this); | 23 socket_->SignalReadPacket.disconnect(this); |
24 } | 24 } |
25 | 25 |
26 void StunServer::OnPacket( | 26 void StunServer::OnPacket( |
27 rtc::AsyncPacketSocket* socket, const char* buf, size_t size, | 27 rtc::AsyncPacketSocket* socket, const char* buf, size_t size, |
28 const rtc::SocketAddress& remote_addr, | 28 const rtc::SocketAddress& remote_addr, |
29 const rtc::PacketTime& packet_time) { | 29 const rtc::PacketTime& packet_time) { |
30 // Parse the STUN message; eat any messages that fail to parse. | 30 // Parse the STUN message; eat any messages that fail to parse. |
31 rtc::ByteBuffer bbuf(buf, size); | 31 rtc::ByteBufferReader bbuf(buf, size); |
32 StunMessage msg; | 32 StunMessage msg; |
33 if (!msg.Read(&bbuf)) { | 33 if (!msg.Read(&bbuf)) { |
34 return; | 34 return; |
35 } | 35 } |
36 | 36 |
37 // TODO: If unknown non-optional (<= 0x7fff) attributes are found, send a | 37 // TODO: If unknown non-optional (<= 0x7fff) attributes are found, send a |
38 // 420 "Unknown Attribute" response. | 38 // 420 "Unknown Attribute" response. |
39 | 39 |
40 // Send the message to the appropriate handler function. | 40 // Send the message to the appropriate handler function. |
41 switch (msg.type()) { | 41 switch (msg.type()) { |
(...skipping 23 matching lines...) Expand all Loading... |
65 StunErrorCodeAttribute* err_code = StunAttribute::CreateErrorCode(); | 65 StunErrorCodeAttribute* 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(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::ByteBuffer 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 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(mapped_addr); |
97 } | 97 } |
98 | 98 |
99 } // namespace cricket | 99 } // namespace cricket |
OLD | NEW |