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/socket.h"
14 #include "rtc_base/socket_server.h"
15
16 namespace cricket {
17
Create(rtc::SocketServer * ss,const rtc::SocketAddress & addr)18 TestStunServer* TestStunServer::Create(rtc::SocketServer* ss,
19 const rtc::SocketAddress& addr) {
20 rtc::Socket* socket = ss->CreateSocket(addr.family(), SOCK_DGRAM);
21 rtc::AsyncUDPSocket* udp_socket = rtc::AsyncUDPSocket::Create(socket, addr);
22
23 return new TestStunServer(udp_socket);
24 }
25
OnBindingRequest(StunMessage * msg,const rtc::SocketAddress & remote_addr)26 void TestStunServer::OnBindingRequest(StunMessage* msg,
27 const rtc::SocketAddress& remote_addr) {
28 if (fake_stun_addr_.IsNil()) {
29 StunServer::OnBindingRequest(msg, remote_addr);
30 } else {
31 StunMessage response(STUN_BINDING_RESPONSE, msg->transaction_id());
32 GetStunBindResponse(msg, fake_stun_addr_, &response);
33 SendResponse(response, remote_addr);
34 }
35 }
36
37 } // namespace cricket
38