Steve Anton | eae3e65 | 2017-10-25 14:46:18 -0700 | [diff] [blame] | 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 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 11 | #include "p2p/base/test_stun_server.h" |
Steve Anton | eae3e65 | 2017-10-25 14:46:18 -0700 | [diff] [blame] | 12 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 13 | #include "rtc_base/async_socket.h" |
| 14 | #include "rtc_base/socket_server.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 15 | |
Steve Anton | eae3e65 | 2017-10-25 14:46:18 -0700 | [diff] [blame] | 16 | namespace cricket { |
| 17 | |
| 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 | |
| 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; |
Min Wang | 1e00dbc | 2019-06-26 13:08:29 -0500 | [diff] [blame] | 33 | GetStunBindResponse(msg, fake_stun_addr_, &response); |
Steve Anton | eae3e65 | 2017-10-25 14:46:18 -0700 | [diff] [blame] | 34 | SendResponse(response, remote_addr); |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | } // namespace cricket |