blob: 9330a000750e37636d938042da65a66b9abe3515 [file] [log] [blame]
Steve Antoneae3e652017-10-25 14:46:18 -07001/*
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
Steve Anton10542f22019-01-11 09:11:00 -080011#include "p2p/base/test_stun_server.h"
Steve Antoneae3e652017-10-25 14:46:18 -070012
Steve Anton10542f22019-01-11 09:11:00 -080013#include "rtc_base/async_socket.h"
14#include "rtc_base/socket_server.h"
Yves Gerey3e707812018-11-28 16:47:49 +010015
Steve Antoneae3e652017-10-25 14:46:18 -070016namespace cricket {
17
18TestStunServer* 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
27void 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;
Min Wang1e00dbc2019-06-26 13:08:29 -050033 GetStunBindResponse(msg, fake_stun_addr_, &response);
Steve Antoneae3e652017-10-25 14:46:18 -070034 SendResponse(response, remote_addr);
35 }
36}
37
38} // namespace cricket