blob: 265b53683ae00b2b4eed03b4561783d86eebe127 [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
11#ifndef P2P_BASE_TESTTURNCUSTOMIZER_H_
12#define P2P_BASE_TESTTURNCUSTOMIZER_H_
13
14#include "api/turncustomizer.h"
Jonas Orelandf0229762017-10-12 11:18:55 +020015#include "rtc_base/gunit.h"
Jonas Orelandbdcee282017-10-10 14:01:40 +020016#include "rtc_base/ptr_util.h"
17
18namespace cricket {
19
20class TestTurnCustomizer : public webrtc::TurnCustomizer {
21 public:
22 TestTurnCustomizer() {}
23 virtual ~TestTurnCustomizer() {}
24
25 enum TestTurnAttributeExtensions {
26 // Test only attribute
Yves Gerey665174f2018-06-19 15:03:05 +020027 STUN_ATTR_COUNTER = 0xFF02 // Number
Jonas Orelandbdcee282017-10-10 14:01:40 +020028 };
29
Yves Gerey665174f2018-06-19 15:03:05 +020030 void MaybeModifyOutgoingStunMessage(cricket::PortInterface* port,
31 cricket::StunMessage* message) override {
Steve Anton6c38cc72017-11-29 10:25:58 -080032 modify_cnt_++;
Jonas Orelandbdcee282017-10-10 14:01:40 +020033
Jonas Orelandf0229762017-10-12 11:18:55 +020034 ASSERT_NE(0, message->type());
Jonas Orelandbdcee282017-10-10 14:01:40 +020035 if (add_counter_) {
36 message->AddAttribute(rtc::MakeUnique<cricket::StunUInt32Attribute>(
37 STUN_ATTR_COUNTER, modify_cnt_));
38 }
39 return;
40 }
41
42 bool AllowChannelData(cricket::PortInterface* port,
43 const void* data,
44 size_t size,
45 bool payload) override {
46 allow_channel_data_cnt_++;
47 return allow_channel_data_;
48 }
49
50 bool add_counter_ = false;
51 bool allow_channel_data_ = true;
52 unsigned int modify_cnt_ = 0;
53 unsigned int allow_channel_data_cnt_ = 0;
54};
55
56} // namespace cricket
57
58#endif // P2P_BASE_TESTTURNCUSTOMIZER_H_