Jonas Oreland | bdcee28 | 2017-10-10 14:01:40 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 The WebRTC Project Authors. All rights reserved. |
| 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | #ifndef P2P_BASE_TESTTURNCUSTOMIZER_H_ |
| 12 | #define P2P_BASE_TESTTURNCUSTOMIZER_H_ |
| 13 | |
| 14 | #include "api/turncustomizer.h" |
Jonas Oreland | f022976 | 2017-10-12 11:18:55 +0200 | [diff] [blame] | 15 | #include "rtc_base/gunit.h" |
Jonas Oreland | bdcee28 | 2017-10-10 14:01:40 +0200 | [diff] [blame] | 16 | #include "rtc_base/ptr_util.h" |
| 17 | |
| 18 | namespace cricket { |
| 19 | |
| 20 | class TestTurnCustomizer : public webrtc::TurnCustomizer { |
| 21 | public: |
| 22 | TestTurnCustomizer() {} |
| 23 | virtual ~TestTurnCustomizer() {} |
| 24 | |
| 25 | enum TestTurnAttributeExtensions { |
| 26 | // Test only attribute |
| 27 | STUN_ATTR_COUNTER = 0xFF02 // Number |
| 28 | }; |
| 29 | |
| 30 | void MaybeModifyOutgoingStunMessage( |
| 31 | cricket::PortInterface* port, |
| 32 | cricket::StunMessage* message) override { |
Steve Anton | 6c38cc7 | 2017-11-29 10:25:58 -0800 | [diff] [blame] | 33 | modify_cnt_++; |
Jonas Oreland | bdcee28 | 2017-10-10 14:01:40 +0200 | [diff] [blame] | 34 | |
Jonas Oreland | f022976 | 2017-10-12 11:18:55 +0200 | [diff] [blame] | 35 | ASSERT_NE(0, message->type()); |
Jonas Oreland | bdcee28 | 2017-10-10 14:01:40 +0200 | [diff] [blame] | 36 | if (add_counter_) { |
| 37 | message->AddAttribute(rtc::MakeUnique<cricket::StunUInt32Attribute>( |
| 38 | STUN_ATTR_COUNTER, modify_cnt_)); |
| 39 | } |
| 40 | return; |
| 41 | } |
| 42 | |
| 43 | bool AllowChannelData(cricket::PortInterface* port, |
| 44 | const void* data, |
| 45 | size_t size, |
| 46 | bool payload) override { |
| 47 | allow_channel_data_cnt_++; |
| 48 | return allow_channel_data_; |
| 49 | } |
| 50 | |
| 51 | bool add_counter_ = false; |
| 52 | bool allow_channel_data_ = true; |
| 53 | unsigned int modify_cnt_ = 0; |
| 54 | unsigned int allow_channel_data_cnt_ = 0; |
| 55 | }; |
| 56 | |
| 57 | } // namespace cricket |
| 58 | |
| 59 | #endif // P2P_BASE_TESTTURNCUSTOMIZER_H_ |