henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 1 | /* |
| 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 Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 11 | #ifndef P2P_BASE_TEST_STUN_SERVER_H_ |
| 12 | #define P2P_BASE_TEST_STUN_SERVER_H_ |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 13 | |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 14 | #include "p2p/base/stun.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 15 | #include "p2p/base/stun_server.h" |
| 16 | #include "rtc_base/async_udp_socket.h" |
| 17 | #include "rtc_base/socket_address.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 18 | #include "rtc_base/thread.h" |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 19 | |
| 20 | namespace cricket { |
| 21 | |
| 22 | // A test STUN server. Useful for unit tests. |
| 23 | class TestStunServer : StunServer { |
| 24 | public: |
| 25 | static TestStunServer* Create(rtc::Thread* thread, |
Steve Anton | eae3e65 | 2017-10-25 14:46:18 -0700 | [diff] [blame] | 26 | const rtc::SocketAddress& addr); |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 27 | |
| 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 Anton | eae3e65 | 2017-10-25 14:46:18 -0700 | [diff] [blame] | 37 | const rtc::SocketAddress& remote_addr) override; |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 38 | |
| 39 | private: |
| 40 | rtc::SocketAddress fake_stun_addr_; |
| 41 | }; |
| 42 | |
| 43 | } // namespace cricket |
| 44 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 45 | #endif // P2P_BASE_TEST_STUN_SERVER_H_ |