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

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

Issue 264793017: Implements RTP header dumping. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix leak Created 6 years, 6 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
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_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
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 P2PSocketType type,
51 net::URLRequestContextGetter* url_context)
52 : P2PSocketHost(message_sender, socket_id),
51 write_pending_(false), 53 write_pending_(false),
52 connected_(false), 54 connected_(false),
53 type_(type), 55 type_(type),
54 url_context_(url_context) { 56 url_context_(url_context) {
55 } 57 }
56 58
57 P2PSocketHostTcpBase::~P2PSocketHostTcpBase() { 59 P2PSocketHostTcpBase::~P2PSocketHostTcpBase() {
58 if (state_ == STATE_OPEN) { 60 if (state_ == STATE_OPEN) {
59 DCHECK(socket_.get()); 61 DCHECK(socket_.get());
60 socket_.reset(); 62 socket_.reset();
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 << remote_address_.ip_address.ToString() 282 << remote_address_.ip_address.ToString()
281 << " before STUN binding is finished. " 283 << " before STUN binding is finished. "
282 << "Terminating connection."; 284 << "Terminating connection.";
283 OnError(); 285 OnError();
284 return; 286 return;
285 } 287 }
286 } 288 }
287 289
288 message_sender_->Send(new P2PMsg_OnDataReceived( 290 message_sender_->Send(new P2PMsg_OnDataReceived(
289 id_, remote_address_.ip_address, data, base::TimeTicks::Now())); 291 id_, remote_address_.ip_address, data, base::TimeTicks::Now()));
292
293 if (dump_incoming_rtp_packet_)
294 DumpRtpPacket(&data[0], data.size(), true);
290 } 295 }
291 296
292 // Note: dscp is not actually used on TCP sockets as this point, 297 // Note: dscp is not actually used on TCP sockets as this point,
293 // but may be honored in the future. 298 // but may be honored in the future.
294 void P2PSocketHostTcpBase::Send(const net::IPEndPoint& to, 299 void P2PSocketHostTcpBase::Send(const net::IPEndPoint& to,
295 const std::vector<char>& data, 300 const std::vector<char>& data,
296 const talk_base::PacketOptions& options, 301 const talk_base::PacketOptions& options,
297 uint64 packet_id) { 302 uint64 packet_id) {
298 if (!socket_) { 303 if (!socket_) {
299 // The Send message may be sent after the an OnError message was 304 // The Send message may be sent after the an OnError message was
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 case P2P_SOCKET_OPT_SNDBUF: 421 case P2P_SOCKET_OPT_SNDBUF:
417 return socket_->SetSendBufferSize(value) == net::OK; 422 return socket_->SetSendBufferSize(value) == net::OK;
418 case P2P_SOCKET_OPT_DSCP: 423 case P2P_SOCKET_OPT_DSCP:
419 return false; // For TCP sockets DSCP setting is not available. 424 return false; // For TCP sockets DSCP setting is not available.
420 default: 425 default:
421 NOTREACHED(); 426 NOTREACHED();
422 return false; 427 return false;
423 } 428 }
424 } 429 }
425 430
426 P2PSocketHostTcp::P2PSocketHostTcp( 431 P2PSocketHostTcp::P2PSocketHostTcp(IPC::Sender* message_sender,
427 IPC::Sender* message_sender, int id, 432 int socket_id,
428 P2PSocketType type, net::URLRequestContextGetter* url_context) 433 P2PSocketType type,
429 : P2PSocketHostTcpBase(message_sender, id, type, url_context) { 434 net::URLRequestContextGetter* url_context)
435 : P2PSocketHostTcpBase(message_sender, socket_id, type, url_context) {
430 DCHECK(type == P2P_SOCKET_TCP_CLIENT || 436 DCHECK(type == P2P_SOCKET_TCP_CLIENT ||
431 type == P2P_SOCKET_SSLTCP_CLIENT || 437 type == P2P_SOCKET_SSLTCP_CLIENT ||
432 type == P2P_SOCKET_TLS_CLIENT); 438 type == P2P_SOCKET_TLS_CLIENT);
433 } 439 }
434 440
435 P2PSocketHostTcp::~P2PSocketHostTcp() { 441 P2PSocketHostTcp::~P2PSocketHostTcp() {
436 } 442 }
437 443
438 int P2PSocketHostTcp::ProcessInput(char* input, int input_len) { 444 int P2PSocketHostTcp::ProcessInput(char* input, int input_len) {
439 if (input_len < kPacketHeaderSize) 445 if (input_len < kPacketHeaderSize)
(...skipping 22 matching lines...) Expand all
462 packet_processing_helpers::ApplyPacketOptions( 468 packet_processing_helpers::ApplyPacketOptions(
463 buffer->data() + kPacketHeaderSize, 469 buffer->data() + kPacketHeaderSize,
464 buffer->BytesRemaining() - kPacketHeaderSize, 470 buffer->BytesRemaining() - kPacketHeaderSize,
465 options, 0); 471 options, 0);
466 472
467 WriteOrQueue(buffer); 473 WriteOrQueue(buffer);
468 } 474 }
469 475
470 // P2PSocketHostStunTcp 476 // P2PSocketHostStunTcp
471 P2PSocketHostStunTcp::P2PSocketHostStunTcp( 477 P2PSocketHostStunTcp::P2PSocketHostStunTcp(
472 IPC::Sender* message_sender, int id, 478 IPC::Sender* message_sender,
473 P2PSocketType type, net::URLRequestContextGetter* url_context) 479 int socket_id,
474 : P2PSocketHostTcpBase(message_sender, id, type, url_context) { 480 P2PSocketType type,
481 net::URLRequestContextGetter* url_context)
482 : P2PSocketHostTcpBase(message_sender, socket_id, type, url_context) {
475 DCHECK(type == P2P_SOCKET_STUN_TCP_CLIENT || 483 DCHECK(type == P2P_SOCKET_STUN_TCP_CLIENT ||
476 type == P2P_SOCKET_STUN_SSLTCP_CLIENT || 484 type == P2P_SOCKET_STUN_SSLTCP_CLIENT ||
477 type == P2P_SOCKET_STUN_TLS_CLIENT); 485 type == P2P_SOCKET_STUN_TLS_CLIENT);
478 } 486 }
479 487
480 P2PSocketHostStunTcp::~P2PSocketHostStunTcp() { 488 P2PSocketHostStunTcp::~P2PSocketHostStunTcp() {
481 } 489 }
482 490
483 int P2PSocketHostStunTcp::ProcessInput(char* input, int input_len) { 491 int P2PSocketHostStunTcp::ProcessInput(char* input, int input_len) {
484 if (input_len < kPacketHeaderSize + kPacketLengthOffset) 492 if (input_len < kPacketHeaderSize + kPacketLengthOffset)
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 540
533 packet_processing_helpers::ApplyPacketOptions( 541 packet_processing_helpers::ApplyPacketOptions(
534 buffer->data(), data.size(), options, 0); 542 buffer->data(), data.size(), options, 0);
535 543
536 if (pad_bytes) { 544 if (pad_bytes) {
537 char padding[4] = {0}; 545 char padding[4] = {0};
538 DCHECK_LE(pad_bytes, 4); 546 DCHECK_LE(pad_bytes, 4);
539 memcpy(buffer->data() + data.size(), padding, pad_bytes); 547 memcpy(buffer->data() + data.size(), padding, pad_bytes);
540 } 548 }
541 WriteOrQueue(buffer); 549 WriteOrQueue(buffer);
550
551 if (dump_outgoing_rtp_packet_)
552 DumpRtpPacket(buffer->data(), data.size(), false);
542 } 553 }
543 554
544 int P2PSocketHostStunTcp::GetExpectedPacketSize( 555 int P2PSocketHostStunTcp::GetExpectedPacketSize(
545 const char* data, int len, int* pad_bytes) { 556 const char* data, int len, int* pad_bytes) {
546 DCHECK_LE(kTurnChannelDataHeaderSize, len); 557 DCHECK_LE(kTurnChannelDataHeaderSize, len);
547 // Both stun and turn had length at offset 2. 558 // Both stun and turn had length at offset 2.
548 int packet_size = base::NetToHost16(*reinterpret_cast<const uint16*>( 559 int packet_size = base::NetToHost16(*reinterpret_cast<const uint16*>(
549 data + kPacketLengthOffset)); 560 data + kPacketLengthOffset));
550 561
551 // Get packet type (STUN or TURN). 562 // Get packet type (STUN or TURN).
552 uint16 msg_type = base::NetToHost16(*reinterpret_cast<const uint16*>(data)); 563 uint16 msg_type = base::NetToHost16(*reinterpret_cast<const uint16*>(data));
553 564
554 *pad_bytes = 0; 565 *pad_bytes = 0;
555 // Add heder length to packet length. 566 // Add heder length to packet length.
556 if ((msg_type & 0xC000) == 0) { 567 if ((msg_type & 0xC000) == 0) {
557 packet_size += kStunHeaderSize; 568 packet_size += kStunHeaderSize;
558 } else { 569 } else {
559 packet_size += kTurnChannelDataHeaderSize; 570 packet_size += kTurnChannelDataHeaderSize;
560 // Calculate any padding if present. 571 // Calculate any padding if present.
561 if (packet_size % 4) 572 if (packet_size % 4)
562 *pad_bytes = 4 - packet_size % 4; 573 *pad_bytes = 4 - packet_size % 4;
563 } 574 }
564 return packet_size; 575 return packet_size;
565 } 576 }
566 577
567 } // namespace content 578 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/p2p/socket_host_tcp.h ('k') | content/browser/renderer_host/p2p/socket_host_tcp_server.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698