| 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 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 int sent = entry->Send(data, size, payload, options); | 526 int sent = entry->Send(data, size, payload, options); |
| 527 if (sent <= 0) { | 527 if (sent <= 0) { |
| 528 return SOCKET_ERROR; | 528 return SOCKET_ERROR; |
| 529 } | 529 } |
| 530 | 530 |
| 531 // The caller of the function is expecting the number of user data bytes, | 531 // The caller of the function is expecting the number of user data bytes, |
| 532 // rather than the size of the packet. | 532 // rather than the size of the packet. |
| 533 return static_cast<int>(size); | 533 return static_cast<int>(size); |
| 534 } | 534 } |
| 535 | 535 |
| 536 void TurnPort::OnReadPacket( | 536 bool TurnPort::HandleIncomingPacket(rtc::AsyncPacketSocket* socket, |
| 537 rtc::AsyncPacketSocket* socket, const char* data, size_t size, | 537 const char* data, size_t size, |
| 538 const rtc::SocketAddress& remote_addr, | 538 const rtc::SocketAddress& remote_addr, |
| 539 const rtc::PacketTime& packet_time) { | 539 const rtc::PacketTime& packet_time) { |
| 540 ASSERT(socket == socket_); | 540 if (socket != socket_) { |
| 541 // The packet was received on a shared socket after we've allocated a new |
| 542 // socket for this TURN port. |
| 543 return false; |
| 544 } |
| 541 | 545 |
| 542 // This is to guard against a STUN response from previous server after | 546 // This is to guard against a STUN response from previous server after |
| 543 // alternative server redirection. TODO(guoweis): add a unit test for this | 547 // alternative server redirection. TODO(guoweis): add a unit test for this |
| 544 // race condition. | 548 // race condition. |
| 545 if (remote_addr != server_address_.address) { | 549 if (remote_addr != server_address_.address) { |
| 546 LOG_J(LS_WARNING, this) << "Discarding TURN message from unknown address:" | 550 LOG_J(LS_WARNING, this) << "Discarding TURN message from unknown address:" |
| 547 << remote_addr.ToString() | 551 << remote_addr.ToString() |
| 548 << ", server_address_:" | 552 << ", server_address_:" |
| 549 << server_address_.address.ToString(); | 553 << server_address_.address.ToString(); |
| 550 return; | 554 return false; |
| 551 } | 555 } |
| 552 | 556 |
| 553 // The message must be at least the size of a channel header. | 557 // The message must be at least the size of a channel header. |
| 554 if (size < TURN_CHANNEL_HEADER_SIZE) { | 558 if (size < TURN_CHANNEL_HEADER_SIZE) { |
| 555 LOG_J(LS_WARNING, this) << "Received TURN message that was too short"; | 559 LOG_J(LS_WARNING, this) << "Received TURN message that was too short"; |
| 556 return; | 560 return false; |
| 557 } | 561 } |
| 558 | 562 |
| 559 if (state_ == STATE_DISCONNECTED) { | 563 if (state_ == STATE_DISCONNECTED) { |
| 560 LOG_J(LS_WARNING, this) | 564 LOG_J(LS_WARNING, this) |
| 561 << "Received TURN message while the Turn port is disconnected"; | 565 << "Received TURN message while the Turn port is disconnected"; |
| 562 return; | 566 return false; |
| 563 } | 567 } |
| 564 | 568 |
| 565 // Check the message type, to see if is a Channel Data message. | 569 // Check the message type, to see if is a Channel Data message. |
| 566 // The message will either be channel data, a TURN data indication, or | 570 // The message will either be channel data, a TURN data indication, or |
| 567 // a response to a previous request. | 571 // a response to a previous request. |
| 568 uint16_t msg_type = rtc::GetBE16(data); | 572 uint16_t msg_type = rtc::GetBE16(data); |
| 569 if (IsTurnChannelData(msg_type)) { | 573 if (IsTurnChannelData(msg_type)) { |
| 570 HandleChannelData(msg_type, data, size, packet_time); | 574 HandleChannelData(msg_type, data, size, packet_time); |
| 571 } else if (msg_type == TURN_DATA_INDICATION) { | 575 return true; |
| 576 |
| 577 } |
| 578 |
| 579 if (msg_type == TURN_DATA_INDICATION) { |
| 572 HandleDataIndication(data, size, packet_time); | 580 HandleDataIndication(data, size, packet_time); |
| 573 } else { | 581 return true; |
| 574 if (SharedSocket() && | 582 } |
| 575 (msg_type == STUN_BINDING_RESPONSE || | |
| 576 msg_type == STUN_BINDING_ERROR_RESPONSE)) { | |
| 577 LOG_J(LS_VERBOSE, this) << | |
| 578 "Ignoring STUN binding response message on shared socket."; | |
| 579 return; | |
| 580 } | |
| 581 | 583 |
| 582 // This must be a response for one of our requests. | 584 if (SharedSocket() && (msg_type == STUN_BINDING_RESPONSE || |
| 583 // Check success responses, but not errors, for MESSAGE-INTEGRITY. | 585 msg_type == STUN_BINDING_ERROR_RESPONSE)) { |
| 584 if (IsStunSuccessResponseType(msg_type) && | 586 LOG_J(LS_VERBOSE, this) << |
| 585 !StunMessage::ValidateMessageIntegrity(data, size, hash())) { | 587 "Ignoring STUN binding response message on shared socket."; |
| 586 LOG_J(LS_WARNING, this) << "Received TURN message with invalid " | 588 return false; |
| 587 << "message integrity, msg_type=" << msg_type; | |
| 588 return; | |
| 589 } | |
| 590 request_manager_.CheckResponse(data, size); | |
| 591 } | 589 } |
| 590 |
| 591 // This must be a response for one of our requests. |
| 592 // Check success responses, but not errors, for MESSAGE-INTEGRITY. |
| 593 if (IsStunSuccessResponseType(msg_type) && |
| 594 !StunMessage::ValidateMessageIntegrity(data, size, hash())) { |
| 595 LOG_J(LS_WARNING, this) << "Received TURN message with invalid " |
| 596 << "message integrity, msg_type=" << msg_type; |
| 597 return true; |
| 598 } |
| 599 request_manager_.CheckResponse(data, size); |
| 600 |
| 601 return true; |
| 602 } |
| 603 |
| 604 void TurnPort::OnReadPacket(rtc::AsyncPacketSocket* socket, |
| 605 const char* data, |
| 606 size_t size, |
| 607 const rtc::SocketAddress& remote_addr, |
| 608 const rtc::PacketTime& packet_time) { |
| 609 HandleIncomingPacket(socket, data, size, remote_addr, packet_time); |
| 592 } | 610 } |
| 593 | 611 |
| 594 void TurnPort::OnSentPacket(rtc::AsyncPacketSocket* socket, | 612 void TurnPort::OnSentPacket(rtc::AsyncPacketSocket* socket, |
| 595 const rtc::SentPacket& sent_packet) { | 613 const rtc::SentPacket& sent_packet) { |
| 596 PortInterface::SignalSentPacket(sent_packet); | 614 PortInterface::SignalSentPacket(sent_packet); |
| 597 } | 615 } |
| 598 | 616 |
| 599 void TurnPort::OnReadyToSend(rtc::AsyncPacketSocket* socket) { | 617 void TurnPort::OnReadyToSend(rtc::AsyncPacketSocket* socket) { |
| 600 if (ready()) { | 618 if (ready()) { |
| 601 Port::OnReadyToSend(); | 619 Port::OnReadyToSend(); |
| (...skipping 910 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1512 } else { | 1530 } else { |
| 1513 state_ = STATE_UNBOUND; | 1531 state_ = STATE_UNBOUND; |
| 1514 port_->DestroyConnection(ext_addr_); | 1532 port_->DestroyConnection(ext_addr_); |
| 1515 } | 1533 } |
| 1516 } | 1534 } |
| 1517 void TurnEntry::OnChannelBindTimeout() { | 1535 void TurnEntry::OnChannelBindTimeout() { |
| 1518 state_ = STATE_UNBOUND; | 1536 state_ = STATE_UNBOUND; |
| 1519 port_->DestroyConnection(ext_addr_); | 1537 port_->DestroyConnection(ext_addr_); |
| 1520 } | 1538 } |
| 1521 } // namespace cricket | 1539 } // namespace cricket |
| OLD | NEW |