| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2012 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 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 TurnServerAllocation* allocation = FindAllocation(&conn); | 209 TurnServerAllocation* allocation = FindAllocation(&conn); |
| 210 if (allocation) { | 210 if (allocation) { |
| 211 allocation->HandleChannelData(data, size); | 211 allocation->HandleChannelData(data, size); |
| 212 } | 212 } |
| 213 } | 213 } |
| 214 } | 214 } |
| 215 | 215 |
| 216 void TurnServer::HandleStunMessage(TurnServerConnection* conn, const char* data, | 216 void TurnServer::HandleStunMessage(TurnServerConnection* conn, const char* data, |
| 217 size_t size) { | 217 size_t size) { |
| 218 TurnMessage msg; | 218 TurnMessage msg; |
| 219 rtc::ByteBuffer buf(data, size); | 219 rtc::ByteBufferReader buf(data, size); |
| 220 if (!msg.Read(&buf) || (buf.Length() > 0)) { | 220 if (!msg.Read(&buf) || (buf.Length() > 0)) { |
| 221 LOG(LS_WARNING) << "Received invalid STUN message"; | 221 LOG(LS_WARNING) << "Received invalid STUN message"; |
| 222 return; | 222 return; |
| 223 } | 223 } |
| 224 | 224 |
| 225 // If it's a STUN binding request, handle that specially. | 225 // If it's a STUN binding request, handle that specially. |
| 226 if (msg.type() == STUN_BINDING_REQUEST) { | 226 if (msg.type() == STUN_BINDING_REQUEST) { |
| 227 HandleBindingRequest(conn, &msg); | 227 HandleBindingRequest(conn, &msg); |
| 228 return; | 228 return; |
| 229 } | 229 } |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 482 const rtc::SocketAddress& addr) { | 482 const rtc::SocketAddress& addr) { |
| 483 TurnMessage resp; | 483 TurnMessage resp; |
| 484 InitErrorResponse(msg, STUN_ERROR_TRY_ALTERNATE, | 484 InitErrorResponse(msg, STUN_ERROR_TRY_ALTERNATE, |
| 485 STUN_ERROR_REASON_TRY_ALTERNATE_SERVER, &resp); | 485 STUN_ERROR_REASON_TRY_ALTERNATE_SERVER, &resp); |
| 486 VERIFY(resp.AddAttribute(new StunAddressAttribute( | 486 VERIFY(resp.AddAttribute(new StunAddressAttribute( |
| 487 STUN_ATTR_ALTERNATE_SERVER, addr))); | 487 STUN_ATTR_ALTERNATE_SERVER, addr))); |
| 488 SendStun(conn, &resp); | 488 SendStun(conn, &resp); |
| 489 } | 489 } |
| 490 | 490 |
| 491 void TurnServer::SendStun(TurnServerConnection* conn, StunMessage* msg) { | 491 void TurnServer::SendStun(TurnServerConnection* conn, StunMessage* msg) { |
| 492 rtc::ByteBuffer buf; | 492 rtc::ByteBufferWriter buf; |
| 493 // Add a SOFTWARE attribute if one is set. | 493 // Add a SOFTWARE attribute if one is set. |
| 494 if (!software_.empty()) { | 494 if (!software_.empty()) { |
| 495 VERIFY(msg->AddAttribute( | 495 VERIFY(msg->AddAttribute( |
| 496 new StunByteStringAttribute(STUN_ATTR_SOFTWARE, software_))); | 496 new StunByteStringAttribute(STUN_ATTR_SOFTWARE, software_))); |
| 497 } | 497 } |
| 498 msg->Write(&buf); | 498 msg->Write(&buf); |
| 499 Send(conn, buf); | 499 Send(conn, buf); |
| 500 } | 500 } |
| 501 | 501 |
| 502 void TurnServer::Send(TurnServerConnection* conn, | 502 void TurnServer::Send(TurnServerConnection* conn, |
| 503 const rtc::ByteBuffer& buf) { | 503 const rtc::ByteBufferWriter& buf) { |
| 504 rtc::PacketOptions options; | 504 rtc::PacketOptions options; |
| 505 conn->socket()->SendTo(buf.Data(), buf.Length(), conn->src(), options); | 505 conn->socket()->SendTo(buf.Data(), buf.Length(), conn->src(), options); |
| 506 } | 506 } |
| 507 | 507 |
| 508 void TurnServer::OnAllocationDestroyed(TurnServerAllocation* allocation) { | 508 void TurnServer::OnAllocationDestroyed(TurnServerAllocation* allocation) { |
| 509 // Removing the internal socket if the connection is not udp. | 509 // Removing the internal socket if the connection is not udp. |
| 510 rtc::AsyncPacketSocket* socket = allocation->conn()->socket(); | 510 rtc::AsyncPacketSocket* socket = allocation->conn()->socket(); |
| 511 InternalSocketMap::iterator iter = server_sockets_.find(socket); | 511 InternalSocketMap::iterator iter = server_sockets_.find(socket); |
| 512 ASSERT(iter != server_sockets_.end()); | 512 ASSERT(iter != server_sockets_.end()); |
| 513 // Skip if the socket serving this allocation is UDP, as this will be shared | 513 // Skip if the socket serving this allocation is UDP, as this will be shared |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 787 | 787 |
| 788 void TurnServerAllocation::OnExternalPacket( | 788 void TurnServerAllocation::OnExternalPacket( |
| 789 rtc::AsyncPacketSocket* socket, | 789 rtc::AsyncPacketSocket* socket, |
| 790 const char* data, size_t size, | 790 const char* data, size_t size, |
| 791 const rtc::SocketAddress& addr, | 791 const rtc::SocketAddress& addr, |
| 792 const rtc::PacketTime& packet_time) { | 792 const rtc::PacketTime& packet_time) { |
| 793 ASSERT(external_socket_.get() == socket); | 793 ASSERT(external_socket_.get() == socket); |
| 794 Channel* channel = FindChannel(addr); | 794 Channel* channel = FindChannel(addr); |
| 795 if (channel) { | 795 if (channel) { |
| 796 // There is a channel bound to this address. Send as a channel message. | 796 // There is a channel bound to this address. Send as a channel message. |
| 797 rtc::ByteBuffer buf; | 797 rtc::ByteBufferWriter buf; |
| 798 buf.WriteUInt16(channel->id()); | 798 buf.WriteUInt16(channel->id()); |
| 799 buf.WriteUInt16(static_cast<uint16_t>(size)); | 799 buf.WriteUInt16(static_cast<uint16_t>(size)); |
| 800 buf.WriteBytes(data, size); | 800 buf.WriteBytes(data, size); |
| 801 server_->Send(&conn_, buf); | 801 server_->Send(&conn_, buf); |
| 802 } else if (HasPermission(addr.ipaddr())) { | 802 } else if (HasPermission(addr.ipaddr())) { |
| 803 // No channel, but a permission exists. Send as a data indication. | 803 // No channel, but a permission exists. Send as a data indication. |
| 804 TurnMessage msg; | 804 TurnMessage msg; |
| 805 msg.SetType(TURN_DATA_INDICATION); | 805 msg.SetType(TURN_DATA_INDICATION); |
| 806 msg.SetTransactionID( | 806 msg.SetTransactionID( |
| 807 rtc::CreateRandomString(kStunTransactionIdLength)); | 807 rtc::CreateRandomString(kStunTransactionIdLength)); |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 948 thread_->PostDelayed(kChannelTimeout, this, MSG_ALLOCATION_TIMEOUT); | 948 thread_->PostDelayed(kChannelTimeout, this, MSG_ALLOCATION_TIMEOUT); |
| 949 } | 949 } |
| 950 | 950 |
| 951 void TurnServerAllocation::Channel::OnMessage(rtc::Message* msg) { | 951 void TurnServerAllocation::Channel::OnMessage(rtc::Message* msg) { |
| 952 ASSERT(msg->message_id == MSG_ALLOCATION_TIMEOUT); | 952 ASSERT(msg->message_id == MSG_ALLOCATION_TIMEOUT); |
| 953 SignalDestroyed(this); | 953 SignalDestroyed(this); |
| 954 delete this; | 954 delete this; |
| 955 } | 955 } |
| 956 | 956 |
| 957 } // namespace cricket | 957 } // namespace cricket |
| OLD | NEW |