test_stun_server.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. #ifndef P2P_BASE_TEST_STUN_SERVER_H_
  11. #define P2P_BASE_TEST_STUN_SERVER_H_
  12. #include "api/transport/stun.h"
  13. #include "p2p/base/stun_server.h"
  14. #include "rtc_base/async_udp_socket.h"
  15. #include "rtc_base/socket_address.h"
  16. #include "rtc_base/thread.h"
  17. namespace cricket {
  18. // A test STUN server. Useful for unit tests.
  19. class TestStunServer : StunServer {
  20. public:
  21. static TestStunServer* Create(rtc::Thread* thread,
  22. const rtc::SocketAddress& addr);
  23. // Set a fake STUN address to return to the client.
  24. void set_fake_stun_addr(const rtc::SocketAddress& addr) {
  25. fake_stun_addr_ = addr;
  26. }
  27. private:
  28. explicit TestStunServer(rtc::AsyncUDPSocket* socket) : StunServer(socket) {}
  29. void OnBindingRequest(StunMessage* msg,
  30. const rtc::SocketAddress& remote_addr) override;
  31. private:
  32. rtc::SocketAddress fake_stun_addr_;
  33. };
  34. } // namespace cricket
  35. #endif // P2P_BASE_TEST_STUN_SERVER_H_