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 11 #ifndef P2P_BASE_TEST_STUN_SERVER_H_ 12 #define P2P_BASE_TEST_STUN_SERVER_H_ 13 14 #include "api/transport/stun.h" 15 #include "p2p/base/stun_server.h" 16 #include "rtc_base/async_udp_socket.h" 17 #include "rtc_base/socket_address.h" 18 #include "rtc_base/socket_server.h" 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::SocketServer* ss, 26 const rtc::SocketAddress& addr); 27 28 // Set a fake STUN address to return to the client. set_fake_stun_addr(const rtc::SocketAddress & addr)29 void set_fake_stun_addr(const rtc::SocketAddress& addr) { 30 fake_stun_addr_ = addr; 31 } 32 33 private: TestStunServer(rtc::AsyncUDPSocket * socket)34 explicit TestStunServer(rtc::AsyncUDPSocket* socket) : StunServer(socket) {} 35 36 void OnBindingRequest(StunMessage* msg, 37 const rtc::SocketAddress& remote_addr) override; 38 39 private: 40 rtc::SocketAddress fake_stun_addr_; 41 }; 42 43 } // namespace cricket 44 45 #endif // P2P_BASE_TEST_STUN_SERVER_H_ 46