Chromium Code Reviews| 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/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
| 9 #include "content/common/p2p_messages.h" | 9 #include "content/common/p2p_messages.h" |
| 10 #include "ipc/ipc_sender.h" | 10 #include "ipc/ipc_sender.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 43 uid <<= 32; | 43 uid <<= 32; |
| 44 uid |= packet_id; | 44 uid |= packet_id; |
| 45 return uid; | 45 return uid; |
| 46 } | 46 } |
| 47 | 47 |
| 48 } // namespace | 48 } // namespace |
| 49 | 49 |
| 50 namespace content { | 50 namespace content { |
| 51 | 51 |
| 52 P2PSocketHostUdp::PendingPacket::PendingPacket( | 52 P2PSocketHostUdp::PendingPacket::PendingPacket( |
| 53 const net::IPEndPoint& to, const std::vector<char>& content, uint64 id) | 53 const net::IPEndPoint& to, |
| 54 const std::vector<char>& content, | |
| 55 uint64 id, | |
| 56 net::DiffServCodePoint dscp_) | |
| 54 : to(to), | 57 : to(to), |
| 55 data(new net::IOBuffer(content.size())), | 58 data(new net::IOBuffer(content.size())), |
| 56 size(content.size()), | 59 size(content.size()), |
| 57 id(id) { | 60 id(id), |
| 61 dscp(dscp_) { | |
| 58 memcpy(data->data(), &content[0], size); | 62 memcpy(data->data(), &content[0], size); |
| 59 } | 63 } |
| 60 | 64 |
| 61 P2PSocketHostUdp::PendingPacket::~PendingPacket() { | 65 P2PSocketHostUdp::PendingPacket::~PendingPacket() { |
| 62 } | 66 } |
| 63 | 67 |
| 64 P2PSocketHostUdp::P2PSocketHostUdp(IPC::Sender* message_sender, int id) | 68 P2PSocketHostUdp::P2PSocketHostUdp(IPC::Sender* message_sender, int id) |
| 65 : P2PSocketHost(message_sender, id), | 69 : P2PSocketHost(message_sender, id), |
| 66 socket_(new net::UDPServerSocket(NULL, net::NetLog::Source())), | 70 socket_(new net::UDPServerSocket(NULL, net::NetLog::Source())), |
| 67 send_pending_(false), | 71 send_pending_(false), |
| 68 send_packet_count_(0) { | 72 send_packet_count_(0), |
| 73 last_dscp_(net::DSCP_CS0) { | |
| 69 } | 74 } |
| 70 | 75 |
| 71 P2PSocketHostUdp::~P2PSocketHostUdp() { | 76 P2PSocketHostUdp::~P2PSocketHostUdp() { |
| 72 if (state_ == STATE_OPEN) { | 77 if (state_ == STATE_OPEN) { |
| 73 DCHECK(socket_.get()); | 78 DCHECK(socket_.get()); |
| 74 socket_.reset(); | 79 socket_.reset(); |
| 75 } | 80 } |
| 76 } | 81 } |
| 77 | 82 |
| 78 bool P2PSocketHostUdp::Init(const net::IPEndPoint& local_address, | 83 bool P2PSocketHostUdp::Init(const net::IPEndPoint& local_address, |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 157 } | 162 } |
| 158 | 163 |
| 159 message_sender_->Send(new P2PMsg_OnDataReceived(id_, recv_address_, data)); | 164 message_sender_->Send(new P2PMsg_OnDataReceived(id_, recv_address_, data)); |
| 160 } else if (result < 0 && !IsTransientError(result)) { | 165 } else if (result < 0 && !IsTransientError(result)) { |
| 161 LOG(ERROR) << "Error when reading from UDP socket: " << result; | 166 LOG(ERROR) << "Error when reading from UDP socket: " << result; |
| 162 OnError(); | 167 OnError(); |
| 163 } | 168 } |
| 164 } | 169 } |
| 165 | 170 |
| 166 void P2PSocketHostUdp::Send(const net::IPEndPoint& to, | 171 void P2PSocketHostUdp::Send(const net::IPEndPoint& to, |
| 167 const std::vector<char>& data) { | 172 const std::vector<char>& data, |
| 173 net::DiffServCodePoint dscp) { | |
| 168 if (!socket_) { | 174 if (!socket_) { |
| 169 // The Send message may be sent after the an OnError message was | 175 // The Send message may be sent after the an OnError message was |
| 170 // sent by hasn't been processed the renderer. | 176 // sent by hasn't been processed the renderer. |
| 171 return; | 177 return; |
| 172 } | 178 } |
| 173 | 179 |
| 174 if (connected_peers_.find(to) == connected_peers_.end()) { | 180 if (connected_peers_.find(to) == connected_peers_.end()) { |
| 175 P2PSocketHost::StunMessageType type; | 181 P2PSocketHost::StunMessageType type; |
| 176 bool stun = GetStunPacketType(&*data.begin(), data.size(), &type); | 182 bool stun = GetStunPacketType(&*data.begin(), data.size(), &type); |
| 177 if (!stun || type == STUN_DATA_INDICATION) { | 183 if (!stun || type == STUN_DATA_INDICATION) { |
| 178 LOG(ERROR) << "Page tried to send a data packet to " << to.ToString() | 184 LOG(ERROR) << "Page tried to send a data packet to " << to.ToString() |
| 179 << " before STUN binding is finished."; | 185 << " before STUN binding is finished."; |
| 180 OnError(); | 186 OnError(); |
| 181 return; | 187 return; |
| 182 } | 188 } |
| 183 } | 189 } |
| 184 | 190 |
| 185 if (send_pending_) { | 191 if (send_pending_) { |
| 186 send_queue_.push_back(PendingPacket(to, data, send_packet_count_)); | 192 send_queue_.push_back(PendingPacket(to, data, send_packet_count_, dscp)); |
| 187 } else { | 193 } else { |
| 188 PendingPacket packet(to, data, send_packet_count_); | 194 PendingPacket packet(to, data, send_packet_count_, dscp); |
| 189 DoSend(packet); | 195 DoSend(packet); |
| 190 } | 196 } |
| 191 ++send_packet_count_; | 197 ++send_packet_count_; |
| 192 } | 198 } |
| 193 | 199 |
| 194 void P2PSocketHostUdp::DoSend(const PendingPacket& packet) { | 200 void P2PSocketHostUdp::DoSend(const PendingPacket& packet) { |
| 195 TRACE_EVENT_ASYNC_BEGIN1("p2p", "Udp::DoSend", | 201 TRACE_EVENT_ASYNC_BEGIN1("p2p", "Udp::DoSend", |
| 196 GetUniqueEventId(this, packet.id), | 202 GetUniqueEventId(this, packet.id), |
| 197 "size", packet.size); | 203 "size", packet.size); |
| 204 if (last_dscp_ != packet.dscp && last_dscp_ != net::DSCP_NO_CHANGE) { | |
| 205 int result = socket_->SetToS(packet.dscp); | |
| 206 if (result == net::OK) { | |
| 207 last_dscp_ = packet.dscp; | |
| 208 } else if (!IsTransientError(result) && last_dscp_ != net::DSCP_CS0) { | |
|
Sergey Ulanov
2013/08/17 05:50:04
IsTransientError() is used for errors returned fro
hubbe
2013/08/21 18:51:36
On some platforms setsockopt() IP_TOS is a privile
| |
| 209 // We receieved a non-transient error, and it seems we have | |
| 210 // not changed the DSCP in the past, disable DSCP as it unlikely | |
| 211 // to work in the future. | |
| 212 last_dscp_ = net::DSCP_NO_CHANGE; | |
| 213 } | |
| 214 } | |
| 198 int result = socket_->SendTo( | 215 int result = socket_->SendTo( |
| 199 packet.data.get(), | 216 packet.data.get(), |
| 200 packet.size, | 217 packet.size, |
| 201 packet.to, | 218 packet.to, |
| 202 base::Bind(&P2PSocketHostUdp::OnSend, base::Unretained(this), packet.id)); | 219 base::Bind(&P2PSocketHostUdp::OnSend, base::Unretained(this), packet.id)); |
| 203 | 220 |
| 204 // sendto() may return an error, e.g. if we've received an ICMP Destination | 221 // sendto() may return an error, e.g. if we've received an ICMP Destination |
| 205 // Unreachable message. When this happens try sending the same packet again, | 222 // Unreachable message. When this happens try sending the same packet again, |
| 206 // and just drop it if it fails again. | 223 // and just drop it if it fails again. |
| 207 if (IsTransientError(result)) { | 224 if (IsTransientError(result)) { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 251 } | 268 } |
| 252 | 269 |
| 253 P2PSocketHost* P2PSocketHostUdp::AcceptIncomingTcpConnection( | 270 P2PSocketHost* P2PSocketHostUdp::AcceptIncomingTcpConnection( |
| 254 const net::IPEndPoint& remote_address, int id) { | 271 const net::IPEndPoint& remote_address, int id) { |
| 255 NOTREACHED(); | 272 NOTREACHED(); |
| 256 OnError(); | 273 OnError(); |
| 257 return NULL; | 274 return NULL; |
| 258 } | 275 } |
| 259 | 276 |
| 260 } // namespace content | 277 } // namespace content |
| OLD | NEW |