blob: 415b13fbf2c8327274ee4e1cfbcdaa01e2b33491 [file] [log] [blame]
Jonas Orelandbdcee282017-10-10 14:01:40 +02001/*
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
Steve Anton10542f22019-01-11 09:11:00 -080011#ifndef P2P_BASE_TEST_TURN_CUSTOMIZER_H_
12#define P2P_BASE_TEST_TURN_CUSTOMIZER_H_
Jonas Orelandbdcee282017-10-10 14:01:40 +020013
Mirko Bonadei317a1f02019-09-17 17:06:18 +020014#include <memory>
15
Steve Anton10542f22019-01-11 09:11:00 -080016#include "api/turn_customizer.h"
Jonas Orelandf0229762017-10-12 11:18:55 +020017#include "rtc_base/gunit.h"
Jonas Orelandbdcee282017-10-10 14:01:40 +020018
19namespace cricket {
20
21class TestTurnCustomizer : public webrtc::TurnCustomizer {
22 public:
23 TestTurnCustomizer() {}
24 virtual ~TestTurnCustomizer() {}
25
26 enum TestTurnAttributeExtensions {
27 // Test only attribute
Yves Gerey665174f2018-06-19 15:03:05 +020028 STUN_ATTR_COUNTER = 0xFF02 // Number
Jonas Orelandbdcee282017-10-10 14:01:40 +020029 };
30
Yves Gerey665174f2018-06-19 15:03:05 +020031 void MaybeModifyOutgoingStunMessage(cricket::PortInterface* port,
32 cricket::StunMessage* message) override {
Steve Anton6c38cc72017-11-29 10:25:58 -080033 modify_cnt_++;
Jonas Orelandbdcee282017-10-10 14:01:40 +020034
Jonas Orelandf0229762017-10-12 11:18:55 +020035 ASSERT_NE(0, message->type());
Jonas Orelandbdcee282017-10-10 14:01:40 +020036 if (add_counter_) {
Mirko Bonadei317a1f02019-09-17 17:06:18 +020037 message->AddAttribute(std::make_unique<cricket::StunUInt32Attribute>(
Jonas Orelandbdcee282017-10-10 14:01:40 +020038 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
Steve Anton10542f22019-01-11 09:11:00 -080059#endif // P2P_BASE_TEST_TURN_CUSTOMIZER_H_