| 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_dispatcher_host.h" | 5 #include "content/browser/renderer_host/p2p/socket_dispatcher_host.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| 11 #include "content/browser/bad_message.h" |
| 11 #include "content/browser/renderer_host/p2p/socket_host.h" | 12 #include "content/browser/renderer_host/p2p/socket_host.h" |
| 12 #include "content/common/p2p_messages.h" | 13 #include "content/common/p2p_messages.h" |
| 13 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
| 14 #include "content/public/browser/resource_context.h" | 15 #include "content/public/browser/resource_context.h" |
| 15 #include "net/base/address_list.h" | 16 #include "net/base/address_list.h" |
| 16 #include "net/base/completion_callback.h" | 17 #include "net/base/completion_callback.h" |
| 17 #include "net/base/net_errors.h" | 18 #include "net/base/net_errors.h" |
| 18 #include "net/base/network_interfaces.h" | 19 #include "net/base/network_interfaces.h" |
| 19 #include "net/base/sys_addrinfo.h" | 20 #include "net/base/sys_addrinfo.h" |
| 20 #include "net/dns/single_request_host_resolver.h" | 21 #include "net/dns/single_request_host_resolver.h" |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 int32_t request_id) { | 231 int32_t request_id) { |
| 231 DnsRequest* request = new DnsRequest(request_id, | 232 DnsRequest* request = new DnsRequest(request_id, |
| 232 resource_context_->GetHostResolver()); | 233 resource_context_->GetHostResolver()); |
| 233 dns_requests_.insert(request); | 234 dns_requests_.insert(request); |
| 234 request->Resolve(host_name, base::Bind( | 235 request->Resolve(host_name, base::Bind( |
| 235 &P2PSocketDispatcherHost::OnAddressResolved, | 236 &P2PSocketDispatcherHost::OnAddressResolved, |
| 236 base::Unretained(this), request)); | 237 base::Unretained(this), request)); |
| 237 } | 238 } |
| 238 | 239 |
| 239 void P2PSocketDispatcherHost::OnCreateSocket( | 240 void P2PSocketDispatcherHost::OnCreateSocket( |
| 240 P2PSocketType type, int socket_id, | 241 P2PSocketType type, |
| 242 int socket_id, |
| 241 const net::IPEndPoint& local_address, | 243 const net::IPEndPoint& local_address, |
| 244 const P2PPortRange& port_range, |
| 242 const P2PHostAndIPEndPoint& remote_address) { | 245 const P2PHostAndIPEndPoint& remote_address) { |
| 246 if (port_range.min_port < port_range.max_port || |
| 247 (port_range.min_port == 0 && port_range.max_port != 0)) { |
| 248 bad_message::ReceivedBadMessage(this, bad_message::SDH_INVALID_PORT_RANGE); |
| 249 return; |
| 250 } |
| 251 |
| 243 if (LookupSocket(socket_id)) { | 252 if (LookupSocket(socket_id)) { |
| 244 LOG(ERROR) << "Received P2PHostMsg_CreateSocket for socket " | 253 LOG(ERROR) << "Received P2PHostMsg_CreateSocket for socket " |
| 245 "that already exists."; | 254 "that already exists."; |
| 246 return; | 255 return; |
| 247 } | 256 } |
| 248 | 257 |
| 249 std::unique_ptr<P2PSocketHost> socket(P2PSocketHost::Create( | 258 std::unique_ptr<P2PSocketHost> socket(P2PSocketHost::Create( |
| 250 this, socket_id, type, url_context_.get(), &throttler_)); | 259 this, socket_id, type, url_context_.get(), &throttler_)); |
| 251 | 260 |
| 252 if (!socket) { | 261 if (!socket) { |
| 253 Send(new P2PMsg_OnError(socket_id)); | 262 Send(new P2PMsg_OnError(socket_id)); |
| 254 return; | 263 return; |
| 255 } | 264 } |
| 256 | 265 |
| 257 if (socket->Init(local_address, remote_address)) { | 266 if (socket->Init(local_address, port_range.min_port, port_range.max_port, |
| 267 remote_address)) { |
| 258 sockets_[socket_id] = socket.release(); | 268 sockets_[socket_id] = socket.release(); |
| 259 | 269 |
| 260 if (dump_incoming_rtp_packet_ || dump_outgoing_rtp_packet_) { | 270 if (dump_incoming_rtp_packet_ || dump_outgoing_rtp_packet_) { |
| 261 sockets_[socket_id]->StartRtpDump(dump_incoming_rtp_packet_, | 271 sockets_[socket_id]->StartRtpDump(dump_incoming_rtp_packet_, |
| 262 dump_outgoing_rtp_packet_, | 272 dump_outgoing_rtp_packet_, |
| 263 packet_callback_); | 273 packet_callback_); |
| 264 } | 274 } |
| 265 } | 275 } |
| 266 } | 276 } |
| 267 | 277 |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 | 414 |
| 405 if (!dump_incoming_rtp_packet_ && !dump_outgoing_rtp_packet_) | 415 if (!dump_incoming_rtp_packet_ && !dump_outgoing_rtp_packet_) |
| 406 packet_callback_.Reset(); | 416 packet_callback_.Reset(); |
| 407 | 417 |
| 408 for (SocketsMap::iterator it = sockets_.begin(); it != sockets_.end(); ++it) | 418 for (SocketsMap::iterator it = sockets_.begin(); it != sockets_.end(); ++it) |
| 409 it->second->StopRtpDump(incoming, outgoing); | 419 it->second->StopRtpDump(incoming, outgoing); |
| 410 } | 420 } |
| 411 } | 421 } |
| 412 | 422 |
| 413 } // namespace content | 423 } // namespace content |
| OLD | NEW |