blob: 44e3927ee9b42a179d4f564fdaadc9bdbf242740 [file] [log] [blame]
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +00001/*
2 * Copyright 2008 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_STUN_SERVER_H_
12#define P2P_BASE_TEST_STUN_SERVER_H_
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000013
Yves Gerey3e707812018-11-28 16:47:49 +010014#include "p2p/base/stun.h"
Steve Anton10542f22019-01-11 09:11:00 -080015#include "p2p/base/stun_server.h"
16#include "rtc_base/async_udp_socket.h"
17#include "rtc_base/socket_address.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#include "rtc_base/thread.h"
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000019
20namespace cricket {
21
22// A test STUN server. Useful for unit tests.
23class TestStunServer : StunServer {
24 public:
25 static TestStunServer* Create(rtc::Thread* thread,
Steve Antoneae3e652017-10-25 14:46:18 -070026 const rtc::SocketAddress& addr);
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000027
28 // Set a fake STUN address to return to the client.
29 void set_fake_stun_addr(const rtc::SocketAddress& addr) {
30 fake_stun_addr_ = addr;
31 }
32
33 private:
34 explicit TestStunServer(rtc::AsyncUDPSocket* socket) : StunServer(socket) {}
35
36 void OnBindingRequest(StunMessage* msg,
Steve Antoneae3e652017-10-25 14:46:18 -070037 const rtc::SocketAddress& remote_addr) override;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000038
39 private:
40 rtc::SocketAddress fake_stun_addr_;
41};
42
43} // namespace cricket
44
Steve Anton10542f22019-01-11 09:11:00 -080045#endif // P2P_BASE_TEST_STUN_SERVER_H_