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 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 | 344 |
345 // Don't bother parsing the packet if we can tell it's not STUN. | 345 // Don't bother parsing the packet if we can tell it's not STUN. |
346 // In ICE mode, all STUN packets will have a valid fingerprint. | 346 // In ICE mode, all STUN packets will have a valid fingerprint. |
347 if (!StunMessage::ValidateFingerprint(data, size)) { | 347 if (!StunMessage::ValidateFingerprint(data, size)) { |
348 return false; | 348 return false; |
349 } | 349 } |
350 | 350 |
351 // Parse the request message. If the packet is not a complete and correct | 351 // Parse the request message. If the packet is not a complete and correct |
352 // STUN message, then ignore it. | 352 // STUN message, then ignore it. |
353 rtc::scoped_ptr<IceMessage> stun_msg(new IceMessage()); | 353 rtc::scoped_ptr<IceMessage> stun_msg(new IceMessage()); |
354 rtc::ByteBuffer buf(data, size); | 354 rtc::ByteBufferReader buf(data, size); |
355 if (!stun_msg->Read(&buf) || (buf.Length() > 0)) { | 355 if (!stun_msg->Read(&buf) || (buf.Length() > 0)) { |
356 return false; | 356 return false; |
357 } | 357 } |
358 | 358 |
359 if (stun_msg->type() == STUN_BINDING_REQUEST) { | 359 if (stun_msg->type() == STUN_BINDING_REQUEST) { |
360 // Check for the presence of USERNAME and MESSAGE-INTEGRITY (if ICE) first. | 360 // Check for the presence of USERNAME and MESSAGE-INTEGRITY (if ICE) first. |
361 // If not present, fail with a 400 Bad Request. | 361 // If not present, fail with a 400 Bad Request. |
362 if (!stun_msg->GetByteString(STUN_ATTR_USERNAME) || | 362 if (!stun_msg->GetByteString(STUN_ATTR_USERNAME) || |
363 !stun_msg->GetByteString(STUN_ATTR_MESSAGE_INTEGRITY)) { | 363 !stun_msg->GetByteString(STUN_ATTR_MESSAGE_INTEGRITY)) { |
364 LOG_J(LS_ERROR, this) << "Received STUN request without username/M-I " | 364 LOG_J(LS_ERROR, this) << "Received STUN request without username/M-I " |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
566 << retransmit_attr->value(); | 566 << retransmit_attr->value(); |
567 } | 567 } |
568 } | 568 } |
569 | 569 |
570 response.AddAttribute( | 570 response.AddAttribute( |
571 new StunXorAddressAttribute(STUN_ATTR_XOR_MAPPED_ADDRESS, addr)); | 571 new StunXorAddressAttribute(STUN_ATTR_XOR_MAPPED_ADDRESS, addr)); |
572 response.AddMessageIntegrity(password_); | 572 response.AddMessageIntegrity(password_); |
573 response.AddFingerprint(); | 573 response.AddFingerprint(); |
574 | 574 |
575 // Send the response message. | 575 // Send the response message. |
576 rtc::ByteBuffer buf; | 576 rtc::ByteBufferWriter buf; |
577 response.Write(&buf); | 577 response.Write(&buf); |
578 rtc::PacketOptions options(DefaultDscpValue()); | 578 rtc::PacketOptions options(DefaultDscpValue()); |
579 auto err = SendTo(buf.Data(), buf.Length(), addr, options, false); | 579 auto err = SendTo(buf.Data(), buf.Length(), addr, options, false); |
580 if (err < 0) { | 580 if (err < 0) { |
581 LOG_J(LS_ERROR, this) | 581 LOG_J(LS_ERROR, this) |
582 << "Failed to send STUN ping response" | 582 << "Failed to send STUN ping response" |
583 << ", to=" << addr.ToSensitiveString() | 583 << ", to=" << addr.ToSensitiveString() |
584 << ", err=" << err | 584 << ", err=" << err |
585 << ", id=" << rtc::hex_encode(response.transaction_id()); | 585 << ", id=" << rtc::hex_encode(response.transaction_id()); |
586 } else { | 586 } else { |
(...skipping 27 matching lines...) Expand all Loading... |
614 response.AddAttribute(error_attr); | 614 response.AddAttribute(error_attr); |
615 | 615 |
616 // Per Section 10.1.2, certain error cases don't get a MESSAGE-INTEGRITY, | 616 // Per Section 10.1.2, certain error cases don't get a MESSAGE-INTEGRITY, |
617 // because we don't have enough information to determine the shared secret. | 617 // because we don't have enough information to determine the shared secret. |
618 if (error_code != STUN_ERROR_BAD_REQUEST && | 618 if (error_code != STUN_ERROR_BAD_REQUEST && |
619 error_code != STUN_ERROR_UNAUTHORIZED) | 619 error_code != STUN_ERROR_UNAUTHORIZED) |
620 response.AddMessageIntegrity(password_); | 620 response.AddMessageIntegrity(password_); |
621 response.AddFingerprint(); | 621 response.AddFingerprint(); |
622 | 622 |
623 // Send the response message. | 623 // Send the response message. |
624 rtc::ByteBuffer buf; | 624 rtc::ByteBufferWriter buf; |
625 response.Write(&buf); | 625 response.Write(&buf); |
626 rtc::PacketOptions options(DefaultDscpValue()); | 626 rtc::PacketOptions options(DefaultDscpValue()); |
627 SendTo(buf.Data(), buf.Length(), addr, options, false); | 627 SendTo(buf.Data(), buf.Length(), addr, options, false); |
628 LOG_J(LS_INFO, this) << "Sending STUN binding error: reason=" << reason | 628 LOG_J(LS_INFO, this) << "Sending STUN binding error: reason=" << reason |
629 << " to " << addr.ToSensitiveString(); | 629 << " to " << addr.ToSensitiveString(); |
630 } | 630 } |
631 | 631 |
632 void Port::OnMessage(rtc::Message *pmsg) { | 632 void Port::OnMessage(rtc::Message *pmsg) { |
633 ASSERT(pmsg->message_id == MSG_DEAD); | 633 ASSERT(pmsg->message_id == MSG_DEAD); |
634 if (dead()) { | 634 if (dead()) { |
(...skipping 809 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1444 ASSERT(sent < 0); | 1444 ASSERT(sent < 0); |
1445 error_ = port_->GetError(); | 1445 error_ = port_->GetError(); |
1446 sent_packets_discarded_++; | 1446 sent_packets_discarded_++; |
1447 } else { | 1447 } else { |
1448 send_rate_tracker_.AddSamples(sent); | 1448 send_rate_tracker_.AddSamples(sent); |
1449 } | 1449 } |
1450 return sent; | 1450 return sent; |
1451 } | 1451 } |
1452 | 1452 |
1453 } // namespace cricket | 1453 } // namespace cricket |
OLD | NEW |