Adopt absl::string_view in p2p/

Bug: webrtc:13579
Change-Id: Ia33afa2a9ad12d1a586087d49f581a93fddb565d
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/262766
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Commit-Queue: Ali Tofigh <alito@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#37381}
This commit is contained in:
Ali Tofigh 2022-06-30 11:58:26 +02:00 committed by WebRTC LUCI CQ
parent 4b97928b30
commit de2ac5a6f3
44 changed files with 353 additions and 319 deletions

View file

@ -800,6 +800,7 @@ if (is_linux || is_chromeos || is_win) {
"../rtc_base:socket_address",
"../rtc_base:socket_server",
"../rtc_base:threading",
"//third_party/abseil-cpp/absl/strings:strings",
]
}
rtc_executable("stunserver") {

View file

@ -14,6 +14,7 @@
#include <string>
#include <utility>
#include "absl/strings/string_view.h"
#include "examples/turnserver/read_auth_file.h"
#include "p2p/base/basic_packet_socket_factory.h"
#include "p2p/base/port_interface.h"
@ -32,12 +33,12 @@ class TurnFileAuth : public cricket::TurnAuthInterface {
explicit TurnFileAuth(std::map<std::string, std::string> name_to_key)
: name_to_key_(std::move(name_to_key)) {}
virtual bool GetKey(const std::string& username,
const std::string& realm,
virtual bool GetKey(absl::string_view username,
absl::string_view realm,
std::string* key) {
// File is stored as lines of <username>=<HA1>.
// Generate HA1 via "echo -n "<username>:<realm>:<password>" | md5sum"
auto it = name_to_key_.find(username);
auto it = name_to_key_.find(std::string(username));
if (it == name_to_key_.end())
return false;
*key = it->second;

View file

@ -173,6 +173,7 @@ if (rtc_include_tests) {
]
absl_deps = [
"//third_party/abseil-cpp/absl/algorithm:container",
"//third_party/abseil-cpp/absl/strings",
"//third_party/abseil-cpp/absl/types:optional",
]
}
@ -230,6 +231,7 @@ if (rtc_include_tests) {
]
absl_deps = [
"//third_party/abseil-cpp/absl/algorithm:container",
"//third_party/abseil-cpp/absl/strings",
"//third_party/abseil-cpp/absl/types:optional",
]
}
@ -335,6 +337,7 @@ rtc_library("p2p_server_utils") {
absl_deps = [
"//third_party/abseil-cpp/absl/algorithm:container",
"//third_party/abseil-cpp/absl/memory",
"//third_party/abseil-cpp/absl/strings",
]
}

View file

@ -19,6 +19,7 @@
#include "absl/algorithm/container.h"
#include "absl/strings/match.h"
#include "absl/strings/string_view.h"
#include "p2p/base/port_allocator.h"
#include "rtc_base/checks.h"
#include "rtc_base/crc32.h"
@ -68,7 +69,7 @@ inline bool TooLongWithoutResponse(
// Helper methods for converting string values of log description fields to
// enum.
webrtc::IceCandidateType GetCandidateTypeByString(const std::string& type) {
webrtc::IceCandidateType GetCandidateTypeByString(absl::string_view type) {
if (type == LOCAL_PORT_TYPE) {
return webrtc::IceCandidateType::kLocal;
} else if (type == STUN_PORT_TYPE) {
@ -82,7 +83,7 @@ webrtc::IceCandidateType GetCandidateTypeByString(const std::string& type) {
}
webrtc::IceCandidatePairProtocol GetProtocolByString(
const std::string& protocol) {
absl::string_view protocol) {
if (protocol == UDP_PROTOCOL_NAME) {
return webrtc::IceCandidatePairProtocol::kUdp;
} else if (protocol == TCP_PROTOCOL_NAME) {

View file

@ -60,7 +60,7 @@ struct CandidatePair final : public CandidatePairInterface {
class Connection : public CandidatePairInterface {
public:
struct SentPing {
SentPing(const std::string id, int64_t sent_time, uint32_t nomination)
SentPing(absl::string_view id, int64_t sent_time, uint32_t nomination)
: id(id), sent_time(sent_time), nomination(nomination) {}
std::string id;

View file

@ -15,6 +15,7 @@
#include <utility>
#include "absl/memory/memory.h"
#include "absl/strings/string_view.h"
#include "api/dtls_transport_interface.h"
#include "api/rtc_event_log/rtc_event_log.h"
#include "logging/rtc_event_log/events/rtc_event_dtls_transport_state.h"
@ -226,7 +227,7 @@ bool DtlsTransport::GetSslCipherSuite(int* cipher) {
return dtls_->GetSslCipherSuite(cipher);
}
bool DtlsTransport::SetRemoteFingerprint(const std::string& digest_alg,
bool DtlsTransport::SetRemoteFingerprint(absl::string_view digest_alg,
const uint8_t* digest,
size_t digest_len) {
rtc::Buffer remote_fingerprint_value(digest, digest_len);
@ -264,7 +265,7 @@ bool DtlsTransport::SetRemoteFingerprint(const std::string& digest_alg,
// At this point we know we are doing DTLS
bool fingerprint_changing = remote_fingerprint_value_.size() > 0u;
remote_fingerprint_value_ = std::move(remote_fingerprint_value);
remote_fingerprint_algorithm_ = digest_alg;
remote_fingerprint_algorithm_ = std::string(digest_alg);
if (dtls_ && !fingerprint_changing) {
// This can occur if DTLS is set up before a remote fingerprint is
@ -312,7 +313,7 @@ std::unique_ptr<rtc::SSLCertChain> DtlsTransport::GetRemoteSSLCertChain()
return dtls_->GetPeerSSLCertChain();
}
bool DtlsTransport::ExportKeyingMaterial(const std::string& label,
bool DtlsTransport::ExportKeyingMaterial(absl::string_view label,
const uint8_t* context,
size_t context_len,
bool use_context,

View file

@ -15,6 +15,7 @@
#include <string>
#include <vector>
#include "absl/strings/string_view.h"
#include "api/crypto/crypto_options.h"
#include "api/dtls_transport_interface.h"
#include "api/sequence_checker.h"
@ -135,7 +136,7 @@ class DtlsTransport : public DtlsTransportInternal {
// SetRemoteFingerprint must be called after SetLocalCertificate, and any
// other methods like SetDtlsRole. It's what triggers the actual DTLS setup.
// TODO(deadbeef): Rename to "Start" like in ORTC?
bool SetRemoteFingerprint(const std::string& digest_alg,
bool SetRemoteFingerprint(absl::string_view digest_alg,
const uint8_t* digest,
size_t digest_len) override;
@ -167,7 +168,7 @@ class DtlsTransport : public DtlsTransportInternal {
// method extracts the keys negotiated during the DTLS handshake, for use in
// external encryption. DTLS-SRTP uses this to extract the needed SRTP keys.
// See the SSLStreamAdapter documentation for info on the specific parameters.
bool ExportKeyingMaterial(const std::string& label,
bool ExportKeyingMaterial(absl::string_view label,
const uint8_t* context,
size_t context_len,
bool use_context,

View file

@ -19,6 +19,7 @@
#include <utility>
#include "absl/base/attributes.h"
#include "absl/strings/string_view.h"
#include "api/crypto/crypto_options.h"
#include "api/dtls_transport_interface.h"
#include "api/scoped_refptr.h"
@ -81,7 +82,7 @@ class DtlsTransportInternal : public rtc::PacketTransportInternal {
virtual std::unique_ptr<rtc::SSLCertChain> GetRemoteSSLCertChain() const = 0;
// Allows key material to be extracted for external encryption.
virtual bool ExportKeyingMaterial(const std::string& label,
virtual bool ExportKeyingMaterial(absl::string_view label,
const uint8_t* context,
size_t context_len,
bool use_context,
@ -89,7 +90,7 @@ class DtlsTransportInternal : public rtc::PacketTransportInternal {
size_t result_len) = 0;
// Set DTLS remote fingerprint. Must be after local identity set.
virtual bool SetRemoteFingerprint(const std::string& digest_alg,
virtual bool SetRemoteFingerprint(absl::string_view digest_alg,
const uint8_t* digest,
size_t digest_len) = 0;

View file

@ -15,6 +15,7 @@
#include <set>
#include <utility>
#include "absl/strings/string_view.h"
#include "api/dtls_transport_interface.h"
#include "p2p/base/fake_ice_transport.h"
#include "p2p/base/packet_transport_internal.h"
@ -64,7 +65,7 @@ void SetRemoteFingerprintFromCert(
class DtlsTestClient : public sigslot::has_slots<> {
public:
explicit DtlsTestClient(const std::string& name) : name_(name) {}
explicit DtlsTestClient(absl::string_view name) : name_(name) {}
void CreateCertificate(rtc::KeyType key_type) {
certificate_ =
rtc::RTCCertificate::Create(rtc::SSLIdentity::Create(name_, key_type));

View file

@ -16,6 +16,7 @@
#include <utility>
#include <vector>
#include "absl/strings/string_view.h"
#include "api/crypto/crypto_options.h"
#include "api/dtls_transport_interface.h"
#include "p2p/base/dtls_transport_internal.h"
@ -140,7 +141,7 @@ class FakeDtlsTransport : public DtlsTransportInternal {
const rtc::SSLFingerprint& dtls_fingerprint() const {
return dtls_fingerprint_;
}
bool SetRemoteFingerprint(const std::string& alg,
bool SetRemoteFingerprint(absl::string_view alg,
const uint8_t* digest,
size_t digest_len) override {
dtls_fingerprint_ =
@ -203,7 +204,7 @@ class FakeDtlsTransport : public DtlsTransportInternal {
}
return std::make_unique<rtc::SSLCertChain>(remote_cert_->Clone());
}
bool ExportKeyingMaterial(const std::string& label,
bool ExportKeyingMaterial(absl::string_view label,
const uint8_t* context,
size_t context_len,
bool use_context,

View file

@ -17,6 +17,7 @@
#include <utility>
#include "absl/algorithm/container.h"
#include "absl/strings/string_view.h"
#include "absl/types/optional.h"
#include "api/ice_transport_interface.h"
#include "api/task_queue/pending_task_safety_flag.h"
@ -31,7 +32,7 @@ namespace cricket {
// constructor).
class FakeIceTransport : public IceTransportInternal {
public:
explicit FakeIceTransport(const std::string& name,
explicit FakeIceTransport(absl::string_view name,
int component,
rtc::Thread* network_thread = nullptr)
: name_(name),

View file

@ -38,8 +38,8 @@ class TestUDPPort : public UDPPort {
const rtc::Network* network,
uint16_t min_port,
uint16_t max_port,
const std::string& username,
const std::string& password,
absl::string_view username,
absl::string_view password,
bool emit_localhost_for_anyaddress,
const webrtc::FieldTrialsView* field_trials) {
TestUDPPort* port =
@ -58,8 +58,8 @@ class TestUDPPort : public UDPPort {
const rtc::Network* network,
uint16_t min_port,
uint16_t max_port,
const std::string& username,
const std::string& password,
absl::string_view username,
absl::string_view password,
bool emit_localhost_for_anyaddress,
const webrtc::FieldTrialsView* field_trials)
: UDPPort(thread,
@ -81,10 +81,10 @@ class FakePortAllocatorSession : public PortAllocatorSession {
FakePortAllocatorSession(PortAllocator* allocator,
rtc::Thread* network_thread,
rtc::PacketSocketFactory* factory,
const std::string& content_name,
absl::string_view content_name,
int component,
const std::string& ice_ufrag,
const std::string& ice_pwd,
absl::string_view ice_ufrag,
absl::string_view ice_pwd,
const webrtc::FieldTrialsView& field_trials)
: PortAllocatorSession(content_name,
component,

View file

@ -10,6 +10,7 @@
#include "p2p/base/ice_transport_internal.h"
#include "absl/strings/string_view.h"
#include "p2p/base/p2p_constants.h"
namespace cricket {
@ -126,13 +127,13 @@ IceTransportInternal::IceTransportInternal() = default;
IceTransportInternal::~IceTransportInternal() = default;
void IceTransportInternal::SetIceCredentials(const std::string& ice_ufrag,
const std::string& ice_pwd) {
void IceTransportInternal::SetIceCredentials(absl::string_view ice_ufrag,
absl::string_view ice_pwd) {
SetIceParameters(IceParameters(ice_ufrag, ice_pwd, false));
}
void IceTransportInternal::SetRemoteIceCredentials(const std::string& ice_ufrag,
const std::string& ice_pwd) {
void IceTransportInternal::SetRemoteIceCredentials(absl::string_view ice_ufrag,
absl::string_view ice_pwd) {
SetRemoteIceParameters(IceParameters(ice_ufrag, ice_pwd, false));
}

View file

@ -16,6 +16,7 @@
#include <string>
#include <vector>
#include "absl/strings/string_view.h"
#include "absl/types/optional.h"
#include "api/candidate.h"
#include "api/rtc_error.h"
@ -259,11 +260,11 @@ class RTC_EXPORT IceTransportInternal : public rtc::PacketTransportInternal {
// remoting/protocol/libjingle_transport_factory.cc
virtual void SetIceProtocolType(IceProtocolType type) {}
virtual void SetIceCredentials(const std::string& ice_ufrag,
const std::string& ice_pwd);
virtual void SetIceCredentials(absl::string_view ice_ufrag,
absl::string_view ice_pwd);
virtual void SetRemoteIceCredentials(const std::string& ice_ufrag,
const std::string& ice_pwd);
virtual void SetRemoteIceCredentials(absl::string_view ice_ufrag,
absl::string_view ice_pwd);
// The ufrag and pwd in `ice_params` must be set
// before candidate gathering can start.

View file

@ -22,6 +22,7 @@
#include "absl/algorithm/container.h"
#include "absl/memory/memory.h"
#include "absl/strings/match.h"
#include "absl/strings/string_view.h"
#include "api/async_dns_resolver.h"
#include "api/candidate.h"
#include "api/field_trials_view.h"
@ -101,10 +102,10 @@ using webrtc::RTCError;
using webrtc::RTCErrorType;
using webrtc::ToQueuedTask;
bool IceCredentialsChanged(const std::string& old_ufrag,
const std::string& old_pwd,
const std::string& new_ufrag,
const std::string& new_pwd) {
bool IceCredentialsChanged(absl::string_view old_ufrag,
absl::string_view old_pwd,
absl::string_view new_ufrag,
absl::string_view new_pwd) {
// The standard (RFC 5245 Section 9.1.1.1) says that ICE restarts MUST change
// both the ufrag and password. However, section 9.2.1.1 says changing the
// ufrag OR password indicates an ICE restart. So, to keep compatibility with
@ -113,7 +114,7 @@ bool IceCredentialsChanged(const std::string& old_ufrag,
}
std::unique_ptr<P2PTransportChannel> P2PTransportChannel::Create(
const std::string& transport_name,
absl::string_view transport_name,
int component,
webrtc::IceTransportInit init) {
if (init.async_resolver_factory()) {
@ -131,7 +132,7 @@ std::unique_ptr<P2PTransportChannel> P2PTransportChannel::Create(
}
P2PTransportChannel::P2PTransportChannel(
const std::string& transport_name,
absl::string_view transport_name,
int component,
PortAllocator* allocator,
const webrtc::FieldTrialsView* field_trials)
@ -146,7 +147,7 @@ P2PTransportChannel::P2PTransportChannel(
// Private constructor, called from Create()
P2PTransportChannel::P2PTransportChannel(
const std::string& transport_name,
absl::string_view transport_name,
int component,
PortAllocator* allocator,
webrtc::AsyncDnsResolverFactoryInterface* async_dns_resolver_factory,
@ -1180,7 +1181,7 @@ void P2PTransportChannel::OnRoleConflict(PortInterface* port) {
}
const IceParameters* P2PTransportChannel::FindRemoteIceFromUfrag(
const std::string& ufrag,
absl::string_view ufrag,
uint32_t* generation) {
RTC_DCHECK_RUN_ON(network_thread_);
const auto& params = remote_ice_parameters_;

View file

@ -32,6 +32,7 @@
#include <vector>
#include "absl/base/attributes.h"
#include "absl/strings/string_view.h"
#include "absl/types/optional.h"
#include "api/array_view.h"
#include "api/async_dns_resolver.h"
@ -84,10 +85,10 @@ enum class IceRestartState { CONNECTING, CONNECTED, DISCONNECTED, MAX_VALUE };
static const int MIN_PINGS_AT_WEAK_PING_INTERVAL = 3;
bool IceCredentialsChanged(const std::string& old_ufrag,
const std::string& old_pwd,
const std::string& new_ufrag,
const std::string& new_pwd);
bool IceCredentialsChanged(absl::string_view old_ufrag,
absl::string_view old_pwd,
absl::string_view new_ufrag,
absl::string_view new_pwd);
// Adds the port on which the candidate originated.
class RemoteCandidate : public Candidate {
@ -106,13 +107,13 @@ class RemoteCandidate : public Candidate {
class RTC_EXPORT P2PTransportChannel : public IceTransportInternal {
public:
static std::unique_ptr<P2PTransportChannel> Create(
const std::string& transport_name,
absl::string_view transport_name,
int component,
webrtc::IceTransportInit init);
// For testing only.
// TODO(zstein): Remove once AsyncDnsResolverFactory is required.
P2PTransportChannel(const std::string& transport_name,
P2PTransportChannel(absl::string_view transport_name,
int component,
PortAllocator* allocator,
const webrtc::FieldTrialsView* field_trials = nullptr);
@ -237,7 +238,7 @@ class RTC_EXPORT P2PTransportChannel : public IceTransportInternal {
private:
P2PTransportChannel(
const std::string& transport_name,
absl::string_view transport_name,
int component,
PortAllocator* allocator,
// DNS resolver factory
@ -357,7 +358,7 @@ class RTC_EXPORT P2PTransportChannel : public IceTransportInternal {
}
// Returns the remote IceParameters and generation that match `ufrag`
// if found, and returns nullptr otherwise.
const IceParameters* FindRemoteIceFromUfrag(const std::string& ufrag,
const IceParameters* FindRemoteIceFromUfrag(absl::string_view ufrag,
uint32_t* generation);
// Returns the index of the latest remote ICE parameters, or 0 if no remote
// ICE parameters have been received.

View file

@ -14,6 +14,7 @@
#include <memory>
#include <utility>
#include "absl/strings/string_view.h"
#include "api/test/mock_async_dns_resolver.h"
#include "p2p/base/basic_ice_controller.h"
#include "p2p/base/connection.h"
@ -141,11 +142,11 @@ cricket::IceConfig CreateIceConfig(
return config;
}
cricket::Candidate CreateUdpCandidate(const std::string& type,
const std::string& ip,
cricket::Candidate CreateUdpCandidate(absl::string_view type,
absl::string_view ip,
int port,
int priority,
const std::string& ufrag = "") {
absl::string_view ufrag = "") {
cricket::Candidate c;
c.set_address(rtc::SocketAddress(ip, port));
c.set_component(cricket::ICE_CANDIDATE_COMPONENT_DEFAULT);
@ -311,10 +312,10 @@ class P2PTransportChannelTestBase : public ::testing::Test,
};
struct Result {
Result(const std::string& controlling_type,
const std::string& controlling_protocol,
const std::string& controlled_type,
const std::string& controlled_protocol,
Result(absl::string_view controlling_type,
absl::string_view controlling_protocol,
absl::string_view controlled_type,
absl::string_view controlled_protocol,
int wait)
: controlling_type(controlling_type),
controlling_protocol(controlling_protocol),
@ -539,7 +540,7 @@ class P2PTransportChannelTestBase : public ::testing::Test,
}
void AddAddress(int endpoint,
const SocketAddress& addr,
const std::string& ifname,
absl::string_view ifname,
rtc::AdapterType adapter_type,
absl::optional<rtc::AdapterType> underlying_vpn_adapter_type =
absl::nullopt) {
@ -855,7 +856,7 @@ class P2PTransportChannelTestBase : public ::testing::Test,
}
// Tcp candidate verification has to be done when they are generated.
void VerifySavedTcpCandidates(int endpoint, const std::string& tcptype) {
void VerifySavedTcpCandidates(int endpoint, absl::string_view tcptype) {
for (auto& data : GetEndpoint(endpoint)->saved_candidates_) {
for (auto& candidate : data->candidates) {
EXPECT_EQ(candidate.protocol(), TCP_PROTOCOL_NAME);
@ -3410,7 +3411,7 @@ class P2PTransportChannelPingTest : public ::testing::Test,
Connection* WaitForConnectionTo(
P2PTransportChannel* ch,
const std::string& ip,
absl::string_view ip,
int port_num,
rtc::ThreadProcessingFakeClock* clock = nullptr) {
if (clock == nullptr) {
@ -3438,7 +3439,7 @@ class P2PTransportChannelPingTest : public ::testing::Test,
}
Connection* GetConnectionTo(P2PTransportChannel* ch,
const std::string& ip,
absl::string_view ip,
int port_num) {
Port* port = GetPort(ch);
if (!port) {
@ -3466,7 +3467,7 @@ class P2PTransportChannelPingTest : public ::testing::Test,
Connection* CreateConnectionWithCandidate(P2PTransportChannel* channel,
rtc::ScopedFakeClock* clock,
const std::string& ip_addr,
absl::string_view ip_addr,
int port,
int priority,
bool writable) {
@ -3498,14 +3499,14 @@ class P2PTransportChannelPingTest : public ::testing::Test,
void ReceivePingOnConnection(
Connection* conn,
const std::string& remote_ufrag,
absl::string_view remote_ufrag,
int priority,
uint32_t nomination,
const absl::optional<std::string>& piggyback_ping_id) {
IceMessage msg(STUN_BINDING_REQUEST);
msg.AddAttribute(std::make_unique<StunByteStringAttribute>(
STUN_ATTR_USERNAME,
conn->local_candidate().username() + ":" + remote_ufrag));
conn->local_candidate().username() + ":" + std::string(remote_ufrag)));
msg.AddAttribute(
std::make_unique<StunUInt32Attribute>(STUN_ATTR_PRIORITY, priority));
if (nomination != 0) {
@ -3524,7 +3525,7 @@ class P2PTransportChannelPingTest : public ::testing::Test,
}
void ReceivePingOnConnection(Connection* conn,
const std::string& remote_ufrag,
absl::string_view remote_ufrag,
int priority,
uint32_t nomination = 0) {
ReceivePingOnConnection(conn, remote_ufrag, priority, nomination,
@ -3563,7 +3564,8 @@ class P2PTransportChannelPingTest : public ::testing::Test,
}
}
bool ConnectionMatchesChangeEvent(Connection* conn, std::string reason) {
bool ConnectionMatchesChangeEvent(Connection* conn,
absl::string_view reason) {
if (!conn) {
return !last_candidate_change_event_.has_value();
} else {
@ -4954,9 +4956,9 @@ class P2PTransportChannelMostLikelyToWorkFirstTest
// types and, for relay local candidate, the expected relay protocol and ping
// it.
void VerifyNextPingableConnection(
const std::string& local_candidate_type,
const std::string& remote_candidate_type,
const std::string& relay_protocol_type = UDP_PROTOCOL_NAME) {
absl::string_view local_candidate_type,
absl::string_view remote_candidate_type,
absl::string_view relay_protocol_type = UDP_PROTOCOL_NAME) {
Connection* conn = FindNextPingableConnectionAndPingIt(channel_.get());
ASSERT_TRUE(conn != nullptr);
EXPECT_EQ(conn->local_candidate().type(), local_candidate_type);

View file

@ -96,9 +96,9 @@ const char TCPTYPE_ACTIVE_STR[] = "active";
const char TCPTYPE_PASSIVE_STR[] = "passive";
const char TCPTYPE_SIMOPEN_STR[] = "so";
std::string Port::ComputeFoundation(const std::string& type,
const std::string& protocol,
const std::string& relay_protocol,
std::string Port::ComputeFoundation(absl::string_view type,
absl::string_view protocol,
absl::string_view relay_protocol,
const rtc::SocketAddress& base_address) {
rtc::StringBuilder sb;
sb << type << base_address.ipaddr().ToString() << protocol << relay_protocol;
@ -106,11 +106,11 @@ std::string Port::ComputeFoundation(const std::string& type,
}
Port::Port(rtc::Thread* thread,
const std::string& type,
absl::string_view type,
rtc::PacketSocketFactory* factory,
const rtc::Network* network,
const std::string& username_fragment,
const std::string& password,
absl::string_view username_fragment,
absl::string_view password,
const webrtc::FieldTrialsView* field_trials)
: thread_(thread),
factory_(factory),
@ -135,13 +135,13 @@ Port::Port(rtc::Thread* thread,
}
Port::Port(rtc::Thread* thread,
const std::string& type,
absl::string_view type,
rtc::PacketSocketFactory* factory,
const rtc::Network* network,
uint16_t min_port,
uint16_t max_port,
const std::string& username_fragment,
const std::string& password,
absl::string_view username_fragment,
absl::string_view password,
const webrtc::FieldTrialsView* field_trials)
: thread_(thread),
factory_(factory),
@ -250,13 +250,13 @@ Connection* Port::GetConnection(const rtc::SocketAddress& remote_addr) {
void Port::AddAddress(const rtc::SocketAddress& address,
const rtc::SocketAddress& base_address,
const rtc::SocketAddress& related_address,
const std::string& protocol,
const std::string& relay_protocol,
const std::string& tcptype,
const std::string& type,
absl::string_view protocol,
absl::string_view relay_protocol,
absl::string_view tcptype,
absl::string_view type,
uint32_t type_preference,
uint32_t relay_preference,
const std::string& url,
absl::string_view url,
bool is_final) {
RTC_DCHECK_RUN_ON(thread_);
if (protocol == TCP_PROTOCOL_NAME && type == LOCAL_PORT_TYPE) {
@ -285,7 +285,7 @@ void Port::AddAddress(const rtc::SocketAddress& address,
}
bool Port::MaybeObfuscateAddress(Candidate* c,
const std::string& type,
absl::string_view type,
bool is_final) {
// TODO(bugs.webrtc.org/9723): Use a config to control the feature of IP
// handling with mDNS.
@ -652,7 +652,7 @@ bool Port::ParseStunUsername(const StunMessage* stun_msg,
bool Port::MaybeIceRoleConflict(const rtc::SocketAddress& addr,
IceMessage* stun_msg,
const std::string& remote_ufrag) {
absl::string_view remote_ufrag) {
// Validate ICE_CONTROLLING or ICE_CONTROLLED attributes.
bool ret = true;
IceRole remote_ice_role = ICEROLE_UNKNOWN;
@ -711,8 +711,8 @@ bool Port::MaybeIceRoleConflict(const rtc::SocketAddress& addr,
return ret;
}
std::string Port::CreateStunUsername(const std::string& remote_username) const {
return remote_username + ":" + username_fragment();
std::string Port::CreateStunUsername(absl::string_view remote_username) const {
return std::string(remote_username) + ":" + username_fragment();
}
bool Port::HandleIncomingPacket(rtc::AsyncPacketSocket* socket,
@ -731,7 +731,7 @@ bool Port::CanHandleIncomingPacketsFrom(const rtc::SocketAddress&) const {
void Port::SendBindingErrorResponse(StunMessage* message,
const rtc::SocketAddress& addr,
int error_code,
const std::string& reason) {
absl::string_view reason) {
RTC_DCHECK(message->type() == STUN_BINDING_REQUEST ||
message->type() == GOOG_PING_REQUEST);
@ -745,7 +745,7 @@ void Port::SendBindingErrorResponse(StunMessage* message,
// maintain backwards compatiblility.
auto error_attr = StunAttribute::CreateErrorCode();
error_attr->SetCode(error_code);
error_attr->SetReason(reason);
error_attr->SetReason(std::string(reason));
response.AddAttribute(std::move(error_attr));
// Per Section 10.1.2, certain error cases don't get a MESSAGE-INTEGRITY,

View file

@ -145,11 +145,11 @@ struct ProtocolAddress {
struct IceCandidateErrorEvent {
IceCandidateErrorEvent() = default;
IceCandidateErrorEvent(std::string address,
IceCandidateErrorEvent(absl::string_view address,
int port,
std::string url,
absl::string_view url,
int error_code,
std::string error_text)
absl::string_view error_text)
: address(std::move(address)),
port(port),
url(std::move(url)),
@ -187,20 +187,20 @@ class Port : public PortInterface,
// 30 seconds.
enum class State { INIT, KEEP_ALIVE_UNTIL_PRUNED, PRUNED };
Port(rtc::Thread* thread,
const std::string& type,
absl::string_view type,
rtc::PacketSocketFactory* factory,
const rtc::Network* network,
const std::string& username_fragment,
const std::string& password,
absl::string_view username_fragment,
absl::string_view password,
const webrtc::FieldTrialsView* field_trials = nullptr);
Port(rtc::Thread* thread,
const std::string& type,
absl::string_view type,
rtc::PacketSocketFactory* factory,
const rtc::Network* network,
uint16_t min_port,
uint16_t max_port,
const std::string& username_fragment,
const std::string& password,
absl::string_view username_fragment,
absl::string_view password,
const webrtc::FieldTrialsView* field_trials = nullptr);
~Port() override;
@ -239,8 +239,8 @@ class Port : public PortInterface,
// For debugging purposes.
const std::string& content_name() const { return content_name_; }
void set_content_name(const std::string& content_name) {
content_name_ = content_name;
void set_content_name(absl::string_view content_name) {
content_name_ = std::string(content_name);
}
int component() const { return component_; }
@ -328,14 +328,14 @@ class Port : public PortInterface,
void SendBindingErrorResponse(StunMessage* message,
const rtc::SocketAddress& addr,
int error_code,
const std::string& reason) override;
absl::string_view reason) override;
void SendUnknownAttributesErrorResponse(
StunMessage* message,
const rtc::SocketAddress& addr,
const std::vector<uint16_t>& unknown_types);
void set_proxy(const std::string& user_agent, const rtc::ProxyInfo& proxy) {
user_agent_ = user_agent;
void set_proxy(absl::string_view user_agent, const rtc::ProxyInfo& proxy) {
user_agent_ = std::string(user_agent);
proxy_ = proxy;
}
const std::string& user_agent() { return user_agent_; }
@ -361,11 +361,11 @@ class Port : public PortInterface,
bool ParseStunUsername(const StunMessage* stun_msg,
std::string* local_username,
std::string* remote_username) const;
std::string CreateStunUsername(const std::string& remote_username) const;
std::string CreateStunUsername(absl::string_view remote_username) const;
bool MaybeIceRoleConflict(const rtc::SocketAddress& addr,
IceMessage* stun_msg,
const std::string& remote_ufrag);
absl::string_view remote_ufrag);
// Called when a packet has been sent to the socket.
// This is made pure virtual to notify subclasses of Port that they MUST
@ -390,9 +390,9 @@ class Port : public PortInterface,
// then the foundation will be different. Two candidate pairs with
// the same foundation pairs are likely to have similar network
// characteristics. Foundations are used in the frozen algorithm.
static std::string ComputeFoundation(const std::string& type,
const std::string& protocol,
const std::string& relay_protocol,
static std::string ComputeFoundation(absl::string_view type,
absl::string_view protocol,
absl::string_view relay_protocol,
const rtc::SocketAddress& base_address);
protected:
@ -400,20 +400,20 @@ class Port : public PortInterface,
virtual void UpdateNetworkCost();
void set_type(const std::string& type) { type_ = type; }
void set_type(absl::string_view type) { type_ = std::string(type); }
rtc::WeakPtr<Port> NewWeakPtr() { return weak_factory_.GetWeakPtr(); }
void AddAddress(const rtc::SocketAddress& address,
const rtc::SocketAddress& base_address,
const rtc::SocketAddress& related_address,
const std::string& protocol,
const std::string& relay_protocol,
const std::string& tcptype,
const std::string& type,
absl::string_view protocol,
absl::string_view relay_protocol,
absl::string_view tcptype,
absl::string_view type,
uint32_t type_preference,
uint32_t relay_preference,
const std::string& url,
absl::string_view url,
bool is_final);
void FinishAddingAddress(const Candidate& c, bool is_final)
@ -529,7 +529,7 @@ class Port : public PortInterface,
field_trials_;
bool MaybeObfuscateAddress(Candidate* c,
const std::string& type,
absl::string_view type,
bool is_final) RTC_RUN_ON(thread_);
friend class Connection;

View file

@ -24,17 +24,17 @@ namespace cricket {
RelayServerConfig::RelayServerConfig() {}
RelayServerConfig::RelayServerConfig(const rtc::SocketAddress& address,
const std::string& username,
const std::string& password,
absl::string_view username,
absl::string_view password,
ProtocolType proto)
: credentials(username, password) {
ports.push_back(ProtocolAddress(address, proto));
}
RelayServerConfig::RelayServerConfig(const std::string& address,
RelayServerConfig::RelayServerConfig(absl::string_view address,
int port,
const std::string& username,
const std::string& password,
absl::string_view username,
absl::string_view password,
ProtocolType proto)
: RelayServerConfig(rtc::SocketAddress(address, port),
username,
@ -42,10 +42,10 @@ RelayServerConfig::RelayServerConfig(const std::string& address,
proto) {}
// Legacy constructor where "secure" and PROTO_TCP implies PROTO_TLS.
RelayServerConfig::RelayServerConfig(const std::string& address,
RelayServerConfig::RelayServerConfig(absl::string_view address,
int port,
const std::string& username,
const std::string& password,
absl::string_view username,
absl::string_view password,
ProtocolType proto,
bool secure)
: RelayServerConfig(address,
@ -58,10 +58,10 @@ RelayServerConfig::RelayServerConfig(const RelayServerConfig&) = default;
RelayServerConfig::~RelayServerConfig() = default;
PortAllocatorSession::PortAllocatorSession(const std::string& content_name,
PortAllocatorSession::PortAllocatorSession(absl::string_view content_name,
int component,
const std::string& ice_ufrag,
const std::string& ice_pwd,
absl::string_view ice_ufrag,
absl::string_view ice_pwd,
uint32_t flags)
: flags_(flags),
generation_(0),
@ -207,10 +207,10 @@ bool PortAllocator::SetConfiguration(
}
std::unique_ptr<PortAllocatorSession> PortAllocator::CreateSession(
const std::string& content_name,
absl::string_view content_name,
int component,
const std::string& ice_ufrag,
const std::string& ice_pwd) {
absl::string_view ice_ufrag,
absl::string_view ice_pwd) {
CheckRunOnValidThreadAndInitialized();
auto session = std::unique_ptr<PortAllocatorSession>(
CreateSessionInternal(content_name, component, ice_ufrag, ice_pwd));
@ -219,10 +219,10 @@ std::unique_ptr<PortAllocatorSession> PortAllocator::CreateSession(
}
std::unique_ptr<PortAllocatorSession> PortAllocator::TakePooledSession(
const std::string& content_name,
absl::string_view content_name,
int component,
const std::string& ice_ufrag,
const std::string& ice_pwd) {
absl::string_view ice_ufrag,
absl::string_view ice_pwd) {
CheckRunOnValidThreadAndInitialized();
RTC_DCHECK(!ice_ufrag.empty());
RTC_DCHECK(!ice_pwd.empty());

View file

@ -135,7 +135,7 @@ enum class TlsCertPolicy {
// TODO(deadbeef): Rename to TurnCredentials (and username to ufrag).
struct RelayCredentials {
RelayCredentials() {}
RelayCredentials(const std::string& username, const std::string& password)
RelayCredentials(absl::string_view username, absl::string_view password)
: username(username), password(password) {}
bool operator==(const RelayCredentials& o) const {
@ -152,19 +152,19 @@ typedef std::vector<ProtocolAddress> PortList;
struct RTC_EXPORT RelayServerConfig {
RelayServerConfig();
RelayServerConfig(const rtc::SocketAddress& address,
const std::string& username,
const std::string& password,
absl::string_view username,
absl::string_view password,
ProtocolType proto);
RelayServerConfig(const std::string& address,
RelayServerConfig(absl::string_view address,
int port,
const std::string& username,
const std::string& password,
absl::string_view username,
absl::string_view password,
ProtocolType proto);
// Legacy constructor where "secure" and PROTO_TCP implies PROTO_TLS.
RelayServerConfig(const std::string& address,
RelayServerConfig(absl::string_view address,
int port,
const std::string& username,
const std::string& password,
absl::string_view username,
absl::string_view password,
ProtocolType proto,
bool secure);
RelayServerConfig(const RelayServerConfig&);
@ -189,10 +189,10 @@ struct RTC_EXPORT RelayServerConfig {
class RTC_EXPORT PortAllocatorSession : public sigslot::has_slots<> {
public:
// Content name passed in mostly for logging and debugging.
PortAllocatorSession(const std::string& content_name,
PortAllocatorSession(absl::string_view content_name,
int component,
const std::string& ice_ufrag,
const std::string& ice_pwd,
absl::string_view ice_ufrag,
absl::string_view ice_pwd,
uint32_t flags);
// Subclasses should clean up any ports created.
@ -300,14 +300,14 @@ class RTC_EXPORT PortAllocatorSession : public sigslot::has_slots<> {
const std::string& password() const { return ice_pwd_; }
private:
void SetIceParameters(const std::string& content_name,
void SetIceParameters(absl::string_view content_name,
int component,
const std::string& ice_ufrag,
const std::string& ice_pwd) {
content_name_ = content_name;
absl::string_view ice_ufrag,
absl::string_view ice_pwd) {
content_name_ = std::string(content_name);
component_ = component;
ice_ufrag_ = ice_ufrag;
ice_pwd_ = ice_pwd;
ice_ufrag_ = std::string(ice_ufrag);
ice_pwd_ = std::string(ice_pwd);
UpdateIceParametersInternal();
}
@ -412,10 +412,10 @@ class RTC_EXPORT PortAllocator : public sigslot::has_slots<> {
virtual void SetVpnList(const std::vector<rtc::NetworkMask>& vpn_list) {}
std::unique_ptr<PortAllocatorSession> CreateSession(
const std::string& content_name,
absl::string_view content_name,
int component,
const std::string& ice_ufrag,
const std::string& ice_pwd);
absl::string_view ice_ufrag,
absl::string_view ice_pwd);
// Get an available pooled session and set the transport information on it.
//
@ -425,10 +425,10 @@ class RTC_EXPORT PortAllocator : public sigslot::has_slots<> {
// return a pooled session with matching ice credentials.
// If no pooled sessions are available, returns null.
std::unique_ptr<PortAllocatorSession> TakePooledSession(
const std::string& content_name,
absl::string_view content_name,
int component,
const std::string& ice_ufrag,
const std::string& ice_pwd);
absl::string_view ice_ufrag,
absl::string_view ice_pwd);
// Returns the next session that would be returned by TakePooledSession
// optionally restricting it to sessions with specified ice credentials.
@ -477,9 +477,9 @@ class RTC_EXPORT PortAllocator : public sigslot::has_slots<> {
return proxy_;
}
void set_proxy(const std::string& agent, const rtc::ProxyInfo& proxy) {
void set_proxy(absl::string_view agent, const rtc::ProxyInfo& proxy) {
CheckRunOnValidThreadIfInitialized();
agent_ = agent;
agent_ = std::string(agent);
proxy_ = proxy;
}

View file

@ -12,6 +12,7 @@
#include <memory>
#include "absl/strings/string_view.h"
#include "p2p/base/fake_port_allocator.h"
#include "rtc_base/thread.h"
#include "rtc_base/virtual_socket_server.h"
@ -50,10 +51,10 @@ class PortAllocatorTest : public ::testing::Test, public sigslot::has_slots<> {
}
std::unique_ptr<cricket::FakePortAllocatorSession> CreateSession(
const std::string& content_name,
absl::string_view content_name,
int component,
const std::string& ice_ufrag,
const std::string& ice_pwd) {
absl::string_view ice_ufrag,
absl::string_view ice_pwd) {
return std::unique_ptr<cricket::FakePortAllocatorSession>(
static_cast<cricket::FakePortAllocatorSession*>(
allocator_

View file

@ -111,7 +111,7 @@ class PortInterface {
virtual void SendBindingErrorResponse(StunMessage* message,
const rtc::SocketAddress& addr,
int error_code,
const std::string& reason) = 0;
absl::string_view reason) = 0;
// Signaled when this port decides to delete itself because it no longer has
// any usefulness.

View file

@ -136,13 +136,13 @@ bool WriteStunMessage(const StunMessage& msg, ByteBufferWriter* buf) {
class TestPort : public Port {
public:
TestPort(rtc::Thread* thread,
const std::string& type,
absl::string_view type,
rtc::PacketSocketFactory* factory,
const rtc::Network* network,
uint16_t min_port,
uint16_t max_port,
const std::string& username_fragment,
const std::string& password)
absl::string_view username_fragment,
absl::string_view password)
: Port(thread,
type,
factory,
@ -192,7 +192,7 @@ class TestPort : public Port {
}
void AddCandidateAddress(const rtc::SocketAddress& addr,
const rtc::SocketAddress& base_address,
const std::string& type,
absl::string_view type,
int type_preference,
bool final) {
AddAddress(addr, base_address, rtc::SocketAddress(), "udp", "", "", type,
@ -616,9 +616,9 @@ class PortTest : public ::testing::Test, public sigslot::has_slots<> {
void ExpectPortsCanConnect(bool can_connect, Port* p1, Port* p2);
// This does all the work and then deletes `port1` and `port2`.
void TestConnectivity(const char* name1,
void TestConnectivity(absl::string_view name1,
std::unique_ptr<Port> port1,
const char* name2,
absl::string_view name2,
std::unique_ptr<Port> port2,
bool accept,
bool same_addr1,
@ -764,15 +764,15 @@ class PortTest : public ::testing::Test, public sigslot::has_slots<> {
}
std::unique_ptr<IceMessage> CreateStunMessageWithUsername(
StunMessageType type,
const std::string& username) {
absl::string_view username) {
std::unique_ptr<IceMessage> msg = CreateStunMessage(type);
msg->AddAttribute(std::make_unique<StunByteStringAttribute>(
STUN_ATTR_USERNAME, username));
STUN_ATTR_USERNAME, std::string(username)));
return msg;
}
std::unique_ptr<TestPort> CreateTestPort(const rtc::SocketAddress& addr,
const std::string& username,
const std::string& password) {
absl::string_view username,
absl::string_view password) {
auto port =
std::make_unique<TestPort>(&main_, "test", &socket_factory_,
MakeNetwork(addr), 0, 0, username, password);
@ -780,8 +780,8 @@ class PortTest : public ::testing::Test, public sigslot::has_slots<> {
return port;
}
std::unique_ptr<TestPort> CreateTestPort(const rtc::SocketAddress& addr,
const std::string& username,
const std::string& password,
absl::string_view username,
absl::string_view password,
cricket::IceRole role,
int tiebreaker) {
auto port = CreateTestPort(addr, username, password);
@ -791,8 +791,8 @@ class PortTest : public ::testing::Test, public sigslot::has_slots<> {
}
// Overload to create a test port given an rtc::Network directly.
std::unique_ptr<TestPort> CreateTestPort(const rtc::Network* network,
const std::string& username,
const std::string& password) {
absl::string_view username,
absl::string_view password) {
auto port = std::make_unique<TestPort>(&main_, "test", &socket_factory_,
network, 0, 0, username, password);
port->SignalRoleConflict.connect(this, &PortTest::OnRoleConflict);
@ -839,9 +839,9 @@ class PortTest : public ::testing::Test, public sigslot::has_slots<> {
webrtc::test::ScopedKeyValueConfig field_trials_;
};
void PortTest::TestConnectivity(const char* name1,
void PortTest::TestConnectivity(absl::string_view name1,
std::unique_ptr<Port> port1,
const char* name2,
absl::string_view name2,
std::unique_ptr<Port> port2,
bool accept,
bool same_addr1,

View file

@ -156,8 +156,8 @@ UDPPort::UDPPort(rtc::Thread* thread,
rtc::PacketSocketFactory* factory,
const rtc::Network* network,
rtc::AsyncPacketSocket* socket,
const std::string& username,
const std::string& password,
absl::string_view username,
absl::string_view password,
bool emit_local_for_anyaddress,
const webrtc::FieldTrialsView* field_trials)
: Port(thread,
@ -184,8 +184,8 @@ UDPPort::UDPPort(rtc::Thread* thread,
const rtc::Network* network,
uint16_t min_port,
uint16_t max_port,
const std::string& username,
const std::string& password,
absl::string_view username,
absl::string_view password,
bool emit_local_for_anyaddress,
const webrtc::FieldTrialsView* field_trials)
: Port(thread,
@ -541,7 +541,7 @@ void UDPPort::OnStunBindingRequestSucceeded(
void UDPPort::OnStunBindingOrResolveRequestFailed(
const rtc::SocketAddress& stun_server_addr,
int error_code,
const std::string& reason) {
absl::string_view reason) {
rtc::StringBuilder url;
url << "stun:" << stun_server_addr.ToString();
SignalCandidateError(
@ -619,8 +619,8 @@ std::unique_ptr<StunPort> StunPort::Create(
const rtc::Network* network,
uint16_t min_port,
uint16_t max_port,
const std::string& username,
const std::string& password,
absl::string_view username,
absl::string_view password,
const ServerAddresses& servers,
absl::optional<int> stun_keepalive_interval,
const webrtc::FieldTrialsView* field_trials) {
@ -640,8 +640,8 @@ StunPort::StunPort(rtc::Thread* thread,
const rtc::Network* network,
uint16_t min_port,
uint16_t max_port,
const std::string& username,
const std::string& password,
absl::string_view username,
absl::string_view password,
const ServerAddresses& servers,
const webrtc::FieldTrialsView* field_trials)
: UDPPort(thread,

View file

@ -38,8 +38,8 @@ class UDPPort : public Port {
rtc::PacketSocketFactory* factory,
const rtc::Network* network,
rtc::AsyncPacketSocket* socket,
const std::string& username,
const std::string& password,
absl::string_view username,
absl::string_view password,
bool emit_local_for_anyaddress,
absl::optional<int> stun_keepalive_interval,
const webrtc::FieldTrialsView* field_trials = nullptr) {
@ -60,8 +60,8 @@ class UDPPort : public Port {
const rtc::Network* network,
uint16_t min_port,
uint16_t max_port,
const std::string& username,
const std::string& password,
absl::string_view username,
absl::string_view password,
bool emit_local_for_anyaddress,
absl::optional<int> stun_keepalive_interval,
const webrtc::FieldTrialsView* field_trials = nullptr) {
@ -127,8 +127,8 @@ class UDPPort : public Port {
const rtc::Network* network,
uint16_t min_port,
uint16_t max_port,
const std::string& username,
const std::string& password,
absl::string_view username,
absl::string_view password,
bool emit_local_for_anyaddress,
const webrtc::FieldTrialsView* field_trials);
@ -136,8 +136,8 @@ class UDPPort : public Port {
rtc::PacketSocketFactory* factory,
const rtc::Network* network,
rtc::AsyncPacketSocket* socket,
const std::string& username,
const std::string& password,
absl::string_view username,
absl::string_view password,
bool emit_local_for_anyaddress,
const webrtc::FieldTrialsView* field_trials);
@ -224,7 +224,7 @@ class UDPPort : public Port {
void OnStunBindingOrResolveRequestFailed(
const rtc::SocketAddress& stun_server_addr,
int error_code,
const std::string& reason);
absl::string_view reason);
// Sends STUN requests to the server.
void OnSendPacket(const void* data, size_t size, StunRequest* req);
@ -274,8 +274,8 @@ class StunPort : public UDPPort {
const rtc::Network* network,
uint16_t min_port,
uint16_t max_port,
const std::string& username,
const std::string& password,
absl::string_view username,
absl::string_view password,
const ServerAddresses& servers,
absl::optional<int> stun_keepalive_interval,
const webrtc::FieldTrialsView* field_trials);
@ -288,8 +288,8 @@ class StunPort : public UDPPort {
const rtc::Network* network,
uint16_t min_port,
uint16_t max_port,
const std::string& username,
const std::string& password,
absl::string_view username,
absl::string_view password,
const ServerAddresses& servers,
const webrtc::FieldTrialsView* field_trials);
};

View file

@ -10,8 +10,10 @@
#include "p2p/base/stun_server.h"
#include <string>
#include <utility>
#include "absl/strings/string_view.h"
#include "rtc_base/byte_buffer.h"
#include "rtc_base/logging.h"
@ -61,13 +63,13 @@ void StunServer::OnBindingRequest(StunMessage* msg,
void StunServer::SendErrorResponse(const StunMessage& msg,
const rtc::SocketAddress& addr,
int error_code,
const char* error_desc) {
absl::string_view error_desc) {
StunMessage err_msg(GetStunErrorResponseType(msg.type()),
msg.transaction_id());
auto err_code = StunAttribute::CreateErrorCode();
err_code->SetCode(error_code);
err_code->SetReason(error_desc);
err_code->SetReason(std::string(error_desc));
err_msg.AddAttribute(std::move(err_code));
SendResponse(err_msg, addr);

View file

@ -16,6 +16,7 @@
#include <memory>
#include "absl/strings/string_view.h"
#include "api/transport/stun.h"
#include "rtc_base/async_packet_socket.h"
#include "rtc_base/async_udp_socket.h"
@ -52,7 +53,7 @@ class StunServer : public sigslot::has_slots<> {
void SendErrorResponse(const StunMessage& msg,
const rtc::SocketAddress& addr,
int error_code,
const char* error_desc);
absl::string_view error_desc);
// Sends the given message to the appropriate destination.
void SendResponse(const StunMessage& msg, const rtc::SocketAddress& addr);

View file

@ -91,8 +91,8 @@ TCPPort::TCPPort(rtc::Thread* thread,
const rtc::Network* network,
uint16_t min_port,
uint16_t max_port,
const std::string& username,
const std::string& password,
absl::string_view username,
absl::string_view password,
bool allow_listen,
const webrtc::FieldTrialsView* field_trials)
: Port(thread,

View file

@ -41,8 +41,8 @@ class TCPPort : public Port {
const rtc::Network* network,
uint16_t min_port,
uint16_t max_port,
const std::string& username,
const std::string& password,
absl::string_view username,
absl::string_view password,
bool allow_listen,
const webrtc::FieldTrialsView* field_trials = nullptr) {
// Using `new` to access a non-public constructor.
@ -72,8 +72,8 @@ class TCPPort : public Port {
const rtc::Network* network,
uint16_t min_port,
uint16_t max_port,
const std::string& username,
const std::string& password,
absl::string_view username,
absl::string_view password,
bool allow_listen,
const webrtc::FieldTrialsView* field_trials);

View file

@ -16,6 +16,7 @@
#include <utility>
#include <vector>
#include "absl/strings/string_view.h"
#include "api/sequence_checker.h"
#include "api/transport/stun.h"
#include "p2p/base/basic_packet_socket_factory.h"
@ -58,7 +59,7 @@ class TestTurnServer : public TurnAuthInterface {
const rtc::SocketAddress& udp_ext_addr,
ProtocolType int_protocol = PROTO_UDP,
bool ignore_bad_cert = true,
const std::string& common_name = "test turn server")
absl::string_view common_name = "test turn server")
: server_(thread), socket_factory_(socket_factory) {
AddInternalSocket(int_addr, int_protocol, ignore_bad_cert, common_name);
server_.SetExternalSocketFactory(
@ -93,7 +94,7 @@ class TestTurnServer : public TurnAuthInterface {
void AddInternalSocket(const rtc::SocketAddress& int_addr,
ProtocolType proto,
bool ignore_bad_cert = true,
const std::string& common_name = "test turn server") {
absl::string_view common_name = "test turn server") {
RTC_DCHECK(thread_checker_.IsCurrent());
if (proto == cricket::PROTO_UDP) {
server_.AddInternalSocket(
@ -142,11 +143,12 @@ class TestTurnServer : public TurnAuthInterface {
private:
// For this test server, succeed if the password is the same as the username.
// Obviously, do not use this in a production environment.
virtual bool GetKey(const std::string& username,
const std::string& realm,
virtual bool GetKey(absl::string_view username,
absl::string_view realm,
std::string* key) {
RTC_DCHECK(thread_checker_.IsCurrent());
return ComputeStunCredentialHash(username, realm, username, key);
return ComputeStunCredentialHash(std::string(username), std::string(realm),
std::string(username), key);
}
TurnServer server_;

View file

@ -12,6 +12,7 @@
#include "absl/strings/ascii.h"
#include "absl/strings/match.h"
#include "absl/strings/string_view.h"
#include "p2p/base/p2p_constants.h"
#include "rtc_base/arraysize.h"
#include "rtc_base/logging.h"
@ -147,8 +148,8 @@ TransportDescription::TransportDescription()
TransportDescription::TransportDescription(
const std::vector<std::string>& transport_options,
const std::string& ice_ufrag,
const std::string& ice_pwd,
absl::string_view ice_ufrag,
absl::string_view ice_pwd,
IceMode ice_mode,
ConnectionRole role,
const rtc::SSLFingerprint* identity_fingerprint)
@ -159,8 +160,8 @@ TransportDescription::TransportDescription(
connection_role(role),
identity_fingerprint(CopyFingerprint(identity_fingerprint)) {}
TransportDescription::TransportDescription(const std::string& ice_ufrag,
const std::string& ice_pwd)
TransportDescription::TransportDescription(absl::string_view ice_ufrag,
absl::string_view ice_pwd)
: ice_ufrag(ice_ufrag),
ice_pwd(ice_pwd),
ice_mode(ICEMODE_FULL),

View file

@ -16,6 +16,7 @@
#include <vector>
#include "absl/algorithm/container.h"
#include "absl/strings/string_view.h"
#include "absl/types/optional.h"
#include "api/rtc_error.h"
#include "p2p/base/p2p_constants.h"
@ -71,8 +72,8 @@ struct IceParameters {
std::string pwd;
bool renomination = false;
IceParameters() = default;
IceParameters(const std::string& ice_ufrag,
const std::string& ice_pwd,
IceParameters(absl::string_view ice_ufrag,
absl::string_view ice_pwd,
bool ice_renomination)
: ufrag(ice_ufrag), pwd(ice_pwd), renomination(ice_renomination) {}
@ -104,24 +105,23 @@ bool ConnectionRoleToString(const ConnectionRole& role, std::string* role_str);
struct TransportDescription {
TransportDescription();
TransportDescription(const std::vector<std::string>& transport_options,
const std::string& ice_ufrag,
const std::string& ice_pwd,
absl::string_view ice_ufrag,
absl::string_view ice_pwd,
IceMode ice_mode,
ConnectionRole role,
const rtc::SSLFingerprint* identity_fingerprint);
TransportDescription(const std::string& ice_ufrag,
const std::string& ice_pwd);
TransportDescription(absl::string_view ice_ufrag, absl::string_view ice_pwd);
TransportDescription(const TransportDescription& from);
~TransportDescription();
TransportDescription& operator=(const TransportDescription& from);
// TODO(deadbeef): Rename to HasIceOption, etc.
bool HasOption(const std::string& option) const {
bool HasOption(absl::string_view option) const {
return absl::c_linear_search(transport_options, option);
}
void AddOption(const std::string& option) {
transport_options.push_back(option);
void AddOption(absl::string_view option) {
transport_options.emplace_back(option);
}
bool secure() const { return identity_fingerprint != nullptr; }

View file

@ -16,6 +16,7 @@
#include <string>
#include <vector>
#include "absl/strings/string_view.h"
#include "p2p/base/p2p_constants.h"
#include "p2p/base/transport_description.h"
#include "rtc_base/copy_on_write_buffer.h"
@ -45,10 +46,10 @@ class TransportDescriptionFactoryTest : public ::testing::Test {
new rtc::FakeSSLIdentity("User2")))) {}
void CheckDesc(const TransportDescription* desc,
const std::string& opt,
const std::string& ice_ufrag,
const std::string& ice_pwd,
const std::string& dtls_alg) {
absl::string_view opt,
absl::string_view ice_ufrag,
absl::string_view ice_pwd,
absl::string_view dtls_alg) {
ASSERT_TRUE(desc != NULL);
EXPECT_EQ(!opt.empty(), desc->HasOption(opt));
if (ice_ufrag.empty() && ice_pwd.empty()) {

View file

@ -106,7 +106,7 @@ class TurnCreatePermissionRequest : public StunRequest,
TurnCreatePermissionRequest(TurnPort* port,
TurnEntry* entry,
const rtc::SocketAddress& ext_addr,
const std::string& remote_ufrag);
absl::string_view remote_ufrag);
void OnSent() override;
void OnResponse(StunMessage* response) override;
void OnErrorResponse(StunMessage* response) override;
@ -149,7 +149,7 @@ class TurnEntry : public sigslot::has_slots<> {
TurnEntry(TurnPort* port,
int channel_id,
const rtc::SocketAddress& ext_addr,
const std::string remote_ufrag);
absl::string_view remote_ufrag);
TurnPort* port() { return port_; }
@ -190,8 +190,8 @@ class TurnEntry : public sigslot::has_slots<> {
sigslot::signal1<TurnEntry*> SignalDestroyed;
const std::string& get_remote_ufrag() const { return remote_ufrag_; }
void set_remote_ufrag(const std::string& remote_ufrag) {
remote_ufrag_ = remote_ufrag;
void set_remote_ufrag(absl::string_view remote_ufrag) {
remote_ufrag_ = std::string(remote_ufrag);
}
private:
@ -212,8 +212,8 @@ TurnPort::TurnPort(rtc::Thread* thread,
rtc::PacketSocketFactory* factory,
const rtc::Network* network,
rtc::AsyncPacketSocket* socket,
const std::string& username,
const std::string& password,
absl::string_view username,
absl::string_view password,
const ProtocolAddress& server_address,
const RelayCredentials& credentials,
int server_priority,
@ -254,8 +254,8 @@ TurnPort::TurnPort(rtc::Thread* thread,
const rtc::Network* network,
uint16_t min_port,
uint16_t max_port,
const std::string& username,
const std::string& password,
absl::string_view username,
absl::string_view password,
const ProtocolAddress& server_address,
const RelayCredentials& credentials,
int server_priority,
@ -330,8 +330,8 @@ void TurnPort::SetTlsCertPolicy(TlsCertPolicy tls_cert_policy) {
tls_cert_policy_ = tls_cert_policy;
}
void TurnPort::SetTurnLoggingId(const std::string& turn_logging_id) {
turn_logging_id_ = turn_logging_id;
void TurnPort::SetTurnLoggingId(absl::string_view turn_logging_id) {
turn_logging_id_ = std::string(turn_logging_id);
}
std::vector<std::string> TurnPort::GetTlsAlpnProtocols() const {
@ -890,7 +890,7 @@ void TurnPort::OnAllocateSuccess(const rtc::SocketAddress& address,
server_priority_, ReconstructedServerUrl(), true);
}
void TurnPort::OnAllocateError(int error_code, const std::string& reason) {
void TurnPort::OnAllocateError(int error_code, absl::string_view reason) {
// We will send SignalPortError asynchronously as this can be sent during
// port initialization. This way it will not be blocking other port
// creation.
@ -1228,7 +1228,7 @@ bool TurnPort::CreateOrRefreshEntry(const rtc::SocketAddress& addr,
bool TurnPort::CreateOrRefreshEntry(const rtc::SocketAddress& addr,
int channel_number,
const std::string& remote_ufrag) {
absl::string_view remote_ufrag) {
TurnEntry* entry = FindEntry(addr);
if (entry == nullptr) {
entry = new TurnEntry(this, channel_number, addr, remote_ufrag);
@ -1638,7 +1638,7 @@ TurnCreatePermissionRequest::TurnCreatePermissionRequest(
TurnPort* port,
TurnEntry* entry,
const rtc::SocketAddress& ext_addr,
const std::string& remote_ufrag)
absl::string_view remote_ufrag)
: StunRequest(
port->request_manager(),
std::make_unique<TurnMessage>(TURN_CREATE_PERMISSION_REQUEST)),
@ -1786,7 +1786,7 @@ void TurnChannelBindRequest::OnEntryDestroyed(TurnEntry* entry) {
TurnEntry::TurnEntry(TurnPort* port,
int channel_id,
const rtc::SocketAddress& ext_addr,
const std::string remote_ufrag)
absl::string_view remote_ufrag)
: port_(port),
channel_id_(channel_id),
ext_addr_(ext_addr),

View file

@ -122,7 +122,7 @@ class TurnPort : public Port {
virtual TlsCertPolicy GetTlsCertPolicy() const;
virtual void SetTlsCertPolicy(TlsCertPolicy tls_cert_policy);
void SetTurnLoggingId(const std::string& turn_logging_id);
void SetTurnLoggingId(absl::string_view turn_logging_id);
virtual std::vector<std::string> GetTlsAlpnProtocols() const;
virtual std::vector<std::string> GetTlsEllipticCurves() const;
@ -212,8 +212,8 @@ class TurnPort : public Port {
rtc::PacketSocketFactory* factory,
const rtc::Network* network,
rtc::AsyncPacketSocket* socket,
const std::string& username,
const std::string& password,
absl::string_view username,
absl::string_view password,
const ProtocolAddress& server_address,
const RelayCredentials& credentials,
int server_priority,
@ -228,8 +228,8 @@ class TurnPort : public Port {
const rtc::Network* network,
uint16_t min_port,
uint16_t max_port,
const std::string& username,
const std::string& password,
absl::string_view username,
absl::string_view password,
const ProtocolAddress& server_address,
const RelayCredentials& credentials,
int server_priority,
@ -245,7 +245,7 @@ class TurnPort : public Port {
bool CreateOrRefreshEntry(const rtc::SocketAddress& addr,
int channel_number,
const std::string& remote_ufrag);
absl::string_view remote_ufrag);
rtc::DiffServCodePoint StunDscpValue() const override;
@ -292,7 +292,7 @@ class TurnPort : public Port {
void OnStunAddress(const rtc::SocketAddress& address);
void OnAllocateSuccess(const rtc::SocketAddress& address,
const rtc::SocketAddress& stun_address);
void OnAllocateError(int error_code, const std::string& reason);
void OnAllocateError(int error_code, absl::string_view reason);
void OnAllocateRequestTimeout();
void HandleDataIndication(const char* data,

View file

@ -9,6 +9,8 @@
*/
#if defined(WEBRTC_POSIX)
#include <dirent.h>
#include "absl/strings/string_view.h"
#endif
#include <list>
@ -263,23 +265,23 @@ class TurnPortTest : public ::testing::Test,
return &networks_.back();
}
bool CreateTurnPort(const std::string& username,
const std::string& password,
bool CreateTurnPort(absl::string_view username,
absl::string_view password,
const ProtocolAddress& server_address) {
return CreateTurnPortWithAllParams(MakeNetwork(kLocalAddr1), username,
password, server_address);
}
bool CreateTurnPort(const rtc::SocketAddress& local_address,
const std::string& username,
const std::string& password,
absl::string_view username,
absl::string_view password,
const ProtocolAddress& server_address) {
return CreateTurnPortWithAllParams(MakeNetwork(local_address), username,
password, server_address);
}
bool CreateTurnPortWithNetwork(const rtc::Network* network,
const std::string& username,
const std::string& password,
absl::string_view username,
absl::string_view password,
const ProtocolAddress& server_address) {
return CreateTurnPortWithAllParams(network, username, password,
server_address);
@ -289,8 +291,8 @@ class TurnPortTest : public ::testing::Test,
// helper methods call this, such that "SetIceRole" and "ConnectSignals" (and
// possibly other things in the future) only happen in one place.
bool CreateTurnPortWithAllParams(const rtc::Network* network,
const std::string& username,
const std::string& password,
absl::string_view username,
absl::string_view password,
const ProtocolAddress& server_address) {
RelayServerConfig config;
config.credentials = RelayCredentials(username, password);
@ -323,8 +325,8 @@ class TurnPortTest : public ::testing::Test,
return true;
}
void CreateSharedTurnPort(const std::string& username,
const std::string& password,
void CreateSharedTurnPort(absl::string_view username,
absl::string_view password,
const ProtocolAddress& server_address) {
RTC_CHECK(server_address.proto == PROTO_UDP);
@ -455,7 +457,7 @@ class TurnPortTest : public ::testing::Test,
}
void TestReconstructedServerUrl(ProtocolType protocol_type,
const char* expected_url) {
absl::string_view expected_url) {
turn_port_->PrepareAddress();
ASSERT_TRUE_SIMULATED_WAIT(
turn_ready_, TimeToGetTurnCandidate(protocol_type), fake_clock_);

View file

@ -16,6 +16,7 @@
#include "absl/algorithm/container.h"
#include "absl/memory/memory.h"
#include "absl/strings/string_view.h"
#include "api/array_view.h"
#include "api/packet_socket_factory.h"
#include "api/task_queue/to_queued_task.h"
@ -111,10 +112,10 @@ int GetStunErrorResponseTypeOrZero(const StunMessage& req) {
}
static void InitErrorResponse(int code,
const std::string& reason,
absl::string_view reason,
StunMessage* resp) {
resp->AddAttribute(std::make_unique<cricket::StunErrorCodeAttribute>(
STUN_ATTR_ERROR_CODE, code, reason));
STUN_ATTR_ERROR_CODE, code, std::string(reason)));
}
TurnServer::TurnServer(rtc::Thread* thread)
@ -316,7 +317,7 @@ bool TurnServer::CheckAuthorization(TurnServerConnection* conn,
StunMessage* msg,
const char* data,
size_t size,
const std::string& key) {
absl::string_view key) {
// RFC 5389, 10.2.2.
RTC_DCHECK(IsStunRequestType(msg->type()));
const StunByteStringAttribute* mi_attr =
@ -350,7 +351,7 @@ bool TurnServer::CheckAuthorization(TurnServerConnection* conn,
}
// Fail if bad MESSAGE_INTEGRITY.
if (key.empty() || msg->ValidateMessageIntegrity(key) !=
if (key.empty() || msg->ValidateMessageIntegrity(std::string(key)) !=
StunMessage::IntegrityStatus::kIntegrityOk) {
SendErrorResponseWithRealmAndNonce(conn, msg, STUN_ERROR_UNAUTHORIZED,
STUN_ERROR_REASON_UNAUTHORIZED);
@ -387,7 +388,7 @@ void TurnServer::HandleBindingRequest(TurnServerConnection* conn,
void TurnServer::HandleAllocateRequest(TurnServerConnection* conn,
const TurnMessage* msg,
const std::string& key) {
absl::string_view key) {
// Check the parameters in the request.
const StunUInt32Attribute* transport_attr =
msg->GetUInt32(STUN_ATTR_REQUESTED_TRANSPORT);
@ -459,7 +460,7 @@ TurnServerAllocation* TurnServer::FindAllocation(TurnServerConnection* conn) {
TurnServerAllocation* TurnServer::CreateAllocation(TurnServerConnection* conn,
int proto,
const std::string& key) {
absl::string_view key) {
rtc::AsyncPacketSocket* external_socket =
(external_socket_factory_)
? external_socket_factory_->CreateUdpSocket(external_addr_, 0, 0)
@ -479,7 +480,7 @@ TurnServerAllocation* TurnServer::CreateAllocation(TurnServerConnection* conn,
void TurnServer::SendErrorResponse(TurnServerConnection* conn,
const StunMessage* req,
int code,
const std::string& reason) {
absl::string_view reason) {
RTC_DCHECK_RUN_ON(thread_);
TurnMessage resp(GetStunErrorResponseTypeOrZero(*req), req->transaction_id());
InitErrorResponse(code, reason, &resp);
@ -492,7 +493,7 @@ void TurnServer::SendErrorResponse(TurnServerConnection* conn,
void TurnServer::SendErrorResponseWithRealmAndNonce(TurnServerConnection* conn,
const StunMessage* msg,
int code,
const std::string& reason) {
absl::string_view reason) {
TurnMessage resp(GetStunErrorResponseTypeOrZero(*msg), msg->transaction_id());
InitErrorResponse(code, reason, &resp);
@ -603,7 +604,7 @@ TurnServerAllocation::TurnServerAllocation(TurnServer* server,
rtc::Thread* thread,
const TurnServerConnection& conn,
rtc::AsyncPacketSocket* socket,
const std::string& key)
absl::string_view key)
: server_(server),
thread_(thread),
conn_(conn),
@ -926,7 +927,7 @@ void TurnServerAllocation::SendBadRequestResponse(const TurnMessage* req) {
void TurnServerAllocation::SendErrorResponse(const TurnMessage* req,
int code,
const std::string& reason) {
absl::string_view reason) {
server_->SendErrorResponse(&conn_, req, code, reason);
}

View file

@ -19,6 +19,7 @@
#include <utility>
#include <vector>
#include "absl/strings/string_view.h"
#include "api/sequence_checker.h"
#include "p2p/base/port_interface.h"
#include "rtc_base/async_packet_socket.h"
@ -73,7 +74,7 @@ class TurnServerAllocation : public rtc::MessageHandlerAutoCleanup,
rtc::Thread* thread,
const TurnServerConnection& conn,
rtc::AsyncPacketSocket* server_socket,
const std::string& key);
absl::string_view key);
~TurnServerAllocation() override;
TurnServerConnection* conn() { return &conn_; }
@ -121,7 +122,7 @@ class TurnServerAllocation : public rtc::MessageHandlerAutoCleanup,
void SendBadRequestResponse(const TurnMessage* req);
void SendErrorResponse(const TurnMessage* req,
int code,
const std::string& reason);
absl::string_view reason);
void SendExternal(const void* data,
size_t size,
const rtc::SocketAddress& peer);
@ -148,8 +149,8 @@ class TurnAuthInterface {
// Gets HA1 for the specified user and realm.
// HA1 = MD5(A1) = MD5(username:realm:password).
// Return true if the given username and realm are valid, or false if not.
virtual bool GetKey(const std::string& username,
const std::string& realm,
virtual bool GetKey(absl::string_view username,
absl::string_view realm,
std::string* key) = 0;
virtual ~TurnAuthInterface() = default;
};
@ -186,9 +187,9 @@ class TurnServer : public sigslot::has_slots<> {
RTC_DCHECK_RUN_ON(thread_);
return realm_;
}
void set_realm(const std::string& realm) {
void set_realm(absl::string_view realm) {
RTC_DCHECK_RUN_ON(thread_);
realm_ = realm;
realm_ = std::string(realm);
}
// Gets/sets the value for the SOFTWARE attribute for TURN messages.
@ -196,9 +197,9 @@ class TurnServer : public sigslot::has_slots<> {
RTC_DCHECK_RUN_ON(thread_);
return software_;
}
void set_software(const std::string& software) {
void set_software(absl::string_view software) {
RTC_DCHECK_RUN_ON(thread_);
software_ = software;
software_ = std::string(software);
}
const AllocationMap& allocations() const {
@ -282,32 +283,32 @@ class TurnServer : public sigslot::has_slots<> {
RTC_RUN_ON(thread_);
void HandleAllocateRequest(TurnServerConnection* conn,
const TurnMessage* msg,
const std::string& key) RTC_RUN_ON(thread_);
absl::string_view key) RTC_RUN_ON(thread_);
bool GetKey(const StunMessage* msg, std::string* key) RTC_RUN_ON(thread_);
bool CheckAuthorization(TurnServerConnection* conn,
StunMessage* msg,
const char* data,
size_t size,
const std::string& key) RTC_RUN_ON(thread_);
absl::string_view key) RTC_RUN_ON(thread_);
bool ValidateNonce(absl::string_view nonce) const RTC_RUN_ON(thread_);
TurnServerAllocation* FindAllocation(TurnServerConnection* conn)
RTC_RUN_ON(thread_);
TurnServerAllocation* CreateAllocation(TurnServerConnection* conn,
int proto,
const std::string& key)
absl::string_view key)
RTC_RUN_ON(thread_);
void SendErrorResponse(TurnServerConnection* conn,
const StunMessage* req,
int code,
const std::string& reason);
absl::string_view reason);
void SendErrorResponseWithRealmAndNonce(TurnServerConnection* conn,
const StunMessage* req,
int code,
const std::string& reason)
absl::string_view reason)
RTC_RUN_ON(thread_);
void SendErrorResponseWithAlternateServer(TurnServerConnection* conn,

View file

@ -91,7 +91,7 @@ int ComparePort(const cricket::Port* a, const cricket::Port* b) {
struct NetworkFilter {
using Predicate = std::function<bool(const rtc::Network*)>;
NetworkFilter(Predicate pred, const std::string& description)
NetworkFilter(Predicate pred, absl::string_view description)
: predRemain(
[pred](const rtc::Network* network) { return !pred(network); }),
description(description) {}
@ -296,10 +296,10 @@ void BasicPortAllocator::Init(RelayPortFactoryInterface* relay_port_factory,
// BasicPortAllocatorSession
BasicPortAllocatorSession::BasicPortAllocatorSession(
BasicPortAllocator* allocator,
const std::string& content_name,
absl::string_view content_name,
int component,
const std::string& ice_ufrag,
const std::string& ice_pwd)
absl::string_view ice_ufrag,
absl::string_view ice_pwd)
: PortAllocatorSession(content_name,
component,
ice_ufrag,
@ -1036,7 +1036,7 @@ void BasicPortAllocatorSession::OnCandidateError(
}
Port* BasicPortAllocatorSession::GetBestTurnPortForNetwork(
const std::string& network_name) const {
absl::string_view network_name) const {
RTC_DCHECK_RUN_ON(network_thread_);
Port* best_turn_port = nullptr;
for (const PortData& data : ports_) {
@ -1701,8 +1701,8 @@ void AllocationSequence::OnPortDestroyed(PortInterface* port) {
PortConfiguration::PortConfiguration(
const ServerAddresses& stun_servers,
const std::string& username,
const std::string& password,
absl::string_view username,
absl::string_view password,
const webrtc::FieldTrialsView* field_trials)
: stun_servers(stun_servers), username(username), password(password) {
if (!stun_servers.empty())

View file

@ -127,10 +127,10 @@ enum class SessionState {
class RTC_EXPORT BasicPortAllocatorSession : public PortAllocatorSession {
public:
BasicPortAllocatorSession(BasicPortAllocator* allocator,
const std::string& content_name,
absl::string_view content_name,
int component,
const std::string& ice_ufrag,
const std::string& ice_pwd);
absl::string_view ice_ufrag,
absl::string_view ice_pwd);
~BasicPortAllocatorSession() override;
virtual BasicPortAllocator* allocator();
@ -270,7 +270,7 @@ class RTC_EXPORT BasicPortAllocatorSession : public PortAllocatorSession {
// append to `candidates`.
void GetCandidatesFromPort(const PortData& data,
std::vector<Candidate>* candidates) const;
Port* GetBestTurnPortForNetwork(const std::string& network_name) const;
Port* GetBestTurnPortForNetwork(absl::string_view network_name) const;
// Returns true if at least one TURN port is pruned.
bool PruneTurnPorts(Port* newly_pairable_turn_port);
bool PruneNewlyPairableTurnPort(PortData* newly_pairable_turn_port);
@ -309,8 +309,8 @@ struct RTC_EXPORT PortConfiguration {
RelayList relays;
PortConfiguration(const ServerAddresses& stun_servers,
const std::string& username,
const std::string& password,
absl::string_view username,
absl::string_view password,
const webrtc::FieldTrialsView* field_trials = nullptr);
// Returns addresses of both the explicitly configured STUN servers,

View file

@ -14,6 +14,7 @@
#include <ostream> // no-presubmit-check TODO(webrtc:8982)
#include "absl/algorithm/container.h"
#include "absl/strings/string_view.h"
#include "p2p/base/basic_packet_socket_factory.h"
#include "p2p/base/p2p_constants.h"
#include "p2p/base/stun_port.h"
@ -173,11 +174,11 @@ class BasicPortAllocatorTestBase : public ::testing::Test,
void AddInterface(const SocketAddress& addr) {
network_manager_.AddInterface(addr);
}
void AddInterface(const SocketAddress& addr, const std::string& if_name) {
void AddInterface(const SocketAddress& addr, absl::string_view if_name) {
network_manager_.AddInterface(addr, if_name);
}
void AddInterface(const SocketAddress& addr,
const std::string& if_name,
absl::string_view if_name,
rtc::AdapterType type) {
network_manager_.AddInterface(addr, if_name, type);
}
@ -251,7 +252,7 @@ class BasicPortAllocatorTestBase : public ::testing::Test,
return true;
}
bool CreateSession(int component, const std::string& content_name) {
bool CreateSession(int component, absl::string_view content_name) {
session_ = CreateSession("session", content_name, component);
if (!session_) {
return false;
@ -259,24 +260,24 @@ class BasicPortAllocatorTestBase : public ::testing::Test,
return true;
}
std::unique_ptr<PortAllocatorSession> CreateSession(const std::string& sid,
std::unique_ptr<PortAllocatorSession> CreateSession(absl::string_view sid,
int component) {
return CreateSession(sid, kContentName, component);
}
std::unique_ptr<PortAllocatorSession> CreateSession(
const std::string& sid,
const std::string& content_name,
absl::string_view sid,
absl::string_view content_name,
int component) {
return CreateSession(sid, content_name, component, kIceUfrag0, kIcePwd0);
}
std::unique_ptr<PortAllocatorSession> CreateSession(
const std::string& sid,
const std::string& content_name,
absl::string_view sid,
absl::string_view content_name,
int component,
const std::string& ice_ufrag,
const std::string& ice_pwd) {
absl::string_view ice_ufrag,
absl::string_view ice_pwd) {
std::unique_ptr<PortAllocatorSession> session =
allocator_->CreateSession(content_name, component, ice_ufrag, ice_pwd);
session->SignalPortReady.connect(this,
@ -307,7 +308,7 @@ class BasicPortAllocatorTestBase : public ::testing::Test,
// Returns the number of ports that have matching type, protocol and
// address.
static int CountPorts(const std::vector<PortInterface*>& ports,
const std::string& type,
absl::string_view type,
ProtocolType protocol,
const SocketAddress& client_addr) {
return absl::c_count_if(
@ -318,8 +319,8 @@ class BasicPortAllocatorTestBase : public ::testing::Test,
}
static int CountCandidates(const std::vector<Candidate>& candidates,
const std::string& type,
const std::string& proto,
absl::string_view type,
absl::string_view proto,
const SocketAddress& addr) {
return absl::c_count_if(
candidates, [type, proto, addr](const Candidate& c) {
@ -330,8 +331,8 @@ class BasicPortAllocatorTestBase : public ::testing::Test,
// Find a candidate and return it.
static bool FindCandidate(const std::vector<Candidate>& candidates,
const std::string& type,
const std::string& proto,
absl::string_view type,
absl::string_view proto,
const SocketAddress& addr,
Candidate* found) {
auto it =
@ -347,8 +348,8 @@ class BasicPortAllocatorTestBase : public ::testing::Test,
// Convenience method to call FindCandidate with no return.
static bool HasCandidate(const std::vector<Candidate>& candidates,
const std::string& type,
const std::string& proto,
absl::string_view type,
absl::string_view proto,
const SocketAddress& addr) {
return FindCandidate(candidates, type, proto, addr, nullptr);
}
@ -356,8 +357,8 @@ class BasicPortAllocatorTestBase : public ::testing::Test,
// Version of HasCandidate that also takes a related address.
static bool HasCandidateWithRelatedAddr(
const std::vector<Candidate>& candidates,
const std::string& type,
const std::string& proto,
absl::string_view type,
absl::string_view proto,
const SocketAddress& addr,
const SocketAddress& related_addr) {
return absl::c_any_of(

View file

@ -86,6 +86,7 @@ rtc_library("emulated_network") {
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",
]
}

View file

@ -15,6 +15,7 @@
#include <memory>
#include <string>
#include "absl/strings/string_view.h"
#include "api/test/network_emulation_manager.h"
#include "api/transport/stun.h"
#include "p2p/base/turn_server.h"
@ -57,10 +58,11 @@ class EmulatedTURNServer : public EmulatedTURNServerInterface,
EmulatedEndpoint* GetPeerEndpoint() const override { return peer_; }
// cricket::TurnAuthInterface
bool GetKey(const std::string& username,
const std::string& realm,
bool GetKey(absl::string_view username,
absl::string_view realm,
std::string* key) override {
return cricket::ComputeStunCredentialHash(username, realm, username, key);
return cricket::ComputeStunCredentialHash(
std::string(username), std::string(realm), std::string(username), key);
}
rtc::AsyncPacketSocket* CreatePeerSocket() { return Wrap(peer_); }