Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1157)

Side by Side Diff: content/browser/renderer_host/p2p/socket_host_udp.cc

Issue 22381012: Allow p2p UDP packages to set DSCP (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: win fix Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "content/browser/renderer_host/p2p/socket_host_throttler.h" 10 #include "content/browser/renderer_host/p2p/socket_host_throttler.h"
(...skipping 26 matching lines...) Expand all
37 error == net::ERR_ACCESS_DENIED || 37 error == net::ERR_ACCESS_DENIED ||
38 error == net::ERR_CONNECTION_RESET || 38 error == net::ERR_CONNECTION_RESET ||
39 error == net::ERR_OUT_OF_MEMORY; 39 error == net::ERR_OUT_OF_MEMORY;
40 } 40 }
41 41
42 } // namespace 42 } // namespace
43 43
44 namespace content { 44 namespace content {
45 45
46 P2PSocketHostUdp::PendingPacket::PendingPacket( 46 P2PSocketHostUdp::PendingPacket::PendingPacket(
47 const net::IPEndPoint& to, const std::vector<char>& content, uint64 id) 47 const net::IPEndPoint& to,
48 const std::vector<char>& content,
49 net::DiffServCodePoint dscp_,
50 uint64 id)
48 : to(to), 51 : to(to),
49 data(new net::IOBuffer(content.size())), 52 data(new net::IOBuffer(content.size())),
50 size(content.size()), 53 size(content.size()),
54 dscp(dscp_),
51 id(id) { 55 id(id) {
52 memcpy(data->data(), &content[0], size); 56 memcpy(data->data(), &content[0], size);
53 } 57 }
54 58
55 P2PSocketHostUdp::PendingPacket::~PendingPacket() { 59 P2PSocketHostUdp::PendingPacket::~PendingPacket() {
56 } 60 }
57 61
58 P2PSocketHostUdp::P2PSocketHostUdp(IPC::Sender* message_sender, 62 P2PSocketHostUdp::P2PSocketHostUdp(IPC::Sender* message_sender,
59 int id, 63 int id,
60 P2PMessageThrottler* throttler) 64 P2PMessageThrottler* throttler)
61 : P2PSocketHost(message_sender, id), 65 : P2PSocketHost(message_sender, id),
62 socket_(new net::UDPServerSocket(NULL, net::NetLog::Source())), 66 socket_(new net::UDPServerSocket(NULL, net::NetLog::Source())),
63 send_pending_(false), 67 send_pending_(false),
68 last_dscp_(net::DSCP_CS0),
64 throttler_(throttler) { 69 throttler_(throttler) {
65 } 70 }
66 71
67 P2PSocketHostUdp::~P2PSocketHostUdp() { 72 P2PSocketHostUdp::~P2PSocketHostUdp() {
68 if (state_ == STATE_OPEN) { 73 if (state_ == STATE_OPEN) {
69 DCHECK(socket_.get()); 74 DCHECK(socket_.get());
70 socket_.reset(); 75 socket_.reset();
71 } 76 }
72 } 77 }
73 78
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 159
155 message_sender_->Send(new P2PMsg_OnDataReceived(id_, recv_address_, data)); 160 message_sender_->Send(new P2PMsg_OnDataReceived(id_, recv_address_, data));
156 } else if (result < 0 && !IsTransientError(result)) { 161 } else if (result < 0 && !IsTransientError(result)) {
157 LOG(ERROR) << "Error when reading from UDP socket: " << result; 162 LOG(ERROR) << "Error when reading from UDP socket: " << result;
158 OnError(); 163 OnError();
159 } 164 }
160 } 165 }
161 166
162 void P2PSocketHostUdp::Send(const net::IPEndPoint& to, 167 void P2PSocketHostUdp::Send(const net::IPEndPoint& to,
163 const std::vector<char>& data, 168 const std::vector<char>& data,
169 net::DiffServCodePoint dscp,
164 uint64 packet_id) { 170 uint64 packet_id) {
165 if (!socket_) { 171 if (!socket_) {
166 // The Send message may be sent after the an OnError message was 172 // The Send message may be sent after the an OnError message was
167 // sent by hasn't been processed the renderer. 173 // sent by hasn't been processed the renderer.
168 return; 174 return;
169 } 175 }
170 176
171 if (!ContainsKey(connected_peers_, to)) { 177 if (!ContainsKey(connected_peers_, to)) {
172 P2PSocketHost::StunMessageType type; 178 P2PSocketHost::StunMessageType type;
173 bool stun = GetStunPacketType(&*data.begin(), data.size(), &type); 179 bool stun = GetStunPacketType(&*data.begin(), data.size(), &type);
174 if (!stun || type == STUN_DATA_INDICATION) { 180 if (!stun || type == STUN_DATA_INDICATION) {
175 LOG(ERROR) << "Page tried to send a data packet to " << to.ToString() 181 LOG(ERROR) << "Page tried to send a data packet to " << to.ToString()
176 << " before STUN binding is finished."; 182 << " before STUN binding is finished.";
177 OnError(); 183 OnError();
178 return; 184 return;
179 } 185 }
180 186
181 if (throttler_->DropNextPacket(data.size())) { 187 if (throttler_->DropNextPacket(data.size())) {
182 LOG(INFO) << "STUN message is dropped due to high volume."; 188 LOG(INFO) << "STUN message is dropped due to high volume.";
183 // Do not reset socket. 189 // Do not reset socket.
184 return; 190 return;
185 } 191 }
186 } 192 }
187 193
188 if (send_pending_) { 194 if (send_pending_) {
189 send_queue_.push_back(PendingPacket(to, data, packet_id)); 195 send_queue_.push_back(PendingPacket(to, data, dscp, packet_id));
190 } else { 196 } else {
191 PendingPacket packet(to, data, packet_id); 197 PendingPacket packet(to, data, dscp, packet_id);
192 DoSend(packet); 198 DoSend(packet);
193 } 199 }
194 } 200 }
195 201
196 void P2PSocketHostUdp::DoSend(const PendingPacket& packet) { 202 void P2PSocketHostUdp::DoSend(const PendingPacket& packet) {
197 TRACE_EVENT_ASYNC_STEP1("p2p", "Send", packet.id, "UdpAsyncSendTo", 203 TRACE_EVENT_ASYNC_STEP1("p2p", "Send", packet.id, "UdpAsyncSendTo",
198 "size", packet.size); 204 "size", packet.size);
205 if (last_dscp_ != packet.dscp && last_dscp_ != net::DSCP_NO_CHANGE) {
206 int result = socket_->SetDiffServCodePoint(packet.dscp);
207 if (result == net::OK) {
208 last_dscp_ = packet.dscp;
209 } else if (!IsTransientError(result) && last_dscp_ != net::DSCP_CS0) {
210 // We receieved a non-transient error, and it seems we have
211 // not changed the DSCP in the past, disable DSCP as it unlikely
212 // to work in the future.
213 last_dscp_ = net::DSCP_NO_CHANGE;
214 }
215 }
199 int result = socket_->SendTo( 216 int result = socket_->SendTo(
200 packet.data.get(), 217 packet.data.get(),
201 packet.size, 218 packet.size,
202 packet.to, 219 packet.to,
203 base::Bind(&P2PSocketHostUdp::OnSend, base::Unretained(this), packet.id)); 220 base::Bind(&P2PSocketHostUdp::OnSend, base::Unretained(this), packet.id));
204 221
205 // sendto() may return an error, e.g. if we've received an ICMP Destination 222 // sendto() may return an error, e.g. if we've received an ICMP Destination
206 // Unreachable message. When this happens try sending the same packet again, 223 // Unreachable message. When this happens try sending the same packet again,
207 // and just drop it if it fails again. 224 // and just drop it if it fails again.
208 if (IsTransientError(result)) { 225 if (IsTransientError(result)) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
OLDNEW
« no previous file with comments | « content/browser/renderer_host/p2p/socket_host_udp.h ('k') | content/browser/renderer_host/p2p/socket_host_udp_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698