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

Unified Diff: webrtc/base/virtualsocketserver.cc

Issue 2261523004: Signal to remove remote candidates if ports are pruned. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: . Created 4 years, 3 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
Index: webrtc/base/virtualsocketserver.cc
diff --git a/webrtc/base/virtualsocketserver.cc b/webrtc/base/virtualsocketserver.cc
index 87775cd63cc6afcd4e2dece01ec32bfde2780adf..8c127f48842502e2385728c70f56893ba47b367b 100644
--- a/webrtc/base/virtualsocketserver.cc
+++ b/webrtc/base/virtualsocketserver.cc
@@ -541,7 +541,6 @@ VirtualSocketServer::VirtualSocketServer(SocketServer* ss)
delay_mean_(0),
delay_stddev_(0),
delay_samples_(NUM_SAMPLES),
- delay_dist_(NULL),
drop_prob_(0.0) {
if (!server_) {
server_ = new PhysicalSocketServer();
@@ -553,7 +552,6 @@ VirtualSocketServer::VirtualSocketServer(SocketServer* ss)
VirtualSocketServer::~VirtualSocketServer() {
delete bindings_;
delete connections_;
- delete delay_dist_;
if (server_owned_) {
delete server_;
}
@@ -781,7 +779,7 @@ static double Random() {
int VirtualSocketServer::Connect(VirtualSocket* socket,
const SocketAddress& remote_addr,
bool use_delay) {
- uint32_t delay = use_delay ? GetRandomTransitDelay() : 0;
+ uint32_t delay = use_delay ? GetRandomTransitDelay(socket) : 0;
VirtualSocket* remote = LookupBinding(remote_addr);
if (!CanInteractWith(socket, remote)) {
LOG(LS_INFO) << "Address family mismatch between "
@@ -803,7 +801,7 @@ bool VirtualSocketServer::Disconnect(VirtualSocket* socket) {
if (socket) {
// If we simulate packets being delayed, we should simulate the
// equivalent of a FIN being delayed as well.
- uint32_t delay = GetRandomTransitDelay();
+ uint32_t delay = GetRandomTransitDelay(socket);
// Remove the mapping.
msg_queue_->PostDelayed(RTC_FROM_HERE, delay, socket, MSG_ID_DISCONNECT);
return true;
@@ -947,7 +945,7 @@ void VirtualSocketServer::AddPacketToNetwork(VirtualSocket* sender,
sender->network_.push_back(entry);
// Find the delay for crossing the many virtual hops of the network.
- uint32_t transit_delay = GetRandomTransitDelay();
+ uint32_t transit_delay = GetRandomTransitDelay(sender);
// When the incoming packet is from a binding of the any address, translate it
// to the default route here such that the recipient will see the default
@@ -1016,8 +1014,17 @@ void VirtualSocketServer::UpdateDelayDistribution() {
// We take a lock just to make sure we don't leak memory.
{
CritScope cs(&delay_crit_);
- delete delay_dist_;
- delay_dist_ = dist;
+ delay_dist_.reset(dist);
+ }
+}
+
+void VirtualSocketServer::UpdateDelayDistributionForIPv6() {
+ Function* dist =
+ CreateDistribution(delay_mean_, delay_stddev_, delay_samples_);
+ // We take a lock just to make sure we don't leak memory.
+ {
+ CritScope cs(&delay_crit_);
+ delay_dist_ipv6_.reset(dist);
}
}
@@ -1060,10 +1067,15 @@ VirtualSocketServer::Function* VirtualSocketServer::CreateDistribution(
return Resample(Invert(Accumulate(f)), 0, 1, samples);
}
-uint32_t VirtualSocketServer::GetRandomTransitDelay() {
- size_t index = rand() % delay_dist_->size();
- double delay = (*delay_dist_)[index].second;
- //LOG_F(LS_INFO) << "random[" << index << "] = " << delay;
+uint32_t VirtualSocketServer::GetRandomTransitDelay(Socket* socket) {
+ Function* delay_dist = delay_dist_.get();
+ if (socket->GetLocalAddress().family() == AF_INET6 && delay_dist_ipv6_) {
+ delay_dist = delay_dist_ipv6_.get();
+ }
+
+ size_t index = rand() % delay_dist->size();
+ double delay = (*delay_dist)[index].second;
+ // LOG_F(LS_INFO) << "random[" << index << "] = " << delay;
return static_cast<uint32_t>(delay);
}

Powered by Google App Engine
This is Rietveld 408576698