summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhubbe@chromium.org <hubbe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-22 00:34:41 +0000
committerhubbe@chromium.org <hubbe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-22 00:34:41 +0000
commita8a442b37af870c13cf4d68f5e1a63b7764f2f1e (patch)
tree5ab2eca565092e6a5feb721b8c037a5866f1f577
parent86ff11ca424f22a71738426abb6244cafca45e7d (diff)
downloadchromium_src-a8a442b37af870c13cf4d68f5e1a63b7764f2f1e.zip
chromium_src-a8a442b37af870c13cf4d68f5e1a63b7764f2f1e.tar.gz
chromium_src-a8a442b37af870c13cf4d68f5e1a63b7764f2f1e.tar.bz2
Implement support for p2p socket UDP packages to set the Differntiated Services Code Point for each package. Will be used by webrtc to hopefully improve performance. (See bug for how we will test this.)
BUG=277022 Review URL: https://codereview.chromium.org/22381012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@229975 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--content/browser/renderer_host/p2p/socket_dispatcher_host.cc3
-rw-r--r--content/browser/renderer_host/p2p/socket_dispatcher_host.h1
-rw-r--r--content/browser/renderer_host/p2p/socket_host.h2
-rw-r--r--content/browser/renderer_host/p2p/socket_host_tcp.cc3
-rw-r--r--content/browser/renderer_host/p2p/socket_host_tcp.h1
-rw-r--r--content/browser/renderer_host/p2p/socket_host_tcp_server.cc1
-rw-r--r--content/browser/renderer_host/p2p/socket_host_tcp_server.h1
-rw-r--r--content/browser/renderer_host/p2p/socket_host_tcp_unittest.cc39
-rw-r--r--content/browser/renderer_host/p2p/socket_host_udp.cc23
-rw-r--r--content/browser/renderer_host/p2p/socket_host_udp.h4
-rw-r--r--content/browser/renderer_host/p2p/socket_host_udp_unittest.cc37
-rw-r--r--content/common/p2p_messages.h4
-rw-r--r--content/renderer/p2p/socket_client.cc13
-rw-r--r--content/renderer/p2p/socket_client.h6
-rw-r--r--net/base/net_util.h28
-rw-r--r--net/dns/mock_mdns_socket_factory.h2
-rw-r--r--net/udp/datagram_server_socket.h4
-rw-r--r--net/udp/udp_server_socket.cc4
-rw-r--r--net/udp/udp_server_socket.h1
-rw-r--r--net/udp/udp_socket_libevent.cc20
-rw-r--r--net/udp/udp_socket_libevent.h5
-rw-r--r--net/udp/udp_socket_win.cc6
-rw-r--r--net/udp/udp_socket_win.h4
23 files changed, 169 insertions, 43 deletions
diff --git a/content/browser/renderer_host/p2p/socket_dispatcher_host.cc b/content/browser/renderer_host/p2p/socket_dispatcher_host.cc
index 63c52c8..1608ae0 100644
--- a/content/browser/renderer_host/p2p/socket_dispatcher_host.cc
+++ b/content/browser/renderer_host/p2p/socket_dispatcher_host.cc
@@ -224,6 +224,7 @@ void P2PSocketDispatcherHost::OnAcceptIncomingTcpConnection(
void P2PSocketDispatcherHost::OnSend(int socket_id,
const net::IPEndPoint& socket_address,
const std::vector<char>& data,
+ net::DiffServCodePoint dscp,
uint64 packet_id) {
P2PSocketHost* socket = LookupSocket(socket_id);
if (!socket) {
@@ -240,7 +241,7 @@ void P2PSocketDispatcherHost::OnSend(int socket_id,
return;
}
- socket->Send(socket_address, data, packet_id);
+ socket->Send(socket_address, data, dscp, packet_id);
}
void P2PSocketDispatcherHost::OnDestroySocket(int socket_id) {
diff --git a/content/browser/renderer_host/p2p/socket_dispatcher_host.h b/content/browser/renderer_host/p2p/socket_dispatcher_host.h
index aeb3e67..b2d76f4 100644
--- a/content/browser/renderer_host/p2p/socket_dispatcher_host.h
+++ b/content/browser/renderer_host/p2p/socket_dispatcher_host.h
@@ -72,6 +72,7 @@ class P2PSocketDispatcherHost
void OnSend(int socket_id,
const net::IPEndPoint& socket_address,
const std::vector<char>& data,
+ net::DiffServCodePoint dscp,
uint64 packet_id);
void OnDestroySocket(int socket_id);
diff --git a/content/browser/renderer_host/p2p/socket_host.h b/content/browser/renderer_host/p2p/socket_host.h
index 0743c30..0ca8e0e 100644
--- a/content/browser/renderer_host/p2p/socket_host.h
+++ b/content/browser/renderer_host/p2p/socket_host.h
@@ -8,6 +8,7 @@
#include "content/common/content_export.h"
#include "content/common/p2p_sockets.h"
#include "net/base/ip_endpoint.h"
+#include "net/udp/datagram_socket.h"
namespace IPC {
class Sender;
@@ -39,6 +40,7 @@ class CONTENT_EXPORT P2PSocketHost {
// Sends |data| on the socket to |to|.
virtual void Send(const net::IPEndPoint& to,
const std::vector<char>& data,
+ net::DiffServCodePoint dscp,
uint64 packet_id) = 0;
virtual P2PSocketHost* AcceptIncomingTcpConnection(
diff --git a/content/browser/renderer_host/p2p/socket_host_tcp.cc b/content/browser/renderer_host/p2p/socket_host_tcp.cc
index 558bb4b..f6865ba 100644
--- a/content/browser/renderer_host/p2p/socket_host_tcp.cc
+++ b/content/browser/renderer_host/p2p/socket_host_tcp.cc
@@ -271,8 +271,11 @@ void P2PSocketHostTcpBase::OnPacket(const std::vector<char>& data) {
message_sender_->Send(new P2PMsg_OnDataReceived(id_, remote_address_, data));
}
+// Note: dscp is not actually used on TCP sockets as this point,
+// but may be honored in the future.
void P2PSocketHostTcpBase::Send(const net::IPEndPoint& to,
const std::vector<char>& data,
+ net::DiffServCodePoint dscp,
uint64 packet_id) {
if (!socket_) {
// The Send message may be sent after the an OnError message was
diff --git a/content/browser/renderer_host/p2p/socket_host_tcp.h b/content/browser/renderer_host/p2p/socket_host_tcp.h
index 13820d8..20de668 100644
--- a/content/browser/renderer_host/p2p/socket_host_tcp.h
+++ b/content/browser/renderer_host/p2p/socket_host_tcp.h
@@ -42,6 +42,7 @@ class CONTENT_EXPORT P2PSocketHostTcpBase : public P2PSocketHost {
const net::IPEndPoint& remote_address) OVERRIDE;
virtual void Send(const net::IPEndPoint& to,
const std::vector<char>& data,
+ net::DiffServCodePoint dscp,
uint64 packet_id) OVERRIDE;
virtual P2PSocketHost* AcceptIncomingTcpConnection(
const net::IPEndPoint& remote_address, int id) OVERRIDE;
diff --git a/content/browser/renderer_host/p2p/socket_host_tcp_server.cc b/content/browser/renderer_host/p2p/socket_host_tcp_server.cc
index 704251f..fc6c7f6 100644
--- a/content/browser/renderer_host/p2p/socket_host_tcp_server.cc
+++ b/content/browser/renderer_host/p2p/socket_host_tcp_server.cc
@@ -116,6 +116,7 @@ void P2PSocketHostTcpServer::OnAccepted(int result) {
void P2PSocketHostTcpServer::Send(const net::IPEndPoint& to,
const std::vector<char>& data,
+ net::DiffServCodePoint dscp,
uint64 packet_id) {
NOTREACHED();
OnError();
diff --git a/content/browser/renderer_host/p2p/socket_host_tcp_server.h b/content/browser/renderer_host/p2p/socket_host_tcp_server.h
index fbcbf08..924e2d3 100644
--- a/content/browser/renderer_host/p2p/socket_host_tcp_server.h
+++ b/content/browser/renderer_host/p2p/socket_host_tcp_server.h
@@ -37,6 +37,7 @@ class CONTENT_EXPORT P2PSocketHostTcpServer : public P2PSocketHost {
const net::IPEndPoint& remote_address) OVERRIDE;
virtual void Send(const net::IPEndPoint& to,
const std::vector<char>& data,
+ net::DiffServCodePoint dscp,
uint64 packet_id) OVERRIDE;
virtual P2PSocketHost* AcceptIncomingTcpConnection(
const net::IPEndPoint& remote_address, int id) OVERRIDE;
diff --git a/content/browser/renderer_host/p2p/socket_host_tcp_unittest.cc b/content/browser/renderer_host/p2p/socket_host_tcp_unittest.cc
index 1740d23..cae88bd 100644
--- a/content/browser/renderer_host/p2p/socket_host_tcp_unittest.cc
+++ b/content/browser/renderer_host/p2p/socket_host_tcp_unittest.cc
@@ -94,15 +94,15 @@ TEST_F(P2PSocketHostTcpTest, SendStunNoAuth) {
std::vector<char> packet1;
CreateStunRequest(&packet1);
- socket_host_->Send(dest_, packet1, 0);
+ socket_host_->Send(dest_, packet1, net::DSCP_NO_CHANGE, 0);
std::vector<char> packet2;
CreateStunResponse(&packet2);
- socket_host_->Send(dest_, packet2, 0);
+ socket_host_->Send(dest_, packet2, net::DSCP_NO_CHANGE, 0);
std::vector<char> packet3;
CreateStunError(&packet3);
- socket_host_->Send(dest_, packet3, 0);
+ socket_host_->Send(dest_, packet3, net::DSCP_NO_CHANGE, 0);
std::string expected_data;
expected_data.append(IntToSize(packet1.size()));
@@ -125,15 +125,15 @@ TEST_F(P2PSocketHostTcpTest, ReceiveStun) {
std::vector<char> packet1;
CreateStunRequest(&packet1);
- socket_host_->Send(dest_, packet1, 0);
+ socket_host_->Send(dest_, packet1, net::DSCP_NO_CHANGE, 0);
std::vector<char> packet2;
CreateStunResponse(&packet2);
- socket_host_->Send(dest_, packet2, 0);
+ socket_host_->Send(dest_, packet2, net::DSCP_NO_CHANGE, 0);
std::vector<char> packet3;
CreateStunError(&packet3);
- socket_host_->Send(dest_, packet3, 0);
+ socket_host_->Send(dest_, packet3, net::DSCP_NO_CHANGE, 0);
std::string received_data;
received_data.append(IntToSize(packet1.size()));
@@ -171,7 +171,7 @@ TEST_F(P2PSocketHostTcpTest, SendDataNoAuth) {
std::vector<char> packet;
CreateRandomPacket(&packet);
- socket_host_->Send(dest_, packet, 0);
+ socket_host_->Send(dest_, packet, net::DSCP_NO_CHANGE, 0);
EXPECT_EQ(0U, sent_data_.size());
}
@@ -197,7 +197,7 @@ TEST_F(P2PSocketHostTcpTest, SendAfterStunRequest) {
// Now we should be able to send any data to |dest_|.
std::vector<char> packet;
CreateRandomPacket(&packet);
- socket_host_->Send(dest_, packet, 0);
+ socket_host_->Send(dest_, packet, net::DSCP_NO_CHANGE, 0);
std::string expected_data;
expected_data.append(IntToSize(packet.size()));
@@ -219,11 +219,12 @@ TEST_F(P2PSocketHostTcpTest, AsyncWrites) {
std::vector<char> packet1;
CreateStunRequest(&packet1);
- socket_host_->Send(dest_, packet1, 0);
+
+ socket_host_->Send(dest_, packet1, net::DSCP_NO_CHANGE, 0);
std::vector<char> packet2;
CreateStunResponse(&packet2);
- socket_host_->Send(dest_, packet2, 0);
+ socket_host_->Send(dest_, packet2, net::DSCP_NO_CHANGE, 0);
message_loop.RunUntilIdle();
@@ -246,15 +247,15 @@ TEST_F(P2PSocketHostStunTcpTest, SendStunNoAuth) {
std::vector<char> packet1;
CreateStunRequest(&packet1);
- socket_host_->Send(dest_, packet1, 0);
+ socket_host_->Send(dest_, packet1, net::DSCP_NO_CHANGE, 0);
std::vector<char> packet2;
CreateStunResponse(&packet2);
- socket_host_->Send(dest_, packet2, 0);
+ socket_host_->Send(dest_, packet2, net::DSCP_NO_CHANGE, 0);
std::vector<char> packet3;
CreateStunError(&packet3);
- socket_host_->Send(dest_, packet3, 0);
+ socket_host_->Send(dest_, packet3, net::DSCP_NO_CHANGE, 0);
std::string expected_data;
expected_data.append(packet1.begin(), packet1.end());
@@ -274,15 +275,15 @@ TEST_F(P2PSocketHostStunTcpTest, ReceiveStun) {
std::vector<char> packet1;
CreateStunRequest(&packet1);
- socket_host_->Send(dest_, packet1, 0);
+ socket_host_->Send(dest_, packet1, net::DSCP_NO_CHANGE, 0);
std::vector<char> packet2;
CreateStunResponse(&packet2);
- socket_host_->Send(dest_, packet2, 0);
+ socket_host_->Send(dest_, packet2, net::DSCP_NO_CHANGE, 0);
std::vector<char> packet3;
CreateStunError(&packet3);
- socket_host_->Send(dest_, packet3, 0);
+ socket_host_->Send(dest_, packet3, net::DSCP_NO_CHANGE, 0);
std::string received_data;
received_data.append(packet1.begin(), packet1.end());
@@ -317,7 +318,7 @@ TEST_F(P2PSocketHostStunTcpTest, SendDataNoAuth) {
std::vector<char> packet;
CreateRandomPacket(&packet);
- socket_host_->Send(dest_, packet, 0);
+ socket_host_->Send(dest_, packet, net::DSCP_NO_CHANGE, 0);
EXPECT_EQ(0U, sent_data_.size());
}
@@ -335,11 +336,11 @@ TEST_F(P2PSocketHostStunTcpTest, AsyncWrites) {
std::vector<char> packet1;
CreateStunRequest(&packet1);
- socket_host_->Send(dest_, packet1, 0);
+ socket_host_->Send(dest_, packet1, net::DSCP_NO_CHANGE,0);
std::vector<char> packet2;
CreateStunResponse(&packet2);
- socket_host_->Send(dest_, packet2, 0);
+ socket_host_->Send(dest_, packet2, net::DSCP_NO_CHANGE, 0);
message_loop.RunUntilIdle();
diff --git a/content/browser/renderer_host/p2p/socket_host_udp.cc b/content/browser/renderer_host/p2p/socket_host_udp.cc
index 41891bb..3fa8cb6 100644
--- a/content/browser/renderer_host/p2p/socket_host_udp.cc
+++ b/content/browser/renderer_host/p2p/socket_host_udp.cc
@@ -44,10 +44,14 @@ bool IsTransientError(int error) {
namespace content {
P2PSocketHostUdp::PendingPacket::PendingPacket(
- const net::IPEndPoint& to, const std::vector<char>& content, uint64 id)
+ const net::IPEndPoint& to,
+ const std::vector<char>& content,
+ net::DiffServCodePoint dscp_,
+ uint64 id)
: to(to),
data(new net::IOBuffer(content.size())),
size(content.size()),
+ dscp(dscp_),
id(id) {
memcpy(data->data(), &content[0], size);
}
@@ -61,6 +65,7 @@ P2PSocketHostUdp::P2PSocketHostUdp(IPC::Sender* message_sender,
: P2PSocketHost(message_sender, id),
socket_(new net::UDPServerSocket(NULL, net::NetLog::Source())),
send_pending_(false),
+ last_dscp_(net::DSCP_CS0),
throttler_(throttler) {
}
@@ -161,6 +166,7 @@ void P2PSocketHostUdp::HandleReadResult(int result) {
void P2PSocketHostUdp::Send(const net::IPEndPoint& to,
const std::vector<char>& data,
+ net::DiffServCodePoint dscp,
uint64 packet_id) {
if (!socket_) {
// The Send message may be sent after the an OnError message was
@@ -186,9 +192,9 @@ void P2PSocketHostUdp::Send(const net::IPEndPoint& to,
}
if (send_pending_) {
- send_queue_.push_back(PendingPacket(to, data, packet_id));
+ send_queue_.push_back(PendingPacket(to, data, dscp, packet_id));
} else {
- PendingPacket packet(to, data, packet_id);
+ PendingPacket packet(to, data, dscp, packet_id);
DoSend(packet);
}
}
@@ -196,6 +202,17 @@ void P2PSocketHostUdp::Send(const net::IPEndPoint& to,
void P2PSocketHostUdp::DoSend(const PendingPacket& packet) {
TRACE_EVENT_ASYNC_STEP1("p2p", "Send", packet.id, "UdpAsyncSendTo",
"size", packet.size);
+ if (last_dscp_ != packet.dscp && last_dscp_ != net::DSCP_NO_CHANGE) {
+ int result = socket_->SetDiffServCodePoint(packet.dscp);
+ if (result == net::OK) {
+ last_dscp_ = packet.dscp;
+ } else if (!IsTransientError(result) && last_dscp_ != net::DSCP_CS0) {
+ // We receieved a non-transient error, and it seems we have
+ // not changed the DSCP in the past, disable DSCP as it unlikely
+ // to work in the future.
+ last_dscp_ = net::DSCP_NO_CHANGE;
+ }
+ }
int result = socket_->SendTo(
packet.data.get(),
packet.size,
diff --git a/content/browser/renderer_host/p2p/socket_host_udp.h b/content/browser/renderer_host/p2p/socket_host_udp.h
index b72a5c6..ad0e354 100644
--- a/content/browser/renderer_host/p2p/socket_host_udp.h
+++ b/content/browser/renderer_host/p2p/socket_host_udp.h
@@ -34,6 +34,7 @@ class CONTENT_EXPORT P2PSocketHostUdp : public P2PSocketHost {
const net::IPEndPoint& remote_address) OVERRIDE;
virtual void Send(const net::IPEndPoint& to,
const std::vector<char>& data,
+ net::DiffServCodePoint dscp,
uint64 packet_id) OVERRIDE;
virtual P2PSocketHost* AcceptIncomingTcpConnection(
const net::IPEndPoint& remote_address, int id) OVERRIDE;
@@ -46,11 +47,13 @@ class CONTENT_EXPORT P2PSocketHostUdp : public P2PSocketHost {
struct PendingPacket {
PendingPacket(const net::IPEndPoint& to,
const std::vector<char>& content,
+ net::DiffServCodePoint dscp,
uint64 id);
~PendingPacket();
net::IPEndPoint to;
scoped_refptr<net::IOBuffer> data;
int size;
+ net::DiffServCodePoint dscp;
uint64 id;
};
@@ -70,6 +73,7 @@ class CONTENT_EXPORT P2PSocketHostUdp : public P2PSocketHost {
std::deque<PendingPacket> send_queue_;
bool send_pending_;
+ net::DiffServCodePoint last_dscp_;
// Set of peer for which we have received STUN binding request or
// response or relay allocation request or response.
diff --git a/content/browser/renderer_host/p2p/socket_host_udp_unittest.cc b/content/browser/renderer_host/p2p/socket_host_udp_unittest.cc
index 1b85b40..5657f47 100644
--- a/content/browser/renderer_host/p2p/socket_host_udp_unittest.cc
+++ b/content/browser/renderer_host/p2p/socket_host_udp_unittest.cc
@@ -150,6 +150,11 @@ class FakeDatagramServerSocket : public net::DatagramServerSocket {
return net::ERR_NOT_IMPLEMENTED;
}
+ virtual int SetDiffServCodePoint(net::DiffServCodePoint dscp) OVERRIDE {
+ NOTIMPLEMENTED();
+ return net::ERR_NOT_IMPLEMENTED;
+ }
+
private:
net::IPEndPoint address_;
std::deque<UDPPacket>* sent_packets_;
@@ -209,15 +214,15 @@ TEST_F(P2PSocketHostUdpTest, SendStunNoAuth) {
std::vector<char> packet1;
CreateStunRequest(&packet1);
- socket_host_->Send(dest1_, packet1, 0);
+ socket_host_->Send(dest1_, packet1, net::DSCP_NO_CHANGE, 0);
std::vector<char> packet2;
CreateStunResponse(&packet2);
- socket_host_->Send(dest1_, packet2, 0);
+ socket_host_->Send(dest1_, packet2, net::DSCP_NO_CHANGE, 0);
std::vector<char> packet3;
CreateStunError(&packet3);
- socket_host_->Send(dest1_, packet3, 0);
+ socket_host_->Send(dest1_, packet3, net::DSCP_NO_CHANGE, 0);
ASSERT_EQ(sent_packets_.size(), 3U);
ASSERT_EQ(sent_packets_[0].second, packet1);
@@ -234,7 +239,7 @@ TEST_F(P2PSocketHostUdpTest, SendDataNoAuth) {
std::vector<char> packet;
CreateRandomPacket(&packet);
- socket_host_->Send(dest1_, packet, 0);
+ socket_host_->Send(dest1_, packet, net::DSCP_NO_CHANGE, 0);
ASSERT_EQ(sent_packets_.size(), 0U);
}
@@ -256,7 +261,7 @@ TEST_F(P2PSocketHostUdpTest, SendAfterStunRequest) {
.WillOnce(DoAll(DeleteArg<0>(), Return(true)));
std::vector<char> packet;
CreateRandomPacket(&packet);
- socket_host_->Send(dest1_, packet, 0);
+ socket_host_->Send(dest1_, packet, net::DSCP_NO_CHANGE, 0);
ASSERT_EQ(1U, sent_packets_.size());
ASSERT_EQ(dest1_, sent_packets_[0].first);
@@ -279,7 +284,7 @@ TEST_F(P2PSocketHostUdpTest, SendAfterStunResponse) {
.WillOnce(DoAll(DeleteArg<0>(), Return(true)));
std::vector<char> packet;
CreateRandomPacket(&packet);
- socket_host_->Send(dest1_, packet, 0);
+ socket_host_->Send(dest1_, packet, net::DSCP_NO_CHANGE, 0);
ASSERT_EQ(1U, sent_packets_.size());
ASSERT_EQ(dest1_, sent_packets_[0].first);
@@ -302,7 +307,7 @@ TEST_F(P2PSocketHostUdpTest, SendAfterStunResponseDifferentHost) {
EXPECT_CALL(sender_, Send(
MatchMessage(static_cast<uint32>(P2PMsg_OnError::ID))))
.WillOnce(DoAll(DeleteArg<0>(), Return(true)));
- socket_host_->Send(dest2_, packet, 0);
+ socket_host_->Send(dest2_, packet, net::DSCP_NO_CHANGE, 0);
}
// Verify throttler not allowing unlimited sending of ICE messages to
@@ -316,12 +321,12 @@ TEST_F(P2PSocketHostUdpTest, ThrottleAfterLimit) {
std::vector<char> packet1;
CreateStunRequest(&packet1);
throttler_.SetSendIceBandwidth(packet1.size() * 2);
- socket_host_->Send(dest1_, packet1, 0);
- socket_host_->Send(dest2_, packet1, 0);
+ socket_host_->Send(dest1_, packet1, net::DSCP_NO_CHANGE, 0);
+ socket_host_->Send(dest2_, packet1, net::DSCP_NO_CHANGE, 0);
net::IPEndPoint dest3 = ParseAddress(kTestIpAddress1, 2222);
// This packet must be dropped by the throttler.
- socket_host_->Send(dest3, packet1, 0);
+ socket_host_->Send(dest3, packet1, net::DSCP_NO_CHANGE, 0);
ASSERT_EQ(sent_packets_.size(), 2U);
}
@@ -345,21 +350,21 @@ TEST_F(P2PSocketHostUdpTest, ThrottleAfterLimitAfterReceive) {
CreateStunRequest(&packet1);
throttler_.SetSendIceBandwidth(packet1.size());
// |dest1_| is known address, throttling will not be applied.
- socket_host_->Send(dest1_, packet1, 0);
+ socket_host_->Send(dest1_, packet1, net::DSCP_NO_CHANGE, 0);
// Trying to send the packet to dest1_ in the same window. It should go.
- socket_host_->Send(dest1_, packet1, 0);
+ socket_host_->Send(dest1_, packet1, net::DSCP_NO_CHANGE, 0);
// Throttler should allow this packet to go through.
- socket_host_->Send(dest2_, packet1, 0);
+ socket_host_->Send(dest2_, packet1, net::DSCP_NO_CHANGE, 0);
net::IPEndPoint dest3 = ParseAddress(kTestIpAddress1, 2223);
// This packet will be dropped, as limit only for a single packet.
- socket_host_->Send(dest3, packet1, 0);
+ socket_host_->Send(dest3, packet1, net::DSCP_NO_CHANGE, 0);
net::IPEndPoint dest4 = ParseAddress(kTestIpAddress1, 2224);
// This packet should also be dropped.
- socket_host_->Send(dest4, packet1, 0);
+ socket_host_->Send(dest4, packet1, net::DSCP_NO_CHANGE, 0);
// |dest1| is known, we can send as many packets to it.
- socket_host_->Send(dest1_, packet1, 0);
+ socket_host_->Send(dest1_, packet1, net::DSCP_NO_CHANGE, 0);
ASSERT_EQ(sent_packets_.size(), 4U);
}
diff --git a/content/common/p2p_messages.h b/content/common/p2p_messages.h
index 4ddc953..2e91ff4 100644
--- a/content/common/p2p_messages.h
+++ b/content/common/p2p_messages.h
@@ -16,6 +16,7 @@
#define IPC_MESSAGE_START P2PMsgStart
IPC_ENUM_TRAITS(content::P2PSocketType)
+IPC_ENUM_TRAITS(net::DiffServCodePoint)
IPC_STRUCT_TRAITS_BEGIN(net::NetworkInterface)
IPC_STRUCT_TRAITS_MEMBER(name)
@@ -73,10 +74,11 @@ IPC_MESSAGE_CONTROL3(P2PHostMsg_AcceptIncomingTcpConnection,
int /* connected_socket_id */)
// TODO(sergeyu): Use shared memory to pass the data.
-IPC_MESSAGE_CONTROL4(P2PHostMsg_Send,
+IPC_MESSAGE_CONTROL5(P2PHostMsg_Send,
int /* socket_id */,
net::IPEndPoint /* socket_address */,
std::vector<char> /* data */,
+ net::DiffServCodePoint /* dscp */,
uint64 /* packet_id */)
IPC_MESSAGE_CONTROL1(P2PHostMsg_DestroySocket,
diff --git a/content/renderer/p2p/socket_client.cc b/content/renderer/p2p/socket_client.cc
index 57e0339..6404941 100644
--- a/content/renderer/p2p/socket_client.cc
+++ b/content/renderer/p2p/socket_client.cc
@@ -63,8 +63,10 @@ void P2PSocketClient::DoInit(P2PSocketType type,
type, socket_id_, local_address, remote_address));
}
-void P2PSocketClient::Send(const net::IPEndPoint& address,
- const std::vector<char>& data) {
+void P2PSocketClient::SendWithDscp(
+ const net::IPEndPoint& address,
+ const std::vector<char>& data,
+ net::DiffServCodePoint dscp) {
if (!ipc_message_loop_->BelongsToCurrentThread()) {
ipc_message_loop_->PostTask(
FROM_HERE, base::Bind(&P2PSocketClient::Send, this, address, data));
@@ -77,10 +79,15 @@ void P2PSocketClient::Send(const net::IPEndPoint& address,
uint64 unique_id = GetUniqueId(random_socket_id_, ++next_packet_id_);
TRACE_EVENT_ASYNC_BEGIN0("p2p", "Send", unique_id);
dispatcher_->SendP2PMessage(new P2PHostMsg_Send(socket_id_, address, data,
- unique_id));
+ dscp, unique_id));
}
}
+void P2PSocketClient::Send(const net::IPEndPoint& address,
+ const std::vector<char>& data) {
+ SendWithDscp(address, data, net::DSCP_DEFAULT);
+}
+
void P2PSocketClient::Close() {
DCHECK(delegate_message_loop_->BelongsToCurrentThread());
diff --git a/content/renderer/p2p/socket_client.h b/content/renderer/p2p/socket_client.h
index fbdca27..e15d813 100644
--- a/content/renderer/p2p/socket_client.h
+++ b/content/renderer/p2p/socket_client.h
@@ -55,6 +55,12 @@ class P2PSocketClient : public base::RefCountedThreadSafe<P2PSocketClient> {
// Send the |data| to the |address|.
void Send(const net::IPEndPoint& address, const std::vector<char>& data);
+ // Send the |data| to the |address| using Differentiated Services Code Point
+ // |dscp|.
+ void SendWithDscp(const net::IPEndPoint& address,
+ const std::vector<char>& data,
+ net::DiffServCodePoint dscp);
+
// Must be called before the socket is destroyed. The delegate may
// not be called after |closed_task| is executed.
void Close();
diff --git a/net/base/net_util.h b/net/base/net_util.h
index d137fe5..5735111 100644
--- a/net/base/net_util.h
+++ b/net/base/net_util.h
@@ -561,6 +561,34 @@ unsigned CommonPrefixLength(const IPAddressNumber& a1,
// Computes the number of leading 1-bits in |mask|.
unsigned MaskPrefixLength(const IPAddressNumber& mask);
+// Differentiated Services Code Point.
+// See http://tools.ietf.org/html/rfc2474 for details.
+enum DiffServCodePoint {
+ DSCP_NO_CHANGE = -1,
+ DSCP_DEFAULT = 0, // Same as DSCP_CS0
+ DSCP_CS0 = 0, // The default
+ DSCP_CS1 = 8, // Bulk/background traffic
+ DSCP_AF11 = 10,
+ DSCP_AF12 = 12,
+ DSCP_AF13 = 14,
+ DSCP_CS2 = 16,
+ DSCP_AF21 = 18,
+ DSCP_AF22 = 20,
+ DSCP_AF23 = 22,
+ DSCP_CS3 = 24,
+ DSCP_AF31 = 26,
+ DSCP_AF32 = 28,
+ DSCP_AF33 = 30,
+ DSCP_CS4 = 32,
+ DSCP_AF41 = 34, // Video
+ DSCP_AF42 = 36, // Video
+ DSCP_AF43 = 38, // Video
+ DSCP_CS5 = 40, // Video
+ DSCP_EF = 46, // Voice
+ DSCP_CS6 = 48, // Voice
+ DSCP_CS7 = 56, // Control messages
+};
+
} // namespace net
#endif // NET_BASE_NET_UTIL_H_
diff --git a/net/dns/mock_mdns_socket_factory.h b/net/dns/mock_mdns_socket_factory.h
index f60b08c5..af54e32 100644
--- a/net/dns/mock_mdns_socket_factory.h
+++ b/net/dns/mock_mdns_socket_factory.h
@@ -57,6 +57,8 @@ class MockMDnsDatagramServerSocket : public DatagramServerSocket {
MOCK_METHOD1(SetMulticastLoopbackMode, int(bool loopback));
+ MOCK_METHOD1(SetDiffServCodePoint, int(DiffServCodePoint dscp));
+
void SetResponsePacket(std::string response_packet);
int HandleRecvNow(IOBuffer* buffer, int size, IPEndPoint* address,
diff --git a/net/udp/datagram_server_socket.h b/net/udp/datagram_server_socket.h
index f2016c0..0561d8a 100644
--- a/net/udp/datagram_server_socket.h
+++ b/net/udp/datagram_server_socket.h
@@ -93,6 +93,10 @@ class NET_EXPORT DatagramServerSocket : public DatagramSocket {
// Should be called before Bind().
// Returns a network error code.
virtual int SetMulticastLoopbackMode(bool loopback) = 0;
+
+ // Set the Differentiated Services Code Point. May do nothing on
+ // some platforms. Returns a network error code.
+ virtual int SetDiffServCodePoint(DiffServCodePoint dscp) = 0;
};
} // namespace net
diff --git a/net/udp/udp_server_socket.cc b/net/udp/udp_server_socket.cc
index 16e4061..79086f8 100644
--- a/net/udp/udp_server_socket.cc
+++ b/net/udp/udp_server_socket.cc
@@ -85,4 +85,8 @@ int UDPServerSocket::SetMulticastLoopbackMode(bool loopback) {
return socket_.SetMulticastLoopbackMode(loopback);
}
+int UDPServerSocket::SetDiffServCodePoint(DiffServCodePoint dscp) {
+ return socket_.SetDiffServCodePoint(dscp);
+}
+
} // namespace net
diff --git a/net/udp/udp_server_socket.h b/net/udp/udp_server_socket.h
index cc475f4..6586f7e 100644
--- a/net/udp/udp_server_socket.h
+++ b/net/udp/udp_server_socket.h
@@ -44,6 +44,7 @@ class NET_EXPORT UDPServerSocket : public DatagramServerSocket {
virtual int LeaveGroup(const IPAddressNumber& group_address) const OVERRIDE;
virtual int SetMulticastTimeToLive(int time_to_live) OVERRIDE;
virtual int SetMulticastLoopbackMode(bool loopback) OVERRIDE;
+ virtual int SetDiffServCodePoint(DiffServCodePoint dscp) OVERRIDE;
private:
UDPSocket socket_;
diff --git a/net/udp/udp_socket_libevent.cc b/net/udp/udp_socket_libevent.cc
index 5ed52f5..990aa57 100644
--- a/net/udp/udp_socket_libevent.cc
+++ b/net/udp/udp_socket_libevent.cc
@@ -652,4 +652,24 @@ int UDPSocketLibevent::SetMulticastLoopbackMode(bool loopback) {
socket_options_ &= ~SOCKET_OPTION_MULTICAST_LOOP;
return OK;
}
+
+int UDPSocketLibevent::SetDiffServCodePoint(DiffServCodePoint dscp) {
+ if (dscp == DSCP_NO_CHANGE) {
+ return OK;
+ }
+ int rv;
+ int dscp_and_ecn = dscp << 2;
+ if (addr_family_ == AF_INET) {
+ rv = setsockopt(socket_, IPPROTO_IP, IP_TOS,
+ &dscp_and_ecn, sizeof(dscp_and_ecn));
+ } else {
+ rv = setsockopt(socket_, IPPROTO_IPV6, IPV6_TCLASS,
+ &dscp_and_ecn, sizeof(dscp_and_ecn));
+ }
+ if (rv < 0)
+ return MapSystemError(errno);
+
+ return OK;
+}
+
} // namespace net
diff --git a/net/udp/udp_socket_libevent.h b/net/udp/udp_socket_libevent.h
index 6c8bf61e0..6e737de 100644
--- a/net/udp/udp_socket_libevent.h
+++ b/net/udp/udp_socket_libevent.h
@@ -152,6 +152,11 @@ class NET_EXPORT UDPSocketLibevent : public base::NonThreadSafe {
// other applications on the same host. See MSDN: http://goo.gl/6vqbj
int SetMulticastLoopbackMode(bool loopback);
+ // Set the differentiated services flags on outgoing packets. May not
+ // do anything on some platforms.
+ // Return a network error code.
+ int SetDiffServCodePoint(DiffServCodePoint dscp);
+
private:
enum SocketOptions {
SOCKET_OPTION_REUSE_ADDRESS = 1 << 0,
diff --git a/net/udp/udp_socket_win.cc b/net/udp/udp_socket_win.cc
index f9ce679..c9f30a7 100644
--- a/net/udp/udp_socket_win.cc
+++ b/net/udp/udp_socket_win.cc
@@ -753,4 +753,10 @@ int UDPSocketWin::SetMulticastLoopbackMode(bool loopback) {
return OK;
}
+// TODO(hubbe): Implement differentiated services for windows.
+// Note: setsockopt(IP_TOS) does not work on windows XP and later.
+int UDPSocketWin::SetDiffServCodePoint(DiffServCodePoint dscp) {
+ return ERR_NOT_IMPLEMENTED;
+}
+
} // namespace net
diff --git a/net/udp/udp_socket_win.h b/net/udp/udp_socket_win.h
index 807b403..142c692 100644
--- a/net/udp/udp_socket_win.h
+++ b/net/udp/udp_socket_win.h
@@ -151,6 +151,10 @@ class NET_EXPORT UDPSocketWin : NON_EXPORTED_BASE(public base::NonThreadSafe) {
// other applications on the same host. See MSDN: http://goo.gl/6vqbj
int SetMulticastLoopbackMode(bool loopback);
+ // Set the differentiated services flags on outgoing packets. May not
+ // do anything on some platforms.
+ int SetDiffServCodePoint(DiffServCodePoint dscp);
+
private:
enum SocketOptions {
SOCKET_OPTION_REUSE_ADDRESS = 1 << 0,