Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1937)

Unified Diff: webrtc/p2p/base/fakeportallocator.h

Issue 2395243005: Prune connections based on network name. (Closed)
Patch Set: . Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | webrtc/p2p/base/p2ptransportchannel.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/p2p/base/fakeportallocator.h
diff --git a/webrtc/p2p/base/fakeportallocator.h b/webrtc/p2p/base/fakeportallocator.h
index a1dbbf872b152748588ecd6b8727c5fc7c341305..20dc2facebc6bcb93779d9d1a5379b81b1aae527 100644
--- a/webrtc/p2p/base/fakeportallocator.h
+++ b/webrtc/p2p/base/fakeportallocator.h
@@ -110,7 +110,6 @@ class FakePortAllocatorSession : public PortAllocatorSession {
"unittest",
rtc::IPAddress(in6addr_loopback),
64),
- port_(),
port_config_count_(0),
stun_servers_(allocator->stun_servers()),
turn_servers_(allocator->turn_servers()) {
@@ -122,18 +121,23 @@ class FakePortAllocatorSession : public PortAllocatorSession {
candidate_filter_ = filter;
}
+ Port* CreatePort(rtc::Network* network) {
+ Port* port = TestUDPPort::Create(network_thread_, factory_, network,
+ network->GetBestIP(), 0, 0, username(),
+ password(), std::string(), false);
+ port->SignalDestroyed.connect(this,
+ &FakePortAllocatorSession::OnPortDestroyed);
skvlad 2016/10/10 18:23:04 Very minor: can this me moved to inside AddPort?
honghaiz3 2016/10/10 19:35:28 Done.
+ AddPort(port);
+ return port;
+ }
+
void StartGettingPorts() override {
- if (!port_) {
- rtc::Network& network =
- (rtc::HasIPv6Enabled() && (flags() & PORTALLOCATOR_ENABLE_IPV6))
- ? ipv6_network_
- : ipv4_network_;
- port_.reset(TestUDPPort::Create(network_thread_, factory_, &network,
- network.GetBestIP(), 0, 0, username(),
- password(), std::string(), false));
- port_->SignalDestroyed.connect(
- this, &FakePortAllocatorSession::OnPortDestroyed);
- AddPort(port_.get());
+ if (!ipv4_port_) {
+ ipv4_port_.reset(CreatePort(&ipv4_network_));
+ }
+ if (!ipv6_port_ && rtc::HasIPv6Enabled() &&
+ (flags() & PORTALLOCATOR_ENABLE_IPV6)) {
+ ipv6_port_.reset(CreatePort(&ipv6_network_));
}
++port_config_count_;
running_ = true;
@@ -149,7 +153,14 @@ class FakePortAllocatorSession : public PortAllocatorSession {
std::vector<Candidate> ReadyCandidates() const override {
return candidates_;
}
- void PruneAllPorts() override { port_->Prune(); }
+ void PruneAllPorts() override {
+ if (ipv4_port_) {
+ ipv4_port_->Prune();
+ }
+ if (ipv6_port_) {
+ ipv6_port_->Prune();
+ }
+ }
bool CandidatesAllocationDone() const override { return allocation_done_; }
int port_config_count() { return port_config_count_; }
@@ -194,14 +205,19 @@ class FakePortAllocatorSession : public PortAllocatorSession {
}
void OnPortDestroyed(cricket::PortInterface* port) {
// Don't want to double-delete port if it deletes itself.
- port_.release();
+ if (port == ipv4_port_.get()) {
+ ipv4_port_.release();
+ } else if (port == ipv6_port_.get()) {
+ ipv6_port_.release();
+ }
}
rtc::Thread* network_thread_;
rtc::PacketSocketFactory* factory_;
rtc::Network ipv4_network_;
rtc::Network ipv6_network_;
- std::unique_ptr<cricket::Port> port_;
+ std::unique_ptr<cricket::Port> ipv4_port_;
+ std::unique_ptr<cricket::Port> ipv6_port_;
int port_config_count_;
std::vector<Candidate> candidates_;
std::vector<PortInterface*> ready_ports_;
« no previous file with comments | « no previous file | webrtc/p2p/base/p2ptransportchannel.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698