| 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.h" | 5 #include "content/browser/renderer_host/p2p/socket_host.h" |
| 6 | 6 |
| 7 #include "base/sys_byteorder.h" | 7 #include "base/sys_byteorder.h" |
| 8 #include "content/browser/renderer_host/p2p/socket_host_tcp.h" | 8 #include "content/browser/renderer_host/p2p/socket_host_tcp.h" |
| 9 #include "content/browser/renderer_host/p2p/socket_host_tcp_server.h" | 9 #include "content/browser/renderer_host/p2p/socket_host_tcp_server.h" |
| 10 #include "content/browser/renderer_host/p2p/socket_host_udp.h" | 10 #include "content/browser/renderer_host/p2p/socket_host_udp.h" |
| 11 | 11 |
| 12 namespace { | 12 namespace { |
| 13 const int kStunHeaderSize = 20; | 13 const int kStunHeaderSize = 20; |
| 14 const uint32 kStunMagicCookie = 0x2112A442; | 14 const uint32 kStunMagicCookie = 0x2112A442; |
| 15 } // namespace | 15 } // namespace |
| 16 | 16 |
| 17 namespace content { | 17 namespace content { |
| 18 | 18 |
| 19 P2PSocketHost::P2PSocketHost(IPC::Sender* message_sender, | 19 P2PSocketHost::P2PSocketHost(IPC::Sender* message_sender, int id) |
| 20 int routing_id, int id) | |
| 21 : message_sender_(message_sender), | 20 : message_sender_(message_sender), |
| 22 routing_id_(routing_id), | |
| 23 id_(id), | 21 id_(id), |
| 24 state_(STATE_UNINITIALIZED) { | 22 state_(STATE_UNINITIALIZED) { |
| 25 } | 23 } |
| 26 | 24 |
| 27 P2PSocketHost::~P2PSocketHost() { } | 25 P2PSocketHost::~P2PSocketHost() { } |
| 28 | 26 |
| 29 // Verifies that the packet |data| has a valid STUN header. | 27 // Verifies that the packet |data| has a valid STUN header. |
| 30 // static | 28 // static |
| 31 bool P2PSocketHost::GetStunPacketType( | 29 bool P2PSocketHost::GetStunPacketType( |
| 32 const char* data, int data_size, StunMessageType* type) { | 30 const char* data, int data_size, StunMessageType* type) { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 } | 66 } |
| 69 | 67 |
| 70 // static | 68 // static |
| 71 bool P2PSocketHost::IsRequestOrResponse(StunMessageType type) { | 69 bool P2PSocketHost::IsRequestOrResponse(StunMessageType type) { |
| 72 return type == STUN_BINDING_REQUEST || type == STUN_BINDING_RESPONSE || | 70 return type == STUN_BINDING_REQUEST || type == STUN_BINDING_RESPONSE || |
| 73 type == STUN_ALLOCATE_REQUEST || type == STUN_ALLOCATE_RESPONSE; | 71 type == STUN_ALLOCATE_REQUEST || type == STUN_ALLOCATE_RESPONSE; |
| 74 } | 72 } |
| 75 | 73 |
| 76 // static | 74 // static |
| 77 P2PSocketHost* P2PSocketHost::Create( | 75 P2PSocketHost* P2PSocketHost::Create( |
| 78 IPC::Sender* message_sender, int routing_id, int id, | 76 IPC::Sender* message_sender, int id, P2PSocketType type) { |
| 79 P2PSocketType type) { | |
| 80 switch (type) { | 77 switch (type) { |
| 81 case P2P_SOCKET_UDP: | 78 case P2P_SOCKET_UDP: |
| 82 return new P2PSocketHostUdp(message_sender, routing_id, id); | 79 return new P2PSocketHostUdp(message_sender, id); |
| 83 | 80 |
| 84 case P2P_SOCKET_TCP_SERVER: | 81 case P2P_SOCKET_TCP_SERVER: |
| 85 return new P2PSocketHostTcpServer(message_sender, routing_id, id); | 82 return new P2PSocketHostTcpServer(message_sender, id); |
| 86 | 83 |
| 87 case P2P_SOCKET_TCP_CLIENT: | 84 case P2P_SOCKET_TCP_CLIENT: |
| 88 return new P2PSocketHostTcp(message_sender, routing_id, id); | 85 return new P2PSocketHostTcp(message_sender, id); |
| 89 } | 86 } |
| 90 | 87 |
| 91 NOTREACHED(); | 88 NOTREACHED(); |
| 92 return NULL; | 89 return NULL; |
| 93 } | 90 } |
| 94 | 91 |
| 95 } // namespace content | 92 } // namespace content |
| OLD | NEW |