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" |
11 #include "jingle/glue/proxy_resolving_client_socket.h" | 11 #include "jingle/glue/proxy_resolving_client_socket.h" |
12 #include "net/base/io_buffer.h" | 12 #include "net/base/io_buffer.h" |
13 #include "net/base/net_errors.h" | 13 #include "net/base/net_errors.h" |
14 #include "net/base/net_util.h" | 14 #include "net/base/net_util.h" |
15 #include "net/socket/client_socket_factory.h" | 15 #include "net/socket/client_socket_factory.h" |
16 #include "net/socket/client_socket_handle.h" | 16 #include "net/socket/client_socket_handle.h" |
17 #include "net/socket/ssl_client_socket.h" | 17 #include "net/socket/ssl_client_socket.h" |
18 #include "net/socket/tcp_client_socket.h" | 18 #include "net/socket/tcp_client_socket.h" |
19 #include "net/url_request/url_request_context.h" | 19 #include "net/url_request/url_request_context.h" |
20 #include "net/url_request/url_request_context_getter.h" | 20 #include "net/url_request/url_request_context_getter.h" |
21 #include "third_party/libjingle/source/talk/base/asyncpacketsocket.h" | |
21 | 22 |
22 namespace { | 23 namespace { |
23 | 24 |
24 typedef uint16 PacketLength; | 25 typedef uint16 PacketLength; |
25 const int kPacketHeaderSize = sizeof(PacketLength); | 26 const int kPacketHeaderSize = sizeof(PacketLength); |
26 const int kReadBufferSize = 4096; | 27 const int kReadBufferSize = 4096; |
27 const int kPacketLengthOffset = 2; | 28 const int kPacketLengthOffset = 2; |
28 const int kTurnChannelDataHeaderSize = 4; | 29 const int kTurnChannelDataHeaderSize = 4; |
29 const int kRecvSocketBufferSize = 128 * 1024; | 30 const int kRecvSocketBufferSize = 128 * 1024; |
30 const int kSendSocketBufferSize = 128 * 1024; | 31 const int kSendSocketBufferSize = 128 * 1024; |
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
447 } | 448 } |
448 | 449 |
449 void P2PSocketHostTcp::DoSend(const net::IPEndPoint& to, | 450 void P2PSocketHostTcp::DoSend(const net::IPEndPoint& to, |
450 const std::vector<char>& data) { | 451 const std::vector<char>& data) { |
451 int size = kPacketHeaderSize + data.size(); | 452 int size = kPacketHeaderSize + data.size(); |
452 scoped_refptr<net::DrainableIOBuffer> buffer = | 453 scoped_refptr<net::DrainableIOBuffer> buffer = |
453 new net::DrainableIOBuffer(new net::IOBuffer(size), size); | 454 new net::DrainableIOBuffer(new net::IOBuffer(size), size); |
454 *reinterpret_cast<uint16*>(buffer->data()) = base::HostToNet16(data.size()); | 455 *reinterpret_cast<uint16*>(buffer->data()) = base::HostToNet16(data.size()); |
455 memcpy(buffer->data() + kPacketHeaderSize, &data[0], data.size()); | 456 memcpy(buffer->data() + kPacketHeaderSize, &data[0], data.size()); |
456 | 457 |
458 talk_base::PacketOptions options; | |
Solis
2014/02/26 15:49:34
So I guess initializing 'options' to something oth
Mallinath (Gone from Chromium)
2014/02/26 19:59:20
Yes.
On 2014/02/26 15:49:34, Solis wrote:
| |
459 MaybeUpdatePacketSendTimeExtn(buffer->data(), buffer->BytesRemaining(), | |
460 options); | |
461 | |
457 WriteOrQueue(buffer); | 462 WriteOrQueue(buffer); |
458 } | 463 } |
459 | 464 |
460 // P2PSocketHostStunTcp | 465 // P2PSocketHostStunTcp |
461 P2PSocketHostStunTcp::P2PSocketHostStunTcp( | 466 P2PSocketHostStunTcp::P2PSocketHostStunTcp( |
462 IPC::Sender* message_sender, int id, | 467 IPC::Sender* message_sender, int id, |
463 P2PSocketType type, net::URLRequestContextGetter* url_context) | 468 P2PSocketType type, net::URLRequestContextGetter* url_context) |
464 : P2PSocketHostTcpBase(message_sender, id, type, url_context) { | 469 : P2PSocketHostTcpBase(message_sender, id, type, url_context) { |
465 DCHECK(type == P2P_SOCKET_STUN_TCP_CLIENT || | 470 DCHECK(type == P2P_SOCKET_STUN_TCP_CLIENT || |
466 type == P2P_SOCKET_STUN_SSLTCP_CLIENT || | 471 type == P2P_SOCKET_STUN_SSLTCP_CLIENT || |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
512 return; | 517 return; |
513 } | 518 } |
514 | 519 |
515 // Add any pad bytes to the total size. | 520 // Add any pad bytes to the total size. |
516 int size = data.size() + pad_bytes; | 521 int size = data.size() + pad_bytes; |
517 | 522 |
518 scoped_refptr<net::DrainableIOBuffer> buffer = | 523 scoped_refptr<net::DrainableIOBuffer> buffer = |
519 new net::DrainableIOBuffer(new net::IOBuffer(size), size); | 524 new net::DrainableIOBuffer(new net::IOBuffer(size), size); |
520 memcpy(buffer->data(), &data[0], data.size()); | 525 memcpy(buffer->data(), &data[0], data.size()); |
521 | 526 |
527 // Update HMAC before writing padding bytes at the end. | |
528 talk_base::PacketOptions options; | |
529 MaybeUpdatePacketSendTimeExtn(buffer->data(), data.size(), options); | |
530 | |
522 if (pad_bytes) { | 531 if (pad_bytes) { |
523 char padding[4] = {0}; | 532 char padding[4] = {0}; |
524 DCHECK_LE(pad_bytes, 4); | 533 DCHECK_LE(pad_bytes, 4); |
525 memcpy(buffer->data() + data.size(), padding, pad_bytes); | 534 memcpy(buffer->data() + data.size(), padding, pad_bytes); |
526 } | 535 } |
527 WriteOrQueue(buffer); | 536 WriteOrQueue(buffer); |
528 } | 537 } |
529 | 538 |
530 int P2PSocketHostStunTcp::GetExpectedPacketSize( | 539 int P2PSocketHostStunTcp::GetExpectedPacketSize( |
531 const char* data, int len, int* pad_bytes) { | 540 const char* data, int len, int* pad_bytes) { |
(...skipping 12 matching lines...) Expand all Loading... | |
544 } else { | 553 } else { |
545 packet_size += kTurnChannelDataHeaderSize; | 554 packet_size += kTurnChannelDataHeaderSize; |
546 // Calculate any padding if present. | 555 // Calculate any padding if present. |
547 if (packet_size % 4) | 556 if (packet_size % 4) |
548 *pad_bytes = 4 - packet_size % 4; | 557 *pad_bytes = 4 - packet_size % 4; |
549 } | 558 } |
550 return packet_size; | 559 return packet_size; |
551 } | 560 } |
552 | 561 |
553 } // namespace content | 562 } // namespace content |
OLD | NEW |