From e0c6bdf07103e6c9aec89763ce91aec33b8d5241 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20M=C3=B6ller?= Date: Thu, 24 Mar 2022 15:18:02 +0100 Subject: [PATCH] Use const rtc::Network* in ports and port allocator No-try: True Bug: webrtc:13869 Change-Id: I6004fa96278263d0d25a1446d7bb8de41a563433 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/256682 Reviewed-by: Tomas Gunnarsson Reviewed-by: Jonas Oreland Commit-Queue: Niels Moller Cr-Commit-Position: refs/heads/main@{#36353} --- p2p/base/fake_port_allocator.h | 4 +- p2p/base/port.cc | 6 +-- p2p/base/port.h | 8 +-- p2p/base/port_interface.h | 2 +- p2p/base/port_unittest.cc | 8 +-- p2p/base/stun_port.cc | 8 +-- p2p/base/stun_port.h | 12 ++--- p2p/base/tcp_port.cc | 2 +- p2p/base/tcp_port.h | 4 +- p2p/base/tcp_port_unittest.cc | 2 +- p2p/base/turn_port.cc | 4 +- p2p/base/turn_port.h | 4 +- p2p/base/turn_port_unittest.cc | 4 +- p2p/client/basic_port_allocator.cc | 60 +++++++++++++---------- p2p/client/basic_port_allocator.h | 18 +++---- p2p/client/relay_port_factory_interface.h | 2 +- rtc_base/nat_unittest.cc | 2 +- rtc_base/network.h | 24 ++++++++- 18 files changed, 101 insertions(+), 73 deletions(-) diff --git a/p2p/base/fake_port_allocator.h b/p2p/base/fake_port_allocator.h index 6366ea84db..e3a239a9a9 100644 --- a/p2p/base/fake_port_allocator.h +++ b/p2p/base/fake_port_allocator.h @@ -31,7 +31,7 @@ class TestUDPPort : public UDPPort { public: static TestUDPPort* Create(rtc::Thread* thread, rtc::PacketSocketFactory* factory, - rtc::Network* network, + const rtc::Network* network, uint16_t min_port, uint16_t max_port, const std::string& username, @@ -50,7 +50,7 @@ class TestUDPPort : public UDPPort { protected: TestUDPPort(rtc::Thread* thread, rtc::PacketSocketFactory* factory, - rtc::Network* network, + const rtc::Network* network, uint16_t min_port, uint16_t max_port, const std::string& username, diff --git a/p2p/base/port.cc b/p2p/base/port.cc index a061688b72..1aefe5fd55 100644 --- a/p2p/base/port.cc +++ b/p2p/base/port.cc @@ -108,7 +108,7 @@ std::string Port::ComputeFoundation(const std::string& type, Port::Port(rtc::Thread* thread, const std::string& type, rtc::PacketSocketFactory* factory, - rtc::Network* network, + const rtc::Network* network, const std::string& username_fragment, const std::string& password) : thread_(thread), @@ -135,7 +135,7 @@ Port::Port(rtc::Thread* thread, Port::Port(rtc::Thread* thread, const std::string& type, rtc::PacketSocketFactory* factory, - rtc::Network* network, + const rtc::Network* network, uint16_t min_port, uint16_t max_port, const std::string& username_fragment, @@ -203,7 +203,7 @@ Port::~Port() { const std::string& Port::Type() const { return type_; } -rtc::Network* Port::Network() const { +const rtc::Network* Port::Network() const { return network_; } diff --git a/p2p/base/port.h b/p2p/base/port.h index 1ec82f7049..ad4387d1ab 100644 --- a/p2p/base/port.h +++ b/p2p/base/port.h @@ -183,13 +183,13 @@ class Port : public PortInterface, Port(rtc::Thread* thread, const std::string& type, rtc::PacketSocketFactory* factory, - rtc::Network* network, + const rtc::Network* network, const std::string& username_fragment, const std::string& password); Port(rtc::Thread* thread, const std::string& type, rtc::PacketSocketFactory* factory, - rtc::Network* network, + const rtc::Network* network, uint16_t min_port, uint16_t max_port, const std::string& username_fragment, @@ -202,7 +202,7 @@ class Port : public PortInterface, // conflit in the value of the 2-tuple, make sure that the implementation that // relies on this 2-tuple for RTTI is properly changed. const std::string& Type() const override; - rtc::Network* Network() const override; + const rtc::Network* Network() const override; // Methods to set/get ICE role and tiebreaker values. IceRole GetIceRole() const override; @@ -457,7 +457,7 @@ class Port : public PortInterface, rtc::PacketSocketFactory* const factory_; std::string type_; bool send_retransmit_count_attribute_; - rtc::Network* network_; + const rtc::Network* network_; uint16_t min_port_; uint16_t max_port_; std::string content_name_; diff --git a/p2p/base/port_interface.h b/p2p/base/port_interface.h index 73c8e36c78..02fd97993a 100644 --- a/p2p/base/port_interface.h +++ b/p2p/base/port_interface.h @@ -49,7 +49,7 @@ class PortInterface { virtual ~PortInterface(); virtual const std::string& Type() const = 0; - virtual rtc::Network* Network() const = 0; + virtual const rtc::Network* Network() const = 0; // Methods to set/get ICE role and tiebreaker values. virtual void SetIceRole(IceRole role) = 0; diff --git a/p2p/base/port_unittest.cc b/p2p/base/port_unittest.cc index c5a89599c5..f5eed7e596 100644 --- a/p2p/base/port_unittest.cc +++ b/p2p/base/port_unittest.cc @@ -136,7 +136,7 @@ class TestPort : public Port { TestPort(rtc::Thread* thread, const std::string& type, rtc::PacketSocketFactory* factory, - rtc::Network* network, + const rtc::Network* network, uint16_t min_port, uint16_t max_port, const std::string& username_fragment, @@ -786,7 +786,7 @@ class PortTest : public ::testing::Test, public sigslot::has_slots<> { return port; } // Overload to create a test port given an rtc::Network directly. - std::unique_ptr CreateTestPort(rtc::Network* network, + std::unique_ptr CreateTestPort(const rtc::Network* network, const std::string& username, const std::string& password) { auto port = std::make_unique(&main_, "test", &socket_factory_, @@ -2106,7 +2106,7 @@ TEST_F(PortTest, TestNetworkInfoAttribute) { rport->SetIceTiebreaker(kTiebreaker2); uint16_t lnetwork_id = 9; - lport->Network()->set_id(lnetwork_id); + test_network->set_id(lnetwork_id); // Send a fake ping from lport to rport. lport->PrepareAddress(); rport->PrepareAddress(); @@ -2127,7 +2127,7 @@ TEST_F(PortTest, TestNetworkInfoAttribute) { // Send a fake ping from rport to lport. test_network->set_type(rtc::ADAPTER_TYPE_CELLULAR); uint16_t rnetwork_id = 8; - rport->Network()->set_id(rnetwork_id); + test_network->set_id(rnetwork_id); Connection* rconn = rport->CreateConnection(lport->Candidates()[0], Port::ORIGIN_MESSAGE); rconn->Ping(0); diff --git a/p2p/base/stun_port.cc b/p2p/base/stun_port.cc index 1ba6486049..4fa42f7a16 100644 --- a/p2p/base/stun_port.cc +++ b/p2p/base/stun_port.cc @@ -153,7 +153,7 @@ bool UDPPort::AddressResolver::GetResolvedAddress( UDPPort::UDPPort(rtc::Thread* thread, rtc::PacketSocketFactory* factory, - rtc::Network* network, + const rtc::Network* network, rtc::AsyncPacketSocket* socket, const std::string& username, const std::string& password, @@ -169,7 +169,7 @@ UDPPort::UDPPort(rtc::Thread* thread, UDPPort::UDPPort(rtc::Thread* thread, rtc::PacketSocketFactory* factory, - rtc::Network* network, + const rtc::Network* network, uint16_t min_port, uint16_t max_port, const std::string& username, @@ -599,7 +599,7 @@ bool UDPPort::HasCandidateWithAddress(const rtc::SocketAddress& addr) const { std::unique_ptr StunPort::Create( rtc::Thread* thread, rtc::PacketSocketFactory* factory, - rtc::Network* network, + const rtc::Network* network, uint16_t min_port, uint16_t max_port, const std::string& username, @@ -619,7 +619,7 @@ std::unique_ptr StunPort::Create( StunPort::StunPort(rtc::Thread* thread, rtc::PacketSocketFactory* factory, - rtc::Network* network, + const rtc::Network* network, uint16_t min_port, uint16_t max_port, const std::string& username, diff --git a/p2p/base/stun_port.h b/p2p/base/stun_port.h index 394c1336e2..99d22a6231 100644 --- a/p2p/base/stun_port.h +++ b/p2p/base/stun_port.h @@ -35,7 +35,7 @@ class UDPPort : public Port { static std::unique_ptr Create( rtc::Thread* thread, rtc::PacketSocketFactory* factory, - rtc::Network* network, + const rtc::Network* network, rtc::AsyncPacketSocket* socket, const std::string& username, const std::string& password, @@ -55,7 +55,7 @@ class UDPPort : public Port { static std::unique_ptr Create( rtc::Thread* thread, rtc::PacketSocketFactory* factory, - rtc::Network* network, + const rtc::Network* network, uint16_t min_port, uint16_t max_port, const std::string& username, @@ -119,7 +119,7 @@ class UDPPort : public Port { protected: UDPPort(rtc::Thread* thread, rtc::PacketSocketFactory* factory, - rtc::Network* network, + const rtc::Network* network, uint16_t min_port, uint16_t max_port, const std::string& username, @@ -128,7 +128,7 @@ class UDPPort : public Port { UDPPort(rtc::Thread* thread, rtc::PacketSocketFactory* factory, - rtc::Network* network, + const rtc::Network* network, rtc::AsyncPacketSocket* socket, const std::string& username, const std::string& password, @@ -264,7 +264,7 @@ class StunPort : public UDPPort { static std::unique_ptr Create( rtc::Thread* thread, rtc::PacketSocketFactory* factory, - rtc::Network* network, + const rtc::Network* network, uint16_t min_port, uint16_t max_port, const std::string& username, @@ -277,7 +277,7 @@ class StunPort : public UDPPort { protected: StunPort(rtc::Thread* thread, rtc::PacketSocketFactory* factory, - rtc::Network* network, + const rtc::Network* network, uint16_t min_port, uint16_t max_port, const std::string& username, diff --git a/p2p/base/tcp_port.cc b/p2p/base/tcp_port.cc index 445b0d03a5..52f74e7a10 100644 --- a/p2p/base/tcp_port.cc +++ b/p2p/base/tcp_port.cc @@ -86,7 +86,7 @@ namespace cricket { TCPPort::TCPPort(rtc::Thread* thread, rtc::PacketSocketFactory* factory, - rtc::Network* network, + const rtc::Network* network, uint16_t min_port, uint16_t max_port, const std::string& username, diff --git a/p2p/base/tcp_port.h b/p2p/base/tcp_port.h index 07d483cc3f..0635ed950e 100644 --- a/p2p/base/tcp_port.h +++ b/p2p/base/tcp_port.h @@ -36,7 +36,7 @@ class TCPPort : public Port { public: static std::unique_ptr Create(rtc::Thread* thread, rtc::PacketSocketFactory* factory, - rtc::Network* network, + const rtc::Network* network, uint16_t min_port, uint16_t max_port, const std::string& username, @@ -66,7 +66,7 @@ class TCPPort : public Port { protected: TCPPort(rtc::Thread* thread, rtc::PacketSocketFactory* factory, - rtc::Network* network, + const rtc::Network* network, uint16_t min_port, uint16_t max_port, const std::string& username, diff --git a/p2p/base/tcp_port_unittest.cc b/p2p/base/tcp_port_unittest.cc index 9af934f10e..ce83c1df00 100644 --- a/p2p/base/tcp_port_unittest.cc +++ b/p2p/base/tcp_port_unittest.cc @@ -85,7 +85,7 @@ class TCPPortTest : public ::testing::Test, public sigslot::has_slots<> { username_, password_, true)); } - std::unique_ptr CreateTCPPort(rtc::Network* network) { + std::unique_ptr CreateTCPPort(const rtc::Network* network) { return std::unique_ptr(TCPPort::Create( &main_, &socket_factory_, network, 0, 0, username_, password_, true)); } diff --git a/p2p/base/turn_port.cc b/p2p/base/turn_port.cc index 3f5b95e0d8..8320983c7b 100644 --- a/p2p/base/turn_port.cc +++ b/p2p/base/turn_port.cc @@ -215,7 +215,7 @@ class TurnEntry : public sigslot::has_slots<> { TurnPort::TurnPort(rtc::Thread* thread, rtc::PacketSocketFactory* factory, - rtc::Network* network, + const rtc::Network* network, rtc::AsyncPacketSocket* socket, const std::string& username, const std::string& password, @@ -248,7 +248,7 @@ TurnPort::TurnPort(rtc::Thread* thread, TurnPort::TurnPort(rtc::Thread* thread, rtc::PacketSocketFactory* factory, - rtc::Network* network, + const rtc::Network* network, uint16_t min_port, uint16_t max_port, const std::string& username, diff --git a/p2p/base/turn_port.h b/p2p/base/turn_port.h index 3328f2fcaa..89e6bd64b3 100644 --- a/p2p/base/turn_port.h +++ b/p2p/base/turn_port.h @@ -205,7 +205,7 @@ class TurnPort : public Port { protected: TurnPort(rtc::Thread* thread, rtc::PacketSocketFactory* factory, - rtc::Network* network, + const rtc::Network* network, rtc::AsyncPacketSocket* socket, const std::string& username, const std::string& password, @@ -220,7 +220,7 @@ class TurnPort : public Port { TurnPort(rtc::Thread* thread, rtc::PacketSocketFactory* factory, - rtc::Network* network, + const rtc::Network* network, uint16_t min_port, uint16_t max_port, const std::string& username, diff --git a/p2p/base/turn_port_unittest.cc b/p2p/base/turn_port_unittest.cc index e713e2b4a7..eca0b5812d 100644 --- a/p2p/base/turn_port_unittest.cc +++ b/p2p/base/turn_port_unittest.cc @@ -277,7 +277,7 @@ class TurnPortTest : public ::testing::Test, password, server_address); } - bool CreateTurnPortWithNetwork(rtc::Network* network, + bool CreateTurnPortWithNetwork(const rtc::Network* network, const std::string& username, const std::string& password, const ProtocolAddress& server_address) { @@ -288,7 +288,7 @@ class TurnPortTest : public ::testing::Test, // Version of CreateTurnPort that takes all possible parameters; all other // helper methods call this, such that "SetIceRole" and "ConnectSignals" (and // possibly other things in the future) only happen in one place. - bool CreateTurnPortWithAllParams(rtc::Network* network, + bool CreateTurnPortWithAllParams(const rtc::Network* network, const std::string& username, const std::string& password, const ProtocolAddress& server_address) { diff --git a/p2p/client/basic_port_allocator.cc b/p2p/client/basic_port_allocator.cc index 20032a99d7..6535ba52ae 100644 --- a/p2p/client/basic_port_allocator.cc +++ b/p2p/client/basic_port_allocator.cc @@ -88,16 +88,18 @@ int ComparePort(const cricket::Port* a, const cricket::Port* b) { } struct NetworkFilter { - using Predicate = std::function; + using Predicate = std::function; NetworkFilter(Predicate pred, const std::string& description) - : predRemain([pred](rtc::Network* network) { return !pred(network); }), + : predRemain( + [pred](const rtc::Network* network) { return !pred(network); }), description(description) {} Predicate predRemain; const std::string description; }; using NetworkList = rtc::NetworkManager::NetworkList; -void FilterNetworks(NetworkList* networks, NetworkFilter filter) { +void FilterNetworks(std::vector* networks, + NetworkFilter filter) { auto start_to_remove = std::partition(networks->begin(), networks->end(), filter.predRemain); if (start_to_remove == networks->end()) { @@ -432,11 +434,11 @@ bool BasicPortAllocatorSession::IsStopped() const { return state_ == SessionState::STOPPED; } -std::vector BasicPortAllocatorSession::GetFailedNetworks() { +std::vector +BasicPortAllocatorSession::GetFailedNetworks() { RTC_DCHECK_RUN_ON(network_thread_); - std::vector networks = GetNetworks(); - + std::vector networks = GetNetworks(); // A network interface may have both IPv4 and IPv6 networks. Only if // neither of the networks has any connections, the network interface // is considered failed and need to be regathered on. @@ -450,7 +452,7 @@ std::vector BasicPortAllocatorSession::GetFailedNetworks() { networks.erase( std::remove_if(networks.begin(), networks.end(), - [networks_with_connection](rtc::Network* network) { + [networks_with_connection](const rtc::Network* network) { // If a network does not have any connection, it is // considered failed. return networks_with_connection.find(network->name()) != @@ -464,7 +466,7 @@ void BasicPortAllocatorSession::RegatherOnFailedNetworks() { RTC_DCHECK_RUN_ON(network_thread_); // Find the list of networks that have no connection. - std::vector failed_networks = GetFailedNetworks(); + std::vector failed_networks = GetFailedNetworks(); if (failed_networks.empty()) { return; } @@ -487,7 +489,7 @@ void BasicPortAllocatorSession::RegatherOnFailedNetworks() { } void BasicPortAllocatorSession::Regather( - const std::vector& networks, + const std::vector& networks, bool disable_equivalent_phases, IceRegatheringReason reason) { RTC_DCHECK_RUN_ON(network_thread_); @@ -696,9 +698,9 @@ void BasicPortAllocatorSession::OnAllocate(int allocation_epoch) { allocation_started_ = true; } -std::vector BasicPortAllocatorSession::GetNetworks() { +std::vector BasicPortAllocatorSession::GetNetworks() { RTC_DCHECK_RUN_ON(network_thread_); - std::vector networks; + std::vector networks; rtc::NetworkManager* network_manager = allocator_->network_manager(); RTC_DCHECK(network_manager != nullptr); // If the network permission state is BLOCKED, we just act as if the flag has @@ -712,35 +714,41 @@ std::vector BasicPortAllocatorSession::GetNetworks() { // traffic by OS is also used here to avoid any local or public IP leakage // during stun process. if (flags() & PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION) { - network_manager->GetAnyAddressNetworks(&networks); + networks = network_manager->GetAnyAddressNetworks(); } else { - network_manager->GetNetworks(&networks); + networks = network_manager->GetNetworks(); // If network enumeration fails, use the ANY address as a fallback, so we // can at least try gathering candidates using the default route chosen by // the OS. Or, if the PORTALLOCATOR_ENABLE_ANY_ADDRESS_PORTS flag is // set, we'll use ANY address candidates either way. - if (networks.empty() || flags() & PORTALLOCATOR_ENABLE_ANY_ADDRESS_PORTS) { - network_manager->GetAnyAddressNetworks(&networks); + if (networks.empty() || + (flags() & PORTALLOCATOR_ENABLE_ANY_ADDRESS_PORTS)) { + std::vector any_address_networks = + network_manager->GetAnyAddressNetworks(); + networks.insert(networks.end(), any_address_networks.begin(), + any_address_networks.end()); } } // Filter out link-local networks if needed. if (flags() & PORTALLOCATOR_DISABLE_LINK_LOCAL_NETWORKS) { NetworkFilter link_local_filter( - [](rtc::Network* network) { return IPIsLinkLocal(network->prefix()); }, + [](const rtc::Network* network) { + return IPIsLinkLocal(network->prefix()); + }, "link-local"); FilterNetworks(&networks, link_local_filter); } // Do some more filtering, depending on the network ignore mask and "disable // costly networks" flag. NetworkFilter ignored_filter( - [this](rtc::Network* network) { + [this](const rtc::Network* network) { return allocator_->GetNetworkIgnoreMask() & network->type(); }, "ignored"); FilterNetworks(&networks, ignored_filter); if (flags() & PORTALLOCATOR_DISABLE_COSTLY_NETWORKS) { uint16_t lowest_cost = rtc::kNetworkCostMax; - for (rtc::Network* network : networks) { + for (const rtc::Network* network : networks) { // Don't determine the lowest cost from a link-local network. // On iOS, a device connected to the computer will get a link-local // network for communicating with the computer, however this network can't @@ -751,7 +759,7 @@ std::vector BasicPortAllocatorSession::GetNetworks() { lowest_cost = std::min(lowest_cost, network->GetCost()); } NetworkFilter costly_filter( - [lowest_cost](rtc::Network* network) { + [lowest_cost](const rtc::Network* network) { return network->GetCost() > lowest_cost + rtc::kNetworkCostLow; }, "costly"); @@ -786,7 +794,7 @@ std::vector BasicPortAllocatorSession::GetNetworks() { void BasicPortAllocatorSession::DoAllocate(bool disable_equivalent) { RTC_DCHECK_RUN_ON(network_thread_); bool done_signal_needed = false; - std::vector networks = GetNetworks(); + std::vector networks = GetNetworks(); if (networks.empty()) { RTC_LOG(LS_WARNING) << "Machine has no networks; no ports will be allocated"; @@ -853,8 +861,8 @@ void BasicPortAllocatorSession::DoAllocate(bool disable_equivalent) { void BasicPortAllocatorSession::OnNetworksChanged() { RTC_DCHECK_RUN_ON(network_thread_); - std::vector networks = GetNetworks(); - std::vector failed_networks; + std::vector networks = GetNetworks(); + std::vector failed_networks; for (AllocationSequence* sequence : sequences_) { // Mark the sequence as "network failed" if its network is not in // `networks`. @@ -887,7 +895,7 @@ void BasicPortAllocatorSession::OnNetworksChanged() { } void BasicPortAllocatorSession::DisableEquivalentPhases( - rtc::Network* network, + const rtc::Network* network, PortConfiguration* config, uint32_t* flags) { RTC_DCHECK_RUN_ON(network_thread_); @@ -1200,7 +1208,7 @@ BasicPortAllocatorSession::PortData* BasicPortAllocatorSession::FindPort( std::vector BasicPortAllocatorSession::GetUnprunedPorts( - const std::vector& networks) { + const std::vector& networks) { RTC_DCHECK_RUN_ON(network_thread_); std::vector unpruned_ports; for (PortData& port : ports_) { @@ -1247,7 +1255,7 @@ void BasicPortAllocator::SetVpnList( AllocationSequence::AllocationSequence( BasicPortAllocatorSession* session, - rtc::Network* network, + const rtc::Network* network, PortConfiguration* config, uint32_t flags, std::function port_allocation_complete_callback) @@ -1289,7 +1297,7 @@ void AllocationSequence::OnNetworkFailed() { Stop(); } -void AllocationSequence::DisableEquivalentPhases(rtc::Network* network, +void AllocationSequence::DisableEquivalentPhases(const rtc::Network* network, PortConfiguration* config, uint32_t* flags) { if (network_failed_) { diff --git a/p2p/client/basic_port_allocator.h b/p2p/client/basic_port_allocator.h index 946aa6b17e..6d650f5c53 100644 --- a/p2p/client/basic_port_allocator.h +++ b/p2p/client/basic_port_allocator.h @@ -236,7 +236,7 @@ class RTC_EXPORT BasicPortAllocatorSession : public PortAllocatorSession { void DoAllocate(bool disable_equivalent_phases); void OnNetworksChanged(); void OnAllocationSequenceObjectsCreated(); - void DisableEquivalentPhases(rtc::Network* network, + void DisableEquivalentPhases(const rtc::Network* network, PortConfiguration* config, uint32_t* flags); void AddAllocatedPort(Port* port, AllocationSequence* seq); @@ -249,9 +249,9 @@ class RTC_EXPORT BasicPortAllocatorSession : public PortAllocatorSession { void MaybeSignalCandidatesAllocationDone(); void OnPortAllocationComplete(); PortData* FindPort(Port* port); - std::vector GetNetworks(); - std::vector GetFailedNetworks(); - void Regather(const std::vector& networks, + std::vector GetNetworks(); + std::vector GetFailedNetworks(); + void Regather(const std::vector& networks, bool disable_equivalent_phases, IceRegatheringReason reason); @@ -259,7 +259,7 @@ class RTC_EXPORT BasicPortAllocatorSession : public PortAllocatorSession { bool CandidatePairable(const Candidate& c, const Port* port) const; std::vector GetUnprunedPorts( - const std::vector& networks); + const std::vector& networks); // Prunes ports and signal the remote side to remove the candidates that // were previously signaled from these ports. void PrunePortsAndRemoveCandidates( @@ -352,7 +352,7 @@ class AllocationSequence : public sigslot::has_slots<> { // event to trigger signal. This can also be achieved by starting a timer in // BPAS, but this is less deterministic. AllocationSequence(BasicPortAllocatorSession* session, - rtc::Network* network, + const rtc::Network* network, PortConfiguration* config, uint32_t flags, std::function port_allocation_complete_callback); @@ -361,14 +361,14 @@ class AllocationSequence : public sigslot::has_slots<> { void OnNetworkFailed(); State state() const { return state_; } - rtc::Network* network() const { return network_; } + const rtc::Network* network() const { return network_; } bool network_failed() const { return network_failed_; } void set_network_failed() { network_failed_ = true; } // Disables the phases for a new sequence that this one already covers for an // equivalent network setup. - void DisableEquivalentPhases(rtc::Network* network, + void DisableEquivalentPhases(const rtc::Network* network, PortConfiguration* config, uint32_t* flags); @@ -401,7 +401,7 @@ class AllocationSequence : public sigslot::has_slots<> { BasicPortAllocatorSession* session_; bool network_failed_ = false; - rtc::Network* network_; + const rtc::Network* network_; // Compared with the new best IP in DisableEquivalentPhases. rtc::IPAddress previous_best_ip_; PortConfiguration* config_; diff --git a/p2p/client/relay_port_factory_interface.h b/p2p/client/relay_port_factory_interface.h index 9417c4d313..7d63facc06 100644 --- a/p2p/client/relay_port_factory_interface.h +++ b/p2p/client/relay_port_factory_interface.h @@ -38,7 +38,7 @@ struct RelayServerConfig; struct CreateRelayPortArgs { rtc::Thread* network_thread; rtc::PacketSocketFactory* socket_factory; - rtc::Network* network; + const rtc::Network* network; const ProtocolAddress* server_address; const RelayServerConfig* config; std::string username; diff --git a/rtc_base/nat_unittest.cc b/rtc_base/nat_unittest.cc index 2e41684b78..af6256fb70 100644 --- a/rtc_base/nat_unittest.cc +++ b/rtc_base/nat_unittest.cc @@ -228,7 +228,7 @@ void TestPhysicalInternal(const SocketAddress& int_addr) { std::vector networks; network_manager.GetNetworks(&networks); networks.erase(std::remove_if(networks.begin(), networks.end(), - [](rtc::Network* network) { + [](const rtc::Network* network) { return rtc::kDefaultNetworkIgnoreMask & network->type(); }), diff --git a/rtc_base/network.h b/rtc_base/network.h index bf14bef0e4..063e25596c 100644 --- a/rtc_base/network.h +++ b/rtc_base/network.h @@ -149,6 +149,15 @@ class RTC_EXPORT NetworkManager : public DefaultLocalAddressProvider, // It makes sure that repeated calls return the same object for a // given network, so that quality is tracked appropriately. Does not // include ignored networks. + virtual std::vector GetNetworks() const { + std::vector networks; + std::vector const_networks; + GetNetworks(&networks); + const_networks.insert(const_networks.begin(), networks.begin(), + networks.end()); + return const_networks; + } + // TODO(bugs.webrtc.org/13869): Delete this overload. virtual void GetNetworks(NetworkList* networks) const = 0; // Returns the current permission state of GetNetworks(). @@ -163,6 +172,15 @@ class RTC_EXPORT NetworkManager : public DefaultLocalAddressProvider, // can optionally be called after GetNetworks. // // TODO(guoweis): remove this body when chromium implements this. + virtual std::vector GetAnyAddressNetworks() { + std::vector networks; + std::vector const_networks; + GetAnyAddressNetworks(&networks); + const_networks.insert(const_networks.begin(), networks.begin(), + networks.end()); + return const_networks; + } + // TODO(bugs.webrtc.org/13869): Delete this overload. virtual void GetAnyAddressNetworks(NetworkList* networks) {} // Dumps the current list of networks in the network manager. @@ -365,12 +383,14 @@ class RTC_EXPORT Network { ~Network(); // This signal is fired whenever type() or underlying_type_for_vpn() changes. - sigslot::signal1 SignalTypeChanged; + // Mutable, to support connecting on the const Network passed to cricket::Port + // constructor. + mutable sigslot::signal1 SignalTypeChanged; // This signal is fired whenever network preference changes. sigslot::signal1 SignalNetworkPreferenceChanged; - const DefaultLocalAddressProvider* default_local_address_provider() { + const DefaultLocalAddressProvider* default_local_address_provider() const { return default_local_address_provider_; } void set_default_local_address_provider(