OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_udp.h" | 5 #include "content/browser/renderer_host/p2p/socket_host_udp.h" |
6 | 6 |
7 #include "content/common/p2p_messages.h" | 7 #include "content/common/p2p_messages.h" |
8 #include "net/base/io_buffer.h" | 8 #include "net/base/io_buffer.h" |
9 #include "net/base/net_errors.h" | 9 #include "net/base/net_errors.h" |
10 #include "net/base/net_util.h" | 10 #include "net/base/net_util.h" |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 | 93 |
94 void P2PSocketHostUdp::DidCompleteRead(int result) { | 94 void P2PSocketHostUdp::DidCompleteRead(int result) { |
95 DCHECK_EQ(state_, STATE_OPEN); | 95 DCHECK_EQ(state_, STATE_OPEN); |
96 | 96 |
97 if (result > 0) { | 97 if (result > 0) { |
98 std::vector<char> data(recv_buffer_->data(), recv_buffer_->data() + result); | 98 std::vector<char> data(recv_buffer_->data(), recv_buffer_->data() + result); |
99 | 99 |
100 if (authorized_peers_.find(recv_address_) == authorized_peers_.end()) { | 100 if (authorized_peers_.find(recv_address_) == authorized_peers_.end()) { |
101 P2PSocketHost::StunMessageType type; | 101 P2PSocketHost::StunMessageType type; |
102 bool stun = GetStunPacketType(&*data.begin(), data.size(), &type); | 102 bool stun = GetStunPacketType(&*data.begin(), data.size(), &type); |
103 if (stun && (type == STUN_BINDING_REQUEST || | 103 if (stun && IsRequestOrResponse(type)) { |
104 type == STUN_BINDING_RESPONSE)) { | |
105 authorized_peers_.insert(recv_address_); | 104 authorized_peers_.insert(recv_address_); |
106 } else if (!stun || type == STUN_DATA_INDICATION) { | 105 } else if (!stun || type == STUN_DATA_INDICATION) { |
107 LOG(ERROR) << "Received unexpected data packet from " | 106 LOG(ERROR) << "Received unexpected data packet from " |
108 << recv_address_.ToString() | 107 << recv_address_.ToString() |
109 << " before STUN binding is finished."; | 108 << " before STUN binding is finished."; |
110 return; | 109 return; |
111 } | 110 } |
112 } | 111 } |
113 | 112 |
114 message_sender_->Send(new P2PMsg_OnDataReceived(routing_id_, id_, | 113 message_sender_->Send(new P2PMsg_OnDataReceived(routing_id_, id_, |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 if (result < 0) | 162 if (result < 0) |
164 OnError(); | 163 OnError(); |
165 } | 164 } |
166 | 165 |
167 P2PSocketHost* P2PSocketHostUdp::AcceptIncomingTcpConnection( | 166 P2PSocketHost* P2PSocketHostUdp::AcceptIncomingTcpConnection( |
168 const net::IPEndPoint& remote_address, int id) { | 167 const net::IPEndPoint& remote_address, int id) { |
169 NOTREACHED(); | 168 NOTREACHED(); |
170 OnError(); | 169 OnError(); |
171 return NULL; | 170 return NULL; |
172 } | 171 } |
OLD | NEW |