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_udp.h" | 5 #include "content/browser/renderer_host/p2p/socket_host_udp.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 switches::kDisableP2PSocketSTUNFilter); | 48 switches::kDisableP2PSocketSTUNFilter); |
49 } | 49 } |
50 | 50 |
51 } // namespace | 51 } // namespace |
52 | 52 |
53 namespace content { | 53 namespace content { |
54 | 54 |
55 P2PSocketHostUdp::PendingPacket::PendingPacket( | 55 P2PSocketHostUdp::PendingPacket::PendingPacket( |
56 const net::IPEndPoint& to, | 56 const net::IPEndPoint& to, |
57 const std::vector<char>& content, | 57 const std::vector<char>& content, |
58 const talk_base::PacketOptions& options, | 58 net::DiffServCodePoint dscp_, |
59 uint64 id) | 59 uint64 id) |
60 : to(to), | 60 : to(to), |
61 data(new net::IOBuffer(content.size())), | 61 data(new net::IOBuffer(content.size())), |
62 size(content.size()), | 62 size(content.size()), |
63 packet_options(options), | 63 dscp(dscp_), |
64 id(id) { | 64 id(id) { |
65 memcpy(data->data(), &content[0], size); | 65 memcpy(data->data(), &content[0], size); |
66 if (!options.packet_time_params.srtp_auth_key.empty()) { | |
67 memcpy(&packet_options.packet_time_params.srtp_auth_key[0], | |
68 &options.packet_time_params.srtp_auth_key[0], | |
69 options.packet_time_params.srtp_auth_key.size()); | |
70 } | |
71 } | 66 } |
72 | 67 |
73 P2PSocketHostUdp::PendingPacket::~PendingPacket() { | 68 P2PSocketHostUdp::PendingPacket::~PendingPacket() { |
74 } | 69 } |
75 | 70 |
76 P2PSocketHostUdp::P2PSocketHostUdp(IPC::Sender* message_sender, | 71 P2PSocketHostUdp::P2PSocketHostUdp(IPC::Sender* message_sender, |
77 int id, | 72 int id, |
78 P2PMessageThrottler* throttler) | 73 P2PMessageThrottler* throttler) |
79 : P2PSocketHost(message_sender, id), | 74 : P2PSocketHost(message_sender, id), |
80 socket_(new net::UDPServerSocket(NULL, net::NetLog::Source())), | 75 socket_(new net::UDPServerSocket(NULL, net::NetLog::Source())), |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 message_sender_->Send(new P2PMsg_OnDataReceived( | 175 message_sender_->Send(new P2PMsg_OnDataReceived( |
181 id_, recv_address_, data, base::TimeTicks::Now())); | 176 id_, recv_address_, data, base::TimeTicks::Now())); |
182 } else if (result < 0 && !IsTransientError(result)) { | 177 } else if (result < 0 && !IsTransientError(result)) { |
183 LOG(ERROR) << "Error when reading from UDP socket: " << result; | 178 LOG(ERROR) << "Error when reading from UDP socket: " << result; |
184 OnError(); | 179 OnError(); |
185 } | 180 } |
186 } | 181 } |
187 | 182 |
188 void P2PSocketHostUdp::Send(const net::IPEndPoint& to, | 183 void P2PSocketHostUdp::Send(const net::IPEndPoint& to, |
189 const std::vector<char>& data, | 184 const std::vector<char>& data, |
190 const talk_base::PacketOptions& options, | 185 net::DiffServCodePoint dscp, |
191 uint64 packet_id) { | 186 uint64 packet_id) { |
192 if (!socket_) { | 187 if (!socket_) { |
193 // The Send message may be sent after the an OnError message was | 188 // The Send message may be sent after the an OnError message was |
194 // sent by hasn't been processed the renderer. | 189 // sent by hasn't been processed the renderer. |
195 return; | 190 return; |
196 } | 191 } |
197 | 192 |
198 if (!ContainsKey(connected_peers_, to) && !AllowUDPWithoutSTUN()) { | 193 if (!ContainsKey(connected_peers_, to) && !AllowUDPWithoutSTUN()) { |
199 P2PSocketHost::StunMessageType type = P2PSocketHost::StunMessageType(); | 194 P2PSocketHost::StunMessageType type = P2PSocketHost::StunMessageType(); |
200 bool stun = GetStunPacketType(&*data.begin(), data.size(), &type); | 195 bool stun = GetStunPacketType(&*data.begin(), data.size(), &type); |
201 if (!stun || type == STUN_DATA_INDICATION) { | 196 if (!stun || type == STUN_DATA_INDICATION) { |
202 LOG(ERROR) << "Page tried to send a data packet to " << to.ToString() | 197 LOG(ERROR) << "Page tried to send a data packet to " << to.ToString() |
203 << " before STUN binding is finished."; | 198 << " before STUN binding is finished."; |
204 OnError(); | 199 OnError(); |
205 return; | 200 return; |
206 } | 201 } |
207 | 202 |
208 if (throttler_->DropNextPacket(data.size())) { | 203 if (throttler_->DropNextPacket(data.size())) { |
209 VLOG(0) << "STUN message is dropped due to high volume."; | 204 VLOG(0) << "STUN message is dropped due to high volume."; |
210 // Do not reset socket. | 205 // Do not reset socket. |
211 return; | 206 return; |
212 } | 207 } |
213 } | 208 } |
214 | 209 |
215 if (send_pending_) { | 210 if (send_pending_) { |
216 send_queue_.push_back(PendingPacket(to, data, options, packet_id)); | 211 send_queue_.push_back(PendingPacket(to, data, dscp, packet_id)); |
217 } else { | 212 } else { |
218 // TODO(mallinath: Remove unnecessary memcpy in this case. | 213 PendingPacket packet(to, data, dscp, packet_id); |
219 PendingPacket packet(to, data, options, packet_id); | |
220 DoSend(packet); | 214 DoSend(packet); |
221 } | 215 } |
222 } | 216 } |
223 | 217 |
224 void P2PSocketHostUdp::DoSend(const PendingPacket& packet) { | 218 void P2PSocketHostUdp::DoSend(const PendingPacket& packet) { |
225 TRACE_EVENT_ASYNC_STEP_INTO1("p2p", "Send", packet.id, "UdpAsyncSendTo", | 219 TRACE_EVENT_ASYNC_STEP_INTO1("p2p", "Send", packet.id, "UdpAsyncSendTo", |
226 "size", packet.size); | 220 "size", packet.size); |
227 // Don't try to set DSCP in following conditions, | 221 // Don't try to set DSCP in following conditions, |
228 // 1. If the outgoing packet is set to DSCP_NO_CHANGE | 222 // 1. If the outgoing packet is set to DSCP_NO_CHANGE |
229 // 2. If no change in DSCP value from last packet | 223 // 2. If no change in DSCP value from last packet |
230 // 3. If there is any error in setting DSCP on socket. | 224 // 3. If there is any error in setting DSCP on socket. |
231 net::DiffServCodePoint dscp = | 225 if (packet.dscp != net::DSCP_NO_CHANGE && |
232 static_cast<net::DiffServCodePoint>(packet.packet_options.dscp); | 226 last_dscp_ != packet.dscp && last_dscp_ != net::DSCP_NO_CHANGE) { |
233 if (dscp != net::DSCP_NO_CHANGE && | 227 int result = socket_->SetDiffServCodePoint(packet.dscp); |
234 last_dscp_ != dscp && last_dscp_ != net::DSCP_NO_CHANGE) { | |
235 int result = socket_->SetDiffServCodePoint(dscp); | |
236 if (result == net::OK) { | 228 if (result == net::OK) { |
237 last_dscp_ = dscp; | 229 last_dscp_ = packet.dscp; |
238 } else if (!IsTransientError(result) && last_dscp_ != net::DSCP_CS0) { | 230 } else if (!IsTransientError(result) && last_dscp_ != net::DSCP_CS0) { |
239 // We receieved a non-transient error, and it seems we have | 231 // We receieved a non-transient error, and it seems we have |
240 // not changed the DSCP in the past, disable DSCP as it unlikely | 232 // not changed the DSCP in the past, disable DSCP as it unlikely |
241 // to work in the future. | 233 // to work in the future. |
242 last_dscp_ = net::DSCP_NO_CHANGE; | 234 last_dscp_ = net::DSCP_NO_CHANGE; |
243 } | 235 } |
244 } | 236 } |
245 int result = socket_->SendTo( | 237 int result = socket_->SendTo( |
246 packet.data.get(), | 238 packet.data.get(), |
247 packet.size, | 239 packet.size, |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 case P2P_SOCKET_OPT_DSCP: | 305 case P2P_SOCKET_OPT_DSCP: |
314 return (net::OK == socket_->SetDiffServCodePoint( | 306 return (net::OK == socket_->SetDiffServCodePoint( |
315 static_cast<net::DiffServCodePoint>(value))) ? true : false; | 307 static_cast<net::DiffServCodePoint>(value))) ? true : false; |
316 default: | 308 default: |
317 NOTREACHED(); | 309 NOTREACHED(); |
318 return false; | 310 return false; |
319 } | 311 } |
320 } | 312 } |
321 | 313 |
322 } // namespace content | 314 } // namespace content |
OLD | NEW |