diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:13:27 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:13:27 +0000 |
commit | 40a355a42d4a9444dc753c04c6608dade2f06a23 (patch) | |
tree | 871fc667d2de662f171103ce5ec067014ef85e61 /third_party/libwebrtc/test/network/emulated_turn_server.cc | |
parent | Adding upstream version 124.0.1. (diff) | |
download | firefox-40a355a42d4a9444dc753c04c6608dade2f06a23.tar.xz firefox-40a355a42d4a9444dc753c04c6608dade2f06a23.zip |
Adding upstream version 125.0.1.upstream/125.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/libwebrtc/test/network/emulated_turn_server.cc')
-rw-r--r-- | third_party/libwebrtc/test/network/emulated_turn_server.cc | 102 |
1 files changed, 53 insertions, 49 deletions
diff --git a/third_party/libwebrtc/test/network/emulated_turn_server.cc b/third_party/libwebrtc/test/network/emulated_turn_server.cc index 0bc7ec6e2a..93724ca8a3 100644 --- a/third_party/libwebrtc/test/network/emulated_turn_server.cc +++ b/third_party/libwebrtc/test/network/emulated_turn_server.cc @@ -14,6 +14,7 @@ #include <utility> #include "api/packet_socket_factory.h" +#include "rtc_base/network/received_packet.h" #include "rtc_base/strings/string_builder.h" #include "rtc_base/task_queue_for_test.h" @@ -22,10 +23,56 @@ namespace { static const char kTestRealm[] = "example.org"; static const char kTestSoftware[] = "TestTurnServer"; +// A wrapper class for cricket::TurnServer to allocate sockets. +class PacketSocketFactoryWrapper : public rtc::PacketSocketFactory { + public: + explicit PacketSocketFactoryWrapper( + webrtc::test::EmulatedTURNServer* turn_server) + : turn_server_(turn_server) {} + ~PacketSocketFactoryWrapper() override {} + + // This method is called from TurnServer when making a TURN ALLOCATION. + // It will create a socket on the `peer_` endpoint. + rtc::AsyncPacketSocket* CreateUdpSocket(const rtc::SocketAddress& address, + uint16_t min_port, + uint16_t max_port) override { + return turn_server_->CreatePeerSocket(); + } + + rtc::AsyncListenSocket* CreateServerTcpSocket( + const rtc::SocketAddress& local_address, + uint16_t min_port, + uint16_t max_port, + int opts) override { + return nullptr; + } + rtc::AsyncPacketSocket* CreateClientTcpSocket( + const rtc::SocketAddress& local_address, + const rtc::SocketAddress& remote_address, + const rtc::ProxyInfo& proxy_info, + const std::string& user_agent, + const rtc::PacketSocketTcpOptions& tcp_options) override { + return nullptr; + } + std::unique_ptr<webrtc::AsyncDnsResolverInterface> CreateAsyncDnsResolver() + override { + return nullptr; + } + + private: + webrtc::test::EmulatedTURNServer* turn_server_; +}; + +} // namespace + +namespace webrtc { +namespace test { + // A wrapper class for copying data between an AsyncPacketSocket and a // EmulatedEndpoint. This is used by the cricket::TurnServer when // sending data back into the emulated network. -class AsyncPacketSocketWrapper : public rtc::AsyncPacketSocket { +class EmulatedTURNServer::AsyncPacketSocketWrapper + : public rtc::AsyncPacketSocket { public: AsyncPacketSocketWrapper(webrtc::test::EmulatedTURNServer* turn_server, webrtc::EmulatedEndpoint* endpoint, @@ -56,6 +103,9 @@ class AsyncPacketSocketWrapper : public rtc::AsyncPacketSocket { return cb; } int Close() override { return 0; } + void NotifyPacketReceived(const rtc::ReceivedPacket& packet) { + rtc::AsyncPacketSocket::NotifyPacketReceived(packet); + } rtc::AsyncPacketSocket::State GetState() const override { return rtc::AsyncPacketSocket::STATE_BOUND; @@ -71,51 +121,6 @@ class AsyncPacketSocketWrapper : public rtc::AsyncPacketSocket { const rtc::SocketAddress local_address_; }; -// A wrapper class for cricket::TurnServer to allocate sockets. -class PacketSocketFactoryWrapper : public rtc::PacketSocketFactory { - public: - explicit PacketSocketFactoryWrapper( - webrtc::test::EmulatedTURNServer* turn_server) - : turn_server_(turn_server) {} - ~PacketSocketFactoryWrapper() override {} - - // This method is called from TurnServer when making a TURN ALLOCATION. - // It will create a socket on the `peer_` endpoint. - rtc::AsyncPacketSocket* CreateUdpSocket(const rtc::SocketAddress& address, - uint16_t min_port, - uint16_t max_port) override { - return turn_server_->CreatePeerSocket(); - } - - rtc::AsyncListenSocket* CreateServerTcpSocket( - const rtc::SocketAddress& local_address, - uint16_t min_port, - uint16_t max_port, - int opts) override { - return nullptr; - } - rtc::AsyncPacketSocket* CreateClientTcpSocket( - const rtc::SocketAddress& local_address, - const rtc::SocketAddress& remote_address, - const rtc::ProxyInfo& proxy_info, - const std::string& user_agent, - const rtc::PacketSocketTcpOptions& tcp_options) override { - return nullptr; - } - std::unique_ptr<webrtc::AsyncDnsResolverInterface> CreateAsyncDnsResolver() - override { - return nullptr; - } - - private: - webrtc::test::EmulatedTURNServer* turn_server_; -}; - -} // namespace - -namespace webrtc { -namespace test { - EmulatedTURNServer::EmulatedTURNServer(std::unique_ptr<rtc::Thread> thread, EmulatedEndpoint* client, EmulatedEndpoint* peer) @@ -170,9 +175,8 @@ void EmulatedTURNServer::OnPacketReceived(webrtc::EmulatedIpPacket packet) { RTC_DCHECK_RUN_ON(thread_.get()); auto it = sockets_.find(packet.to); if (it != sockets_.end()) { - it->second->SignalReadPacket( - it->second, reinterpret_cast<const char*>(packet.cdata()), - packet.size(), packet.from, packet.arrival_time.ms()); + it->second->NotifyPacketReceived( + rtc::ReceivedPacket(packet.data, packet.from, packet.arrival_time)); } }); } |