| 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 |
| 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; |
| 33 | GetStunBindResponse(msg, fake_stun_addr_, &response); |
| 34 | SendResponse(response, remote_addr); |
| 35 | } |
| 36 | } |
| 37 |
| 38 | } // namespace cricket |
| 39 |