| Index: content/browser/renderer_host/p2p_socket_host.cc
|
| diff --git a/content/browser/renderer_host/p2p_socket_host.cc b/content/browser/renderer_host/p2p_socket_host.cc
|
| index c1e8849e97f2634ea001626426af4c7e2c1d3707..39e01196b51aa2343760176c73b3914c4069227a 100644
|
| --- a/content/browser/renderer_host/p2p_socket_host.cc
|
| +++ b/content/browser/renderer_host/p2p_socket_host.cc
|
| @@ -4,26 +4,86 @@
|
|
|
| #include "content/browser/renderer_host/p2p_socket_host.h"
|
|
|
| +#include "build/build_config.h"
|
| +
|
| +#if defined(OS_WIN)
|
| +#include <winsock2.h> // for htonl
|
| +#else
|
| +#include <arpa/inet.h>
|
| +#endif
|
| +
|
| #include "content/browser/renderer_host/p2p_socket_host_udp.h"
|
|
|
| -P2PSocketHost::P2PSocketHost(P2PSocketsHost* host, int routing_id, int id)
|
| - : host_(host), routing_id_(routing_id), id_(id) {
|
| +namespace {
|
| +const int kStunHeaderSize = 20;
|
| +const uint32 kStunMagicCookie = 0x2112A442;
|
| +} // namespace
|
| +
|
| +P2PSocketHost::P2PSocketHost(IPC::Message::Sender* message_sender,
|
| + int routing_id, int id)
|
| + : message_sender_(message_sender), routing_id_(routing_id), id_(id) {
|
| }
|
|
|
| P2PSocketHost::~P2PSocketHost() { }
|
|
|
| +// Verifies that the packet |data| has a valid STUN header.
|
| +bool P2PSocketHost::GetStunPacketType(
|
| + const char* data, int data_size, StunMessageType* type) {
|
| +
|
| + if (data_size < kStunHeaderSize)
|
| + return false;
|
| +
|
| + // TODO(sergeyu): Fix libjingle to format STUN message according to
|
| + // RFC5389 and validate STUN magic cookie here.
|
| + //
|
| + // uint32 cookie = ntohl(*reinterpret_cast<const uint32*>(data + 4));
|
| + // if (cookie != kStunMagicCookie)
|
| + // return false;
|
| +
|
| + uint16 length = ntohs(*reinterpret_cast<const uint16*>(data + 2));
|
| + if (length != data_size - kStunHeaderSize)
|
| + return false;
|
| +
|
| + int message_type = ntohs(*reinterpret_cast<const uint16*>(data));
|
| +
|
| + // Verify that the type is known:
|
| + switch (message_type) {
|
| + case STUN_BINDING_REQUEST:
|
| + case STUN_BINDING_RESPONSE:
|
| + case STUN_BINDING_ERROR_RESPONSE:
|
| + case STUN_SHARED_SECRET_REQUEST:
|
| + case STUN_SHARED_SECRET_RESPONSE:
|
| + case STUN_SHARED_SECRET_ERROR_RESPONSE:
|
| + case STUN_ALLOCATE_REQUEST:
|
| + case STUN_ALLOCATE_RESPONSE:
|
| + case STUN_ALLOCATE_ERROR_RESPONSE:
|
| + case STUN_SEND_REQUEST:
|
| + case STUN_SEND_RESPONSE:
|
| + case STUN_SEND_ERROR_RESPONSE:
|
| + case STUN_DATA_INDICATION:
|
| + *type = static_cast<StunMessageType>(message_type);
|
| + return true;
|
| +
|
| + default:
|
| + return false;
|
| + }
|
| +}
|
| +
|
| // static
|
| P2PSocketHost* P2PSocketHost::Create(
|
| - P2PSocketsHost* host, int routing_id, int id, P2PSocketType type) {
|
| + IPC::Message::Sender* message_sender, int routing_id, int id,
|
| + P2PSocketType type) {
|
| switch (type) {
|
| case P2P_SOCKET_UDP:
|
| - return new P2PSocketHostUdp(host, routing_id, id);
|
| + return new P2PSocketHostUdp(message_sender, routing_id, id);
|
|
|
| case P2P_SOCKET_TCP_SERVER:
|
| // TODO(sergeyu): Implement TCP sockets support.
|
| + NOTIMPLEMENTED();
|
| return NULL;
|
|
|
| case P2P_SOCKET_TCP_CLIENT:
|
| + NOTIMPLEMENTED();
|
| return NULL;
|
| }
|
|
|
|
|