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_address",
"../rtc_base:socket_server", "../rtc_base:socket_server",
"../rtc_base:threading", "../rtc_base:threading",
"//third_party/abseil-cpp/absl/strings:strings",
] ]
} }
rtc_executable("stunserver") { rtc_executable("stunserver") {

View file

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

View file

@ -173,6 +173,7 @@ if (rtc_include_tests) {
] ]
absl_deps = [ absl_deps = [
"//third_party/abseil-cpp/absl/algorithm:container", "//third_party/abseil-cpp/absl/algorithm:container",
"//third_party/abseil-cpp/absl/strings",
"//third_party/abseil-cpp/absl/types:optional", "//third_party/abseil-cpp/absl/types:optional",
] ]
} }
@ -230,6 +231,7 @@ if (rtc_include_tests) {
] ]
absl_deps = [ absl_deps = [
"//third_party/abseil-cpp/absl/algorithm:container", "//third_party/abseil-cpp/absl/algorithm:container",
"//third_party/abseil-cpp/absl/strings",
"//third_party/abseil-cpp/absl/types:optional", "//third_party/abseil-cpp/absl/types:optional",
] ]
} }
@ -335,6 +337,7 @@ rtc_library("p2p_server_utils") {
absl_deps = [ absl_deps = [
"//third_party/abseil-cpp/absl/algorithm:container", "//third_party/abseil-cpp/absl/algorithm:container",
"//third_party/abseil-cpp/absl/memory", "//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/algorithm/container.h"
#include "absl/strings/match.h" #include "absl/strings/match.h"
#include "absl/strings/string_view.h"
#include "p2p/base/port_allocator.h" #include "p2p/base/port_allocator.h"
#include "rtc_base/checks.h" #include "rtc_base/checks.h"
#include "rtc_base/crc32.h" #include "rtc_base/crc32.h"
@ -68,7 +69,7 @@ inline bool TooLongWithoutResponse(
// Helper methods for converting string values of log description fields to // Helper methods for converting string values of log description fields to
// enum. // enum.
webrtc::IceCandidateType GetCandidateTypeByString(const std::string& type) { webrtc::IceCandidateType GetCandidateTypeByString(absl::string_view type) {
if (type == LOCAL_PORT_TYPE) { if (type == LOCAL_PORT_TYPE) {
return webrtc::IceCandidateType::kLocal; return webrtc::IceCandidateType::kLocal;
} else if (type == STUN_PORT_TYPE) { } else if (type == STUN_PORT_TYPE) {
@ -82,7 +83,7 @@ webrtc::IceCandidateType GetCandidateTypeByString(const std::string& type) {
} }
webrtc::IceCandidatePairProtocol GetProtocolByString( webrtc::IceCandidatePairProtocol GetProtocolByString(
const std::string& protocol) { absl::string_view protocol) {
if (protocol == UDP_PROTOCOL_NAME) { if (protocol == UDP_PROTOCOL_NAME) {
return webrtc::IceCandidatePairProtocol::kUdp; return webrtc::IceCandidatePairProtocol::kUdp;
} else if (protocol == TCP_PROTOCOL_NAME) { } else if (protocol == TCP_PROTOCOL_NAME) {

View file

@ -60,7 +60,7 @@ struct CandidatePair final : public CandidatePairInterface {
class Connection : public CandidatePairInterface { class Connection : public CandidatePairInterface {
public: public:
struct SentPing { 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) {} : id(id), sent_time(sent_time), nomination(nomination) {}
std::string id; std::string id;

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -14,6 +14,7 @@
#include <memory> #include <memory>
#include <utility> #include <utility>
#include "absl/strings/string_view.h"
#include "api/test/mock_async_dns_resolver.h" #include "api/test/mock_async_dns_resolver.h"
#include "p2p/base/basic_ice_controller.h" #include "p2p/base/basic_ice_controller.h"
#include "p2p/base/connection.h" #include "p2p/base/connection.h"
@ -141,11 +142,11 @@ cricket::IceConfig CreateIceConfig(
return config; return config;
} }
cricket::Candidate CreateUdpCandidate(const std::string& type, cricket::Candidate CreateUdpCandidate(absl::string_view type,
const std::string& ip, absl::string_view ip,
int port, int port,
int priority, int priority,
const std::string& ufrag = "") { absl::string_view ufrag = "") {
cricket::Candidate c; cricket::Candidate c;
c.set_address(rtc::SocketAddress(ip, port)); c.set_address(rtc::SocketAddress(ip, port));
c.set_component(cricket::ICE_CANDIDATE_COMPONENT_DEFAULT); c.set_component(cricket::ICE_CANDIDATE_COMPONENT_DEFAULT);
@ -311,10 +312,10 @@ class P2PTransportChannelTestBase : public ::testing::Test,
}; };
struct Result { struct Result {
Result(const std::string& controlling_type, Result(absl::string_view controlling_type,
const std::string& controlling_protocol, absl::string_view controlling_protocol,
const std::string& controlled_type, absl::string_view controlled_type,
const std::string& controlled_protocol, absl::string_view controlled_protocol,
int wait) int wait)
: controlling_type(controlling_type), : controlling_type(controlling_type),
controlling_protocol(controlling_protocol), controlling_protocol(controlling_protocol),
@ -539,7 +540,7 @@ class P2PTransportChannelTestBase : public ::testing::Test,
} }
void AddAddress(int endpoint, void AddAddress(int endpoint,
const SocketAddress& addr, const SocketAddress& addr,
const std::string& ifname, absl::string_view ifname,
rtc::AdapterType adapter_type, rtc::AdapterType adapter_type,
absl::optional<rtc::AdapterType> underlying_vpn_adapter_type = absl::optional<rtc::AdapterType> underlying_vpn_adapter_type =
absl::nullopt) { absl::nullopt) {
@ -855,7 +856,7 @@ class P2PTransportChannelTestBase : public ::testing::Test,
} }
// Tcp candidate verification has to be done when they are generated. // 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& data : GetEndpoint(endpoint)->saved_candidates_) {
for (auto& candidate : data->candidates) { for (auto& candidate : data->candidates) {
EXPECT_EQ(candidate.protocol(), TCP_PROTOCOL_NAME); EXPECT_EQ(candidate.protocol(), TCP_PROTOCOL_NAME);
@ -3410,7 +3411,7 @@ class P2PTransportChannelPingTest : public ::testing::Test,
Connection* WaitForConnectionTo( Connection* WaitForConnectionTo(
P2PTransportChannel* ch, P2PTransportChannel* ch,
const std::string& ip, absl::string_view ip,
int port_num, int port_num,
rtc::ThreadProcessingFakeClock* clock = nullptr) { rtc::ThreadProcessingFakeClock* clock = nullptr) {
if (clock == nullptr) { if (clock == nullptr) {
@ -3438,7 +3439,7 @@ class P2PTransportChannelPingTest : public ::testing::Test,
} }
Connection* GetConnectionTo(P2PTransportChannel* ch, Connection* GetConnectionTo(P2PTransportChannel* ch,
const std::string& ip, absl::string_view ip,
int port_num) { int port_num) {
Port* port = GetPort(ch); Port* port = GetPort(ch);
if (!port) { if (!port) {
@ -3466,7 +3467,7 @@ class P2PTransportChannelPingTest : public ::testing::Test,
Connection* CreateConnectionWithCandidate(P2PTransportChannel* channel, Connection* CreateConnectionWithCandidate(P2PTransportChannel* channel,
rtc::ScopedFakeClock* clock, rtc::ScopedFakeClock* clock,
const std::string& ip_addr, absl::string_view ip_addr,
int port, int port,
int priority, int priority,
bool writable) { bool writable) {
@ -3498,14 +3499,14 @@ class P2PTransportChannelPingTest : public ::testing::Test,
void ReceivePingOnConnection( void ReceivePingOnConnection(
Connection* conn, Connection* conn,
const std::string& remote_ufrag, absl::string_view remote_ufrag,
int priority, int priority,
uint32_t nomination, uint32_t nomination,
const absl::optional<std::string>& piggyback_ping_id) { const absl::optional<std::string>& piggyback_ping_id) {
IceMessage msg(STUN_BINDING_REQUEST); IceMessage msg(STUN_BINDING_REQUEST);
msg.AddAttribute(std::make_unique<StunByteStringAttribute>( msg.AddAttribute(std::make_unique<StunByteStringAttribute>(
STUN_ATTR_USERNAME, STUN_ATTR_USERNAME,
conn->local_candidate().username() + ":" + remote_ufrag)); conn->local_candidate().username() + ":" + std::string(remote_ufrag)));
msg.AddAttribute( msg.AddAttribute(
std::make_unique<StunUInt32Attribute>(STUN_ATTR_PRIORITY, priority)); std::make_unique<StunUInt32Attribute>(STUN_ATTR_PRIORITY, priority));
if (nomination != 0) { if (nomination != 0) {
@ -3524,7 +3525,7 @@ class P2PTransportChannelPingTest : public ::testing::Test,
} }
void ReceivePingOnConnection(Connection* conn, void ReceivePingOnConnection(Connection* conn,
const std::string& remote_ufrag, absl::string_view remote_ufrag,
int priority, int priority,
uint32_t nomination = 0) { uint32_t nomination = 0) {
ReceivePingOnConnection(conn, remote_ufrag, priority, nomination, 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) { if (!conn) {
return !last_candidate_change_event_.has_value(); return !last_candidate_change_event_.has_value();
} else { } else {
@ -4954,9 +4956,9 @@ class P2PTransportChannelMostLikelyToWorkFirstTest
// types and, for relay local candidate, the expected relay protocol and ping // types and, for relay local candidate, the expected relay protocol and ping
// it. // it.
void VerifyNextPingableConnection( void VerifyNextPingableConnection(
const std::string& local_candidate_type, absl::string_view local_candidate_type,
const std::string& remote_candidate_type, absl::string_view remote_candidate_type,
const std::string& relay_protocol_type = UDP_PROTOCOL_NAME) { absl::string_view relay_protocol_type = UDP_PROTOCOL_NAME) {
Connection* conn = FindNextPingableConnectionAndPingIt(channel_.get()); Connection* conn = FindNextPingableConnectionAndPingIt(channel_.get());
ASSERT_TRUE(conn != nullptr); ASSERT_TRUE(conn != nullptr);
EXPECT_EQ(conn->local_candidate().type(), local_candidate_type); 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_PASSIVE_STR[] = "passive";
const char TCPTYPE_SIMOPEN_STR[] = "so"; const char TCPTYPE_SIMOPEN_STR[] = "so";
std::string Port::ComputeFoundation(const std::string& type, std::string Port::ComputeFoundation(absl::string_view type,
const std::string& protocol, absl::string_view protocol,
const std::string& relay_protocol, absl::string_view relay_protocol,
const rtc::SocketAddress& base_address) { const rtc::SocketAddress& base_address) {
rtc::StringBuilder sb; rtc::StringBuilder sb;
sb << type << base_address.ipaddr().ToString() << protocol << relay_protocol; 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, Port::Port(rtc::Thread* thread,
const std::string& type, absl::string_view type,
rtc::PacketSocketFactory* factory, rtc::PacketSocketFactory* factory,
const rtc::Network* network, const rtc::Network* network,
const std::string& username_fragment, absl::string_view username_fragment,
const std::string& password, absl::string_view password,
const webrtc::FieldTrialsView* field_trials) const webrtc::FieldTrialsView* field_trials)
: thread_(thread), : thread_(thread),
factory_(factory), factory_(factory),
@ -135,13 +135,13 @@ Port::Port(rtc::Thread* thread,
} }
Port::Port(rtc::Thread* thread, Port::Port(rtc::Thread* thread,
const std::string& type, absl::string_view type,
rtc::PacketSocketFactory* factory, rtc::PacketSocketFactory* factory,
const rtc::Network* network, const rtc::Network* network,
uint16_t min_port, uint16_t min_port,
uint16_t max_port, uint16_t max_port,
const std::string& username_fragment, absl::string_view username_fragment,
const std::string& password, absl::string_view password,
const webrtc::FieldTrialsView* field_trials) const webrtc::FieldTrialsView* field_trials)
: thread_(thread), : thread_(thread),
factory_(factory), factory_(factory),
@ -250,13 +250,13 @@ Connection* Port::GetConnection(const rtc::SocketAddress& remote_addr) {
void Port::AddAddress(const rtc::SocketAddress& address, void Port::AddAddress(const rtc::SocketAddress& address,
const rtc::SocketAddress& base_address, const rtc::SocketAddress& base_address,
const rtc::SocketAddress& related_address, const rtc::SocketAddress& related_address,
const std::string& protocol, absl::string_view protocol,
const std::string& relay_protocol, absl::string_view relay_protocol,
const std::string& tcptype, absl::string_view tcptype,
const std::string& type, absl::string_view type,
uint32_t type_preference, uint32_t type_preference,
uint32_t relay_preference, uint32_t relay_preference,
const std::string& url, absl::string_view url,
bool is_final) { bool is_final) {
RTC_DCHECK_RUN_ON(thread_); RTC_DCHECK_RUN_ON(thread_);
if (protocol == TCP_PROTOCOL_NAME && type == LOCAL_PORT_TYPE) { 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, bool Port::MaybeObfuscateAddress(Candidate* c,
const std::string& type, absl::string_view type,
bool is_final) { bool is_final) {
// TODO(bugs.webrtc.org/9723): Use a config to control the feature of IP // TODO(bugs.webrtc.org/9723): Use a config to control the feature of IP
// handling with mDNS. // handling with mDNS.
@ -652,7 +652,7 @@ bool Port::ParseStunUsername(const StunMessage* stun_msg,
bool Port::MaybeIceRoleConflict(const rtc::SocketAddress& addr, bool Port::MaybeIceRoleConflict(const rtc::SocketAddress& addr,
IceMessage* stun_msg, IceMessage* stun_msg,
const std::string& remote_ufrag) { absl::string_view remote_ufrag) {
// Validate ICE_CONTROLLING or ICE_CONTROLLED attributes. // Validate ICE_CONTROLLING or ICE_CONTROLLED attributes.
bool ret = true; bool ret = true;
IceRole remote_ice_role = ICEROLE_UNKNOWN; IceRole remote_ice_role = ICEROLE_UNKNOWN;
@ -711,8 +711,8 @@ bool Port::MaybeIceRoleConflict(const rtc::SocketAddress& addr,
return ret; return ret;
} }
std::string Port::CreateStunUsername(const std::string& remote_username) const { std::string Port::CreateStunUsername(absl::string_view remote_username) const {
return remote_username + ":" + username_fragment(); return std::string(remote_username) + ":" + username_fragment();
} }
bool Port::HandleIncomingPacket(rtc::AsyncPacketSocket* socket, bool Port::HandleIncomingPacket(rtc::AsyncPacketSocket* socket,
@ -731,7 +731,7 @@ bool Port::CanHandleIncomingPacketsFrom(const rtc::SocketAddress&) const {
void Port::SendBindingErrorResponse(StunMessage* message, void Port::SendBindingErrorResponse(StunMessage* message,
const rtc::SocketAddress& addr, const rtc::SocketAddress& addr,
int error_code, int error_code,
const std::string& reason) { absl::string_view reason) {
RTC_DCHECK(message->type() == STUN_BINDING_REQUEST || RTC_DCHECK(message->type() == STUN_BINDING_REQUEST ||
message->type() == GOOG_PING_REQUEST); message->type() == GOOG_PING_REQUEST);
@ -745,7 +745,7 @@ void Port::SendBindingErrorResponse(StunMessage* message,
// maintain backwards compatiblility. // maintain backwards compatiblility.
auto error_attr = StunAttribute::CreateErrorCode(); auto error_attr = StunAttribute::CreateErrorCode();
error_attr->SetCode(error_code); error_attr->SetCode(error_code);
error_attr->SetReason(reason); error_attr->SetReason(std::string(reason));
response.AddAttribute(std::move(error_attr)); response.AddAttribute(std::move(error_attr));
// Per Section 10.1.2, certain error cases don't get a MESSAGE-INTEGRITY, // Per Section 10.1.2, certain error cases don't get a MESSAGE-INTEGRITY,

View file

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

View file

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

View file

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

View file

@ -12,6 +12,7 @@
#include <memory> #include <memory>
#include "absl/strings/string_view.h"
#include "p2p/base/fake_port_allocator.h" #include "p2p/base/fake_port_allocator.h"
#include "rtc_base/thread.h" #include "rtc_base/thread.h"
#include "rtc_base/virtual_socket_server.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( std::unique_ptr<cricket::FakePortAllocatorSession> CreateSession(
const std::string& content_name, absl::string_view content_name,
int component, int component,
const std::string& ice_ufrag, absl::string_view ice_ufrag,
const std::string& ice_pwd) { absl::string_view ice_pwd) {
return std::unique_ptr<cricket::FakePortAllocatorSession>( return std::unique_ptr<cricket::FakePortAllocatorSession>(
static_cast<cricket::FakePortAllocatorSession*>( static_cast<cricket::FakePortAllocatorSession*>(
allocator_ allocator_

View file

@ -111,7 +111,7 @@ class PortInterface {
virtual void SendBindingErrorResponse(StunMessage* message, virtual void SendBindingErrorResponse(StunMessage* message,
const rtc::SocketAddress& addr, const rtc::SocketAddress& addr,
int error_code, 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 // Signaled when this port decides to delete itself because it no longer has
// any usefulness. // any usefulness.

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -86,6 +86,7 @@ rtc_library("emulated_network") {
absl_deps = [ absl_deps = [
"//third_party/abseil-cpp/absl/algorithm:container", "//third_party/abseil-cpp/absl/algorithm:container",
"//third_party/abseil-cpp/absl/memory", "//third_party/abseil-cpp/absl/memory",
"//third_party/abseil-cpp/absl/strings",
"//third_party/abseil-cpp/absl/types:optional", "//third_party/abseil-cpp/absl/types:optional",
] ]
} }

View file

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