diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-15 03:35:49 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-15 03:35:49 +0000 |
commit | d8bbc7858622b6d9c278469aab701ca0b609cddf (patch) | |
tree | eff41dc61d9f714852212739e6b3738b82a2af87 /third_party/libwebrtc/rtc_base/nat_server.cc | |
parent | Releasing progress-linux version 125.0.3-1~progress7.99u1. (diff) | |
download | firefox-d8bbc7858622b6d9c278469aab701ca0b609cddf.tar.xz firefox-d8bbc7858622b6d9c278469aab701ca0b609cddf.zip |
Merging upstream version 126.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/libwebrtc/rtc_base/nat_server.cc')
-rw-r--r-- | third_party/libwebrtc/rtc_base/nat_server.cc | 76 |
1 files changed, 49 insertions, 27 deletions
diff --git a/third_party/libwebrtc/rtc_base/nat_server.cc b/third_party/libwebrtc/rtc_base/nat_server.cc index b818685efb..c274cedf18 100644 --- a/third_party/libwebrtc/rtc_base/nat_server.cc +++ b/third_party/libwebrtc/rtc_base/nat_server.cc @@ -10,12 +10,15 @@ #include "rtc_base/nat_server.h" +#include <cstddef> #include <memory> #include "rtc_base/checks.h" #include "rtc_base/logging.h" #include "rtc_base/nat_socket_factory.h" +#include "rtc_base/network/received_packet.h" #include "rtc_base/socket_adapters.h" +#include "rtc_base/socket_address.h" namespace rtc { @@ -125,17 +128,27 @@ class NATProxyServer : public ProxyServer { }; NATServer::NATServer(NATType type, + rtc::Thread& internal_socket_thread, SocketFactory* internal, const SocketAddress& internal_udp_addr, const SocketAddress& internal_tcp_addr, + rtc::Thread& external_socket_thread, SocketFactory* external, const SocketAddress& external_ip) - : external_(external), external_ip_(external_ip.ipaddr(), 0) { + : internal_socket_thread_(internal_socket_thread), + external_socket_thread_(external_socket_thread), + external_(external), + external_ip_(external_ip.ipaddr(), 0) { nat_ = NAT::Create(type); - udp_server_socket_ = AsyncUDPSocket::Create(internal, internal_udp_addr); - udp_server_socket_->SignalReadPacket.connect(this, - &NATServer::OnInternalUDPPacket); + internal_socket_thread_.BlockingCall([&] { + udp_server_socket_ = AsyncUDPSocket::Create(internal, internal_udp_addr); + udp_server_socket_->RegisterReceivedPacketCallback( + [&](rtc::AsyncPacketSocket* socket, const rtc::ReceivedPacket& packet) { + OnInternalUDPPacket(socket, packet); + }); + }); + tcp_proxy_server_ = new NATProxyServer(internal, internal_tcp_addr, external, external_ip); @@ -156,10 +169,11 @@ NATServer::~NATServer() { } void NATServer::OnInternalUDPPacket(AsyncPacketSocket* socket, - const char* buf, - size_t size, - const SocketAddress& addr, - const int64_t& /* packet_time_us */) { + const rtc::ReceivedPacket& packet) { + RTC_DCHECK(internal_socket_thread_.IsCurrent()); + const char* buf = reinterpret_cast<const char*>(packet.payload().data()); + size_t size = packet.payload().size(); + const SocketAddress& addr = packet.source_address(); // Read the intended destination from the wire. SocketAddress dest_addr; size_t length = UnpackAddressFromNAT(buf, size, &dest_addr); @@ -182,10 +196,8 @@ void NATServer::OnInternalUDPPacket(AsyncPacketSocket* socket, } void NATServer::OnExternalUDPPacket(AsyncPacketSocket* socket, - const char* buf, - size_t size, - const SocketAddress& remote_addr, - const int64_t& /* packet_time_us */) { + const rtc::ReceivedPacket& packet) { + RTC_DCHECK(external_socket_thread_.IsCurrent()); SocketAddress local_addr = socket->GetLocalAddress(); // Find the translation for this addresses. @@ -193,36 +205,46 @@ void NATServer::OnExternalUDPPacket(AsyncPacketSocket* socket, RTC_DCHECK(iter != ext_map_->end()); // Allow the NAT to reject this packet. - if (ShouldFilterOut(iter->second, remote_addr)) { - RTC_LOG(LS_INFO) << "Packet from " << remote_addr.ToSensitiveString() + if (ShouldFilterOut(iter->second, packet.source_address())) { + RTC_LOG(LS_INFO) << "Packet from " + << packet.source_address().ToSensitiveString() << " was filtered out by the NAT."; return; } // Forward this packet to the internal address. // First prepend the address in a quasi-STUN format. - std::unique_ptr<char[]> real_buf(new char[size + kNATEncodedIPv6AddressSize]); + std::unique_ptr<char[]> real_buf( + new char[packet.payload().size() + kNATEncodedIPv6AddressSize]); size_t addrlength = PackAddressForNAT( - real_buf.get(), size + kNATEncodedIPv6AddressSize, remote_addr); + real_buf.get(), packet.payload().size() + kNATEncodedIPv6AddressSize, + packet.source_address()); // Copy the data part after the address. rtc::PacketOptions options; - memcpy(real_buf.get() + addrlength, buf, size); - udp_server_socket_->SendTo(real_buf.get(), size + addrlength, + memcpy(real_buf.get() + addrlength, packet.payload().data(), + packet.payload().size()); + udp_server_socket_->SendTo(real_buf.get(), + packet.payload().size() + addrlength, iter->second->route.source(), options); } void NATServer::Translate(const SocketAddressPair& route) { - AsyncUDPSocket* socket = AsyncUDPSocket::Create(external_, external_ip_); + external_socket_thread_.BlockingCall([&] { + AsyncUDPSocket* socket = AsyncUDPSocket::Create(external_, external_ip_); - if (!socket) { - RTC_LOG(LS_ERROR) << "Couldn't find a free port!"; - return; - } + if (!socket) { + RTC_LOG(LS_ERROR) << "Couldn't find a free port!"; + return; + } - TransEntry* entry = new TransEntry(route, socket, nat_); - (*int_map_)[route] = entry; - (*ext_map_)[socket->GetLocalAddress()] = entry; - socket->SignalReadPacket.connect(this, &NATServer::OnExternalUDPPacket); + TransEntry* entry = new TransEntry(route, socket, nat_); + (*int_map_)[route] = entry; + (*ext_map_)[socket->GetLocalAddress()] = entry; + socket->RegisterReceivedPacketCallback( + [&](rtc::AsyncPacketSocket* socket, const rtc::ReceivedPacket& packet) { + OnExternalUDPPacket(socket, packet); + }); + }); } bool NATServer::ShouldFilterOut(TransEntry* entry, |