| 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_tcp.h" | 5 #include "content/browser/renderer_host/p2p/socket_host_tcp.h" |
| 6 | 6 |
| 7 #include "base/sys_byteorder.h" | 7 #include "base/sys_byteorder.h" |
| 8 #include "content/common/p2p_messages.h" | 8 #include "content/common/p2p_messages.h" |
| 9 #include "ipc/ipc_sender.h" | 9 #include "ipc/ipc_sender.h" |
| 10 #include "jingle/glue/fake_ssl_client_socket.h" | 10 #include "jingle/glue/fake_ssl_client_socket.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 bool IsPseudoTlsClientSocket(content::P2PSocketType type) { | 38 bool IsPseudoTlsClientSocket(content::P2PSocketType type) { |
| 39 return (type == content::P2P_SOCKET_SSLTCP_CLIENT || | 39 return (type == content::P2P_SOCKET_SSLTCP_CLIENT || |
| 40 type == content::P2P_SOCKET_STUN_SSLTCP_CLIENT); | 40 type == content::P2P_SOCKET_STUN_SSLTCP_CLIENT); |
| 41 } | 41 } |
| 42 | 42 |
| 43 } // namespace | 43 } // namespace |
| 44 | 44 |
| 45 namespace content { | 45 namespace content { |
| 46 | 46 |
| 47 P2PSocketHostTcpBase::P2PSocketHostTcpBase( | 47 P2PSocketHostTcpBase::P2PSocketHostTcpBase( |
| 48 IPC::Sender* message_sender, int id, | 48 IPC::Sender* message_sender, |
| 49 P2PSocketType type, net::URLRequestContextGetter* url_context) | 49 int socket_id, |
| 50 : P2PSocketHost(message_sender, id), | 50 int render_process_host_id, |
| 51 P2PSocketType type, |
| 52 net::URLRequestContextGetter* url_context) |
| 53 : P2PSocketHost(message_sender, socket_id, render_process_host_id), |
| 51 write_pending_(false), | 54 write_pending_(false), |
| 52 connected_(false), | 55 connected_(false), |
| 53 type_(type), | 56 type_(type), |
| 54 url_context_(url_context) { | 57 url_context_(url_context) { |
| 55 } | 58 } |
| 56 | 59 |
| 57 P2PSocketHostTcpBase::~P2PSocketHostTcpBase() { | 60 P2PSocketHostTcpBase::~P2PSocketHostTcpBase() { |
| 58 if (state_ == STATE_OPEN) { | 61 if (state_ == STATE_OPEN) { |
| 59 DCHECK(socket_.get()); | 62 DCHECK(socket_.get()); |
| 60 socket_.reset(); | 63 socket_.reset(); |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 << remote_address_.ip_address.ToString() | 283 << remote_address_.ip_address.ToString() |
| 281 << " before STUN binding is finished. " | 284 << " before STUN binding is finished. " |
| 282 << "Terminating connection."; | 285 << "Terminating connection."; |
| 283 OnError(); | 286 OnError(); |
| 284 return; | 287 return; |
| 285 } | 288 } |
| 286 } | 289 } |
| 287 | 290 |
| 288 message_sender_->Send(new P2PMsg_OnDataReceived( | 291 message_sender_->Send(new P2PMsg_OnDataReceived( |
| 289 id_, remote_address_.ip_address, data, base::TimeTicks::Now())); | 292 id_, remote_address_.ip_address, data, base::TimeTicks::Now())); |
| 293 |
| 294 if (dump_incoming_rtp_packet_) |
| 295 DumpRtpPacket(data.data(), data.size(), true); |
| 290 } | 296 } |
| 291 | 297 |
| 292 // Note: dscp is not actually used on TCP sockets as this point, | 298 // Note: dscp is not actually used on TCP sockets as this point, |
| 293 // but may be honored in the future. | 299 // but may be honored in the future. |
| 294 void P2PSocketHostTcpBase::Send(const net::IPEndPoint& to, | 300 void P2PSocketHostTcpBase::Send(const net::IPEndPoint& to, |
| 295 const std::vector<char>& data, | 301 const std::vector<char>& data, |
| 296 const talk_base::PacketOptions& options, | 302 const talk_base::PacketOptions& options, |
| 297 uint64 packet_id) { | 303 uint64 packet_id) { |
| 298 if (!socket_) { | 304 if (!socket_) { |
| 299 // The Send message may be sent after the an OnError message was | 305 // The Send message may be sent after the an OnError message was |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 case P2P_SOCKET_OPT_SNDBUF: | 422 case P2P_SOCKET_OPT_SNDBUF: |
| 417 return socket_->SetSendBufferSize(value) == net::OK; | 423 return socket_->SetSendBufferSize(value) == net::OK; |
| 418 case P2P_SOCKET_OPT_DSCP: | 424 case P2P_SOCKET_OPT_DSCP: |
| 419 return false; // For TCP sockets DSCP setting is not available. | 425 return false; // For TCP sockets DSCP setting is not available. |
| 420 default: | 426 default: |
| 421 NOTREACHED(); | 427 NOTREACHED(); |
| 422 return false; | 428 return false; |
| 423 } | 429 } |
| 424 } | 430 } |
| 425 | 431 |
| 426 P2PSocketHostTcp::P2PSocketHostTcp( | 432 P2PSocketHostTcp::P2PSocketHostTcp(IPC::Sender* message_sender, |
| 427 IPC::Sender* message_sender, int id, | 433 int socket_id, |
| 428 P2PSocketType type, net::URLRequestContextGetter* url_context) | 434 int render_process_host_id, |
| 429 : P2PSocketHostTcpBase(message_sender, id, type, url_context) { | 435 P2PSocketType type, |
| 436 net::URLRequestContextGetter* url_context) |
| 437 : P2PSocketHostTcpBase(message_sender, |
| 438 socket_id, |
| 439 render_process_host_id, |
| 440 type, |
| 441 url_context) { |
| 430 DCHECK(type == P2P_SOCKET_TCP_CLIENT || | 442 DCHECK(type == P2P_SOCKET_TCP_CLIENT || |
| 431 type == P2P_SOCKET_SSLTCP_CLIENT || | 443 type == P2P_SOCKET_SSLTCP_CLIENT || |
| 432 type == P2P_SOCKET_TLS_CLIENT); | 444 type == P2P_SOCKET_TLS_CLIENT); |
| 433 } | 445 } |
| 434 | 446 |
| 435 P2PSocketHostTcp::~P2PSocketHostTcp() { | 447 P2PSocketHostTcp::~P2PSocketHostTcp() { |
| 436 } | 448 } |
| 437 | 449 |
| 438 int P2PSocketHostTcp::ProcessInput(char* input, int input_len) { | 450 int P2PSocketHostTcp::ProcessInput(char* input, int input_len) { |
| 439 if (input_len < kPacketHeaderSize) | 451 if (input_len < kPacketHeaderSize) |
| (...skipping 22 matching lines...) Expand all Loading... |
| 462 packet_processing_helpers::ApplyPacketOptions( | 474 packet_processing_helpers::ApplyPacketOptions( |
| 463 buffer->data() + kPacketHeaderSize, | 475 buffer->data() + kPacketHeaderSize, |
| 464 buffer->BytesRemaining() - kPacketHeaderSize, | 476 buffer->BytesRemaining() - kPacketHeaderSize, |
| 465 options, 0); | 477 options, 0); |
| 466 | 478 |
| 467 WriteOrQueue(buffer); | 479 WriteOrQueue(buffer); |
| 468 } | 480 } |
| 469 | 481 |
| 470 // P2PSocketHostStunTcp | 482 // P2PSocketHostStunTcp |
| 471 P2PSocketHostStunTcp::P2PSocketHostStunTcp( | 483 P2PSocketHostStunTcp::P2PSocketHostStunTcp( |
| 472 IPC::Sender* message_sender, int id, | 484 IPC::Sender* message_sender, |
| 473 P2PSocketType type, net::URLRequestContextGetter* url_context) | 485 int socket_id, |
| 474 : P2PSocketHostTcpBase(message_sender, id, type, url_context) { | 486 int render_process_host_id, |
| 487 P2PSocketType type, |
| 488 net::URLRequestContextGetter* url_context) |
| 489 : P2PSocketHostTcpBase(message_sender, |
| 490 socket_id, |
| 491 render_process_host_id, |
| 492 type, |
| 493 url_context) { |
| 475 DCHECK(type == P2P_SOCKET_STUN_TCP_CLIENT || | 494 DCHECK(type == P2P_SOCKET_STUN_TCP_CLIENT || |
| 476 type == P2P_SOCKET_STUN_SSLTCP_CLIENT || | 495 type == P2P_SOCKET_STUN_SSLTCP_CLIENT || |
| 477 type == P2P_SOCKET_STUN_TLS_CLIENT); | 496 type == P2P_SOCKET_STUN_TLS_CLIENT); |
| 478 } | 497 } |
| 479 | 498 |
| 480 P2PSocketHostStunTcp::~P2PSocketHostStunTcp() { | 499 P2PSocketHostStunTcp::~P2PSocketHostStunTcp() { |
| 481 } | 500 } |
| 482 | 501 |
| 483 int P2PSocketHostStunTcp::ProcessInput(char* input, int input_len) { | 502 int P2PSocketHostStunTcp::ProcessInput(char* input, int input_len) { |
| 484 if (input_len < kPacketHeaderSize + kPacketLengthOffset) | 503 if (input_len < kPacketHeaderSize + kPacketLengthOffset) |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 532 | 551 |
| 533 packet_processing_helpers::ApplyPacketOptions( | 552 packet_processing_helpers::ApplyPacketOptions( |
| 534 buffer->data(), data.size(), options, 0); | 553 buffer->data(), data.size(), options, 0); |
| 535 | 554 |
| 536 if (pad_bytes) { | 555 if (pad_bytes) { |
| 537 char padding[4] = {0}; | 556 char padding[4] = {0}; |
| 538 DCHECK_LE(pad_bytes, 4); | 557 DCHECK_LE(pad_bytes, 4); |
| 539 memcpy(buffer->data() + data.size(), padding, pad_bytes); | 558 memcpy(buffer->data() + data.size(), padding, pad_bytes); |
| 540 } | 559 } |
| 541 WriteOrQueue(buffer); | 560 WriteOrQueue(buffer); |
| 561 |
| 562 if (dump_outgoing_rtp_packet_) |
| 563 DumpRtpPacket(buffer->data(), data.size(), false); |
| 542 } | 564 } |
| 543 | 565 |
| 544 int P2PSocketHostStunTcp::GetExpectedPacketSize( | 566 int P2PSocketHostStunTcp::GetExpectedPacketSize( |
| 545 const char* data, int len, int* pad_bytes) { | 567 const char* data, int len, int* pad_bytes) { |
| 546 DCHECK_LE(kTurnChannelDataHeaderSize, len); | 568 DCHECK_LE(kTurnChannelDataHeaderSize, len); |
| 547 // Both stun and turn had length at offset 2. | 569 // Both stun and turn had length at offset 2. |
| 548 int packet_size = base::NetToHost16(*reinterpret_cast<const uint16*>( | 570 int packet_size = base::NetToHost16(*reinterpret_cast<const uint16*>( |
| 549 data + kPacketLengthOffset)); | 571 data + kPacketLengthOffset)); |
| 550 | 572 |
| 551 // Get packet type (STUN or TURN). | 573 // Get packet type (STUN or TURN). |
| 552 uint16 msg_type = base::NetToHost16(*reinterpret_cast<const uint16*>(data)); | 574 uint16 msg_type = base::NetToHost16(*reinterpret_cast<const uint16*>(data)); |
| 553 | 575 |
| 554 *pad_bytes = 0; | 576 *pad_bytes = 0; |
| 555 // Add heder length to packet length. | 577 // Add heder length to packet length. |
| 556 if ((msg_type & 0xC000) == 0) { | 578 if ((msg_type & 0xC000) == 0) { |
| 557 packet_size += kStunHeaderSize; | 579 packet_size += kStunHeaderSize; |
| 558 } else { | 580 } else { |
| 559 packet_size += kTurnChannelDataHeaderSize; | 581 packet_size += kTurnChannelDataHeaderSize; |
| 560 // Calculate any padding if present. | 582 // Calculate any padding if present. |
| 561 if (packet_size % 4) | 583 if (packet_size % 4) |
| 562 *pad_bytes = 4 - packet_size % 4; | 584 *pad_bytes = 4 - packet_size % 4; |
| 563 } | 585 } |
| 564 return packet_size; | 586 return packet_size; |
| 565 } | 587 } |
| 566 | 588 |
| 567 } // namespace content | 589 } // namespace content |
| OLD | NEW |