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

Side by Side Diff: content/browser/renderer_host/p2p/socket_host_udp.cc

Issue 2300983003: Fix P2PSocketHostUdp to handle dropped packets properly. (Closed)
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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/renderer_host/p2p/socket_host_udp.h" 5 #include "content/browser/renderer_host/p2p/socket_host_udp.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/metrics/field_trial.h" 9 #include "base/metrics/field_trial.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 void P2PSocketHostUdp::Send(const net::IPEndPoint& to, 263 void P2PSocketHostUdp::Send(const net::IPEndPoint& to,
264 const std::vector<char>& data, 264 const std::vector<char>& data,
265 const rtc::PacketOptions& options, 265 const rtc::PacketOptions& options,
266 uint64_t packet_id) { 266 uint64_t packet_id) {
267 if (!socket_) { 267 if (!socket_) {
268 // The Send message may be sent after the an OnError message was 268 // The Send message may be sent after the an OnError message was
269 // sent by hasn't been processed the renderer. 269 // sent by hasn't been processed the renderer.
270 return; 270 return;
271 } 271 }
272 272
273 if (!base::ContainsKey(connected_peers_, to)) {
274 P2PSocketHost::StunMessageType type = P2PSocketHost::StunMessageType();
275 bool stun = GetStunPacketType(&*data.begin(), data.size(), &type);
276 if (!stun || type == STUN_DATA_INDICATION) {
277 LOG(ERROR) << "Page tried to send a data packet to " << to.ToString()
278 << " before STUN binding is finished.";
279 OnError();
280 return;
281 }
282
283 if (throttler_->DropNextPacket(data.size())) {
284 VLOG(0) << "STUN message is dropped due to high volume.";
285 // Do not reset socket.
286 return;
287 }
288 }
289
290 IncrementTotalSentPackets(); 273 IncrementTotalSentPackets();
291 274
292 if (send_pending_) { 275 if (send_pending_) {
293 send_queue_.push_back(PendingPacket(to, data, options, packet_id)); 276 send_queue_.push_back(PendingPacket(to, data, options, packet_id));
294 IncrementDelayedBytes(data.size()); 277 IncrementDelayedBytes(data.size());
295 IncrementDelayedPackets(); 278 IncrementDelayedPackets();
296 } else { 279 } else {
297 // TODO(mallinath: Remove unnecessary memcpy in this case. 280 // TODO(mallinath: Remove unnecessary memcpy in this case.
298 PendingPacket packet(to, data, options, packet_id); 281 PendingPacket packet(to, data, options, packet_id);
299 DoSend(packet); 282 DoSend(packet);
300 } 283 }
301 } 284 }
302 285
303 void P2PSocketHostUdp::DoSend(const PendingPacket& packet) { 286 void P2PSocketHostUdp::DoSend(const PendingPacket& packet) {
287 base::TimeTicks send_time = base::TimeTicks::Now();
288
289 if (!base::ContainsKey(connected_peers_, packet.to)) {
290 P2PSocketHost::StunMessageType type = P2PSocketHost::StunMessageType();
291 bool stun = GetStunPacketType(packet.data->data(), packet.size, &type);
292 if (!stun || type == STUN_DATA_INDICATION) {
293 LOG(ERROR) << "Page tried to send a data packet to "
294 << packet.to.ToString() << " before STUN binding is finished.";
295 OnError();
296 return;
297 }
298
299 if (throttler_->DropNextPacket(packet.size)) {
300 VLOG(0) << "STUN message is dropped due to high volume.";
301 message_sender_->Send(new P2PMsg_OnSendComplete(
302 id_, P2PSendPacketMetrics(packet.id, packet.packet_options.packet_id,
303 send_time)));
pthatcher2 2016/09/02 05:21:19 We should leave a comment about how important it i
Sergey Ulanov 2016/09/02 17:00:46 Done.
304 // Do not reset socket.
305 return;
306 }
307 }
308
304 TRACE_EVENT_ASYNC_STEP_INTO1("p2p", "Send", packet.id, "UdpAsyncSendTo", 309 TRACE_EVENT_ASYNC_STEP_INTO1("p2p", "Send", packet.id, "UdpAsyncSendTo",
305 "size", packet.size); 310 "size", packet.size);
306 // Don't try to set DSCP in following conditions, 311 // Don't try to set DSCP in following conditions,
307 // 1. If the outgoing packet is set to DSCP_NO_CHANGE 312 // 1. If the outgoing packet is set to DSCP_NO_CHANGE
308 // 2. If no change in DSCP value from last packet 313 // 2. If no change in DSCP value from last packet
309 // 3. If there is any error in setting DSCP on socket. 314 // 3. If there is any error in setting DSCP on socket.
310 net::DiffServCodePoint dscp = 315 net::DiffServCodePoint dscp =
311 static_cast<net::DiffServCodePoint>(packet.packet_options.dscp); 316 static_cast<net::DiffServCodePoint>(packet.packet_options.dscp);
312 if (dscp != net::DSCP_NO_CHANGE && last_dscp_ != dscp && 317 if (dscp != net::DSCP_NO_CHANGE && last_dscp_ != dscp &&
313 last_dscp_ != net::DSCP_NO_CHANGE) { 318 last_dscp_ != net::DSCP_NO_CHANGE) {
314 int result = socket_->SetDiffServCodePoint(dscp); 319 int result = socket_->SetDiffServCodePoint(dscp);
315 if (result == net::OK) { 320 if (result == net::OK) {
316 last_dscp_ = dscp; 321 last_dscp_ = dscp;
317 } else if (!IsTransientError(result) && last_dscp_ != net::DSCP_CS0) { 322 } else if (!IsTransientError(result) && last_dscp_ != net::DSCP_CS0) {
318 // We receieved a non-transient error, and it seems we have 323 // We receieved a non-transient error, and it seems we have
319 // not changed the DSCP in the past, disable DSCP as it unlikely 324 // not changed the DSCP in the past, disable DSCP as it unlikely
320 // to work in the future. 325 // to work in the future.
321 last_dscp_ = net::DSCP_NO_CHANGE; 326 last_dscp_ = net::DSCP_NO_CHANGE;
322 } 327 }
323 } 328 }
324 329
325 base::TimeTicks send_time = base::TimeTicks::Now();
326 cricket::ApplyPacketOptions(reinterpret_cast<uint8_t*>(packet.data->data()), 330 cricket::ApplyPacketOptions(reinterpret_cast<uint8_t*>(packet.data->data()),
327 packet.size, 331 packet.size,
328 packet.packet_options.packet_time_params, 332 packet.packet_options.packet_time_params,
329 (send_time - base::TimeTicks()).InMicroseconds()); 333 (send_time - base::TimeTicks()).InMicroseconds());
330 auto callback_binding = 334 auto callback_binding =
331 base::Bind(&P2PSocketHostUdp::OnSend, base::Unretained(this), packet.id, 335 base::Bind(&P2PSocketHostUdp::OnSend, base::Unretained(this), packet.id,
332 packet.packet_options.packet_id, send_time); 336 packet.packet_options.packet_id, send_time);
333 int result = socket_->SendTo(packet.data.get(), packet.size, packet.to, 337 int result = socket_->SendTo(packet.data.get(), packet.size, packet.to,
334 callback_binding); 338 callback_binding);
335 339
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 net::UDPServerSocket* socket = new net::UDPServerSocket( 440 net::UDPServerSocket* socket = new net::UDPServerSocket(
437 GetContentClient()->browser()->GetNetLog(), net::NetLog::Source()); 441 GetContentClient()->browser()->GetNetLog(), net::NetLog::Source());
438 #if defined(OS_WIN) 442 #if defined(OS_WIN)
439 socket->UseNonBlockingIO(); 443 socket->UseNonBlockingIO();
440 #endif 444 #endif
441 445
442 return base::WrapUnique(socket); 446 return base::WrapUnique(socket);
443 } 447 }
444 448
445 } // namespace content 449 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698