Add absl::string_view version of PortInterface::SupportsProtocol()
This is the first step of migrating SupportsProtocol() to absl::string_view. The std::string version will be removed once all downstream users have migrated and have implemented the absl::string_view version. Bug: webrtc:13579 Change-Id: Ib609b9bab0c2e525553daddb1e365050bbe1c1f5 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/265806 Reviewed-by: Harald Alvestrand <hta@webrtc.org> Commit-Queue: Ali Tofigh <alito@webrtc.org> Cr-Commit-Position: refs/heads/main@{#37211}
This commit is contained in:

committed by
WebRTC LUCI CQ

parent
bed8507b95
commit
ea5a944921
@ -290,6 +290,7 @@ if (rtc_include_tests) {
|
||||
absl_deps = [
|
||||
"//third_party/abseil-cpp/absl/algorithm:container",
|
||||
"//third_party/abseil-cpp/absl/memory",
|
||||
"//third_party/abseil-cpp/absl/strings",
|
||||
"//third_party/abseil-cpp/absl/types:optional",
|
||||
]
|
||||
}
|
||||
|
@ -10,10 +10,18 @@
|
||||
|
||||
#include "p2p/base/port_interface.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
|
||||
namespace cricket {
|
||||
|
||||
PortInterface::PortInterface() = default;
|
||||
|
||||
PortInterface::~PortInterface() = default;
|
||||
|
||||
bool PortInterface::SupportsProtocol(absl::string_view protocol) const {
|
||||
return SupportsProtocol(std::string(protocol));
|
||||
}
|
||||
|
||||
} // namespace cricket
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "absl/types/optional.h"
|
||||
#include "api/candidate.h"
|
||||
#include "p2p/base/transport_description.h"
|
||||
@ -60,7 +61,10 @@ class PortInterface {
|
||||
|
||||
virtual bool SharedSocket() const = 0;
|
||||
|
||||
// TODO(webrtc:13579): Remove std::string version once downstream users have
|
||||
// migrated to the absl::string_view version.
|
||||
virtual bool SupportsProtocol(const std::string& protocol) const = 0;
|
||||
virtual bool SupportsProtocol(absl::string_view protocol) const;
|
||||
|
||||
// PrepareAddress will attempt to get an address for this port that other
|
||||
// clients can send to. It may take some time before the address is ready.
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "absl/types/optional.h"
|
||||
#include "api/candidate.h"
|
||||
#include "api/packet_socket_factory.h"
|
||||
@ -179,6 +180,10 @@ class TestPort : public Port {
|
||||
}
|
||||
|
||||
virtual bool SupportsProtocol(const std::string& protocol) const {
|
||||
return SupportsProtocol(absl::string_view(protocol));
|
||||
}
|
||||
|
||||
virtual bool SupportsProtocol(absl::string_view protocol) const {
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -3546,22 +3551,29 @@ TEST_F(PortTest, TestPortNotTimeoutUntilPruned) {
|
||||
|
||||
TEST_F(PortTest, TestSupportsProtocol) {
|
||||
auto udp_port = CreateUdpPort(kLocalAddr1);
|
||||
EXPECT_TRUE(udp_port->SupportsProtocol(UDP_PROTOCOL_NAME));
|
||||
EXPECT_FALSE(udp_port->SupportsProtocol(TCP_PROTOCOL_NAME));
|
||||
EXPECT_TRUE(udp_port->SupportsProtocol(absl::string_view(UDP_PROTOCOL_NAME)));
|
||||
EXPECT_FALSE(
|
||||
udp_port->SupportsProtocol(absl::string_view(TCP_PROTOCOL_NAME)));
|
||||
|
||||
auto stun_port = CreateStunPort(kLocalAddr1, nat_socket_factory1());
|
||||
EXPECT_TRUE(stun_port->SupportsProtocol(UDP_PROTOCOL_NAME));
|
||||
EXPECT_FALSE(stun_port->SupportsProtocol(TCP_PROTOCOL_NAME));
|
||||
EXPECT_TRUE(
|
||||
stun_port->SupportsProtocol(absl::string_view(UDP_PROTOCOL_NAME)));
|
||||
EXPECT_FALSE(
|
||||
stun_port->SupportsProtocol(absl::string_view(TCP_PROTOCOL_NAME)));
|
||||
|
||||
auto tcp_port = CreateTcpPort(kLocalAddr1);
|
||||
EXPECT_TRUE(tcp_port->SupportsProtocol(TCP_PROTOCOL_NAME));
|
||||
EXPECT_TRUE(tcp_port->SupportsProtocol(SSLTCP_PROTOCOL_NAME));
|
||||
EXPECT_FALSE(tcp_port->SupportsProtocol(UDP_PROTOCOL_NAME));
|
||||
EXPECT_TRUE(tcp_port->SupportsProtocol(absl::string_view(TCP_PROTOCOL_NAME)));
|
||||
EXPECT_TRUE(
|
||||
tcp_port->SupportsProtocol(absl::string_view(SSLTCP_PROTOCOL_NAME)));
|
||||
EXPECT_FALSE(
|
||||
tcp_port->SupportsProtocol(absl::string_view(UDP_PROTOCOL_NAME)));
|
||||
|
||||
auto turn_port =
|
||||
CreateTurnPort(kLocalAddr1, nat_socket_factory1(), PROTO_UDP, PROTO_UDP);
|
||||
EXPECT_TRUE(turn_port->SupportsProtocol(UDP_PROTOCOL_NAME));
|
||||
EXPECT_FALSE(turn_port->SupportsProtocol(TCP_PROTOCOL_NAME));
|
||||
EXPECT_TRUE(
|
||||
turn_port->SupportsProtocol(absl::string_view(UDP_PROTOCOL_NAME)));
|
||||
EXPECT_FALSE(
|
||||
turn_port->SupportsProtocol(absl::string_view(TCP_PROTOCOL_NAME)));
|
||||
}
|
||||
|
||||
// Test that SetIceParameters updates the component, ufrag and password
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "absl/memory/memory.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "api/transport/stun.h"
|
||||
#include "p2p/base/connection.h"
|
||||
#include "p2p/base/p2p_constants.h"
|
||||
@ -348,6 +349,10 @@ bool UDPPort::HandleIncomingPacket(rtc::AsyncPacketSocket* socket,
|
||||
}
|
||||
|
||||
bool UDPPort::SupportsProtocol(const std::string& protocol) const {
|
||||
return SupportsProtocol(absl::string_view(protocol));
|
||||
}
|
||||
|
||||
bool UDPPort::SupportsProtocol(absl::string_view protocol) const {
|
||||
return protocol == UDP_PROTOCOL_NAME;
|
||||
}
|
||||
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include <string>
|
||||
|
||||
#include "absl/memory/memory.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "p2p/base/port.h"
|
||||
#include "p2p/base/stun_request.h"
|
||||
#include "rtc_base/async_packet_socket.h"
|
||||
@ -101,6 +102,7 @@ class UDPPort : public Port {
|
||||
int64_t packet_time_us) override;
|
||||
|
||||
bool SupportsProtocol(const std::string& protocol) const override;
|
||||
bool SupportsProtocol(absl::string_view protocol) const override;
|
||||
ProtocolType GetProtocol() const override;
|
||||
|
||||
void GetStunStats(absl::optional<StunStats>* stats) override;
|
||||
|
@ -73,6 +73,7 @@
|
||||
|
||||
#include "absl/algorithm/container.h"
|
||||
#include "absl/memory/memory.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "p2p/base/p2p_constants.h"
|
||||
#include "rtc_base/checks.h"
|
||||
#include "rtc_base/ip_address.h"
|
||||
@ -269,6 +270,10 @@ int TCPPort::GetError() {
|
||||
}
|
||||
|
||||
bool TCPPort::SupportsProtocol(const std::string& protocol) const {
|
||||
return SupportsProtocol(absl::string_view(protocol));
|
||||
}
|
||||
|
||||
bool TCPPort::SupportsProtocol(absl::string_view protocol) const {
|
||||
return protocol == TCP_PROTOCOL_NAME || protocol == SSLTCP_PROTOCOL_NAME;
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include <string>
|
||||
|
||||
#include "absl/memory/memory.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "p2p/base/connection.h"
|
||||
#include "p2p/base/port.h"
|
||||
#include "rtc_base/async_packet_socket.h"
|
||||
@ -63,6 +64,7 @@ class TCPPort : public Port {
|
||||
int SetOption(rtc::Socket::Option opt, int value) override;
|
||||
int GetError() override;
|
||||
bool SupportsProtocol(const std::string& protocol) const override;
|
||||
bool SupportsProtocol(absl::string_view protocol) const override;
|
||||
ProtocolType GetProtocol() const override;
|
||||
|
||||
protected:
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
#include "absl/algorithm/container.h"
|
||||
#include "absl/strings/match.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "absl/types/optional.h"
|
||||
#include "api/transport/stun.h"
|
||||
#include "p2p/base/connection.h"
|
||||
@ -763,6 +764,10 @@ void TurnPort::OnReadyToSend(rtc::AsyncPacketSocket* socket) {
|
||||
}
|
||||
|
||||
bool TurnPort::SupportsProtocol(const std::string& protocol) const {
|
||||
return SupportsProtocol(absl::string_view(protocol));
|
||||
}
|
||||
|
||||
bool TurnPort::SupportsProtocol(absl::string_view protocol) const {
|
||||
// Turn port only connects to UDP candidates.
|
||||
return protocol == UDP_PROTOCOL_NAME;
|
||||
}
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "absl/memory/memory.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "api/async_dns_resolver.h"
|
||||
#include "p2p/base/port.h"
|
||||
#include "p2p/client/basic_port_allocator.h"
|
||||
@ -159,6 +160,7 @@ class TurnPort : public Port {
|
||||
const rtc::SentPacket& sent_packet) override;
|
||||
virtual void OnReadyToSend(rtc::AsyncPacketSocket* socket);
|
||||
bool SupportsProtocol(const std::string& protocol) const override;
|
||||
bool SupportsProtocol(absl::string_view protocol) const override;
|
||||
|
||||
void OnSocketConnect(rtc::AsyncPacketSocket* socket);
|
||||
void OnSocketClose(rtc::AsyncPacketSocket* socket, int error);
|
||||
|
Reference in New Issue
Block a user