| OLD | NEW |
| 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 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 DoRead(); | 229 DoRead(); |
| 230 } | 230 } |
| 231 } | 231 } |
| 232 | 232 |
| 233 void P2PSocketHostUdp::HandleReadResult(int result) { | 233 void P2PSocketHostUdp::HandleReadResult(int result) { |
| 234 DCHECK_EQ(STATE_OPEN, state_); | 234 DCHECK_EQ(STATE_OPEN, state_); |
| 235 | 235 |
| 236 if (result > 0) { | 236 if (result > 0) { |
| 237 std::vector<char> data(recv_buffer_->data(), recv_buffer_->data() + result); | 237 std::vector<char> data(recv_buffer_->data(), recv_buffer_->data() + result); |
| 238 | 238 |
| 239 if (!ContainsKey(connected_peers_, recv_address_)) { | 239 if (!base::ContainsKey(connected_peers_, recv_address_)) { |
| 240 P2PSocketHost::StunMessageType type; | 240 P2PSocketHost::StunMessageType type; |
| 241 bool stun = GetStunPacketType(&*data.begin(), data.size(), &type); | 241 bool stun = GetStunPacketType(&*data.begin(), data.size(), &type); |
| 242 if ((stun && IsRequestOrResponse(type))) { | 242 if ((stun && IsRequestOrResponse(type))) { |
| 243 connected_peers_.insert(recv_address_); | 243 connected_peers_.insert(recv_address_); |
| 244 } else if (!stun || type == STUN_DATA_INDICATION) { | 244 } else if (!stun || type == STUN_DATA_INDICATION) { |
| 245 LOG(ERROR) << "Received unexpected data packet from " | 245 LOG(ERROR) << "Received unexpected data packet from " |
| 246 << recv_address_.ToString() | 246 << recv_address_.ToString() |
| 247 << " before STUN binding is finished."; | 247 << " before STUN binding is finished."; |
| 248 return; | 248 return; |
| 249 } | 249 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 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 (!ContainsKey(connected_peers_, to)) { | 273 if (!base::ContainsKey(connected_peers_, to)) { |
| 274 P2PSocketHost::StunMessageType type = P2PSocketHost::StunMessageType(); | 274 P2PSocketHost::StunMessageType type = P2PSocketHost::StunMessageType(); |
| 275 bool stun = GetStunPacketType(&*data.begin(), data.size(), &type); | 275 bool stun = GetStunPacketType(&*data.begin(), data.size(), &type); |
| 276 if (!stun || type == STUN_DATA_INDICATION) { | 276 if (!stun || type == STUN_DATA_INDICATION) { |
| 277 LOG(ERROR) << "Page tried to send a data packet to " << to.ToString() | 277 LOG(ERROR) << "Page tried to send a data packet to " << to.ToString() |
| 278 << " before STUN binding is finished."; | 278 << " before STUN binding is finished."; |
| 279 OnError(); | 279 OnError(); |
| 280 return; | 280 return; |
| 281 } | 281 } |
| 282 | 282 |
| 283 if (throttler_->DropNextPacket(data.size())) { | 283 if (throttler_->DropNextPacket(data.size())) { |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 net::UDPServerSocket* socket = new net::UDPServerSocket( | 435 net::UDPServerSocket* socket = new net::UDPServerSocket( |
| 436 GetContentClient()->browser()->GetNetLog(), net::NetLog::Source()); | 436 GetContentClient()->browser()->GetNetLog(), net::NetLog::Source()); |
| 437 #if defined(OS_WIN) | 437 #if defined(OS_WIN) |
| 438 socket->UseNonBlockingIO(); | 438 socket->UseNonBlockingIO(); |
| 439 #endif | 439 #endif |
| 440 | 440 |
| 441 return base::WrapUnique(socket); | 441 return base::WrapUnique(socket); |
| 442 } | 442 } |
| 443 | 443 |
| 444 } // namespace content | 444 } // namespace content |
| OLD | NEW |