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}
diff --git a/examples/BUILD.gn b/examples/BUILD.gn
index 26a51b2..17cfc7b3 100644
--- a/examples/BUILD.gn
+++ b/examples/BUILD.gn
@@ -800,6 +800,7 @@
"../rtc_base:socket_address",
"../rtc_base:socket_server",
"../rtc_base:threading",
+ "//third_party/abseil-cpp/absl/strings:strings",
]
}
rtc_executable("stunserver") {
diff --git a/examples/turnserver/turnserver_main.cc b/examples/turnserver/turnserver_main.cc
index 055d9ba..8db6162 100644
--- a/examples/turnserver/turnserver_main.cc
+++ b/examples/turnserver/turnserver_main.cc
@@ -14,6 +14,7 @@
#include <string>
#include <utility>
+#include "absl/strings/string_view.h"
#include "examples/turnserver/read_auth_file.h"
#include "p2p/base/basic_packet_socket_factory.h"
#include "p2p/base/port_interface.h"
@@ -32,12 +33,12 @@
explicit TurnFileAuth(std::map<std::string, std::string> name_to_key)
: name_to_key_(std::move(name_to_key)) {}
- virtual bool GetKey(const std::string& username,
- const std::string& realm,
+ virtual bool GetKey(absl::string_view username,
+ absl::string_view realm,
std::string* key) {
// File is stored as lines of <username>=<HA1>.
// Generate HA1 via "echo -n "<username>:<realm>:<password>" | md5sum"
- auto it = name_to_key_.find(username);
+ auto it = name_to_key_.find(std::string(username));
if (it == name_to_key_.end())
return false;
*key = it->second;
diff --git a/p2p/BUILD.gn b/p2p/BUILD.gn
index 29fd289..18264ef 100644
--- a/p2p/BUILD.gn
+++ b/p2p/BUILD.gn
@@ -173,6 +173,7 @@
]
absl_deps = [
"//third_party/abseil-cpp/absl/algorithm:container",
+ "//third_party/abseil-cpp/absl/strings",
"//third_party/abseil-cpp/absl/types:optional",
]
}
@@ -230,6 +231,7 @@
]
absl_deps = [
"//third_party/abseil-cpp/absl/algorithm:container",
+ "//third_party/abseil-cpp/absl/strings",
"//third_party/abseil-cpp/absl/types:optional",
]
}
@@ -335,6 +337,7 @@
absl_deps = [
"//third_party/abseil-cpp/absl/algorithm:container",
"//third_party/abseil-cpp/absl/memory",
+ "//third_party/abseil-cpp/absl/strings",
]
}
diff --git a/p2p/base/connection.cc b/p2p/base/connection.cc
index 7e4633a..9aefdf6 100644
--- a/p2p/base/connection.cc
+++ b/p2p/base/connection.cc
@@ -19,6 +19,7 @@
#include "absl/algorithm/container.h"
#include "absl/strings/match.h"
+#include "absl/strings/string_view.h"
#include "p2p/base/port_allocator.h"
#include "rtc_base/checks.h"
#include "rtc_base/crc32.h"
@@ -68,7 +69,7 @@
// Helper methods for converting string values of log description fields to
// enum.
-webrtc::IceCandidateType GetCandidateTypeByString(const std::string& type) {
+webrtc::IceCandidateType GetCandidateTypeByString(absl::string_view type) {
if (type == LOCAL_PORT_TYPE) {
return webrtc::IceCandidateType::kLocal;
} else if (type == STUN_PORT_TYPE) {
@@ -82,7 +83,7 @@
}
webrtc::IceCandidatePairProtocol GetProtocolByString(
- const std::string& protocol) {
+ absl::string_view protocol) {
if (protocol == UDP_PROTOCOL_NAME) {
return webrtc::IceCandidatePairProtocol::kUdp;
} else if (protocol == TCP_PROTOCOL_NAME) {
diff --git a/p2p/base/connection.h b/p2p/base/connection.h
index 9e19d07..bd17294 100644
--- a/p2p/base/connection.h
+++ b/p2p/base/connection.h
@@ -60,7 +60,7 @@
class Connection : public CandidatePairInterface {
public:
struct SentPing {
- SentPing(const std::string id, int64_t sent_time, uint32_t nomination)
+ SentPing(absl::string_view id, int64_t sent_time, uint32_t nomination)
: id(id), sent_time(sent_time), nomination(nomination) {}
std::string id;
diff --git a/p2p/base/dtls_transport.cc b/p2p/base/dtls_transport.cc
index bf8583f..2ebc983 100644
--- a/p2p/base/dtls_transport.cc
+++ b/p2p/base/dtls_transport.cc
@@ -15,6 +15,7 @@
#include <utility>
#include "absl/memory/memory.h"
+#include "absl/strings/string_view.h"
#include "api/dtls_transport_interface.h"
#include "api/rtc_event_log/rtc_event_log.h"
#include "logging/rtc_event_log/events/rtc_event_dtls_transport_state.h"
@@ -226,7 +227,7 @@
return dtls_->GetSslCipherSuite(cipher);
}
-bool DtlsTransport::SetRemoteFingerprint(const std::string& digest_alg,
+bool DtlsTransport::SetRemoteFingerprint(absl::string_view digest_alg,
const uint8_t* digest,
size_t digest_len) {
rtc::Buffer remote_fingerprint_value(digest, digest_len);
@@ -264,7 +265,7 @@
// At this point we know we are doing DTLS
bool fingerprint_changing = remote_fingerprint_value_.size() > 0u;
remote_fingerprint_value_ = std::move(remote_fingerprint_value);
- remote_fingerprint_algorithm_ = digest_alg;
+ remote_fingerprint_algorithm_ = std::string(digest_alg);
if (dtls_ && !fingerprint_changing) {
// This can occur if DTLS is set up before a remote fingerprint is
@@ -312,7 +313,7 @@
return dtls_->GetPeerSSLCertChain();
}
-bool DtlsTransport::ExportKeyingMaterial(const std::string& label,
+bool DtlsTransport::ExportKeyingMaterial(absl::string_view label,
const uint8_t* context,
size_t context_len,
bool use_context,
diff --git a/p2p/base/dtls_transport.h b/p2p/base/dtls_transport.h
index d503a92..a78226c 100644
--- a/p2p/base/dtls_transport.h
+++ b/p2p/base/dtls_transport.h
@@ -15,6 +15,7 @@
#include <string>
#include <vector>
+#include "absl/strings/string_view.h"
#include "api/crypto/crypto_options.h"
#include "api/dtls_transport_interface.h"
#include "api/sequence_checker.h"
@@ -135,7 +136,7 @@
// SetRemoteFingerprint must be called after SetLocalCertificate, and any
// other methods like SetDtlsRole. It's what triggers the actual DTLS setup.
// TODO(deadbeef): Rename to "Start" like in ORTC?
- bool SetRemoteFingerprint(const std::string& digest_alg,
+ bool SetRemoteFingerprint(absl::string_view digest_alg,
const uint8_t* digest,
size_t digest_len) override;
@@ -167,7 +168,7 @@
// method extracts the keys negotiated during the DTLS handshake, for use in
// external encryption. DTLS-SRTP uses this to extract the needed SRTP keys.
// See the SSLStreamAdapter documentation for info on the specific parameters.
- bool ExportKeyingMaterial(const std::string& label,
+ bool ExportKeyingMaterial(absl::string_view label,
const uint8_t* context,
size_t context_len,
bool use_context,
diff --git a/p2p/base/dtls_transport_internal.h b/p2p/base/dtls_transport_internal.h
index 24c682f..061d1e9 100644
--- a/p2p/base/dtls_transport_internal.h
+++ b/p2p/base/dtls_transport_internal.h
@@ -19,6 +19,7 @@
#include <utility>
#include "absl/base/attributes.h"
+#include "absl/strings/string_view.h"
#include "api/crypto/crypto_options.h"
#include "api/dtls_transport_interface.h"
#include "api/scoped_refptr.h"
@@ -81,7 +82,7 @@
virtual std::unique_ptr<rtc::SSLCertChain> GetRemoteSSLCertChain() const = 0;
// Allows key material to be extracted for external encryption.
- virtual bool ExportKeyingMaterial(const std::string& label,
+ virtual bool ExportKeyingMaterial(absl::string_view label,
const uint8_t* context,
size_t context_len,
bool use_context,
@@ -89,7 +90,7 @@
size_t result_len) = 0;
// Set DTLS remote fingerprint. Must be after local identity set.
- virtual bool SetRemoteFingerprint(const std::string& digest_alg,
+ virtual bool SetRemoteFingerprint(absl::string_view digest_alg,
const uint8_t* digest,
size_t digest_len) = 0;
diff --git a/p2p/base/dtls_transport_unittest.cc b/p2p/base/dtls_transport_unittest.cc
index 80691ab..cb04bf7 100644
--- a/p2p/base/dtls_transport_unittest.cc
+++ b/p2p/base/dtls_transport_unittest.cc
@@ -15,6 +15,7 @@
#include <set>
#include <utility>
+#include "absl/strings/string_view.h"
#include "api/dtls_transport_interface.h"
#include "p2p/base/fake_ice_transport.h"
#include "p2p/base/packet_transport_internal.h"
@@ -64,7 +65,7 @@
class DtlsTestClient : public sigslot::has_slots<> {
public:
- explicit DtlsTestClient(const std::string& name) : name_(name) {}
+ explicit DtlsTestClient(absl::string_view name) : name_(name) {}
void CreateCertificate(rtc::KeyType key_type) {
certificate_ =
rtc::RTCCertificate::Create(rtc::SSLIdentity::Create(name_, key_type));
diff --git a/p2p/base/fake_dtls_transport.h b/p2p/base/fake_dtls_transport.h
index 5f0ea2e..23d4710 100644
--- a/p2p/base/fake_dtls_transport.h
+++ b/p2p/base/fake_dtls_transport.h
@@ -16,6 +16,7 @@
#include <utility>
#include <vector>
+#include "absl/strings/string_view.h"
#include "api/crypto/crypto_options.h"
#include "api/dtls_transport_interface.h"
#include "p2p/base/dtls_transport_internal.h"
@@ -140,7 +141,7 @@
const rtc::SSLFingerprint& dtls_fingerprint() const {
return dtls_fingerprint_;
}
- bool SetRemoteFingerprint(const std::string& alg,
+ bool SetRemoteFingerprint(absl::string_view alg,
const uint8_t* digest,
size_t digest_len) override {
dtls_fingerprint_ =
@@ -203,7 +204,7 @@
}
return std::make_unique<rtc::SSLCertChain>(remote_cert_->Clone());
}
- bool ExportKeyingMaterial(const std::string& label,
+ bool ExportKeyingMaterial(absl::string_view label,
const uint8_t* context,
size_t context_len,
bool use_context,
diff --git a/p2p/base/fake_ice_transport.h b/p2p/base/fake_ice_transport.h
index 7a3d834..4c636cf 100644
--- a/p2p/base/fake_ice_transport.h
+++ b/p2p/base/fake_ice_transport.h
@@ -17,6 +17,7 @@
#include <utility>
#include "absl/algorithm/container.h"
+#include "absl/strings/string_view.h"
#include "absl/types/optional.h"
#include "api/ice_transport_interface.h"
#include "api/task_queue/pending_task_safety_flag.h"
@@ -31,7 +32,7 @@
// constructor).
class FakeIceTransport : public IceTransportInternal {
public:
- explicit FakeIceTransport(const std::string& name,
+ explicit FakeIceTransport(absl::string_view name,
int component,
rtc::Thread* network_thread = nullptr)
: name_(name),
diff --git a/p2p/base/fake_port_allocator.h b/p2p/base/fake_port_allocator.h
index e4528bc..e92825e 100644
--- a/p2p/base/fake_port_allocator.h
+++ b/p2p/base/fake_port_allocator.h
@@ -38,8 +38,8 @@
const rtc::Network* network,
uint16_t min_port,
uint16_t max_port,
- const std::string& username,
- const std::string& password,
+ absl::string_view username,
+ absl::string_view password,
bool emit_localhost_for_anyaddress,
const webrtc::FieldTrialsView* field_trials) {
TestUDPPort* port =
@@ -58,8 +58,8 @@
const rtc::Network* network,
uint16_t min_port,
uint16_t max_port,
- const std::string& username,
- const std::string& password,
+ absl::string_view username,
+ absl::string_view password,
bool emit_localhost_for_anyaddress,
const webrtc::FieldTrialsView* field_trials)
: UDPPort(thread,
@@ -81,10 +81,10 @@
FakePortAllocatorSession(PortAllocator* allocator,
rtc::Thread* network_thread,
rtc::PacketSocketFactory* factory,
- const std::string& content_name,
+ absl::string_view content_name,
int component,
- const std::string& ice_ufrag,
- const std::string& ice_pwd,
+ absl::string_view ice_ufrag,
+ absl::string_view ice_pwd,
const webrtc::FieldTrialsView& field_trials)
: PortAllocatorSession(content_name,
component,
diff --git a/p2p/base/ice_transport_internal.cc b/p2p/base/ice_transport_internal.cc
index 104a95b..fab6f20 100644
--- a/p2p/base/ice_transport_internal.cc
+++ b/p2p/base/ice_transport_internal.cc
@@ -10,6 +10,7 @@
#include "p2p/base/ice_transport_internal.h"
+#include "absl/strings/string_view.h"
#include "p2p/base/p2p_constants.h"
namespace cricket {
@@ -126,13 +127,13 @@
IceTransportInternal::~IceTransportInternal() = default;
-void IceTransportInternal::SetIceCredentials(const std::string& ice_ufrag,
- const std::string& ice_pwd) {
+void IceTransportInternal::SetIceCredentials(absl::string_view ice_ufrag,
+ absl::string_view ice_pwd) {
SetIceParameters(IceParameters(ice_ufrag, ice_pwd, false));
}
-void IceTransportInternal::SetRemoteIceCredentials(const std::string& ice_ufrag,
- const std::string& ice_pwd) {
+void IceTransportInternal::SetRemoteIceCredentials(absl::string_view ice_ufrag,
+ absl::string_view ice_pwd) {
SetRemoteIceParameters(IceParameters(ice_ufrag, ice_pwd, false));
}
diff --git a/p2p/base/ice_transport_internal.h b/p2p/base/ice_transport_internal.h
index 4f74ac7..3a93ab0 100644
--- a/p2p/base/ice_transport_internal.h
+++ b/p2p/base/ice_transport_internal.h
@@ -16,6 +16,7 @@
#include <string>
#include <vector>
+#include "absl/strings/string_view.h"
#include "absl/types/optional.h"
#include "api/candidate.h"
#include "api/rtc_error.h"
@@ -259,11 +260,11 @@
// remoting/protocol/libjingle_transport_factory.cc
virtual void SetIceProtocolType(IceProtocolType type) {}
- virtual void SetIceCredentials(const std::string& ice_ufrag,
- const std::string& ice_pwd);
+ virtual void SetIceCredentials(absl::string_view ice_ufrag,
+ absl::string_view ice_pwd);
- virtual void SetRemoteIceCredentials(const std::string& ice_ufrag,
- const std::string& ice_pwd);
+ virtual void SetRemoteIceCredentials(absl::string_view ice_ufrag,
+ absl::string_view ice_pwd);
// The ufrag and pwd in `ice_params` must be set
// before candidate gathering can start.
diff --git a/p2p/base/p2p_transport_channel.cc b/p2p/base/p2p_transport_channel.cc
index 509b332..3283294 100644
--- a/p2p/base/p2p_transport_channel.cc
+++ b/p2p/base/p2p_transport_channel.cc
@@ -22,6 +22,7 @@
#include "absl/algorithm/container.h"
#include "absl/memory/memory.h"
#include "absl/strings/match.h"
+#include "absl/strings/string_view.h"
#include "api/async_dns_resolver.h"
#include "api/candidate.h"
#include "api/field_trials_view.h"
@@ -101,10 +102,10 @@
using webrtc::RTCErrorType;
using webrtc::ToQueuedTask;
-bool IceCredentialsChanged(const std::string& old_ufrag,
- const std::string& old_pwd,
- const std::string& new_ufrag,
- const std::string& new_pwd) {
+bool IceCredentialsChanged(absl::string_view old_ufrag,
+ absl::string_view old_pwd,
+ absl::string_view new_ufrag,
+ absl::string_view new_pwd) {
// The standard (RFC 5245 Section 9.1.1.1) says that ICE restarts MUST change
// both the ufrag and password. However, section 9.2.1.1 says changing the
// ufrag OR password indicates an ICE restart. So, to keep compatibility with
@@ -113,7 +114,7 @@
}
std::unique_ptr<P2PTransportChannel> P2PTransportChannel::Create(
- const std::string& transport_name,
+ absl::string_view transport_name,
int component,
webrtc::IceTransportInit init) {
if (init.async_resolver_factory()) {
@@ -131,7 +132,7 @@
}
P2PTransportChannel::P2PTransportChannel(
- const std::string& transport_name,
+ absl::string_view transport_name,
int component,
PortAllocator* allocator,
const webrtc::FieldTrialsView* field_trials)
@@ -146,7 +147,7 @@
// Private constructor, called from Create()
P2PTransportChannel::P2PTransportChannel(
- const std::string& transport_name,
+ absl::string_view transport_name,
int component,
PortAllocator* allocator,
webrtc::AsyncDnsResolverFactoryInterface* async_dns_resolver_factory,
@@ -1180,7 +1181,7 @@
}
const IceParameters* P2PTransportChannel::FindRemoteIceFromUfrag(
- const std::string& ufrag,
+ absl::string_view ufrag,
uint32_t* generation) {
RTC_DCHECK_RUN_ON(network_thread_);
const auto& params = remote_ice_parameters_;
diff --git a/p2p/base/p2p_transport_channel.h b/p2p/base/p2p_transport_channel.h
index df60629..981bd9a 100644
--- a/p2p/base/p2p_transport_channel.h
+++ b/p2p/base/p2p_transport_channel.h
@@ -32,6 +32,7 @@
#include <vector>
#include "absl/base/attributes.h"
+#include "absl/strings/string_view.h"
#include "absl/types/optional.h"
#include "api/array_view.h"
#include "api/async_dns_resolver.h"
@@ -84,10 +85,10 @@
static const int MIN_PINGS_AT_WEAK_PING_INTERVAL = 3;
-bool IceCredentialsChanged(const std::string& old_ufrag,
- const std::string& old_pwd,
- const std::string& new_ufrag,
- const std::string& new_pwd);
+bool IceCredentialsChanged(absl::string_view old_ufrag,
+ absl::string_view old_pwd,
+ absl::string_view new_ufrag,
+ absl::string_view new_pwd);
// Adds the port on which the candidate originated.
class RemoteCandidate : public Candidate {
@@ -106,13 +107,13 @@
class RTC_EXPORT P2PTransportChannel : public IceTransportInternal {
public:
static std::unique_ptr<P2PTransportChannel> Create(
- const std::string& transport_name,
+ absl::string_view transport_name,
int component,
webrtc::IceTransportInit init);
// For testing only.
// TODO(zstein): Remove once AsyncDnsResolverFactory is required.
- P2PTransportChannel(const std::string& transport_name,
+ P2PTransportChannel(absl::string_view transport_name,
int component,
PortAllocator* allocator,
const webrtc::FieldTrialsView* field_trials = nullptr);
@@ -237,7 +238,7 @@
private:
P2PTransportChannel(
- const std::string& transport_name,
+ absl::string_view transport_name,
int component,
PortAllocator* allocator,
// DNS resolver factory
@@ -357,7 +358,7 @@
}
// Returns the remote IceParameters and generation that match `ufrag`
// if found, and returns nullptr otherwise.
- const IceParameters* FindRemoteIceFromUfrag(const std::string& ufrag,
+ const IceParameters* FindRemoteIceFromUfrag(absl::string_view ufrag,
uint32_t* generation);
// Returns the index of the latest remote ICE parameters, or 0 if no remote
// ICE parameters have been received.
diff --git a/p2p/base/p2p_transport_channel_unittest.cc b/p2p/base/p2p_transport_channel_unittest.cc
index 8ff81fc..28576f4 100644
--- a/p2p/base/p2p_transport_channel_unittest.cc
+++ b/p2p/base/p2p_transport_channel_unittest.cc
@@ -14,6 +14,7 @@
#include <memory>
#include <utility>
+#include "absl/strings/string_view.h"
#include "api/test/mock_async_dns_resolver.h"
#include "p2p/base/basic_ice_controller.h"
#include "p2p/base/connection.h"
@@ -141,11 +142,11 @@
return config;
}
-cricket::Candidate CreateUdpCandidate(const std::string& type,
- const std::string& ip,
+cricket::Candidate CreateUdpCandidate(absl::string_view type,
+ absl::string_view ip,
int port,
int priority,
- const std::string& ufrag = "") {
+ absl::string_view ufrag = "") {
cricket::Candidate c;
c.set_address(rtc::SocketAddress(ip, port));
c.set_component(cricket::ICE_CANDIDATE_COMPONENT_DEFAULT);
@@ -311,10 +312,10 @@
};
struct Result {
- Result(const std::string& controlling_type,
- const std::string& controlling_protocol,
- const std::string& controlled_type,
- const std::string& controlled_protocol,
+ Result(absl::string_view controlling_type,
+ absl::string_view controlling_protocol,
+ absl::string_view controlled_type,
+ absl::string_view controlled_protocol,
int wait)
: controlling_type(controlling_type),
controlling_protocol(controlling_protocol),
@@ -539,7 +540,7 @@
}
void AddAddress(int endpoint,
const SocketAddress& addr,
- const std::string& ifname,
+ absl::string_view ifname,
rtc::AdapterType adapter_type,
absl::optional<rtc::AdapterType> underlying_vpn_adapter_type =
absl::nullopt) {
@@ -855,7 +856,7 @@
}
// Tcp candidate verification has to be done when they are generated.
- void VerifySavedTcpCandidates(int endpoint, const std::string& tcptype) {
+ void VerifySavedTcpCandidates(int endpoint, absl::string_view tcptype) {
for (auto& data : GetEndpoint(endpoint)->saved_candidates_) {
for (auto& candidate : data->candidates) {
EXPECT_EQ(candidate.protocol(), TCP_PROTOCOL_NAME);
@@ -3410,7 +3411,7 @@
Connection* WaitForConnectionTo(
P2PTransportChannel* ch,
- const std::string& ip,
+ absl::string_view ip,
int port_num,
rtc::ThreadProcessingFakeClock* clock = nullptr) {
if (clock == nullptr) {
@@ -3438,7 +3439,7 @@
}
Connection* GetConnectionTo(P2PTransportChannel* ch,
- const std::string& ip,
+ absl::string_view ip,
int port_num) {
Port* port = GetPort(ch);
if (!port) {
@@ -3466,7 +3467,7 @@
Connection* CreateConnectionWithCandidate(P2PTransportChannel* channel,
rtc::ScopedFakeClock* clock,
- const std::string& ip_addr,
+ absl::string_view ip_addr,
int port,
int priority,
bool writable) {
@@ -3498,14 +3499,14 @@
void ReceivePingOnConnection(
Connection* conn,
- const std::string& remote_ufrag,
+ absl::string_view remote_ufrag,
int priority,
uint32_t nomination,
const absl::optional<std::string>& piggyback_ping_id) {
IceMessage msg(STUN_BINDING_REQUEST);
msg.AddAttribute(std::make_unique<StunByteStringAttribute>(
STUN_ATTR_USERNAME,
- conn->local_candidate().username() + ":" + remote_ufrag));
+ conn->local_candidate().username() + ":" + std::string(remote_ufrag)));
msg.AddAttribute(
std::make_unique<StunUInt32Attribute>(STUN_ATTR_PRIORITY, priority));
if (nomination != 0) {
@@ -3524,7 +3525,7 @@
}
void ReceivePingOnConnection(Connection* conn,
- const std::string& remote_ufrag,
+ absl::string_view remote_ufrag,
int priority,
uint32_t nomination = 0) {
ReceivePingOnConnection(conn, remote_ufrag, priority, nomination,
@@ -3563,7 +3564,8 @@
}
}
- bool ConnectionMatchesChangeEvent(Connection* conn, std::string reason) {
+ bool ConnectionMatchesChangeEvent(Connection* conn,
+ absl::string_view reason) {
if (!conn) {
return !last_candidate_change_event_.has_value();
} else {
@@ -4954,9 +4956,9 @@
// types and, for relay local candidate, the expected relay protocol and ping
// it.
void VerifyNextPingableConnection(
- const std::string& local_candidate_type,
- const std::string& remote_candidate_type,
- const std::string& relay_protocol_type = UDP_PROTOCOL_NAME) {
+ absl::string_view local_candidate_type,
+ absl::string_view remote_candidate_type,
+ absl::string_view relay_protocol_type = UDP_PROTOCOL_NAME) {
Connection* conn = FindNextPingableConnectionAndPingIt(channel_.get());
ASSERT_TRUE(conn != nullptr);
EXPECT_EQ(conn->local_candidate().type(), local_candidate_type);
diff --git a/p2p/base/port.cc b/p2p/base/port.cc
index d9584e3..d622664 100644
--- a/p2p/base/port.cc
+++ b/p2p/base/port.cc
@@ -96,9 +96,9 @@
const char TCPTYPE_PASSIVE_STR[] = "passive";
const char TCPTYPE_SIMOPEN_STR[] = "so";
-std::string Port::ComputeFoundation(const std::string& type,
- const std::string& protocol,
- const std::string& relay_protocol,
+std::string Port::ComputeFoundation(absl::string_view type,
+ absl::string_view protocol,
+ absl::string_view relay_protocol,
const rtc::SocketAddress& base_address) {
rtc::StringBuilder sb;
sb << type << base_address.ipaddr().ToString() << protocol << relay_protocol;
@@ -106,11 +106,11 @@
}
Port::Port(rtc::Thread* thread,
- const std::string& type,
+ absl::string_view type,
rtc::PacketSocketFactory* factory,
const rtc::Network* network,
- const std::string& username_fragment,
- const std::string& password,
+ absl::string_view username_fragment,
+ absl::string_view password,
const webrtc::FieldTrialsView* field_trials)
: thread_(thread),
factory_(factory),
@@ -135,13 +135,13 @@
}
Port::Port(rtc::Thread* thread,
- const std::string& type,
+ absl::string_view type,
rtc::PacketSocketFactory* factory,
const rtc::Network* network,
uint16_t min_port,
uint16_t max_port,
- const std::string& username_fragment,
- const std::string& password,
+ absl::string_view username_fragment,
+ absl::string_view password,
const webrtc::FieldTrialsView* field_trials)
: thread_(thread),
factory_(factory),
@@ -250,13 +250,13 @@
void Port::AddAddress(const rtc::SocketAddress& address,
const rtc::SocketAddress& base_address,
const rtc::SocketAddress& related_address,
- const std::string& protocol,
- const std::string& relay_protocol,
- const std::string& tcptype,
- const std::string& type,
+ absl::string_view protocol,
+ absl::string_view relay_protocol,
+ absl::string_view tcptype,
+ absl::string_view type,
uint32_t type_preference,
uint32_t relay_preference,
- const std::string& url,
+ absl::string_view url,
bool is_final) {
RTC_DCHECK_RUN_ON(thread_);
if (protocol == TCP_PROTOCOL_NAME && type == LOCAL_PORT_TYPE) {
@@ -285,7 +285,7 @@
}
bool Port::MaybeObfuscateAddress(Candidate* c,
- const std::string& type,
+ absl::string_view type,
bool is_final) {
// TODO(bugs.webrtc.org/9723): Use a config to control the feature of IP
// handling with mDNS.
@@ -652,7 +652,7 @@
bool Port::MaybeIceRoleConflict(const rtc::SocketAddress& addr,
IceMessage* stun_msg,
- const std::string& remote_ufrag) {
+ absl::string_view remote_ufrag) {
// Validate ICE_CONTROLLING or ICE_CONTROLLED attributes.
bool ret = true;
IceRole remote_ice_role = ICEROLE_UNKNOWN;
@@ -711,8 +711,8 @@
return ret;
}
-std::string Port::CreateStunUsername(const std::string& remote_username) const {
- return remote_username + ":" + username_fragment();
+std::string Port::CreateStunUsername(absl::string_view remote_username) const {
+ return std::string(remote_username) + ":" + username_fragment();
}
bool Port::HandleIncomingPacket(rtc::AsyncPacketSocket* socket,
@@ -731,7 +731,7 @@
void Port::SendBindingErrorResponse(StunMessage* message,
const rtc::SocketAddress& addr,
int error_code,
- const std::string& reason) {
+ absl::string_view reason) {
RTC_DCHECK(message->type() == STUN_BINDING_REQUEST ||
message->type() == GOOG_PING_REQUEST);
@@ -745,7 +745,7 @@
// maintain backwards compatiblility.
auto error_attr = StunAttribute::CreateErrorCode();
error_attr->SetCode(error_code);
- error_attr->SetReason(reason);
+ error_attr->SetReason(std::string(reason));
response.AddAttribute(std::move(error_attr));
// Per Section 10.1.2, certain error cases don't get a MESSAGE-INTEGRITY,
diff --git a/p2p/base/port.h b/p2p/base/port.h
index fca5619..8803e6c 100644
--- a/p2p/base/port.h
+++ b/p2p/base/port.h
@@ -145,11 +145,11 @@
struct IceCandidateErrorEvent {
IceCandidateErrorEvent() = default;
- IceCandidateErrorEvent(std::string address,
+ IceCandidateErrorEvent(absl::string_view address,
int port,
- std::string url,
+ absl::string_view url,
int error_code,
- std::string error_text)
+ absl::string_view error_text)
: address(std::move(address)),
port(port),
url(std::move(url)),
@@ -187,20 +187,20 @@
// 30 seconds.
enum class State { INIT, KEEP_ALIVE_UNTIL_PRUNED, PRUNED };
Port(rtc::Thread* thread,
- const std::string& type,
+ absl::string_view type,
rtc::PacketSocketFactory* factory,
const rtc::Network* network,
- const std::string& username_fragment,
- const std::string& password,
+ absl::string_view username_fragment,
+ absl::string_view password,
const webrtc::FieldTrialsView* field_trials = nullptr);
Port(rtc::Thread* thread,
- const std::string& type,
+ absl::string_view type,
rtc::PacketSocketFactory* factory,
const rtc::Network* network,
uint16_t min_port,
uint16_t max_port,
- const std::string& username_fragment,
- const std::string& password,
+ absl::string_view username_fragment,
+ absl::string_view password,
const webrtc::FieldTrialsView* field_trials = nullptr);
~Port() override;
@@ -239,8 +239,8 @@
// For debugging purposes.
const std::string& content_name() const { return content_name_; }
- void set_content_name(const std::string& content_name) {
- content_name_ = content_name;
+ void set_content_name(absl::string_view content_name) {
+ content_name_ = std::string(content_name);
}
int component() const { return component_; }
@@ -328,14 +328,14 @@
void SendBindingErrorResponse(StunMessage* message,
const rtc::SocketAddress& addr,
int error_code,
- const std::string& reason) override;
+ absl::string_view reason) override;
void SendUnknownAttributesErrorResponse(
StunMessage* message,
const rtc::SocketAddress& addr,
const std::vector<uint16_t>& unknown_types);
- void set_proxy(const std::string& user_agent, const rtc::ProxyInfo& proxy) {
- user_agent_ = user_agent;
+ void set_proxy(absl::string_view user_agent, const rtc::ProxyInfo& proxy) {
+ user_agent_ = std::string(user_agent);
proxy_ = proxy;
}
const std::string& user_agent() { return user_agent_; }
@@ -361,11 +361,11 @@
bool ParseStunUsername(const StunMessage* stun_msg,
std::string* local_username,
std::string* remote_username) const;
- std::string CreateStunUsername(const std::string& remote_username) const;
+ std::string CreateStunUsername(absl::string_view remote_username) const;
bool MaybeIceRoleConflict(const rtc::SocketAddress& addr,
IceMessage* stun_msg,
- const std::string& remote_ufrag);
+ absl::string_view remote_ufrag);
// Called when a packet has been sent to the socket.
// This is made pure virtual to notify subclasses of Port that they MUST
@@ -390,9 +390,9 @@
// then the foundation will be different. Two candidate pairs with
// the same foundation pairs are likely to have similar network
// characteristics. Foundations are used in the frozen algorithm.
- static std::string ComputeFoundation(const std::string& type,
- const std::string& protocol,
- const std::string& relay_protocol,
+ static std::string ComputeFoundation(absl::string_view type,
+ absl::string_view protocol,
+ absl::string_view relay_protocol,
const rtc::SocketAddress& base_address);
protected:
@@ -400,20 +400,20 @@
virtual void UpdateNetworkCost();
- void set_type(const std::string& type) { type_ = type; }
+ void set_type(absl::string_view type) { type_ = std::string(type); }
rtc::WeakPtr<Port> NewWeakPtr() { return weak_factory_.GetWeakPtr(); }
void AddAddress(const rtc::SocketAddress& address,
const rtc::SocketAddress& base_address,
const rtc::SocketAddress& related_address,
- const std::string& protocol,
- const std::string& relay_protocol,
- const std::string& tcptype,
- const std::string& type,
+ absl::string_view protocol,
+ absl::string_view relay_protocol,
+ absl::string_view tcptype,
+ absl::string_view type,
uint32_t type_preference,
uint32_t relay_preference,
- const std::string& url,
+ absl::string_view url,
bool is_final);
void FinishAddingAddress(const Candidate& c, bool is_final)
@@ -529,7 +529,7 @@
field_trials_;
bool MaybeObfuscateAddress(Candidate* c,
- const std::string& type,
+ absl::string_view type,
bool is_final) RTC_RUN_ON(thread_);
friend class Connection;
diff --git a/p2p/base/port_allocator.cc b/p2p/base/port_allocator.cc
index fc556a0..d22b428 100644
--- a/p2p/base/port_allocator.cc
+++ b/p2p/base/port_allocator.cc
@@ -24,17 +24,17 @@
RelayServerConfig::RelayServerConfig() {}
RelayServerConfig::RelayServerConfig(const rtc::SocketAddress& address,
- const std::string& username,
- const std::string& password,
+ absl::string_view username,
+ absl::string_view password,
ProtocolType proto)
: credentials(username, password) {
ports.push_back(ProtocolAddress(address, proto));
}
-RelayServerConfig::RelayServerConfig(const std::string& address,
+RelayServerConfig::RelayServerConfig(absl::string_view address,
int port,
- const std::string& username,
- const std::string& password,
+ absl::string_view username,
+ absl::string_view password,
ProtocolType proto)
: RelayServerConfig(rtc::SocketAddress(address, port),
username,
@@ -42,10 +42,10 @@
proto) {}
// Legacy constructor where "secure" and PROTO_TCP implies PROTO_TLS.
-RelayServerConfig::RelayServerConfig(const std::string& address,
+RelayServerConfig::RelayServerConfig(absl::string_view address,
int port,
- const std::string& username,
- const std::string& password,
+ absl::string_view username,
+ absl::string_view password,
ProtocolType proto,
bool secure)
: RelayServerConfig(address,
@@ -58,10 +58,10 @@
RelayServerConfig::~RelayServerConfig() = default;
-PortAllocatorSession::PortAllocatorSession(const std::string& content_name,
+PortAllocatorSession::PortAllocatorSession(absl::string_view content_name,
int component,
- const std::string& ice_ufrag,
- const std::string& ice_pwd,
+ absl::string_view ice_ufrag,
+ absl::string_view ice_pwd,
uint32_t flags)
: flags_(flags),
generation_(0),
@@ -207,10 +207,10 @@
}
std::unique_ptr<PortAllocatorSession> PortAllocator::CreateSession(
- const std::string& content_name,
+ absl::string_view content_name,
int component,
- const std::string& ice_ufrag,
- const std::string& ice_pwd) {
+ absl::string_view ice_ufrag,
+ absl::string_view ice_pwd) {
CheckRunOnValidThreadAndInitialized();
auto session = std::unique_ptr<PortAllocatorSession>(
CreateSessionInternal(content_name, component, ice_ufrag, ice_pwd));
@@ -219,10 +219,10 @@
}
std::unique_ptr<PortAllocatorSession> PortAllocator::TakePooledSession(
- const std::string& content_name,
+ absl::string_view content_name,
int component,
- const std::string& ice_ufrag,
- const std::string& ice_pwd) {
+ absl::string_view ice_ufrag,
+ absl::string_view ice_pwd) {
CheckRunOnValidThreadAndInitialized();
RTC_DCHECK(!ice_ufrag.empty());
RTC_DCHECK(!ice_pwd.empty());
diff --git a/p2p/base/port_allocator.h b/p2p/base/port_allocator.h
index 8d46c0d..420560c 100644
--- a/p2p/base/port_allocator.h
+++ b/p2p/base/port_allocator.h
@@ -135,7 +135,7 @@
// TODO(deadbeef): Rename to TurnCredentials (and username to ufrag).
struct RelayCredentials {
RelayCredentials() {}
- RelayCredentials(const std::string& username, const std::string& password)
+ RelayCredentials(absl::string_view username, absl::string_view password)
: username(username), password(password) {}
bool operator==(const RelayCredentials& o) const {
@@ -152,19 +152,19 @@
struct RTC_EXPORT RelayServerConfig {
RelayServerConfig();
RelayServerConfig(const rtc::SocketAddress& address,
- const std::string& username,
- const std::string& password,
+ absl::string_view username,
+ absl::string_view password,
ProtocolType proto);
- RelayServerConfig(const std::string& address,
+ RelayServerConfig(absl::string_view address,
int port,
- const std::string& username,
- const std::string& password,
+ absl::string_view username,
+ absl::string_view password,
ProtocolType proto);
// Legacy constructor where "secure" and PROTO_TCP implies PROTO_TLS.
- RelayServerConfig(const std::string& address,
+ RelayServerConfig(absl::string_view address,
int port,
- const std::string& username,
- const std::string& password,
+ absl::string_view username,
+ absl::string_view password,
ProtocolType proto,
bool secure);
RelayServerConfig(const RelayServerConfig&);
@@ -189,10 +189,10 @@
class RTC_EXPORT PortAllocatorSession : public sigslot::has_slots<> {
public:
// Content name passed in mostly for logging and debugging.
- PortAllocatorSession(const std::string& content_name,
+ PortAllocatorSession(absl::string_view content_name,
int component,
- const std::string& ice_ufrag,
- const std::string& ice_pwd,
+ absl::string_view ice_ufrag,
+ absl::string_view ice_pwd,
uint32_t flags);
// Subclasses should clean up any ports created.
@@ -300,14 +300,14 @@
const std::string& password() const { return ice_pwd_; }
private:
- void SetIceParameters(const std::string& content_name,
+ void SetIceParameters(absl::string_view content_name,
int component,
- const std::string& ice_ufrag,
- const std::string& ice_pwd) {
- content_name_ = content_name;
+ absl::string_view ice_ufrag,
+ absl::string_view ice_pwd) {
+ content_name_ = std::string(content_name);
component_ = component;
- ice_ufrag_ = ice_ufrag;
- ice_pwd_ = ice_pwd;
+ ice_ufrag_ = std::string(ice_ufrag);
+ ice_pwd_ = std::string(ice_pwd);
UpdateIceParametersInternal();
}
@@ -412,10 +412,10 @@
virtual void SetVpnList(const std::vector<rtc::NetworkMask>& vpn_list) {}
std::unique_ptr<PortAllocatorSession> CreateSession(
- const std::string& content_name,
+ absl::string_view content_name,
int component,
- const std::string& ice_ufrag,
- const std::string& ice_pwd);
+ absl::string_view ice_ufrag,
+ absl::string_view ice_pwd);
// Get an available pooled session and set the transport information on it.
//
@@ -425,10 +425,10 @@
// return a pooled session with matching ice credentials.
// If no pooled sessions are available, returns null.
std::unique_ptr<PortAllocatorSession> TakePooledSession(
- const std::string& content_name,
+ absl::string_view content_name,
int component,
- const std::string& ice_ufrag,
- const std::string& ice_pwd);
+ absl::string_view ice_ufrag,
+ absl::string_view ice_pwd);
// Returns the next session that would be returned by TakePooledSession
// optionally restricting it to sessions with specified ice credentials.
@@ -477,9 +477,9 @@
return proxy_;
}
- void set_proxy(const std::string& agent, const rtc::ProxyInfo& proxy) {
+ void set_proxy(absl::string_view agent, const rtc::ProxyInfo& proxy) {
CheckRunOnValidThreadIfInitialized();
- agent_ = agent;
+ agent_ = std::string(agent);
proxy_ = proxy;
}
diff --git a/p2p/base/port_allocator_unittest.cc b/p2p/base/port_allocator_unittest.cc
index e566ef8..4d8f055 100644
--- a/p2p/base/port_allocator_unittest.cc
+++ b/p2p/base/port_allocator_unittest.cc
@@ -12,6 +12,7 @@
#include <memory>
+#include "absl/strings/string_view.h"
#include "p2p/base/fake_port_allocator.h"
#include "rtc_base/thread.h"
#include "rtc_base/virtual_socket_server.h"
@@ -50,10 +51,10 @@
}
std::unique_ptr<cricket::FakePortAllocatorSession> CreateSession(
- const std::string& content_name,
+ absl::string_view content_name,
int component,
- const std::string& ice_ufrag,
- const std::string& ice_pwd) {
+ absl::string_view ice_ufrag,
+ absl::string_view ice_pwd) {
return std::unique_ptr<cricket::FakePortAllocatorSession>(
static_cast<cricket::FakePortAllocatorSession*>(
allocator_
diff --git a/p2p/base/port_interface.h b/p2p/base/port_interface.h
index f8df041..29c2741 100644
--- a/p2p/base/port_interface.h
+++ b/p2p/base/port_interface.h
@@ -111,7 +111,7 @@
virtual void SendBindingErrorResponse(StunMessage* message,
const rtc::SocketAddress& addr,
int error_code,
- const std::string& reason) = 0;
+ absl::string_view reason) = 0;
// Signaled when this port decides to delete itself because it no longer has
// any usefulness.
diff --git a/p2p/base/port_unittest.cc b/p2p/base/port_unittest.cc
index a0edd46..595743d 100644
--- a/p2p/base/port_unittest.cc
+++ b/p2p/base/port_unittest.cc
@@ -136,13 +136,13 @@
class TestPort : public Port {
public:
TestPort(rtc::Thread* thread,
- const std::string& type,
+ absl::string_view type,
rtc::PacketSocketFactory* factory,
const rtc::Network* network,
uint16_t min_port,
uint16_t max_port,
- const std::string& username_fragment,
- const std::string& password)
+ absl::string_view username_fragment,
+ absl::string_view password)
: Port(thread,
type,
factory,
@@ -192,7 +192,7 @@
}
void AddCandidateAddress(const rtc::SocketAddress& addr,
const rtc::SocketAddress& base_address,
- const std::string& type,
+ absl::string_view type,
int type_preference,
bool final) {
AddAddress(addr, base_address, rtc::SocketAddress(), "udp", "", "", type,
@@ -616,9 +616,9 @@
void ExpectPortsCanConnect(bool can_connect, Port* p1, Port* p2);
// This does all the work and then deletes `port1` and `port2`.
- void TestConnectivity(const char* name1,
+ void TestConnectivity(absl::string_view name1,
std::unique_ptr<Port> port1,
- const char* name2,
+ absl::string_view name2,
std::unique_ptr<Port> port2,
bool accept,
bool same_addr1,
@@ -764,15 +764,15 @@
}
std::unique_ptr<IceMessage> CreateStunMessageWithUsername(
StunMessageType type,
- const std::string& username) {
+ absl::string_view username) {
std::unique_ptr<IceMessage> msg = CreateStunMessage(type);
msg->AddAttribute(std::make_unique<StunByteStringAttribute>(
- STUN_ATTR_USERNAME, username));
+ STUN_ATTR_USERNAME, std::string(username)));
return msg;
}
std::unique_ptr<TestPort> CreateTestPort(const rtc::SocketAddress& addr,
- const std::string& username,
- const std::string& password) {
+ absl::string_view username,
+ absl::string_view password) {
auto port =
std::make_unique<TestPort>(&main_, "test", &socket_factory_,
MakeNetwork(addr), 0, 0, username, password);
@@ -780,8 +780,8 @@
return port;
}
std::unique_ptr<TestPort> CreateTestPort(const rtc::SocketAddress& addr,
- const std::string& username,
- const std::string& password,
+ absl::string_view username,
+ absl::string_view password,
cricket::IceRole role,
int tiebreaker) {
auto port = CreateTestPort(addr, username, password);
@@ -791,8 +791,8 @@
}
// Overload to create a test port given an rtc::Network directly.
std::unique_ptr<TestPort> CreateTestPort(const rtc::Network* network,
- const std::string& username,
- const std::string& password) {
+ absl::string_view username,
+ absl::string_view password) {
auto port = std::make_unique<TestPort>(&main_, "test", &socket_factory_,
network, 0, 0, username, password);
port->SignalRoleConflict.connect(this, &PortTest::OnRoleConflict);
@@ -839,9 +839,9 @@
webrtc::test::ScopedKeyValueConfig field_trials_;
};
-void PortTest::TestConnectivity(const char* name1,
+void PortTest::TestConnectivity(absl::string_view name1,
std::unique_ptr<Port> port1,
- const char* name2,
+ absl::string_view name2,
std::unique_ptr<Port> port2,
bool accept,
bool same_addr1,
diff --git a/p2p/base/stun_port.cc b/p2p/base/stun_port.cc
index e48283c..8074cbe 100644
--- a/p2p/base/stun_port.cc
+++ b/p2p/base/stun_port.cc
@@ -156,8 +156,8 @@
rtc::PacketSocketFactory* factory,
const rtc::Network* network,
rtc::AsyncPacketSocket* socket,
- const std::string& username,
- const std::string& password,
+ absl::string_view username,
+ absl::string_view password,
bool emit_local_for_anyaddress,
const webrtc::FieldTrialsView* field_trials)
: Port(thread,
@@ -184,8 +184,8 @@
const rtc::Network* network,
uint16_t min_port,
uint16_t max_port,
- const std::string& username,
- const std::string& password,
+ absl::string_view username,
+ absl::string_view password,
bool emit_local_for_anyaddress,
const webrtc::FieldTrialsView* field_trials)
: Port(thread,
@@ -541,7 +541,7 @@
void UDPPort::OnStunBindingOrResolveRequestFailed(
const rtc::SocketAddress& stun_server_addr,
int error_code,
- const std::string& reason) {
+ absl::string_view reason) {
rtc::StringBuilder url;
url << "stun:" << stun_server_addr.ToString();
SignalCandidateError(
@@ -619,8 +619,8 @@
const rtc::Network* network,
uint16_t min_port,
uint16_t max_port,
- const std::string& username,
- const std::string& password,
+ absl::string_view username,
+ absl::string_view password,
const ServerAddresses& servers,
absl::optional<int> stun_keepalive_interval,
const webrtc::FieldTrialsView* field_trials) {
@@ -640,8 +640,8 @@
const rtc::Network* network,
uint16_t min_port,
uint16_t max_port,
- const std::string& username,
- const std::string& password,
+ absl::string_view username,
+ absl::string_view password,
const ServerAddresses& servers,
const webrtc::FieldTrialsView* field_trials)
: UDPPort(thread,
diff --git a/p2p/base/stun_port.h b/p2p/base/stun_port.h
index fd814a9..83a90fa 100644
--- a/p2p/base/stun_port.h
+++ b/p2p/base/stun_port.h
@@ -38,8 +38,8 @@
rtc::PacketSocketFactory* factory,
const rtc::Network* network,
rtc::AsyncPacketSocket* socket,
- const std::string& username,
- const std::string& password,
+ absl::string_view username,
+ absl::string_view password,
bool emit_local_for_anyaddress,
absl::optional<int> stun_keepalive_interval,
const webrtc::FieldTrialsView* field_trials = nullptr) {
@@ -60,8 +60,8 @@
const rtc::Network* network,
uint16_t min_port,
uint16_t max_port,
- const std::string& username,
- const std::string& password,
+ absl::string_view username,
+ absl::string_view password,
bool emit_local_for_anyaddress,
absl::optional<int> stun_keepalive_interval,
const webrtc::FieldTrialsView* field_trials = nullptr) {
@@ -127,8 +127,8 @@
const rtc::Network* network,
uint16_t min_port,
uint16_t max_port,
- const std::string& username,
- const std::string& password,
+ absl::string_view username,
+ absl::string_view password,
bool emit_local_for_anyaddress,
const webrtc::FieldTrialsView* field_trials);
@@ -136,8 +136,8 @@
rtc::PacketSocketFactory* factory,
const rtc::Network* network,
rtc::AsyncPacketSocket* socket,
- const std::string& username,
- const std::string& password,
+ absl::string_view username,
+ absl::string_view password,
bool emit_local_for_anyaddress,
const webrtc::FieldTrialsView* field_trials);
@@ -224,7 +224,7 @@
void OnStunBindingOrResolveRequestFailed(
const rtc::SocketAddress& stun_server_addr,
int error_code,
- const std::string& reason);
+ absl::string_view reason);
// Sends STUN requests to the server.
void OnSendPacket(const void* data, size_t size, StunRequest* req);
@@ -274,8 +274,8 @@
const rtc::Network* network,
uint16_t min_port,
uint16_t max_port,
- const std::string& username,
- const std::string& password,
+ absl::string_view username,
+ absl::string_view password,
const ServerAddresses& servers,
absl::optional<int> stun_keepalive_interval,
const webrtc::FieldTrialsView* field_trials);
@@ -288,8 +288,8 @@
const rtc::Network* network,
uint16_t min_port,
uint16_t max_port,
- const std::string& username,
- const std::string& password,
+ absl::string_view username,
+ absl::string_view password,
const ServerAddresses& servers,
const webrtc::FieldTrialsView* field_trials);
};
diff --git a/p2p/base/stun_server.cc b/p2p/base/stun_server.cc
index a64eaaa..7827a0b 100644
--- a/p2p/base/stun_server.cc
+++ b/p2p/base/stun_server.cc
@@ -10,8 +10,10 @@
#include "p2p/base/stun_server.h"
+#include <string>
#include <utility>
+#include "absl/strings/string_view.h"
#include "rtc_base/byte_buffer.h"
#include "rtc_base/logging.h"
@@ -61,13 +63,13 @@
void StunServer::SendErrorResponse(const StunMessage& msg,
const rtc::SocketAddress& addr,
int error_code,
- const char* error_desc) {
+ absl::string_view error_desc) {
StunMessage err_msg(GetStunErrorResponseType(msg.type()),
msg.transaction_id());
auto err_code = StunAttribute::CreateErrorCode();
err_code->SetCode(error_code);
- err_code->SetReason(error_desc);
+ err_code->SetReason(std::string(error_desc));
err_msg.AddAttribute(std::move(err_code));
SendResponse(err_msg, addr);
diff --git a/p2p/base/stun_server.h b/p2p/base/stun_server.h
index 54d8d90..505773b 100644
--- a/p2p/base/stun_server.h
+++ b/p2p/base/stun_server.h
@@ -16,6 +16,7 @@
#include <memory>
+#include "absl/strings/string_view.h"
#include "api/transport/stun.h"
#include "rtc_base/async_packet_socket.h"
#include "rtc_base/async_udp_socket.h"
@@ -52,7 +53,7 @@
void SendErrorResponse(const StunMessage& msg,
const rtc::SocketAddress& addr,
int error_code,
- const char* error_desc);
+ absl::string_view error_desc);
// Sends the given message to the appropriate destination.
void SendResponse(const StunMessage& msg, const rtc::SocketAddress& addr);
diff --git a/p2p/base/tcp_port.cc b/p2p/base/tcp_port.cc
index 978ce12..87165ac 100644
--- a/p2p/base/tcp_port.cc
+++ b/p2p/base/tcp_port.cc
@@ -91,8 +91,8 @@
const rtc::Network* network,
uint16_t min_port,
uint16_t max_port,
- const std::string& username,
- const std::string& password,
+ absl::string_view username,
+ absl::string_view password,
bool allow_listen,
const webrtc::FieldTrialsView* field_trials)
: Port(thread,
diff --git a/p2p/base/tcp_port.h b/p2p/base/tcp_port.h
index 063c173..ff69e6e 100644
--- a/p2p/base/tcp_port.h
+++ b/p2p/base/tcp_port.h
@@ -41,8 +41,8 @@
const rtc::Network* network,
uint16_t min_port,
uint16_t max_port,
- const std::string& username,
- const std::string& password,
+ absl::string_view username,
+ absl::string_view password,
bool allow_listen,
const webrtc::FieldTrialsView* field_trials = nullptr) {
// Using `new` to access a non-public constructor.
@@ -72,8 +72,8 @@
const rtc::Network* network,
uint16_t min_port,
uint16_t max_port,
- const std::string& username,
- const std::string& password,
+ absl::string_view username,
+ absl::string_view password,
bool allow_listen,
const webrtc::FieldTrialsView* field_trials);
diff --git a/p2p/base/test_turn_server.h b/p2p/base/test_turn_server.h
index 7110a8a..4070372 100644
--- a/p2p/base/test_turn_server.h
+++ b/p2p/base/test_turn_server.h
@@ -16,6 +16,7 @@
#include <utility>
#include <vector>
+#include "absl/strings/string_view.h"
#include "api/sequence_checker.h"
#include "api/transport/stun.h"
#include "p2p/base/basic_packet_socket_factory.h"
@@ -58,7 +59,7 @@
const rtc::SocketAddress& udp_ext_addr,
ProtocolType int_protocol = PROTO_UDP,
bool ignore_bad_cert = true,
- const std::string& common_name = "test turn server")
+ absl::string_view common_name = "test turn server")
: server_(thread), socket_factory_(socket_factory) {
AddInternalSocket(int_addr, int_protocol, ignore_bad_cert, common_name);
server_.SetExternalSocketFactory(
@@ -93,7 +94,7 @@
void AddInternalSocket(const rtc::SocketAddress& int_addr,
ProtocolType proto,
bool ignore_bad_cert = true,
- const std::string& common_name = "test turn server") {
+ absl::string_view common_name = "test turn server") {
RTC_DCHECK(thread_checker_.IsCurrent());
if (proto == cricket::PROTO_UDP) {
server_.AddInternalSocket(
@@ -142,11 +143,12 @@
private:
// For this test server, succeed if the password is the same as the username.
// Obviously, do not use this in a production environment.
- virtual bool GetKey(const std::string& username,
- const std::string& realm,
+ virtual bool GetKey(absl::string_view username,
+ absl::string_view realm,
std::string* key) {
RTC_DCHECK(thread_checker_.IsCurrent());
- return ComputeStunCredentialHash(username, realm, username, key);
+ return ComputeStunCredentialHash(std::string(username), std::string(realm),
+ std::string(username), key);
}
TurnServer server_;
diff --git a/p2p/base/transport_description.cc b/p2p/base/transport_description.cc
index 1281910..f3b1fbb 100644
--- a/p2p/base/transport_description.cc
+++ b/p2p/base/transport_description.cc
@@ -12,6 +12,7 @@
#include "absl/strings/ascii.h"
#include "absl/strings/match.h"
+#include "absl/strings/string_view.h"
#include "p2p/base/p2p_constants.h"
#include "rtc_base/arraysize.h"
#include "rtc_base/logging.h"
@@ -147,8 +148,8 @@
TransportDescription::TransportDescription(
const std::vector<std::string>& transport_options,
- const std::string& ice_ufrag,
- const std::string& ice_pwd,
+ absl::string_view ice_ufrag,
+ absl::string_view ice_pwd,
IceMode ice_mode,
ConnectionRole role,
const rtc::SSLFingerprint* identity_fingerprint)
@@ -159,8 +160,8 @@
connection_role(role),
identity_fingerprint(CopyFingerprint(identity_fingerprint)) {}
-TransportDescription::TransportDescription(const std::string& ice_ufrag,
- const std::string& ice_pwd)
+TransportDescription::TransportDescription(absl::string_view ice_ufrag,
+ absl::string_view ice_pwd)
: ice_ufrag(ice_ufrag),
ice_pwd(ice_pwd),
ice_mode(ICEMODE_FULL),
diff --git a/p2p/base/transport_description.h b/p2p/base/transport_description.h
index 6a9d36b..7d28ad5 100644
--- a/p2p/base/transport_description.h
+++ b/p2p/base/transport_description.h
@@ -16,6 +16,7 @@
#include <vector>
#include "absl/algorithm/container.h"
+#include "absl/strings/string_view.h"
#include "absl/types/optional.h"
#include "api/rtc_error.h"
#include "p2p/base/p2p_constants.h"
@@ -71,8 +72,8 @@
std::string pwd;
bool renomination = false;
IceParameters() = default;
- IceParameters(const std::string& ice_ufrag,
- const std::string& ice_pwd,
+ IceParameters(absl::string_view ice_ufrag,
+ absl::string_view ice_pwd,
bool ice_renomination)
: ufrag(ice_ufrag), pwd(ice_pwd), renomination(ice_renomination) {}
@@ -104,24 +105,23 @@
struct TransportDescription {
TransportDescription();
TransportDescription(const std::vector<std::string>& transport_options,
- const std::string& ice_ufrag,
- const std::string& ice_pwd,
+ absl::string_view ice_ufrag,
+ absl::string_view ice_pwd,
IceMode ice_mode,
ConnectionRole role,
const rtc::SSLFingerprint* identity_fingerprint);
- TransportDescription(const std::string& ice_ufrag,
- const std::string& ice_pwd);
+ TransportDescription(absl::string_view ice_ufrag, absl::string_view ice_pwd);
TransportDescription(const TransportDescription& from);
~TransportDescription();
TransportDescription& operator=(const TransportDescription& from);
// TODO(deadbeef): Rename to HasIceOption, etc.
- bool HasOption(const std::string& option) const {
+ bool HasOption(absl::string_view option) const {
return absl::c_linear_search(transport_options, option);
}
- void AddOption(const std::string& option) {
- transport_options.push_back(option);
+ void AddOption(absl::string_view option) {
+ transport_options.emplace_back(option);
}
bool secure() const { return identity_fingerprint != nullptr; }
diff --git a/p2p/base/transport_description_factory_unittest.cc b/p2p/base/transport_description_factory_unittest.cc
index 75e6e8e..0da5b7c 100644
--- a/p2p/base/transport_description_factory_unittest.cc
+++ b/p2p/base/transport_description_factory_unittest.cc
@@ -16,6 +16,7 @@
#include <string>
#include <vector>
+#include "absl/strings/string_view.h"
#include "p2p/base/p2p_constants.h"
#include "p2p/base/transport_description.h"
#include "rtc_base/copy_on_write_buffer.h"
@@ -45,10 +46,10 @@
new rtc::FakeSSLIdentity("User2")))) {}
void CheckDesc(const TransportDescription* desc,
- const std::string& opt,
- const std::string& ice_ufrag,
- const std::string& ice_pwd,
- const std::string& dtls_alg) {
+ absl::string_view opt,
+ absl::string_view ice_ufrag,
+ absl::string_view ice_pwd,
+ absl::string_view dtls_alg) {
ASSERT_TRUE(desc != NULL);
EXPECT_EQ(!opt.empty(), desc->HasOption(opt));
if (ice_ufrag.empty() && ice_pwd.empty()) {
diff --git a/p2p/base/turn_port.cc b/p2p/base/turn_port.cc
index f78015f..c1b4c10 100644
--- a/p2p/base/turn_port.cc
+++ b/p2p/base/turn_port.cc
@@ -106,7 +106,7 @@
TurnCreatePermissionRequest(TurnPort* port,
TurnEntry* entry,
const rtc::SocketAddress& ext_addr,
- const std::string& remote_ufrag);
+ absl::string_view remote_ufrag);
void OnSent() override;
void OnResponse(StunMessage* response) override;
void OnErrorResponse(StunMessage* response) override;
@@ -149,7 +149,7 @@
TurnEntry(TurnPort* port,
int channel_id,
const rtc::SocketAddress& ext_addr,
- const std::string remote_ufrag);
+ absl::string_view remote_ufrag);
TurnPort* port() { return port_; }
@@ -190,8 +190,8 @@
sigslot::signal1<TurnEntry*> SignalDestroyed;
const std::string& get_remote_ufrag() const { return remote_ufrag_; }
- void set_remote_ufrag(const std::string& remote_ufrag) {
- remote_ufrag_ = remote_ufrag;
+ void set_remote_ufrag(absl::string_view remote_ufrag) {
+ remote_ufrag_ = std::string(remote_ufrag);
}
private:
@@ -212,8 +212,8 @@
rtc::PacketSocketFactory* factory,
const rtc::Network* network,
rtc::AsyncPacketSocket* socket,
- const std::string& username,
- const std::string& password,
+ absl::string_view username,
+ absl::string_view password,
const ProtocolAddress& server_address,
const RelayCredentials& credentials,
int server_priority,
@@ -254,8 +254,8 @@
const rtc::Network* network,
uint16_t min_port,
uint16_t max_port,
- const std::string& username,
- const std::string& password,
+ absl::string_view username,
+ absl::string_view password,
const ProtocolAddress& server_address,
const RelayCredentials& credentials,
int server_priority,
@@ -330,8 +330,8 @@
tls_cert_policy_ = tls_cert_policy;
}
-void TurnPort::SetTurnLoggingId(const std::string& turn_logging_id) {
- turn_logging_id_ = turn_logging_id;
+void TurnPort::SetTurnLoggingId(absl::string_view turn_logging_id) {
+ turn_logging_id_ = std::string(turn_logging_id);
}
std::vector<std::string> TurnPort::GetTlsAlpnProtocols() const {
@@ -890,7 +890,7 @@
server_priority_, ReconstructedServerUrl(), true);
}
-void TurnPort::OnAllocateError(int error_code, const std::string& reason) {
+void TurnPort::OnAllocateError(int error_code, absl::string_view reason) {
// We will send SignalPortError asynchronously as this can be sent during
// port initialization. This way it will not be blocking other port
// creation.
@@ -1228,7 +1228,7 @@
bool TurnPort::CreateOrRefreshEntry(const rtc::SocketAddress& addr,
int channel_number,
- const std::string& remote_ufrag) {
+ absl::string_view remote_ufrag) {
TurnEntry* entry = FindEntry(addr);
if (entry == nullptr) {
entry = new TurnEntry(this, channel_number, addr, remote_ufrag);
@@ -1638,7 +1638,7 @@
TurnPort* port,
TurnEntry* entry,
const rtc::SocketAddress& ext_addr,
- const std::string& remote_ufrag)
+ absl::string_view remote_ufrag)
: StunRequest(
port->request_manager(),
std::make_unique<TurnMessage>(TURN_CREATE_PERMISSION_REQUEST)),
@@ -1786,7 +1786,7 @@
TurnEntry::TurnEntry(TurnPort* port,
int channel_id,
const rtc::SocketAddress& ext_addr,
- const std::string remote_ufrag)
+ absl::string_view remote_ufrag)
: port_(port),
channel_id_(channel_id),
ext_addr_(ext_addr),
diff --git a/p2p/base/turn_port.h b/p2p/base/turn_port.h
index 08b3669..8a77b9f 100644
--- a/p2p/base/turn_port.h
+++ b/p2p/base/turn_port.h
@@ -122,7 +122,7 @@
virtual TlsCertPolicy GetTlsCertPolicy() const;
virtual void SetTlsCertPolicy(TlsCertPolicy tls_cert_policy);
- void SetTurnLoggingId(const std::string& turn_logging_id);
+ void SetTurnLoggingId(absl::string_view turn_logging_id);
virtual std::vector<std::string> GetTlsAlpnProtocols() const;
virtual std::vector<std::string> GetTlsEllipticCurves() const;
@@ -212,8 +212,8 @@
rtc::PacketSocketFactory* factory,
const rtc::Network* network,
rtc::AsyncPacketSocket* socket,
- const std::string& username,
- const std::string& password,
+ absl::string_view username,
+ absl::string_view password,
const ProtocolAddress& server_address,
const RelayCredentials& credentials,
int server_priority,
@@ -228,8 +228,8 @@
const rtc::Network* network,
uint16_t min_port,
uint16_t max_port,
- const std::string& username,
- const std::string& password,
+ absl::string_view username,
+ absl::string_view password,
const ProtocolAddress& server_address,
const RelayCredentials& credentials,
int server_priority,
@@ -245,7 +245,7 @@
bool CreateOrRefreshEntry(const rtc::SocketAddress& addr,
int channel_number,
- const std::string& remote_ufrag);
+ absl::string_view remote_ufrag);
rtc::DiffServCodePoint StunDscpValue() const override;
@@ -292,7 +292,7 @@
void OnStunAddress(const rtc::SocketAddress& address);
void OnAllocateSuccess(const rtc::SocketAddress& address,
const rtc::SocketAddress& stun_address);
- void OnAllocateError(int error_code, const std::string& reason);
+ void OnAllocateError(int error_code, absl::string_view reason);
void OnAllocateRequestTimeout();
void HandleDataIndication(const char* data,
diff --git a/p2p/base/turn_port_unittest.cc b/p2p/base/turn_port_unittest.cc
index ecde0ce..ff529cb 100644
--- a/p2p/base/turn_port_unittest.cc
+++ b/p2p/base/turn_port_unittest.cc
@@ -9,6 +9,8 @@
*/
#if defined(WEBRTC_POSIX)
#include <dirent.h>
+
+#include "absl/strings/string_view.h"
#endif
#include <list>
@@ -263,23 +265,23 @@
return &networks_.back();
}
- bool CreateTurnPort(const std::string& username,
- const std::string& password,
+ bool CreateTurnPort(absl::string_view username,
+ absl::string_view password,
const ProtocolAddress& server_address) {
return CreateTurnPortWithAllParams(MakeNetwork(kLocalAddr1), username,
password, server_address);
}
bool CreateTurnPort(const rtc::SocketAddress& local_address,
- const std::string& username,
- const std::string& password,
+ absl::string_view username,
+ absl::string_view password,
const ProtocolAddress& server_address) {
return CreateTurnPortWithAllParams(MakeNetwork(local_address), username,
password, server_address);
}
bool CreateTurnPortWithNetwork(const rtc::Network* network,
- const std::string& username,
- const std::string& password,
+ absl::string_view username,
+ absl::string_view password,
const ProtocolAddress& server_address) {
return CreateTurnPortWithAllParams(network, username, password,
server_address);
@@ -289,8 +291,8 @@
// helper methods call this, such that "SetIceRole" and "ConnectSignals" (and
// possibly other things in the future) only happen in one place.
bool CreateTurnPortWithAllParams(const rtc::Network* network,
- const std::string& username,
- const std::string& password,
+ absl::string_view username,
+ absl::string_view password,
const ProtocolAddress& server_address) {
RelayServerConfig config;
config.credentials = RelayCredentials(username, password);
@@ -323,8 +325,8 @@
return true;
}
- void CreateSharedTurnPort(const std::string& username,
- const std::string& password,
+ void CreateSharedTurnPort(absl::string_view username,
+ absl::string_view password,
const ProtocolAddress& server_address) {
RTC_CHECK(server_address.proto == PROTO_UDP);
@@ -455,7 +457,7 @@
}
void TestReconstructedServerUrl(ProtocolType protocol_type,
- const char* expected_url) {
+ absl::string_view expected_url) {
turn_port_->PrepareAddress();
ASSERT_TRUE_SIMULATED_WAIT(
turn_ready_, TimeToGetTurnCandidate(protocol_type), fake_clock_);
diff --git a/p2p/base/turn_server.cc b/p2p/base/turn_server.cc
index 95ff533..bf050c2 100644
--- a/p2p/base/turn_server.cc
+++ b/p2p/base/turn_server.cc
@@ -16,6 +16,7 @@
#include "absl/algorithm/container.h"
#include "absl/memory/memory.h"
+#include "absl/strings/string_view.h"
#include "api/array_view.h"
#include "api/packet_socket_factory.h"
#include "api/task_queue/to_queued_task.h"
@@ -111,10 +112,10 @@
}
static void InitErrorResponse(int code,
- const std::string& reason,
+ absl::string_view reason,
StunMessage* resp) {
resp->AddAttribute(std::make_unique<cricket::StunErrorCodeAttribute>(
- STUN_ATTR_ERROR_CODE, code, reason));
+ STUN_ATTR_ERROR_CODE, code, std::string(reason)));
}
TurnServer::TurnServer(rtc::Thread* thread)
@@ -316,7 +317,7 @@
StunMessage* msg,
const char* data,
size_t size,
- const std::string& key) {
+ absl::string_view key) {
// RFC 5389, 10.2.2.
RTC_DCHECK(IsStunRequestType(msg->type()));
const StunByteStringAttribute* mi_attr =
@@ -350,7 +351,7 @@
}
// Fail if bad MESSAGE_INTEGRITY.
- if (key.empty() || msg->ValidateMessageIntegrity(key) !=
+ if (key.empty() || msg->ValidateMessageIntegrity(std::string(key)) !=
StunMessage::IntegrityStatus::kIntegrityOk) {
SendErrorResponseWithRealmAndNonce(conn, msg, STUN_ERROR_UNAUTHORIZED,
STUN_ERROR_REASON_UNAUTHORIZED);
@@ -387,7 +388,7 @@
void TurnServer::HandleAllocateRequest(TurnServerConnection* conn,
const TurnMessage* msg,
- const std::string& key) {
+ absl::string_view key) {
// Check the parameters in the request.
const StunUInt32Attribute* transport_attr =
msg->GetUInt32(STUN_ATTR_REQUESTED_TRANSPORT);
@@ -459,7 +460,7 @@
TurnServerAllocation* TurnServer::CreateAllocation(TurnServerConnection* conn,
int proto,
- const std::string& key) {
+ absl::string_view key) {
rtc::AsyncPacketSocket* external_socket =
(external_socket_factory_)
? external_socket_factory_->CreateUdpSocket(external_addr_, 0, 0)
@@ -479,7 +480,7 @@
void TurnServer::SendErrorResponse(TurnServerConnection* conn,
const StunMessage* req,
int code,
- const std::string& reason) {
+ absl::string_view reason) {
RTC_DCHECK_RUN_ON(thread_);
TurnMessage resp(GetStunErrorResponseTypeOrZero(*req), req->transaction_id());
InitErrorResponse(code, reason, &resp);
@@ -492,7 +493,7 @@
void TurnServer::SendErrorResponseWithRealmAndNonce(TurnServerConnection* conn,
const StunMessage* msg,
int code,
- const std::string& reason) {
+ absl::string_view reason) {
TurnMessage resp(GetStunErrorResponseTypeOrZero(*msg), msg->transaction_id());
InitErrorResponse(code, reason, &resp);
@@ -603,7 +604,7 @@
rtc::Thread* thread,
const TurnServerConnection& conn,
rtc::AsyncPacketSocket* socket,
- const std::string& key)
+ absl::string_view key)
: server_(server),
thread_(thread),
conn_(conn),
@@ -926,7 +927,7 @@
void TurnServerAllocation::SendErrorResponse(const TurnMessage* req,
int code,
- const std::string& reason) {
+ absl::string_view reason) {
server_->SendErrorResponse(&conn_, req, code, reason);
}
diff --git a/p2p/base/turn_server.h b/p2p/base/turn_server.h
index 95c7a4d..fdbb528 100644
--- a/p2p/base/turn_server.h
+++ b/p2p/base/turn_server.h
@@ -19,6 +19,7 @@
#include <utility>
#include <vector>
+#include "absl/strings/string_view.h"
#include "api/sequence_checker.h"
#include "p2p/base/port_interface.h"
#include "rtc_base/async_packet_socket.h"
@@ -73,7 +74,7 @@
rtc::Thread* thread,
const TurnServerConnection& conn,
rtc::AsyncPacketSocket* server_socket,
- const std::string& key);
+ absl::string_view key);
~TurnServerAllocation() override;
TurnServerConnection* conn() { return &conn_; }
@@ -121,7 +122,7 @@
void SendBadRequestResponse(const TurnMessage* req);
void SendErrorResponse(const TurnMessage* req,
int code,
- const std::string& reason);
+ absl::string_view reason);
void SendExternal(const void* data,
size_t size,
const rtc::SocketAddress& peer);
@@ -148,8 +149,8 @@
// Gets HA1 for the specified user and realm.
// HA1 = MD5(A1) = MD5(username:realm:password).
// Return true if the given username and realm are valid, or false if not.
- virtual bool GetKey(const std::string& username,
- const std::string& realm,
+ virtual bool GetKey(absl::string_view username,
+ absl::string_view realm,
std::string* key) = 0;
virtual ~TurnAuthInterface() = default;
};
@@ -186,9 +187,9 @@
RTC_DCHECK_RUN_ON(thread_);
return realm_;
}
- void set_realm(const std::string& realm) {
+ void set_realm(absl::string_view realm) {
RTC_DCHECK_RUN_ON(thread_);
- realm_ = realm;
+ realm_ = std::string(realm);
}
// Gets/sets the value for the SOFTWARE attribute for TURN messages.
@@ -196,9 +197,9 @@
RTC_DCHECK_RUN_ON(thread_);
return software_;
}
- void set_software(const std::string& software) {
+ void set_software(absl::string_view software) {
RTC_DCHECK_RUN_ON(thread_);
- software_ = software;
+ software_ = std::string(software);
}
const AllocationMap& allocations() const {
@@ -282,32 +283,32 @@
RTC_RUN_ON(thread_);
void HandleAllocateRequest(TurnServerConnection* conn,
const TurnMessage* msg,
- const std::string& key) RTC_RUN_ON(thread_);
+ absl::string_view key) RTC_RUN_ON(thread_);
bool GetKey(const StunMessage* msg, std::string* key) RTC_RUN_ON(thread_);
bool CheckAuthorization(TurnServerConnection* conn,
StunMessage* msg,
const char* data,
size_t size,
- const std::string& key) RTC_RUN_ON(thread_);
+ absl::string_view key) RTC_RUN_ON(thread_);
bool ValidateNonce(absl::string_view nonce) const RTC_RUN_ON(thread_);
TurnServerAllocation* FindAllocation(TurnServerConnection* conn)
RTC_RUN_ON(thread_);
TurnServerAllocation* CreateAllocation(TurnServerConnection* conn,
int proto,
- const std::string& key)
+ absl::string_view key)
RTC_RUN_ON(thread_);
void SendErrorResponse(TurnServerConnection* conn,
const StunMessage* req,
int code,
- const std::string& reason);
+ absl::string_view reason);
void SendErrorResponseWithRealmAndNonce(TurnServerConnection* conn,
const StunMessage* req,
int code,
- const std::string& reason)
+ absl::string_view reason)
RTC_RUN_ON(thread_);
void SendErrorResponseWithAlternateServer(TurnServerConnection* conn,
diff --git a/p2p/client/basic_port_allocator.cc b/p2p/client/basic_port_allocator.cc
index 4cecc11..6aedf90 100644
--- a/p2p/client/basic_port_allocator.cc
+++ b/p2p/client/basic_port_allocator.cc
@@ -91,7 +91,7 @@
struct NetworkFilter {
using Predicate = std::function<bool(const rtc::Network*)>;
- NetworkFilter(Predicate pred, const std::string& description)
+ NetworkFilter(Predicate pred, absl::string_view description)
: predRemain(
[pred](const rtc::Network* network) { return !pred(network); }),
description(description) {}
@@ -296,10 +296,10 @@
// BasicPortAllocatorSession
BasicPortAllocatorSession::BasicPortAllocatorSession(
BasicPortAllocator* allocator,
- const std::string& content_name,
+ absl::string_view content_name,
int component,
- const std::string& ice_ufrag,
- const std::string& ice_pwd)
+ absl::string_view ice_ufrag,
+ absl::string_view ice_pwd)
: PortAllocatorSession(content_name,
component,
ice_ufrag,
@@ -1036,7 +1036,7 @@
}
Port* BasicPortAllocatorSession::GetBestTurnPortForNetwork(
- const std::string& network_name) const {
+ absl::string_view network_name) const {
RTC_DCHECK_RUN_ON(network_thread_);
Port* best_turn_port = nullptr;
for (const PortData& data : ports_) {
@@ -1701,8 +1701,8 @@
PortConfiguration::PortConfiguration(
const ServerAddresses& stun_servers,
- const std::string& username,
- const std::string& password,
+ absl::string_view username,
+ absl::string_view password,
const webrtc::FieldTrialsView* field_trials)
: stun_servers(stun_servers), username(username), password(password) {
if (!stun_servers.empty())
diff --git a/p2p/client/basic_port_allocator.h b/p2p/client/basic_port_allocator.h
index 86001b5..9634a0e 100644
--- a/p2p/client/basic_port_allocator.h
+++ b/p2p/client/basic_port_allocator.h
@@ -127,10 +127,10 @@
class RTC_EXPORT BasicPortAllocatorSession : public PortAllocatorSession {
public:
BasicPortAllocatorSession(BasicPortAllocator* allocator,
- const std::string& content_name,
+ absl::string_view content_name,
int component,
- const std::string& ice_ufrag,
- const std::string& ice_pwd);
+ absl::string_view ice_ufrag,
+ absl::string_view ice_pwd);
~BasicPortAllocatorSession() override;
virtual BasicPortAllocator* allocator();
@@ -270,7 +270,7 @@
// append to `candidates`.
void GetCandidatesFromPort(const PortData& data,
std::vector<Candidate>* candidates) const;
- Port* GetBestTurnPortForNetwork(const std::string& network_name) const;
+ Port* GetBestTurnPortForNetwork(absl::string_view network_name) const;
// Returns true if at least one TURN port is pruned.
bool PruneTurnPorts(Port* newly_pairable_turn_port);
bool PruneNewlyPairableTurnPort(PortData* newly_pairable_turn_port);
@@ -309,8 +309,8 @@
RelayList relays;
PortConfiguration(const ServerAddresses& stun_servers,
- const std::string& username,
- const std::string& password,
+ absl::string_view username,
+ absl::string_view password,
const webrtc::FieldTrialsView* field_trials = nullptr);
// Returns addresses of both the explicitly configured STUN servers,
diff --git a/p2p/client/basic_port_allocator_unittest.cc b/p2p/client/basic_port_allocator_unittest.cc
index 8fc40a6..8faebbf 100644
--- a/p2p/client/basic_port_allocator_unittest.cc
+++ b/p2p/client/basic_port_allocator_unittest.cc
@@ -14,6 +14,7 @@
#include <ostream> // no-presubmit-check TODO(webrtc:8982)
#include "absl/algorithm/container.h"
+#include "absl/strings/string_view.h"
#include "p2p/base/basic_packet_socket_factory.h"
#include "p2p/base/p2p_constants.h"
#include "p2p/base/stun_port.h"
@@ -173,11 +174,11 @@
void AddInterface(const SocketAddress& addr) {
network_manager_.AddInterface(addr);
}
- void AddInterface(const SocketAddress& addr, const std::string& if_name) {
+ void AddInterface(const SocketAddress& addr, absl::string_view if_name) {
network_manager_.AddInterface(addr, if_name);
}
void AddInterface(const SocketAddress& addr,
- const std::string& if_name,
+ absl::string_view if_name,
rtc::AdapterType type) {
network_manager_.AddInterface(addr, if_name, type);
}
@@ -251,7 +252,7 @@
return true;
}
- bool CreateSession(int component, const std::string& content_name) {
+ bool CreateSession(int component, absl::string_view content_name) {
session_ = CreateSession("session", content_name, component);
if (!session_) {
return false;
@@ -259,24 +260,24 @@
return true;
}
- std::unique_ptr<PortAllocatorSession> CreateSession(const std::string& sid,
+ std::unique_ptr<PortAllocatorSession> CreateSession(absl::string_view sid,
int component) {
return CreateSession(sid, kContentName, component);
}
std::unique_ptr<PortAllocatorSession> CreateSession(
- const std::string& sid,
- const std::string& content_name,
+ absl::string_view sid,
+ absl::string_view content_name,
int component) {
return CreateSession(sid, content_name, component, kIceUfrag0, kIcePwd0);
}
std::unique_ptr<PortAllocatorSession> CreateSession(
- const std::string& sid,
- const std::string& content_name,
+ absl::string_view sid,
+ absl::string_view content_name,
int component,
- const std::string& ice_ufrag,
- const std::string& ice_pwd) {
+ absl::string_view ice_ufrag,
+ absl::string_view ice_pwd) {
std::unique_ptr<PortAllocatorSession> session =
allocator_->CreateSession(content_name, component, ice_ufrag, ice_pwd);
session->SignalPortReady.connect(this,
@@ -307,7 +308,7 @@
// Returns the number of ports that have matching type, protocol and
// address.
static int CountPorts(const std::vector<PortInterface*>& ports,
- const std::string& type,
+ absl::string_view type,
ProtocolType protocol,
const SocketAddress& client_addr) {
return absl::c_count_if(
@@ -318,8 +319,8 @@
}
static int CountCandidates(const std::vector<Candidate>& candidates,
- const std::string& type,
- const std::string& proto,
+ absl::string_view type,
+ absl::string_view proto,
const SocketAddress& addr) {
return absl::c_count_if(
candidates, [type, proto, addr](const Candidate& c) {
@@ -330,8 +331,8 @@
// Find a candidate and return it.
static bool FindCandidate(const std::vector<Candidate>& candidates,
- const std::string& type,
- const std::string& proto,
+ absl::string_view type,
+ absl::string_view proto,
const SocketAddress& addr,
Candidate* found) {
auto it =
@@ -347,8 +348,8 @@
// Convenience method to call FindCandidate with no return.
static bool HasCandidate(const std::vector<Candidate>& candidates,
- const std::string& type,
- const std::string& proto,
+ absl::string_view type,
+ absl::string_view proto,
const SocketAddress& addr) {
return FindCandidate(candidates, type, proto, addr, nullptr);
}
@@ -356,8 +357,8 @@
// Version of HasCandidate that also takes a related address.
static bool HasCandidateWithRelatedAddr(
const std::vector<Candidate>& candidates,
- const std::string& type,
- const std::string& proto,
+ absl::string_view type,
+ absl::string_view proto,
const SocketAddress& addr,
const SocketAddress& related_addr) {
return absl::c_any_of(
diff --git a/test/network/BUILD.gn b/test/network/BUILD.gn
index fc4f4bc..7878a45 100644
--- a/test/network/BUILD.gn
+++ b/test/network/BUILD.gn
@@ -86,6 +86,7 @@
absl_deps = [
"//third_party/abseil-cpp/absl/algorithm:container",
"//third_party/abseil-cpp/absl/memory",
+ "//third_party/abseil-cpp/absl/strings",
"//third_party/abseil-cpp/absl/types:optional",
]
}
diff --git a/test/network/emulated_turn_server.h b/test/network/emulated_turn_server.h
index b8a18d3..9cb0cea 100644
--- a/test/network/emulated_turn_server.h
+++ b/test/network/emulated_turn_server.h
@@ -15,6 +15,7 @@
#include <memory>
#include <string>
+#include "absl/strings/string_view.h"
#include "api/test/network_emulation_manager.h"
#include "api/transport/stun.h"
#include "p2p/base/turn_server.h"
@@ -57,10 +58,11 @@
EmulatedEndpoint* GetPeerEndpoint() const override { return peer_; }
// cricket::TurnAuthInterface
- bool GetKey(const std::string& username,
- const std::string& realm,
+ bool GetKey(absl::string_view username,
+ absl::string_view realm,
std::string* key) override {
- return cricket::ComputeStunCredentialHash(username, realm, username, key);
+ return cricket::ComputeStunCredentialHash(
+ std::string(username), std::string(realm), std::string(username), key);
}
rtc::AsyncPacketSocket* CreatePeerSocket() { return Wrap(peer_); }