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