You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
1.3 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  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. #include "p2p/base/test_stun_server.h"
  11. #include "rtc_base/async_socket.h"
  12. #include "rtc_base/socket_server.h"
  13. namespace cricket {
  14. TestStunServer* TestStunServer::Create(rtc::Thread* thread,
  15. const rtc::SocketAddress& addr) {
  16. rtc::AsyncSocket* socket =
  17. thread->socketserver()->CreateAsyncSocket(addr.family(), SOCK_DGRAM);
  18. rtc::AsyncUDPSocket* udp_socket = rtc::AsyncUDPSocket::Create(socket, addr);
  19. return new TestStunServer(udp_socket);
  20. }
  21. void TestStunServer::OnBindingRequest(StunMessage* msg,
  22. const rtc::SocketAddress& remote_addr) {
  23. if (fake_stun_addr_.IsNil()) {
  24. StunServer::OnBindingRequest(msg, remote_addr);
  25. } else {
  26. StunMessage response;
  27. GetStunBindResponse(msg, fake_stun_addr_, &response);
  28. SendResponse(response, remote_addr);
  29. }
  30. }
  31. } // namespace cricket