Add method to modify magic cookie of a STUN message

Bug: webrtc:8934
Change-Id: I0228e9f2f677ece090b0f2744f138b9b2f797d48
Reviewed-on: https://webrtc-review.googlesource.com/57585
Reviewed-by: Taylor Brandstetter <deadbeef@webrtc.org>
Commit-Queue: Jonas Oreland <jonaso@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#22217}
This commit is contained in:
Jonas Oreland
2018-02-27 08:45:13 +01:00
committed by Commit Bot
parent 0ffaaa26f9
commit 7ca6311e14
2 changed files with 12 additions and 2 deletions

View File

@ -49,7 +49,8 @@ const uint32_t STUN_FINGERPRINT_XOR_VALUE = 0x5354554E;
StunMessage::StunMessage()
: type_(0),
length_(0),
transaction_id_(EMPTY_TRANSACTION_ID) {
transaction_id_(EMPTY_TRANSACTION_ID),
stun_magic_cookie_(kStunMagicCookie) {
RTC_DCHECK(IsValidTransactionId(transaction_id_));
}
@ -394,7 +395,7 @@ bool StunMessage::Write(ByteBufferWriter* buf) const {
buf->WriteUInt16(type_);
buf->WriteUInt16(length_);
if (!IsLegacy())
buf->WriteUInt32(kStunMagicCookie);
buf->WriteUInt32(stun_magic_cookie_);
buf->WriteString(transaction_id_);
for (const auto& attr : attrs_) {
@ -412,6 +413,10 @@ StunMessage* StunMessage::CreateNew() const {
return new StunMessage();
}
void StunMessage::SetStunMagicCookie(uint32_t val) {
stun_magic_cookie_ = val;
}
StunAttributeValueType StunMessage::GetAttributeValueType(int type) const {
switch (type) {
case STUN_ATTR_MAPPED_ADDRESS: return STUN_VALUE_ADDRESS;

View File

@ -194,6 +194,10 @@ class StunMessage {
// Creates an empty message. Overridable by derived classes.
virtual StunMessage* CreateNew() const;
// Modify the stun magic cookie used for this STUN message.
// This is used for testing.
void SetStunMagicCookie(uint32_t val);
protected:
// Verifies that the given attribute is allowed for this message.
virtual StunAttributeValueType GetAttributeValueType(int type) const;
@ -207,6 +211,7 @@ class StunMessage {
uint16_t length_;
std::string transaction_id_;
std::vector<std::unique_ptr<StunAttribute>> attrs_;
uint32_t stun_magic_cookie_;
};
// Base class for all STUN/TURN attributes.