Refactor StunProber to use const rtc::Network*
Bug: webrtc:13869 Change-Id: I99645f6b845d2f12c90b3b39aa7bd3f2849a717c Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/257165 Reviewed-by: Harald Alvestrand <hta@webrtc.org> Commit-Queue: Niels Moller <nisse@webrtc.org> Cr-Commit-Position: refs/heads/main@{#36387}
This commit is contained in:

committed by
WebRTC LUCI CQ

parent
38f35db4d4
commit
1e39da3092
@ -38,6 +38,16 @@ void IncrementCounterByAddress(std::map<T, int>* counter_per_ip, const T& ip) {
|
||||
counter_per_ip->insert(std::make_pair(ip, 0)).first->second++;
|
||||
}
|
||||
|
||||
std::vector<const rtc::Network*> NetworkListToConst(
|
||||
const rtc::NetworkManager::NetworkList networks) {
|
||||
std::vector<const rtc::Network*> result;
|
||||
result.reserve(networks.size());
|
||||
for (const rtc::Network* network : networks) {
|
||||
result.push_back(network);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
// A requester tracks the requests and responses from a single socket to many
|
||||
@ -256,6 +266,14 @@ void StunProber::ObserverAdapter::OnFinished(StunProber* stunprober,
|
||||
StunProber::StunProber(rtc::PacketSocketFactory* socket_factory,
|
||||
rtc::Thread* thread,
|
||||
const rtc::NetworkManager::NetworkList& networks)
|
||||
: interval_ms_(0),
|
||||
socket_factory_(socket_factory),
|
||||
thread_(thread),
|
||||
networks_(NetworkListToConst(networks)) {}
|
||||
|
||||
StunProber::StunProber(rtc::PacketSocketFactory* socket_factory,
|
||||
rtc::Thread* thread,
|
||||
std::vector<const rtc::Network*> networks)
|
||||
: interval_ms_(0),
|
||||
socket_factory_(socket_factory),
|
||||
thread_(thread),
|
||||
|
@ -95,9 +95,15 @@ class RTC_EXPORT StunProber : public sigslot::has_slots<> {
|
||||
std::set<std::string> srflx_addrs;
|
||||
};
|
||||
|
||||
// TODO(bugs.webrtc.org/13869): Delete, use constructor with const
|
||||
// rtc::Network*.
|
||||
ABSL_DEPRECATED("bugs.webrtc.org/13869")
|
||||
StunProber(rtc::PacketSocketFactory* socket_factory,
|
||||
rtc::Thread* thread,
|
||||
const rtc::NetworkManager::NetworkList& networks);
|
||||
StunProber(rtc::PacketSocketFactory* socket_factory,
|
||||
rtc::Thread* thread,
|
||||
std::vector<const rtc::Network*> networks);
|
||||
~StunProber() override;
|
||||
|
||||
StunProber(const StunProber&) = delete;
|
||||
@ -240,7 +246,7 @@ class RTC_EXPORT StunProber : public sigslot::has_slots<> {
|
||||
// AsyncCallback.
|
||||
ObserverAdapter observer_adapter_;
|
||||
|
||||
rtc::NetworkManager::NetworkList networks_;
|
||||
const std::vector<const rtc::Network*> networks_;
|
||||
|
||||
webrtc::ScopedTaskSafety task_safety_;
|
||||
};
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
#include "p2p/base/basic_packet_socket_factory.h"
|
||||
#include "p2p/base/test_stun_server.h"
|
||||
@ -40,7 +41,7 @@ const rtc::SocketAddress kStunMappedAddr("77.77.77.77", 0);
|
||||
class StunProberTest : public ::testing::Test {
|
||||
public:
|
||||
StunProberTest()
|
||||
: ss_(new rtc::VirtualSocketServer()),
|
||||
: ss_(std::make_unique<rtc::VirtualSocketServer>()),
|
||||
main_(ss_.get()),
|
||||
result_(StunProber::SUCCESS),
|
||||
stun_server_1_(cricket::TestStunServer::Create(ss_.get(), kStunAddr1)),
|
||||
@ -54,12 +55,12 @@ class StunProberTest : public ::testing::Test {
|
||||
|
||||
void StartProbing(rtc::PacketSocketFactory* socket_factory,
|
||||
const std::vector<rtc::SocketAddress>& addrs,
|
||||
const rtc::NetworkManager::NetworkList& networks,
|
||||
std::vector<const rtc::Network*> networks,
|
||||
bool shared_socket,
|
||||
uint16_t interval,
|
||||
uint16_t pings_per_ip) {
|
||||
prober.reset(
|
||||
new StunProber(socket_factory, rtc::Thread::Current(), networks));
|
||||
prober = std::make_unique<StunProber>(
|
||||
socket_factory, rtc::Thread::Current(), std::move(networks));
|
||||
prober->Start(addrs, shared_socket, interval, pings_per_ip,
|
||||
100 /* timeout_ms */, [this](StunProber* prober, int result) {
|
||||
this->StopCallback(prober, result);
|
||||
@ -77,7 +78,7 @@ class StunProberTest : public ::testing::Test {
|
||||
rtc::Network ipv4_network1("test_eth0", "Test Network Adapter 1",
|
||||
rtc::IPAddress(0x12345600U), 24);
|
||||
ipv4_network1.AddIP(rtc::IPAddress(0x12345678));
|
||||
rtc::NetworkManager::NetworkList networks;
|
||||
std::vector<const rtc::Network*> networks;
|
||||
networks.push_back(&ipv4_network1);
|
||||
|
||||
auto socket_factory =
|
||||
@ -93,8 +94,8 @@ class StunProberTest : public ::testing::Test {
|
||||
// kFailedStunAddr.
|
||||
const uint32_t total_pings_reported = total_pings_tried - pings_per_ip;
|
||||
|
||||
StartProbing(socket_factory.get(), addrs, networks, shared_mode, 3,
|
||||
pings_per_ip);
|
||||
StartProbing(socket_factory.get(), addrs, std::move(networks), shared_mode,
|
||||
3, pings_per_ip);
|
||||
|
||||
WAIT(stopped_, 1000);
|
||||
|
||||
|
Reference in New Issue
Block a user